Skip to content

Commit

Permalink
documentation & readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Mar 25, 2024
1 parent 5b8d1ec commit 1f88429
Show file tree
Hide file tree
Showing 4 changed files with 605 additions and 537 deletions.
57 changes: 22 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,40 @@
# tx-trie
# tx-trie: Ethereum Transaction Trie / Transaction Receipt Trie Handler

Ethereum Transaction Trie / Transaction Receipt Trie Handler
A comprehensive handler for Ethereum transaction tries and transaction receipt tries, tested with various EIPs including Legacy, EIP-2930, EIP-1559, and EIP-4844.

_Legacy, eip 2930, eip 1559, eip 4844 all tested_
## Features

- [x] Transaction Trie Handler
- [x] Build Trie with target block number
- [x] Build Trie with target tx hash
- [x] Get proof by tx index
- **Transaction Trie Handler**

- [x] Build a trie with a target block number
- [x] Build a trie with a target transaction hash
- [x] Retrieve proof by transaction index
- [x] Verify proof
- [x] Transaction Receipt Trie Handler
- [x] Build Trie with target block number
- [x] Build Trie with target tx hash
- [x] Get proof by tx index

- **Transaction Receipt Trie Handler**
- [x] Build a trie with a target block number
- [x] Build a trie with a target transaction hash
- [x] Retrieve proof by transaction index
- [x] Verify proof

## Install
## Installation

Use the following command to add `tx-trie` to your project:

```bash
❯ cargo add tx-trie
```

## Example

### Build tx Trie with target tx hash

```rust
let mut mpt_handler = MptHandler::new(MAINNET_RPC_URL).await?;
let tx_hash = B256::from(hex!(
"ef1503cc8bd82da1552389183a097126bae21a889390a7be556b1f69d8c75c29"
));
mpt_handler
.build_tx_tree_from_tx_hash(tx_hash)
.await
?;

let tx_index = mpt_handler.tx_hash_to_tx_index(tx_hash)?;
let proof = mpt_handler.get_proof(tx_index)?;
mpt_handler.verify_proof(tx_index, proof.clone())?;
```

### Build tx Trie with target block number or target tx hash
### Building a Transaction Trie with a Target Block Number or Target Transaction Hash

```rust
let target_tx_hash = B256::from(hex!(
"1fcb1196d8a3bff0bcf13309d2d2bb1a23ae1ac13f5674c801be0ff9254d5ab5"
));

let mut txs_mpt_handler = TxsMptHandler::new(MAINNET_RPC_URL).await?;
let mut txs_mpt_handler = TxsMptHandler::new(MAINNET_RPC_URL)?;

txs_mpt_handler
.build_tx_tree_from_block(4370000)
Expand All @@ -59,7 +46,7 @@ txs_mpt_handler
.verify_proof(tx_index, proof.clone())?;

// You can either build with target tx hash. Both root match.
let mut txs_mpt_handler2 = TxsMptHandler::new(MAINNET_RPC_URL).await?;
let mut txs_mpt_handler2 = TxsMptHandler::new(MAINNET_RPC_URL)?;
txs_mpt_handler2
.build_tx_tree_from_tx_hash(target_tx_hash)
.await?;
Expand All @@ -70,15 +57,15 @@ assert_eq!(
);
```

### Build tx receipts Trie with target block number
### Building a Transaction Receipts Trie with a Target Block Number

```rust
// 4844 transaction
let target_tx_hash = B256::from(hex!(
"9c1fbda4f649ac806ab0faefbe94e1a60282eb374ead6aa01bac042f52b28a8c"
));

let mut tx_receipts_mpt_handler = TxReceiptsMptHandler::new(MAINNET_RPC_URL).await?;
let mut tx_receipts_mpt_handler = TxReceiptsMptHandler::new(MAINNET_RPC_URL)?;
tx_receipts_mpt_handler
.build_tx_receipts_tree_from_block(19426589)
.await?;
Expand All @@ -93,4 +80,4 @@ tx_receipts_mpt_handler

### Dependency

For Trie implementation, have a dependency with [eth_trie](https://crates.io/crates/eth_trie) crate.
For trie implementation, this project depends on the [eth_trie](https://crates.io/crates/eth_trie) crate.
Loading

0 comments on commit 1f88429

Please sign in to comment.