comparison README.md @ 32:e947bfd3db1a

Add images to readme
author Dennis C. M. <dennis@denniscm.com>
date Wed, 20 Nov 2024 08:53:39 +0000
parents 58692905e183
children bd0ec5cb2300
comparison
equal deleted inserted replaced
31:58692905e183 32:e947bfd3db1a
1 # bitcaviar-plus
1 2
2 # bitcaviar-plus 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 ```
3 89
4 ## Attribution 90 ## Attribution
5 91
6 - [blockchain-parser](https://github.com/ragestack/blockchain-parser/blob/master/blockchain-parser.py) 92 - [blockchain-parser](https://github.com/ragestack/blockchain-parser/blob/master/blockchain-parser.py)
7 - [bitcoinbook](https://github.com/bitcoinbook/bitcoinbook) 93 - [bitcoinbook](https://github.com/bitcoinbook/bitcoinbook)