1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::{AccountInfo, Bytecode, B160, B256, U256};
use auto_impl::auto_impl;
#[auto_impl(& mut, Box)]
pub trait State {
type Error;
fn basic(&mut self, address: B160) -> Result<Option<AccountInfo>, Self::Error>;
fn code_by_hash(&mut self, code_hash: B256) -> Result<Bytecode, Self::Error>;
fn storage(&mut self, address: B160, index: U256) -> Result<U256, Self::Error>;
}
#[auto_impl(&, Box, Arc)]
pub trait StateRef {
type Error;
fn basic(&self, address: B160) -> Result<Option<AccountInfo>, Self::Error>;
fn code_by_hash(&self, code_hash: B256) -> Result<Bytecode, Self::Error>;
fn storage(&self, address: B160, index: U256) -> Result<U256, Self::Error>;
}
impl<T> State for &T
where
T: StateRef,
{
type Error = <T as StateRef>::Error;
fn basic(&mut self, address: B160) -> Result<Option<AccountInfo>, Self::Error> {
StateRef::basic(*self, address)
}
fn code_by_hash(&mut self, code_hash: B256) -> Result<Bytecode, Self::Error> {
StateRef::code_by_hash(*self, code_hash)
}
fn storage(&mut self, address: B160, index: U256) -> Result<U256, Self::Error> {
StateRef::storage(*self, address, index)
}
}