Bitcoin Forum
December 18, 2017, 08:17:08 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: opening the database with Perl  (Read 1071 times)
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 01, 2012, 09:51:44 AM
 #1


I can see in the bitcointools 's python code that database are DB_BTREE, so I tried:

Code:
use DB_File;
my $db = tie my %h, 'DB_File', ".bitcoin/blockindex.dat", O_RDONLY, 0644, $DB_BTREE;
END { undef $db, untie %h if defined $db }

printf "%s: %d\n", $_, length($_) for keys %h;

but this gives me only one line:

main: 4

What am I missing?  I can understand the the data is a bit serialized or something but I had expexted to have at least a bigger entry.

1513585028
Hero Member
*
Offline Offline

Posts: 1513585028

View Profile Personal Message (Offline)

Ignore
1513585028
Reply with quote  #2

1513585028
Report to moderator
1513585028
Hero Member
*
Offline Offline

Posts: 1513585028

View Profile Personal Message (Offline)

Ignore
1513585028
Reply with quote  #2

1513585028
Report to moderator
1513585028
Hero Member
*
Offline Offline

Posts: 1513585028

View Profile Personal Message (Offline)

Ignore
1513585028
Reply with quote  #2

1513585028
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1513585028
Hero Member
*
Offline Offline

Posts: 1513585028

View Profile Personal Message (Offline)

Ignore
1513585028
Reply with quote  #2

1513585028
Report to moderator
2112
Legendary
*
Offline Offline

Activity: 1988



View Profile
January 01, 2012, 10:58:25 AM
 #2

main: 4
What am I missing?
All Berkeley DB database files in Satoshi client are "multiple database capable". In effect they are B-trees of B-trees, where top-level B-tree contains only one node with key "main".

I don't know how to get to the 2nd-level B-tree in Perl. Probably it is documented somewhere.

Please comment, critique, criticize or ridicule BIP 2112: https://bitcointalk.org/index.php?topic=54382.0
Long-term mining prognosis: https://bitcointalk.org/index.php?topic=91101.0
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 02, 2012, 10:39:12 AM
 #3

I finally managed to open the database using the BerkeleyDB module instead of DB_File.

In short:

Code:
tie my %blkindex, 'BerkeleyDB::Btree',
-Filename => 'blkindex.dat',
-Subname => 'main',

I still have to figure out the equivalent of the 'cursor.set_range("\x0ablockindex")' in Gavin's bitcointools, though.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!