comparison README.md @ 14:feae0cd7fea1

refactor code
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Tue, 26 Oct 2021 10:04:04 +0200
parents 4bbe48c95079
children 25b0a9a206c4
comparison
equal deleted inserted replaced
13:4bbe48c95079 14:feae0cd7fea1
27 27
28 def parse_entire_blockchain(): 28 def parse_entire_blockchain():
29 file_counter = -1 29 file_counter = -1
30 while True: 30 while True:
31 file_counter += 1 31 file_counter += 1
32 file_name = '/Users/dennis/Bitcoin/blocks/blk{}.dat'.format(str(file_counter).zfill(5)) 32 file_name = 'path/to/file/blk{}.dat'.format(str(file_counter).zfill(5))
33 with open(file_name, 'rb') as f: 33 with open(file_name, 'rb') as f:
34 file_size = os.path.getsize(file_name) 34 file_size = os.path.getsize(file_name)
35 while f.tell() < file_size: 35 while f.tell() < file_size:
36 block = deserialize_block(f) 36 block = deserialize_block(f)
37 ``` 37 ```
38 38
39 ### Example output 39 ### Example output
40 ```json 40 ```json
41 { 41 {
42 "magic_number": "f9beb4d9", 42 "magic_number":"f9beb4d9",
43 "size": "0000011d", 43 "size":"0000011d",
44 "id": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", 44 "id":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
45 "transaction_count": "01", 45 "transaction_count":"01",
46 "header": 46 "header":{
47 "version":"00000001",
48 "previous_block_id":"0000000000000000000000000000000000000000000000000000000000000000",
49 "merkle_root":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
50 "time":"495fab29",
51 "bits":"1d00ffff",
52 "nonce":"7c2bac1d"
53 },
54 "transactions":[
47 { 55 {
48 "version": "00000001", 56 "version":"00000001",
49 "previous_block_id": "0000000000000000000000000000000000000000000000000000000000000000", 57 "input_count":"01",
50 "merkle_root": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", 58 "output_count":"01",
51 "time": "495fab29", 59 "lock_time":"00000000",
52 "bits": "1d00ffff", 60 "id":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
53 "nonce": "7c2bac1d" 61 "inputs":[
54 },
55 "transactions":
56 [
57 { 62 {
58 "version": "00000001", 63 "id":"0000000000000000000000000000000000000000000000000000000000000000",
59 "input_count": "01", 64 "vout":"ffffffff",
60 "output_count": "01", 65 "script_sig_size":"4d",
61 "lock_time": "00000000", 66 "script_sig":"04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73",
62 "id": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", 67 "sequence":"ffffffff"
63 "inputs":
64 [
65 {
66 "id": "0000000000000000000000000000000000000000000000000000000000000000",
67 "vout": "ffffffff",
68 "script_sig_size": "4d",
69 "script_sig": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73",
70 "sequence": "ffffffff"
71 }
72 ],
73 "outputs":
74 [
75 {
76 "value": "000000012a05f200",
77 "script_pub_key_size": "43",
78 "script_pub_key": "4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"
79 }
80 ]
81 } 68 }
82 ] 69 ],
70 "outputs":[
71 {
72 "value":"000000012a05f200",
73 "script_pub_key_size":"43",
74 "script_pub_key":"4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"
75 }
76 ]
77 }
78 ]
83 } 79 }
84 ``` 80 ```
85 81
86 ## Attribution 82 ## Attribution
87 - [blockchain-parser](https://github.com/ragestack/blockchain-parser/blob/master/blockchain-parser.py) 83 - [blockchain-parser](https://github.com/ragestack/blockchain-parser/blob/master/blockchain-parser.py)