# HG changeset patch # User Dennis Concepcion Martin # Date 1636907803 -3600 # Node ID 139c77ea99b7a4ac14d7330de484e336ed4e9acd # Parent 32061555853ceee19d9eb8b82cff0eca50ae183b add plyvel diff -r 32061555853c -r 139c77ea99b7 requirements.txt --- a/requirements.txt Sun Nov 14 17:35:18 2021 +0100 +++ b/requirements.txt Sun Nov 14 17:36:43 2021 +0100 @@ -1,1 +1,2 @@ -testfixtures~=6.18.3 \ No newline at end of file +testfixtures~=6.18.3 +plyvel~=1.3.0 \ No newline at end of file diff -r 32061555853c -r 139c77ea99b7 tests/implementation_testing.py --- a/tests/implementation_testing.py Sun Nov 14 17:35:18 2021 +0100 +++ b/tests/implementation_testing.py Sun Nov 14 17:36:43 2021 +0100 @@ -1,13 +1,13 @@ import os +import plyvel +import tempfile from bitcaviar_plus.block import deserialize_block +from bitcaviar_plus.block import __deserialize_header from bitcaviar_plus.errors import InvalidMagicBytes -import plyvel -# noinspection PyUnresolvedReferences def parse_genesis_block(): blk_path = '/bitcoin-node/.bitcoin/blocks/blk00355.dat' - db = plyvel.DB('/bitcoin-node/.bitcoin/blocks/index/', create_if_missing=False) with open(blk_path, 'rb') as f: file_size = os.path.getsize(blk_path) @@ -18,5 +18,29 @@ print(e) +# noinspection PyUnresolvedReferences +def iterate_leveldb_keys(): + db = plyvel.DB('/bitcoin-node/.bitcoin/blocks/index/', create_if_missing=False) + for key, value in db: + print('---- RAW KEY ----') + print(key.hex()) + print('---- LITTLE ENDIAN KEY ----') + print(key[::-1].hex()) + print('---- RAW VALUE ----') + print(value[::-1].hex()) + exit() + + +# noinspection PyUnresolvedReferences +def search_block(): + db = plyvel.DB('/bitcoin-node/.bitcoin/blocks/index/', create_if_missing=False) + search_type = bytes.fromhex('62') # 'b' (block) in hex is 62 + block_hash = bytes.fromhex('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')[::-1] + key = search_type + block_hash + value = db.get(key) + print(value.hex()) + db.close() + + if __name__ == '__main__': - parse_genesis_block() + search_block()