implement storage_at_id
This commit is contained in:
parent
2b7fae8fa6
commit
3405f3eab1
@ -578,6 +578,13 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
||||
self.state().storage_at(address, position)
|
||||
}
|
||||
|
||||
fn storage_at_id(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
||||
match id {
|
||||
BlockID::Latest => Some(self.storage_at(address, position)),
|
||||
id => self.state_at_id(id).map(|s| s.storage_at(address, position)),
|
||||
}
|
||||
}
|
||||
|
||||
fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction> {
|
||||
self.transaction_address(id).and_then(|address| self.chain.transaction(&address))
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ pub trait BlockChainClient : Sync + Send {
|
||||
|
||||
/// Account balance at a specific block ID.
|
||||
///
|
||||
/// Must not fail if `id` is `BlockID::Latest`.
|
||||
/// Will fail if the block is not valid or the block's root hash has been
|
||||
/// pruned from the DB.
|
||||
fn balance_at_id(&self, address: &Address, id: BlockID) -> Option<U256> {
|
||||
@ -89,9 +90,18 @@ pub trait BlockChainClient : Sync + Send {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get value of the storage at given position.
|
||||
/// Get value of the storage at given position from the latest state.
|
||||
fn storage_at(&self, address: &Address, position: &H256) -> H256;
|
||||
|
||||
/// Get value of the storage at given position form the latest state.
|
||||
fn storage_at_id(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
||||
if let BlockID::Latest = id {
|
||||
Some(self.storage_at(address, position))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Get transaction with given hash.
|
||||
fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction>;
|
||||
|
||||
|
@ -361,9 +361,9 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> where
|
||||
fn storage_at(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params_default_third::<Address, U256>(params)
|
||||
.and_then(|(address, position, block_number,)| match block_number {
|
||||
BlockNumber::Pending => to_value(&U256::from(take_weak!(self.miner).storage_at(take_weak!(self.client).deref(), &address, &H256::from(position)))),
|
||||
BlockNumber::Pending => to_value(&U256::from(take_weak!(self.miner).storage_at(&*take_weak!(self.client), &address, &H256::from(position)))),
|
||||
BlockNumber::Latest => to_value(&U256::from(take_weak!(self.client).storage_at(&address, &H256::from(position)))),
|
||||
_ => Err(Error::invalid_params()),
|
||||
id => to_value(&try!(take_weak!(self.client).storage_at_id(&address, &H256::from(position), id.into()).ok_or_else(make_unsupported_err))),
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user