fuel_core_client/client/schema/
gas_price.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
use crate::client::schema::{
    schema,
    U32,
    U64,
};

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct LatestGasPrice {
    pub gas_price: U64,
    pub block_height: U32,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl", graphql_type = "Query")]
pub struct QueryLatestGasPrice {
    pub latest_gas_price: LatestGasPrice,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct EstimateGasPrice {
    pub gas_price: U64,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct BlockHorizonArgs {
    pub block_horizon: Option<U32>,
}

impl From<u32> for BlockHorizonArgs {
    fn from(block_horizon: u32) -> Self {
        Self {
            block_horizon: Some(block_horizon.into()),
        }
    }
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
    schema_path = "./assets/schema.sdl",
    graphql_type = "Query",
    variables = "BlockHorizonArgs"
)]
pub struct QueryEstimateGasPrice {
    #[arguments(blockHorizon: $block_horizon)]
    pub estimate_gas_price: EstimateGasPrice,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn latest_gas_price_query_gql_output() {
        use cynic::QueryBuilder;
        let operation = QueryLatestGasPrice::build(());
        insta::assert_snapshot!(operation.query)
    }

    #[test]
    fn estimate_gas_price_query_gql_output() {
        use cynic::QueryBuilder;
        let arbitrary_horizon = 10;
        let operation = QueryEstimateGasPrice::build(arbitrary_horizon.into());
        insta::assert_snapshot!(operation.query)
    }
}