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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![forbid(unsafe_code)]
use crate::account_with_state_view::{AccountWithStateView, AsAccountWithStateView};
use anyhow::Result;
use aptos_crypto::HashValue;
use aptos_types::{
account_address::AccountAddress, state_store::state_key::StateKey, transaction::Version,
};
use std::ops::Deref;
pub mod account_with_state_cache;
pub mod account_with_state_view;
pub trait StateView: Sync {
fn id(&self) -> StateViewId {
StateViewId::Miscellaneous
}
fn get_state_value(&self, state_key: &StateKey) -> Result<Option<Vec<u8>>>;
fn is_genesis(&self) -> bool;
}
#[derive(Copy, Clone)]
pub enum StateViewId {
ChunkExecution { first_version: Version },
BlockExecution { block_id: HashValue },
TransactionValidation { base_version: Version },
Miscellaneous,
}
impl<R, S> StateView for R
where
R: Deref<Target = S> + Sync,
S: StateView,
{
fn id(&self) -> StateViewId {
self.deref().id()
}
fn get_state_value(&self, state_key: &StateKey) -> Result<Option<Vec<u8>>> {
self.deref().get_state_value(state_key)
}
fn is_genesis(&self) -> bool {
self.deref().is_genesis()
}
}
impl<'a, S: 'a + StateView> AsAccountWithStateView<'a> for S {
fn as_account_with_state_view(
&'a self,
account_address: &'a AccountAddress,
) -> AccountWithStateView {
AccountWithStateView::new(account_address, self)
}
}