fuel_core_client/client/schema/
upgrades.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::client::schema::schema;

use crate::client::{
    schema::{
        chain::ConsensusParameters,
        primitives::HexString,
    },
    ConversionError,
};

use fuel_core_types::fuel_vm::UploadedBytecode as VmUploadedBytecode;

#[derive(cynic::QueryVariables, Debug)]
pub struct ConsensusParametersByVersionArgs {
    pub version: i32,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
    schema_path = "./assets/schema.sdl",
    graphql_type = "Query",
    variables = "ConsensusParametersByVersionArgs"
)]
pub struct ConsensusParametersByVersionQuery {
    #[arguments(version: $version)]
    pub consensus_parameters: Option<ConsensusParameters>,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct StateTransitionBytecodeByVersionArgs {
    pub version: i32,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
    schema_path = "./assets/schema.sdl",
    graphql_type = "Query",
    variables = "StateTransitionBytecodeByVersionArgs"
)]
pub struct StateTransitionBytecodeByVersionQuery {
    #[arguments(version: $version)]
    pub state_transition_bytecode_by_version: Option<StateTransitionBytecode>,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct StateTransitionBytecodeByRootArgs {
    pub root: HexString,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
    schema_path = "./assets/schema.sdl",
    graphql_type = "Query",
    variables = "StateTransitionBytecodeByRootArgs"
)]
pub struct StateTransitionBytecodeByRootQuery {
    #[arguments(root: $root)]
    pub state_transition_bytecode_by_root: Option<StateTransitionBytecode>,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct StateTransitionBytecode {
    pub root: HexString,
    pub bytecode: UploadedBytecode,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct UploadedBytecode {
    pub bytecode: HexString,
    pub uploaded_subsections_number: Option<i32>,
    pub completed: bool,
}

// GrapqhQL translation

impl TryFrom<UploadedBytecode> for VmUploadedBytecode {
    type Error = ConversionError;
    fn try_from(value: UploadedBytecode) -> Result<Self, Self::Error> {
        Ok(match value.completed {
            true => Self::Completed(value.bytecode.into()),
            false => Self::Uncompleted {
                bytecode: value.bytecode.into(),
                uploaded_subsections_number: value
                    .uploaded_subsections_number
                    .ok_or_else(|| {
                        ConversionError::MissingField(
                            "uploaded_subsections_number".to_string(),
                        )
                    })?
                    .try_into()?,
            },
        })
    }
}