Skip to content

Commit 5b8d1ec

Browse files
authored
Merge pull request #2 from HerodotusDev/receipt-trie
receipt trie support
2 parents e80c393 + 745f854 commit 5b8d1ec

File tree

4 files changed

+566
-57
lines changed

4 files changed

+566
-57
lines changed

README.md

+53-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# tx-trie
22

3-
Ethereum Transaction Tries Handler
3+
Ethereum Transaction Trie / Transaction Receipt Trie Handler
4+
5+
_Legacy, eip 2930, eip 1559, eip 4844 all tested_
46

57
- [x] Transaction Trie Handler
68
- [x] Build Trie with target block number
79
- [x] Build Trie with target tx hash
810
- [x] Get proof by tx index
911
- [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
1517

1618
## Install
1719

@@ -21,7 +23,7 @@ Ethereum Transaction Tries Handler
2123

2224
## Example
2325

24-
### Build Trie with target tx hash
26+
### Build tx Trie with target tx hash
2527

2628
```rust
2729
let mut mpt_handler = MptHandler::new(MAINNET_RPC_URL).await?;
@@ -38,22 +40,55 @@ let proof = mpt_handler.get_proof(tx_index)?;
3840
mpt_handler.verify_proof(tx_index, proof.clone())?;
3941
```
4042

41-
### Build Trie with target block number
43+
### Build tx Trie with target block number or target tx hash
4244

4345
```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+
));
4649

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
5177
let target_tx_hash = B256::from(hex!(
52-
"d1b736880e62738b04a1f277f099784bbdf548157d30d4edc41269553013ef13"
78+
"9c1fbda4f649ac806ab0faefbe94e1a60282eb374ead6aa01bac042f52b28a8c"
5379
));
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())?;
5792
```
5893

5994
### Dependency

0 commit comments

Comments
 (0)