Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Add getProof to provider (#459)
Browse files Browse the repository at this point in the history
* Add getProof to provider

* Format updates

* Add docs

* Remove fill_tx method, not sure how it got there

* Fix removed Trace type

* Remove test, eth_getProof not supported by ganache
  • Loading branch information
drewstone authored Sep 18, 2021
1 parent b915f93 commit 83e953b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ethers-core/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ pub use txpool::*;

mod trace;
pub use trace::*;

mod proof;
pub use proof::*;
19 changes: 19 additions & 0 deletions ethers-core/src/types/proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::types::{Bytes, H256, U256};
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct StorageProof {
pub key: H256,
pub proof: Vec<Bytes>,
pub value: U256,
}

#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct EIP1186ProofResponse {
balance: U256,
code_hash: H256,
nonce: U256,
storage_hash: H256,
account_proof: Vec<Bytes>,
storage_proof: Vec<StorageProof>,
}
12 changes: 12 additions & 0 deletions ethers-providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,18 @@ pub trait Middleware: Sync + Send + Debug {
.map_err(FromErr::from)
}

async fn get_proof<T: Into<NameOrAddress> + Send + Sync>(
&self,
from: T,
locations: Vec<H256>,
block: Option<BlockId>,
) -> Result<EIP1186ProofResponse, Self::Error> {
self.inner()
.get_proof(from, locations, block)
.await
.map_err(FromErr::from)
}

// Mempool inspection for Geth's API

async fn txpool_content(&self) -> Result<TxpoolContent, Self::Error> {
Expand Down
30 changes: 26 additions & 4 deletions ethers-providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ use ethers_core::{
abi::{self, Detokenize, ParamType},
types::{
transaction::{eip2718::TypedTransaction, eip2930::AccessListWithGasUsed},
Address, Block, BlockId, BlockNumber, BlockTrace, Bytes, Filter, Log, NameOrAddress,
Selector, Signature, Trace, TraceFilter, TraceType, Transaction, TransactionReceipt,
TxHash, TxpoolContent, TxpoolInspect, TxpoolStatus, H256, U256, U64,
Address, Block, BlockId, BlockNumber, BlockTrace, Bytes, EIP1186ProofResponse, Filter, Log,
NameOrAddress, Selector, Signature, Trace, TraceFilter, TraceType, Transaction,
TransactionReceipt, TxHash, TxpoolContent, TxpoolInspect, TxpoolStatus, H256, U256, U64,
},
utils,
};

#[cfg(feature = "celo")]
use crate::CeloMiddleware;
use crate::Middleware;
Expand Down Expand Up @@ -582,6 +581,29 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
self.request("eth_getCode", [at, block]).await
}

/// Returns the EIP-1186 proof response
/// https://github.com/ethereum/EIPs/issues/1186
async fn get_proof<T: Into<NameOrAddress> + Send + Sync>(
&self,
from: T,
locations: Vec<H256>,
block: Option<BlockId>,
) -> Result<EIP1186ProofResponse, ProviderError> {
let from = match from.into() {
NameOrAddress::Name(ens_name) => self.resolve_name(&ens_name).await?,
NameOrAddress::Address(addr) => addr,
};

let from = utils::serialize(&from);
let locations = locations
.iter()
.map(|location| utils::serialize(&location))
.collect();
let block = utils::serialize(&block.unwrap_or_else(|| BlockNumber::Latest.into()));

self.request("eth_getProof", [from, locations, block]).await
}

////// Ethereum Naming Service
// The Ethereum Naming Service (ENS) allows easy to remember and use names to
// be assigned to Ethereum addresses. Any provider operation which takes an address
Expand Down
1 change: 1 addition & 0 deletions ethers-providers/src/transports/quorum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl<T: JsonRpcClientWrapper> QuorumProvider<T> {
| "eth_createAccessList"
| "eth_getStorageAt"
| "eth_getCode"
| "eth_getProof"
| "trace_call"
| "trace_block" => {
// calls that include the block number in the params at the last index of json array
Expand Down

0 comments on commit 83e953b

Please sign in to comment.