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
#![forbid(unsafe_code)]
use anyhow::Result;
use diem_state_view::StateView;
use diem_types::access_path::AccessPath;
use move_core_types::language_storage::ModuleId;
use std::collections::HashMap;
pub(crate) struct GenesisStateView {
data: HashMap<AccessPath, Vec<u8>>,
}
impl GenesisStateView {
pub(crate) fn new() -> Self {
Self {
data: HashMap::new(),
}
}
pub(crate) fn add_module(&mut self, module_id: &ModuleId, blob: &[u8]) {
let access_path = AccessPath::from(module_id);
self.data.insert(access_path, blob.to_vec());
}
}
impl StateView for GenesisStateView {
fn get(&self, access_path: &AccessPath) -> Result<Option<Vec<u8>>> {
Ok(self.data.get(access_path).cloned())
}
fn is_genesis(&self) -> bool {
true
}
}