Add getProof to provider (#459)

* 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
This commit is contained in:
drewstone 2021-09-18 02:01:02 -04:00 committed by GitHub
parent b915f93339
commit 83e953bc2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 4 deletions

View File

@ -47,3 +47,6 @@ pub use txpool::*;
mod trace;
pub use trace::*;
mod proof;
pub use proof::*;

View File

@ -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>,
}

View File

@ -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> {

View File

@ -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;
@ -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

View File

@ -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