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
use crate::serialization::HexNumber;
use fuel_core_interfaces::{
db::Error,
model::BlockHeight,
};
use serde::{
Deserialize,
Serialize,
};
use serde_with::{
serde_as,
skip_serializing_none,
};
use super::{
coin::CoinConfig,
contract::ContractConfig,
message::MessageConfig,
};
#[serde_as]
#[skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
pub struct StateConfig {
pub coins: Option<Vec<CoinConfig>>,
pub contracts: Option<Vec<ContractConfig>>,
pub messages: Option<Vec<MessageConfig>>,
#[serde_as(as = "Option<HexNumber>")]
#[serde(default)]
pub height: Option<BlockHeight>,
}
impl StateConfig {
pub fn generate_state_config<T>(db: T) -> anyhow::Result<Self>
where
T: ChainConfigDb,
{
Ok(StateConfig {
coins: db.get_coin_config()?,
contracts: db.get_contract_config()?,
messages: db.get_message_config()?,
height: db.get_block_height()?,
})
}
}
pub trait ChainConfigDb {
fn get_coin_config(&self) -> anyhow::Result<Option<Vec<CoinConfig>>>;
fn get_contract_config(&self) -> Result<Option<Vec<ContractConfig>>, anyhow::Error>;
fn get_message_config(&self) -> Result<Option<Vec<MessageConfig>>, Error>;
fn get_block_height(&self) -> Result<Option<BlockHeight>, Error>;
}