Mercurial > public > bitcaviar-plus
annotate README.md @ 33:ce76ca96d80f
update tags
author | convert-repo |
---|---|
date | Tue, 03 Jun 2025 13:20:40 +0000 |
parents | e947bfd3db1a |
children | bd0ec5cb2300 |
rev | line source |
---|---|
32 | 1 # bitcaviar-plus |
17 | 2 |
32 | 3 I want to learn more about the technology behind Bitcoin, so what better way to do so than by making a project? |
4 | |
5 Here is a Bitcoin parser written in Python that I made. It was a very nice learning experience. | |
6 | |
7 ## Installation | |
8 ```bash | |
9 python setup.py install | |
10 ``` | |
11 | |
12 ## Usage | |
13 | |
14 To deserialize the genesis block: | |
15 | |
16 ```python | |
17 from bitcaviar_plus.block import deserialize_block | |
18 | |
19 | |
20 def parse_genesis_block(): | |
21 with open('path/to/file/blk00000.dat', 'rb') as f: | |
22 block = deserialize_block(f) | |
23 print(block) | |
24 To deserialize the entire blockchain: | |
25 | |
26 import os | |
27 from bitcaviar_plus.block import deserialize_block | |
28 from bitcaviar_plus.errors import InvalidMagicBytes | |
29 | |
30 | |
31 def parse_entire_blockchain(): | |
32 file_counter = -1 | |
33 while True: | |
34 file_counter += 1 | |
35 file_name = 'path/to/file/blk{}.dat'.format(str(file_counter).zfill(5)) | |
36 with open(file_name, 'rb') as f: | |
37 file_size = os.path.getsize(file_name) | |
38 while f.tell() < file_size: | |
39 try: | |
40 block = deserialize_block(f) | |
41 except InvalidMagicBytes as e: | |
42 print(e) | |
43 | |
44 ``` | |
45 | |
46 This is the output: | |
47 | |
48 ```json | |
49 { | |
50 "magic_number": "f9beb4d9", | |
51 "size": "0000011d", | |
52 "id": "000000000019d6...", | |
53 "transaction_count": "01", | |
54 "header": { | |
55 "version": "00000001", | |
56 "previous_block_id": "00000000000000...", | |
57 "merkle_root": "4a5e1e4baab89f3a32...", | |
58 "time": "495fab29", | |
59 "bits": "1d00ffff", | |
60 "nonce": "7c2bac1d" | |
61 }, | |
62 "transactions": [ | |
63 { | |
64 "version": "00000001", | |
65 "input_count": "01", | |
66 "output_count": "01", | |
67 "lock_time": "00000000", | |
68 "id": "4a5e1e4baab89f3a32518a8...", | |
69 "inputs": [ | |
70 { | |
71 "id": "0000000000000000000000...", | |
72 "vout": "ffffffff", | |
73 "script_sig_size": "4d", | |
74 "script_sig": "04ffff001d01044554686520546...", | |
75 "sequence": "ffffffff" | |
76 } | |
77 ], | |
78 "outputs": [ | |
79 { | |
80 "value": "000000012a05f200", | |
81 "script_pub_key_size": "43", | |
82 "script_pub_key": "4104678afdb0fe55482719..." | |
83 } | |
84 ] | |
85 } | |
86 ] | |
87 } | |
88 ``` | |
13
4bbe48c95079
add instructions
Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
parents:
4
diff
changeset
|
89 |
30 | 90 ## Attribution |
28
30535f42d0ff
refactor code
Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
parents:
21
diff
changeset
|
91 |
30 | 92 - [blockchain-parser](https://github.com/ragestack/blockchain-parser/blob/master/blockchain-parser.py) |
93 - [bitcoinbook](https://github.com/bitcoinbook/bitcoinbook) | |
94 - [learnmeabitcoin.com](https://learnmeabitcoin.com/) | |
13
4bbe48c95079
add instructions
Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
parents:
4
diff
changeset
|
95 |