changeset 24:139c77ea99b7

add plyvel
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Sun, 14 Nov 2021 17:36:43 +0100
parents 32061555853c
children c75ee64c812c
files requirements.txt tests/implementation_testing.py
diffstat 2 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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()