use crate::schema::scalars::{
Bytes32,
U16,
};
use async_graphql::{
Object,
Union,
};
#[derive(Union)]
pub enum UpgradePurpose {
ConsensusParameters(ConsensusParametersPurpose),
StateTransition(StateTransitionPurpose),
}
pub struct ConsensusParametersPurpose {
witness_index: U16,
checksum: Bytes32,
}
#[Object]
impl ConsensusParametersPurpose {
async fn witness_index(&self) -> U16 {
self.witness_index
}
async fn checksum(&self) -> Bytes32 {
self.checksum
}
}
pub struct StateTransitionPurpose {
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(),
})
}
}
}
}