Skip to content

Commit a0e9a89

Browse files
committed
more documentation
1 parent a1f5b27 commit a0e9a89

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/main/java/prof7bit/bitcoin/wallettool/fileformats/WalletDatHandler.xtend

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,39 +441,71 @@ class BerkeleyDBLeafPage extends BerkeleyDBPage {
441441

442442
/**
443443
* Right after the header of a b-tree leaf page there is a
444-
* table with 16bit words, each data item has an entry in this
444+
* table with 16bit words, each item has an entry in this
445445
* table. They are the offsets of the actual data (relative to
446-
* the start of the page). Given a page buffer of a b-tree
447-
* page and an item index this function will look up the table
448-
* and return the offset (relative to page start) of this item.
446+
* the start of the page). Given an item index this function
447+
* will look up the table and return the offset (relative to
448+
* page start) of this item. Each row of data (key + value)
449+
* is actually made up of 2 consecutive items, the key and
450+
* the value. This method does not need to care whether its
451+
* a key or a value, it just takes an index and returns the
452+
* offset where to find the data.
449453
*/
450454
private def getItemOffset(int index) {
451455
val lookup_table_offs = SIZE_LEAF_HEADER + 2 * index
452456
b.getShort(lookup_table_offs).bitwiseAnd(0xffff)
453457
}
454458

459+
/**
460+
* read bytes from the specified offset and copy them
461+
* into a new ByteBuffer. The returned ByteBuffer will
462+
* be configured for little endian reading.
463+
*/
455464
private def getBytes(int offset, int size){
456465
val a = newByteArrayOfSize(size)
457466
b.position(offset)
458467
b.get(a)
459468
ByteBuffer.wrap(a).order(ByteOrder.LITTLE_ENDIAN)
460469
}
461470

471+
/**
472+
* get the type of the item with the index,
473+
* FIXME: see db_page.h for type constants
474+
*/
462475
def getItemType(int index){
463476
val offset = getItemOffset(index)
464477
b.get(offset + 2)
465478
}
466479

480+
/**
481+
* get the item data at the index, return it in
482+
* a newly allocated ByteBuffer. The Buffer will
483+
* be configured as little endian. "Item" can be
484+
* either a key or a value, its up to higher
485+
* levels to know what it actually is, as far as
486+
* this method is concerned its just a bunch of
487+
* bytes addressed by an index number.
488+
*/
467489
def getItemData(int index){
468490
val offset = getItemOffset(index)
469491
val size = b.getShort(offset).bitwiseAnd(0xffff)
470492
getBytes(offset + 3, size)
471493
}
472494

495+
/**
496+
* page number of next leaf page in this tree
497+
* or 0 if this is the last leaf page.
498+
*/
473499
def getNextLeafPage() throws IOException {
474500
new BerkeleyDBLeafPage(raf, nextPgno, pgsize)
475501
}
476502

503+
/**
504+
* Get count of items on this page. This is twice
505+
* the number of key/value pairs because key and
506+
* value are separate items. They are stored in
507+
* alternating sequence: {k1, v1, k2, v2, .., kn, vn}
508+
*/
477509
def getEntryCount() {
478510
b.getShort(20)
479511
}

0 commit comments

Comments
 (0)