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
use crate::on_chain_config::OnChainConfig;
use anyhow::{format_err, Result};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum OnChainConsensusConfig {
V1(ConsensusConfigV1),
}
impl OnChainConsensusConfig {
pub fn two_chain(&self) -> bool {
match &self {
OnChainConsensusConfig::V1(config) => config.two_chain,
}
}
}
impl Default for OnChainConsensusConfig {
fn default() -> Self {
OnChainConsensusConfig::V1(ConsensusConfigV1::default())
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ConsensusConfigV1 {
pub two_chain: bool,
}
impl Default for ConsensusConfigV1 {
fn default() -> Self {
Self { two_chain: false }
}
}
impl OnChainConfig for OnChainConsensusConfig {
const IDENTIFIER: &'static str = "DiemConsensusConfig";
fn deserialize_into_config(bytes: &[u8]) -> Result<Self> {
let raw_bytes: Vec<u8> = bcs::from_bytes(bytes)?;
bcs::from_bytes(&raw_bytes)
.map_err(|e| format_err!("[on-chain config] Failed to deserialize into config: {}", e))
}
}