fix: eth_getProof response (#12370)

This commit is contained in:
Arsenii Kulikov
2024-11-07 23:31:17 +04:00
committed by GitHub
parent d0baf926bf
commit 29da7d744a
2 changed files with 18 additions and 9 deletions

View File

@ -122,7 +122,7 @@ pub trait EthState: LoadState + SpawnBlocking {
let proof = state
.proof(Default::default(), address, &storage_keys)
.map_err(Self::Error::from_eth_err)?;
Ok(from_primitive_account_proof(proof))
Ok(from_primitive_account_proof(proof, keys))
})
.await
})

View File

@ -5,16 +5,18 @@ use alloy_rpc_types_eth::{EIP1186AccountProofResponse, EIP1186StorageProof};
use reth_trie_common::{AccountProof, StorageProof};
/// Creates a new rpc storage proof from a primitive storage proof type.
pub fn from_primitive_storage_proof(proof: StorageProof) -> EIP1186StorageProof {
EIP1186StorageProof {
key: JsonStorageKey::Hash(proof.key),
value: proof.value,
proof: proof.proof,
}
pub fn from_primitive_storage_proof(
proof: StorageProof,
slot: JsonStorageKey,
) -> EIP1186StorageProof {
EIP1186StorageProof { key: slot, value: proof.value, proof: proof.proof }
}
/// Creates a new rpc account proof from a primitive account proof type.
pub fn from_primitive_account_proof(proof: AccountProof) -> EIP1186AccountProofResponse {
pub fn from_primitive_account_proof(
proof: AccountProof,
slots: Vec<JsonStorageKey>,
) -> EIP1186AccountProofResponse {
let info = proof.info.unwrap_or_default();
EIP1186AccountProofResponse {
address: proof.address,
@ -23,6 +25,13 @@ pub fn from_primitive_account_proof(proof: AccountProof) -> EIP1186AccountProofR
nonce: info.nonce,
storage_hash: proof.storage_root,
account_proof: proof.proof,
storage_proof: proof.storage_proofs.into_iter().map(from_primitive_storage_proof).collect(),
storage_proof: proof
.storage_proofs
.into_iter()
.filter_map(|proof| {
let input_slot = slots.iter().find(|s| s.as_b256() == proof.key)?;
Some(from_primitive_storage_proof(proof, *input_slot))
})
.collect(),
}
}