1
1
# tx-trie
2
2
3
- Ethereum Transaction Tries Handler
3
+ Ethereum Transaction Trie / Transaction Receipt Trie Handler
4
+
5
+ _ Legacy, eip 2930, eip 1559, eip 4844 all tested_
4
6
5
7
- [x] Transaction Trie Handler
6
8
- [x] Build Trie with target block number
7
9
- [x] Build Trie with target tx hash
8
10
- [x] Get proof by tx index
9
11
- [x] Verify proof
10
- - [ ] Transaction Receipt Trie Handler
11
- - [ ] Build Trie with target block number
12
- - [ ] Build Trie with target tx hash
13
- - [ ] Get proof by tx index
14
- - [ ] Verify proof
12
+ - [x ] Transaction Receipt Trie Handler
13
+ - [x ] Build Trie with target block number
14
+ - [x ] Build Trie with target tx hash
15
+ - [x ] Get proof by tx index
16
+ - [x ] Verify proof
15
17
16
18
## Install
17
19
@@ -21,7 +23,7 @@ Ethereum Transaction Tries Handler
21
23
22
24
## Example
23
25
24
- ### Build Trie with target tx hash
26
+ ### Build tx Trie with target tx hash
25
27
26
28
``` rust
27
29
let mut mpt_handler = MptHandler :: new (MAINNET_RPC_URL ). await ? ;
@@ -38,22 +40,55 @@ let proof = mpt_handler.get_proof(tx_index)?;
38
40
mpt_handler . verify_proof (tx_index , proof . clone ())? ;
39
41
```
40
42
41
- ### Build Trie with target block number
43
+ ### Build tx Trie with target block number or target tx hash
42
44
43
45
``` rust
44
- let mut mpt_handler = MptHandler :: new (MAINNET_RPC_URL ). await ? ;
45
- let mut mpt_handler = MptHandler :: new (MAINNET_RPC_URL ). await ? ;
46
+ let target_tx_hash = B256 :: from (hex! (
47
+ " 1fcb1196d8a3bff0bcf13309d2d2bb1a23ae1ac13f5674c801be0ff9254d5ab5"
48
+ ));
46
49
47
- mpt_handler
48
- . build_tx_tree_from_block (19487818 )
49
- . await
50
- ? ;
50
+ let mut txs_mpt_handler = TxsMptHandler :: new (MAINNET_RPC_URL ). await ? ;
51
+
52
+ txs_mpt_handler
53
+ . build_tx_tree_from_block (4370000 )
54
+ . await ? ;
55
+
56
+ let tx_index = txs_mpt_handler . tx_hash_to_tx_index (target_tx_hash )? ;
57
+ let proof = txs_mpt_handler . get_proof (tx_index )? ;
58
+ txs_mpt_handler
59
+ . verify_proof (tx_index , proof . clone ())? ;
60
+
61
+ // You can either build with target tx hash. Both root match.
62
+ let mut txs_mpt_handler2 = TxsMptHandler :: new (MAINNET_RPC_URL ). await ? ;
63
+ txs_mpt_handler2
64
+ . build_tx_tree_from_tx_hash (target_tx_hash )
65
+ . await ? ;
66
+
67
+ assert_eq! (
68
+ txs_mpt_handler . get_root (). unwrap (),
69
+ txs_mpt_handler2 . get_root (). unwrap ()
70
+ );
71
+ ```
72
+
73
+ ### Build tx receipts Trie with target block number
74
+
75
+ ``` rust
76
+ // 4844 transaction
51
77
let target_tx_hash = B256 :: from (hex! (
52
- " d1b736880e62738b04a1f277f099784bbdf548157d30d4edc41269553013ef13 "
78
+ " 9c1fbda4f649ac806ab0faefbe94e1a60282eb374ead6aa01bac042f52b28a8c "
53
79
));
54
- let tx_index = mpt_handler . tx_hash_to_tx_index (target_tx_hash )? ;
55
- let proof = mpt_handler . get_proof (tx_index )? ;
56
- mpt_handler . verify_proof (tx_index , proof . clone ())? ;
80
+
81
+ let mut tx_receipts_mpt_handler = TxReceiptsMptHandler :: new (MAINNET_RPC_URL ). await ? ;
82
+ tx_receipts_mpt_handler
83
+ . build_tx_receipts_tree_from_block (19426589 )
84
+ . await ? ;
85
+
86
+ let tx_index = tx_receipts_mpt_handler
87
+ . tx_hash_to_tx_index (target_tx_hash )
88
+ . await ? ;
89
+ let proof = tx_receipts_mpt_handler . get_proof (tx_index )? ;
90
+ tx_receipts_mpt_handler
91
+ . verify_proof (tx_index , proof . clone ())? ;
57
92
```
58
93
59
94
### Dependency
0 commit comments