ckb_chain_spec/versionbits/
convert.rs

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
use crate::versionbits::{Deployment, DeploymentPos, ThresholdState};
use ckb_jsonrpc_types::{
    self, DeploymentInfo, DeploymentPos as JsonDeploymentPos, DeploymentState,
};

impl From<ThresholdState> for DeploymentState {
    fn from(state: ThresholdState) -> Self {
        match state {
            ThresholdState::Defined => DeploymentState::Defined,
            ThresholdState::Started => DeploymentState::Started,
            ThresholdState::LockedIn => DeploymentState::LockedIn,
            ThresholdState::Active => DeploymentState::Active,
            ThresholdState::Failed => DeploymentState::Failed,
        }
    }
}

impl From<Deployment> for DeploymentInfo {
    fn from(deployment: Deployment) -> Self {
        DeploymentInfo {
            bit: deployment.bit,
            start: deployment.start.into(),
            timeout: deployment.timeout.into(),
            min_activation_epoch: deployment.min_activation_epoch.into(),
            period: deployment.period.into(),
            threshold: deployment.threshold.into(),
            state: DeploymentState::Defined,
            since: 0.into(),
        }
    }
}

impl From<Deployment> for ckb_jsonrpc_types::Deployment {
    fn from(deployment: Deployment) -> Self {
        ckb_jsonrpc_types::Deployment {
            bit: deployment.bit,
            start: deployment.start.into(),
            timeout: deployment.timeout.into(),
            min_activation_epoch: deployment.min_activation_epoch.into(),
            period: deployment.period.into(),
            threshold: deployment.threshold.into(),
        }
    }
}

impl From<DeploymentPos> for JsonDeploymentPos {
    fn from(pos: DeploymentPos) -> Self {
        match pos {
            DeploymentPos::Testdummy => JsonDeploymentPos::Testdummy,
            DeploymentPos::LightClient => JsonDeploymentPos::LightClient,
        }
    }
}