fuel_core/schema/tx/
upgrade_purpose.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::schema::scalars::{
    Bytes32,
    U16,
};
use async_graphql::{
    Object,
    Union,
};

#[derive(Union)]
pub enum UpgradePurpose {
    /// The upgrade is performed to change the consensus parameters.
    ConsensusParameters(ConsensusParametersPurpose),
    /// The upgrade is performed to change the state transition function.
    StateTransition(StateTransitionPurpose),
}

pub struct ConsensusParametersPurpose {
    /// The index of the witness in the [`Witnesses`] field that contains
    /// the serialized consensus parameters.
    witness_index: U16,
    /// The hash of the serialized consensus parameters.
    /// Since the serialized consensus parameters live inside witnesses(malleable
    /// data), any party can override them. The `checksum` is used to verify that the
    /// data was not modified.
    checksum: Bytes32,
}

#[Object]
impl ConsensusParametersPurpose {
    async fn witness_index(&self) -> U16 {
        self.witness_index
    }

    async fn checksum(&self) -> Bytes32 {
        self.checksum
    }
}

pub struct StateTransitionPurpose {
    /// The Merkle root of the new bytecode of the state transition function.
    /// The bytecode must be present on the blockchain(should be known by the
    /// network) at the moment of inclusion of this transaction.
    root: Bytes32,
}

#[Object]
impl StateTransitionPurpose {
    async fn root(&self) -> Bytes32 {
        self.root
    }
}

impl From<fuel_core_types::fuel_tx::UpgradePurpose> for UpgradePurpose {
    fn from(value: fuel_core_types::fuel_tx::UpgradePurpose) -> Self {
        match value {
            fuel_core_types::fuel_tx::UpgradePurpose::ConsensusParameters {
                witness_index,
                checksum,
            } => UpgradePurpose::ConsensusParameters(ConsensusParametersPurpose {
                witness_index: witness_index.into(),
                checksum: checksum.into(),
            }),
            fuel_core_types::fuel_tx::UpgradePurpose::StateTransition { root } => {
                UpgradePurpose::StateTransition(StateTransitionPurpose {
                    root: root.into(),
                })
            }
        }
    }
}