Skip to content

Commit

Permalink
chore: add CLI to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
petscheit committed Apr 8, 2024
1 parent 1230738 commit 830f0c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# eth-trie-proofs

A comprehensive proofs handler for Ethereum trie. Tested with various EIPs including Legacy, EIP-2930, EIP-1559, and EIP-4844.
A comprehensive proofs handler for Ethereum trie. Tested with various EIPs including Legacy, EIP-2930, EIP-1559, and EIP-4844. This repository exposes the proof building functionalities, and a CLI version.

## Features

Expand All @@ -19,6 +19,22 @@ A comprehensive proofs handler for Ethereum trie. Tested with various EIPs inclu
- [x] Retrieve proof by transaction index
- [x] Verify proof

## CLI Tool

The CLI tool supports generating proofs for transactions and receipts. Use the following commands based on your requirements:

**Generate a Proof via CLI**
To generate a proof for a transaction, use the following command:

`cargo run --bin eth-trie-proofs tx <TRANSACTION_HASH> [RPC_URL]`

To generate a receipt proof:

`cargo run --bin eth-trie-proofs receipt <TRANSACTION_HASH> [RPC_URL]`

As a default, `https://ethereum-rpc.publicnode.com` is used as an RPC provider. This will probably work for recent transactions, but it is advised to use a dedicated RPC.


## Installation

Use the following command to add `eth-trie-proofs` to your project:
Expand Down
9 changes: 2 additions & 7 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use serde_with::serde_as;
use eth_trie_proofs::tx_receipt_trie::TxReceiptsMptHandler;
use eth_trie_proofs::Error;


#[derive(Debug, Parser)]
#[command(name = "eth-trie-proof")]
#[command(version, about, long_about = None)]
Expand Down Expand Up @@ -75,9 +74,7 @@ async fn main() -> Result<(), Error> {
async fn generate_tx_proof(tx_hash: &str, rpc_url: &str) -> Result<(), Error> {
let mut txs_mpt_handler = TxsMptHandler::new(rpc_url)?;
let tx_hash = B256::from_hex(tx_hash).unwrap();
txs_mpt_handler
.build_tx_tree_from_tx_hash(tx_hash)
.await?;
txs_mpt_handler.build_tx_tree_from_tx_hash(tx_hash).await?;
let index = txs_mpt_handler.tx_hash_to_tx_index(tx_hash)?;
let proof = txs_mpt_handler.get_proof(index)?;
let root = txs_mpt_handler.get_root()?;
Expand All @@ -94,9 +91,7 @@ async fn generate_receipt_proof(tx_hash: &str, rpc_url: &str) -> Result<(), Erro
tx_receipts_mpt_handler
.build_tx_receipt_tree_from_tx_hash(tx_hash)
.await?;
let index = tx_receipts_mpt_handler
.tx_hash_to_tx_index(tx_hash)
.await?;
let index = tx_receipts_mpt_handler.tx_hash_to_tx_index(tx_hash).await?;
let proof = tx_receipts_mpt_handler.get_proof(index)?;
let root = tx_receipts_mpt_handler.get_root()?;

Expand Down

0 comments on commit 830f0c1

Please sign in to comment.