implemented eth_storageAt rpc method, added more tests for rpc
This commit is contained in:
@@ -453,6 +453,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
||||
self.state().balance(address)
|
||||
}
|
||||
|
||||
fn storage_at(&self, address: &Address, position: &H256) -> H256 {
|
||||
self.state().storage_at(address, position)
|
||||
}
|
||||
|
||||
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction> {
|
||||
match id {
|
||||
TransactionId::Hash(ref hash) => self.chain.transaction_address(hash),
|
||||
|
||||
@@ -69,6 +69,9 @@ pub trait BlockChainClient : Sync + Send {
|
||||
/// Get address balance.
|
||||
fn balance(&self, address: &Address) -> U256;
|
||||
|
||||
/// Get value of the storage at given position.
|
||||
fn storage_at(&self, address: &Address, position: &H256) -> H256;
|
||||
|
||||
/// Get transaction with given hash.
|
||||
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>;
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ pub struct TestBlockChainClient {
|
||||
pub difficulty: RwLock<U256>,
|
||||
/// Balances.
|
||||
pub balances: RwLock<HashMap<Address, U256>>,
|
||||
/// Storage.
|
||||
pub storage: RwLock<HashMap<(Address, H256), H256>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -74,6 +76,7 @@ impl TestBlockChainClient {
|
||||
last_hash: RwLock::new(H256::new()),
|
||||
difficulty: RwLock::new(From::from(0)),
|
||||
balances: RwLock::new(HashMap::new()),
|
||||
storage: RwLock::new(HashMap::new()),
|
||||
};
|
||||
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
||||
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
||||
@@ -84,6 +87,10 @@ impl TestBlockChainClient {
|
||||
self.balances.write().unwrap().insert(address, balance);
|
||||
}
|
||||
|
||||
pub fn set_storage(&mut self, address: Address, position: H256, value: H256) {
|
||||
self.storage.write().unwrap().insert((address, position), value);
|
||||
}
|
||||
|
||||
/// Add blocks to test client.
|
||||
pub fn add_blocks(&mut self, count: usize, with: EachBlockWith) {
|
||||
let len = self.numbers.read().unwrap().len();
|
||||
@@ -182,6 +189,10 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
self.balances.read().unwrap().get(address).cloned().unwrap_or_else(U256::zero)
|
||||
}
|
||||
|
||||
fn storage_at(&self, address: &Address, position: &H256) -> H256 {
|
||||
self.storage.read().unwrap().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new)
|
||||
}
|
||||
|
||||
fn transaction(&self, _id: TransactionId) -> Option<LocalizedTransaction> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user