Skip to main content

fuel_core_client/client/schema/
chain.rs

1use crate::client::schema::{
2    Address,
3    AssetId,
4    ConversionError,
5    U16,
6    U32,
7    U64,
8    block::Block,
9    schema,
10};
11
12#[derive(cynic::QueryFragment, Clone, Debug)]
13#[cynic(schema_path = "./assets/schema.sdl")]
14pub struct ConsensusParameters {
15    pub version: ConsensusParametersVersion,
16    pub tx_params: TxParameters,
17    pub predicate_params: PredicateParameters,
18    pub script_params: ScriptParameters,
19    pub contract_params: ContractParameters,
20    pub fee_params: FeeParameters,
21    pub base_asset_id: AssetId,
22    pub block_gas_limit: U64,
23    pub block_transaction_size_limit: U64,
24    pub chain_id: U64,
25    pub gas_costs: GasCosts,
26    pub privileged_address: Address,
27}
28
29#[derive(cynic::Enum, Clone, Debug)]
30#[cynic(schema_path = "./assets/schema.sdl")]
31pub enum ConsensusParametersVersion {
32    V1,
33    #[cynic(fallback)]
34    Unknown,
35}
36
37#[derive(cynic::QueryFragment, Clone, Debug)]
38#[cynic(schema_path = "./assets/schema.sdl")]
39pub struct TxParameters {
40    pub version: TxParametersVersion,
41    pub max_inputs: U16,
42    pub max_outputs: U16,
43    pub max_witnesses: U32,
44    pub max_gas_per_tx: U64,
45    pub max_size: U64,
46    pub max_bytecode_subsections: U16,
47}
48
49#[derive(cynic::Enum, Clone, Debug)]
50#[cynic(schema_path = "./assets/schema.sdl")]
51pub enum TxParametersVersion {
52    V1,
53    #[cynic(fallback)]
54    Unknown,
55}
56
57impl TryFrom<TxParameters> for fuel_core_types::fuel_tx::TxParameters {
58    type Error = ConversionError;
59
60    fn try_from(params: TxParameters) -> Result<Self, Self::Error> {
61        match params.version {
62            TxParametersVersion::V1 => Ok(
63                fuel_core_types::fuel_tx::consensus_parameters::TxParametersV1 {
64                    max_inputs: params.max_inputs.into(),
65                    max_outputs: params.max_outputs.into(),
66                    max_witnesses: params.max_witnesses.into(),
67                    max_gas_per_tx: params.max_gas_per_tx.into(),
68                    max_size: params.max_size.into(),
69                    max_bytecode_subsections: params.max_bytecode_subsections.into(),
70                }
71                .into(),
72            ),
73            _ => Err(ConversionError::UnknownVariant("TxParametersVersion")),
74        }
75    }
76}
77
78#[derive(cynic::QueryFragment, Clone, Debug)]
79#[cynic(schema_path = "./assets/schema.sdl")]
80pub struct PredicateParameters {
81    pub version: PredicateParametersVersion,
82    pub max_predicate_length: U64,
83    pub max_predicate_data_length: U64,
84    pub max_message_data_length: U64,
85    pub max_gas_per_predicate: U64,
86}
87
88#[derive(cynic::Enum, Clone, Debug)]
89#[cynic(schema_path = "./assets/schema.sdl")]
90pub enum PredicateParametersVersion {
91    V1,
92    #[cynic(fallback)]
93    Unknown,
94}
95
96impl TryFrom<PredicateParameters> for fuel_core_types::fuel_tx::PredicateParameters {
97    type Error = ConversionError;
98
99    fn try_from(params: PredicateParameters) -> Result<Self, Self::Error> {
100        match params.version {
101            PredicateParametersVersion::V1 => Ok(
102                fuel_core_types::fuel_tx::consensus_parameters::PredicateParametersV1 {
103                    max_predicate_length: params.max_predicate_length.into(),
104                    max_predicate_data_length: params.max_predicate_data_length.into(),
105                    max_message_data_length: params.max_message_data_length.into(),
106                    max_gas_per_predicate: params.max_gas_per_predicate.into(),
107                }
108                .into(),
109            ),
110            _ => Err(ConversionError::UnknownVariant(
111                "PredicateParametersVersion",
112            )),
113        }
114    }
115}
116
117#[derive(cynic::QueryFragment, Clone, Debug)]
118#[cynic(schema_path = "./assets/schema.sdl")]
119pub struct ScriptParameters {
120    pub version: ScriptParametersVersion,
121    pub max_script_length: U64,
122    pub max_script_data_length: U64,
123    pub max_storage_slot_length: U64,
124}
125
126#[derive(cynic::Enum, Clone, Debug)]
127#[cynic(schema_path = "./assets/schema.sdl")]
128pub enum ScriptParametersVersion {
129    V1,
130    V2,
131    #[cynic(fallback)]
132    Unknown,
133}
134
135impl TryFrom<ScriptParameters> for fuel_core_types::fuel_tx::ScriptParameters {
136    type Error = ConversionError;
137
138    fn try_from(params: ScriptParameters) -> Result<Self, Self::Error> {
139        match params.version {
140            ScriptParametersVersion::V1 => Ok(
141                fuel_core_types::fuel_tx::consensus_parameters::ScriptParametersV1 {
142                    max_script_length: params.max_script_length.into(),
143                    max_script_data_length: params.max_script_data_length.into(),
144                }
145                .into(),
146            ),
147            ScriptParametersVersion::V2 => Ok(
148                fuel_core_types::fuel_tx::consensus_parameters::ScriptParametersV2 {
149                    max_script_length: params.max_script_length.into(),
150                    max_script_data_length: params.max_script_data_length.into(),
151                    max_storage_slot_length: params.max_storage_slot_length.into(),
152                }
153                .into(),
154            ),
155            _ => Err(ConversionError::UnknownVariant("ScriptParametersVersion")),
156        }
157    }
158}
159
160#[derive(cynic::QueryFragment, Clone, Debug)]
161#[cynic(schema_path = "./assets/schema.sdl")]
162pub struct ContractParameters {
163    pub version: ContractParametersVersion,
164    pub contract_max_size: U64,
165    pub max_storage_slots: U64,
166}
167
168#[derive(cynic::Enum, Clone, Debug)]
169#[cynic(schema_path = "./assets/schema.sdl")]
170pub enum ContractParametersVersion {
171    V1,
172    #[cynic(fallback)]
173    Unknown,
174}
175
176impl TryFrom<ContractParameters> for fuel_core_types::fuel_tx::ContractParameters {
177    type Error = ConversionError;
178
179    fn try_from(params: ContractParameters) -> Result<Self, Self::Error> {
180        match params.version {
181            ContractParametersVersion::V1 => Ok(
182                fuel_core_types::fuel_tx::consensus_parameters::ContractParametersV1 {
183                    contract_max_size: params.contract_max_size.into(),
184                    max_storage_slots: params.max_storage_slots.into(),
185                }
186                .into(),
187            ),
188            _ => Err(ConversionError::UnknownVariant("ContractParametersVersion")),
189        }
190    }
191}
192
193#[derive(cynic::QueryFragment, Clone, Debug)]
194#[cynic(schema_path = "./assets/schema.sdl")]
195pub struct FeeParameters {
196    pub version: FeeParametersVersion,
197    pub gas_price_factor: U64,
198    pub gas_per_byte: U64,
199}
200
201#[derive(cynic::Enum, Clone, Debug)]
202#[cynic(schema_path = "./assets/schema.sdl")]
203pub enum FeeParametersVersion {
204    V1,
205    #[cynic(fallback)]
206    Unknown,
207}
208
209impl TryFrom<FeeParameters> for fuel_core_types::fuel_tx::FeeParameters {
210    type Error = ConversionError;
211
212    fn try_from(params: FeeParameters) -> Result<Self, Self::Error> {
213        match params.version {
214            FeeParametersVersion::V1 => Ok(
215                fuel_core_types::fuel_tx::consensus_parameters::FeeParametersV1 {
216                    gas_price_factor: params.gas_price_factor.into(),
217                    gas_per_byte: params.gas_per_byte.into(),
218                }
219                .into(),
220            ),
221            _ => Err(ConversionError::UnknownVariant("FeeParametersVersion")),
222        }
223    }
224}
225
226#[derive(cynic::QueryFragment, Clone, Debug)]
227#[cynic(schema_path = "./assets/schema.sdl")]
228pub struct GasCosts {
229    pub version: GasCostsVersion,
230    pub add: U64,
231    pub addi: U64,
232    pub and: U64,
233    pub andi: U64,
234    pub bal: U64,
235    pub bhei: U64,
236    pub bhsh: U64,
237    pub burn: U64,
238    pub cb: U64,
239    pub cfsi: U64,
240    pub div: U64,
241    pub divi: U64,
242    pub eck1: U64,
243    pub ecr1: U64,
244    pub ed19: U64,
245    pub eq: U64,
246    pub exp: U64,
247    pub expi: U64,
248    pub flag: U64,
249    pub gm: U64,
250    pub gt: U64,
251    pub gtf: U64,
252    pub ji: U64,
253    pub jmp: U64,
254    pub jne: U64,
255    pub jnei: U64,
256    pub jnzi: U64,
257    pub jmpf: U64,
258    pub jmpb: U64,
259    pub jnzf: U64,
260    pub jnzb: U64,
261    pub jnef: U64,
262    pub jneb: U64,
263    pub lb: U64,
264    pub log: U64,
265    pub lt: U64,
266    pub lw: U64,
267    pub mint: U64,
268    pub mlog: U64,
269    pub mod_op: U64,
270    pub modi: U64,
271    pub move_op: U64,
272    pub movi: U64,
273    pub mroo: U64,
274    pub mul: U64,
275    pub muli: U64,
276    pub mldv: U64,
277    pub niop: Option<U64>,
278    pub noop: U64,
279    pub not: U64,
280    pub or: U64,
281    pub ori: U64,
282    pub poph: U64,
283    pub popl: U64,
284    pub pshh: U64,
285    pub pshl: U64,
286    pub ret: U64,
287    pub rvrt: U64,
288    pub sb: U64,
289    pub sll: U64,
290    pub slli: U64,
291    pub srl: U64,
292    pub srli: U64,
293    pub srw: Option<U64>,
294    pub sub: U64,
295    pub subi: U64,
296    pub sw: U64,
297    pub sww: Option<U64>,
298    pub time: U64,
299    pub tr: U64,
300    pub tro: U64,
301    pub wdcm: U64,
302    pub wqcm: U64,
303    pub wdop: U64,
304    pub wqop: U64,
305    pub wdml: U64,
306    pub wqml: U64,
307    pub wddv: U64,
308    pub wqdv: U64,
309    pub wdmd: U64,
310    pub wqmd: U64,
311    pub wdam: U64,
312    pub wqam: U64,
313    pub wdmm: U64,
314    pub wqmm: U64,
315    pub xor: U64,
316    pub xori: U64,
317    pub ecop: Option<U64>,
318
319    pub aloc_dependent_cost: DependentCost,
320    pub bsiz: Option<DependentCost>,
321    pub bldd: Option<DependentCost>,
322    pub cfe: DependentCost,
323    pub cfei_dependent_cost: DependentCost,
324    pub call: DependentCost,
325    pub ccp: DependentCost,
326    pub croo: DependentCost,
327    pub csiz: DependentCost,
328    pub ed19_dependent_cost: DependentCost,
329    pub k256: DependentCost,
330    pub ldc: DependentCost,
331    pub logd: DependentCost,
332    pub mcl: DependentCost,
333    pub mcli: DependentCost,
334    pub mcp: DependentCost,
335    pub mcpi: DependentCost,
336    pub meq: DependentCost,
337    pub retd: DependentCost,
338    pub s256: DependentCost,
339    pub scwq: Option<DependentCost>,
340    pub smo: DependentCost,
341    pub srwq: Option<DependentCost>,
342    pub swwq: Option<DependentCost>,
343    pub epar: Option<DependentCost>,
344
345    // V7 storage operation costs (absent in V6)
346    pub storage_read_cold: Option<DependentCost>,
347    pub storage_read_hot: Option<DependentCost>,
348    pub storage_write: Option<DependentCost>,
349    pub storage_clear: Option<DependentCost>,
350
351    // Non-opcodes prices
352    pub contract_root: DependentCost,
353    pub state_root: DependentCost,
354    pub vm_initialization: DependentCost,
355    pub new_storage_per_byte: U64,
356}
357
358#[derive(cynic::Enum, Clone, Debug)]
359#[cynic(schema_path = "./assets/schema.sdl")]
360pub enum GasCostsVersion {
361    V1,
362    #[cynic(fallback)]
363    Unknown,
364}
365
366impl TryFrom<GasCosts> for fuel_core_types::fuel_tx::GasCosts {
367    type Error = ConversionError;
368
369    fn try_from(value: GasCosts) -> Result<Self, Self::Error> {
370        use fuel_core_types::fuel_tx::consensus_parameters::{
371            DependentCost,
372            gas::{
373                GasCostsValuesV6,
374                GasCostsValuesV7,
375            },
376        };
377
378        match value.version {
379            GasCostsVersion::V1 => {
380                // Distinguish V7 from V6 by presence of new storage fields
381                if let Some(storage_read_cold) = value.storage_read_cold {
382                    Ok(fuel_core_types::fuel_tx::GasCosts::new(
383                        GasCostsValuesV7 {
384                            add: value.add.into(),
385                            addi: value.addi.into(),
386                            and: value.and.into(),
387                            andi: value.andi.into(),
388                            bal: value.bal.into(),
389                            bhei: value.bhei.into(),
390                            bhsh: value.bhsh.into(),
391                            burn: value.burn.into(),
392                            cb: value.cb.into(),
393                            cfsi: value.cfsi.into(),
394                            div: value.div.into(),
395                            divi: value.divi.into(),
396                            eck1: value.eck1.into(),
397                            ecr1: value.ecr1.into(),
398                            eq: value.eq.into(),
399                            exp: value.exp.into(),
400                            expi: value.expi.into(),
401                            flag: value.flag.into(),
402                            gm: value.gm.into(),
403                            gt: value.gt.into(),
404                            gtf: value.gtf.into(),
405                            ji: value.ji.into(),
406                            jmp: value.jmp.into(),
407                            jne: value.jne.into(),
408                            jnei: value.jnei.into(),
409                            jnzi: value.jnzi.into(),
410                            jmpf: value.jmpf.into(),
411                            jmpb: value.jmpb.into(),
412                            jnzf: value.jnzf.into(),
413                            jnzb: value.jnzb.into(),
414                            jnef: value.jnef.into(),
415                            jneb: value.jneb.into(),
416                            lb: value.lb.into(),
417                            log: value.log.into(),
418                            lt: value.lt.into(),
419                            lw: value.lw.into(),
420                            mint: value.mint.into(),
421                            mlog: value.mlog.into(),
422                            mod_op: value.mod_op.into(),
423                            modi: value.modi.into(),
424                            move_op: value.move_op.into(),
425                            movi: value.movi.into(),
426                            mroo: value.mroo.into(),
427                            mul: value.mul.into(),
428                            muli: value.muli.into(),
429                            mldv: value.mldv.into(),
430                            niop: value.niop.map(Into::into).unwrap_or(0),
431                            noop: value.noop.into(),
432                            not: value.not.into(),
433                            or: value.or.into(),
434                            ori: value.ori.into(),
435                            poph: value.poph.into(),
436                            popl: value.popl.into(),
437                            pshh: value.pshh.into(),
438                            pshl: value.pshl.into(),
439                            ret: value.ret.into(),
440                            rvrt: value.rvrt.into(),
441                            sb: value.sb.into(),
442                            sll: value.sll.into(),
443                            slli: value.slli.into(),
444                            srl: value.srl.into(),
445                            srli: value.srli.into(),
446                            sub: value.sub.into(),
447                            subi: value.subi.into(),
448                            sw: value.sw.into(),
449                            time: value.time.into(),
450                            tr: value.tr.into(),
451                            tro: value.tro.into(),
452                            wdcm: value.wdcm.into(),
453                            wqcm: value.wqcm.into(),
454                            wdop: value.wdop.into(),
455                            wqop: value.wqop.into(),
456                            wdml: value.wdml.into(),
457                            wqml: value.wqml.into(),
458                            wddv: value.wddv.into(),
459                            wqdv: value.wqdv.into(),
460                            wdmd: value.wdmd.into(),
461                            wqmd: value.wqmd.into(),
462                            wdam: value.wdam.into(),
463                            wqam: value.wqam.into(),
464                            wdmm: value.wdmm.into(),
465                            wqmm: value.wqmm.into(),
466                            xor: value.xor.into(),
467                            xori: value.xori.into(),
468                            ecop: value.ecop.map(Into::into).unwrap_or(0),
469
470                            aloc: value.aloc_dependent_cost.into(),
471                            bsiz: value
472                                .bsiz
473                                .map(Into::into)
474                                .unwrap_or(DependentCost::free()),
475                            bldd: value
476                                .bldd
477                                .map(Into::into)
478                                .unwrap_or(DependentCost::free()),
479                            cfe: value.cfe.into(),
480                            cfei: value.cfei_dependent_cost.into(),
481                            call: value.call.into(),
482                            ccp: value.ccp.into(),
483                            croo: value.croo.into(),
484                            csiz: value.csiz.into(),
485                            ed19: value.ed19_dependent_cost.into(),
486                            k256: value.k256.into(),
487                            ldc: value.ldc.into(),
488                            logd: value.logd.into(),
489                            mcl: value.mcl.into(),
490                            mcli: value.mcli.into(),
491                            mcp: value.mcp.into(),
492                            mcpi: value.mcpi.into(),
493                            meq: value.meq.into(),
494                            retd: value.retd.into(),
495                            s256: value.s256.into(),
496                            smo: value.smo.into(),
497                            epar: value
498                                .epar
499                                .map(Into::into)
500                                .unwrap_or(DependentCost::free()),
501
502                            storage_read_cold: storage_read_cold.into(),
503                            storage_read_hot: value
504                                .storage_read_hot
505                                .map(Into::into)
506                                .unwrap_or(DependentCost::free()),
507                            storage_write: value
508                                .storage_write
509                                .map(Into::into)
510                                .unwrap_or(DependentCost::free()),
511                            storage_clear: value
512                                .storage_clear
513                                .map(Into::into)
514                                .unwrap_or(DependentCost::free()),
515
516                            contract_root: value.contract_root.into(),
517                            state_root: value.state_root.into(),
518                            vm_initialization: value.vm_initialization.into(),
519                            new_storage_per_byte: value.new_storage_per_byte.into(),
520                        }
521                        .into(),
522                    ))
523                } else {
524                    Ok(fuel_core_types::fuel_tx::GasCosts::new(
525                        GasCostsValuesV6 {
526                            add: value.add.into(),
527                            addi: value.addi.into(),
528                            and: value.and.into(),
529                            andi: value.andi.into(),
530                            bal: value.bal.into(),
531                            bhei: value.bhei.into(),
532                            bhsh: value.bhsh.into(),
533                            burn: value.burn.into(),
534                            cb: value.cb.into(),
535                            cfsi: value.cfsi.into(),
536                            div: value.div.into(),
537                            divi: value.divi.into(),
538                            eck1: value.eck1.into(),
539                            ecr1: value.ecr1.into(),
540                            eq: value.eq.into(),
541                            exp: value.exp.into(),
542                            expi: value.expi.into(),
543                            flag: value.flag.into(),
544                            gm: value.gm.into(),
545                            gt: value.gt.into(),
546                            gtf: value.gtf.into(),
547                            ji: value.ji.into(),
548                            jmp: value.jmp.into(),
549                            jne: value.jne.into(),
550                            jnei: value.jnei.into(),
551                            jnzi: value.jnzi.into(),
552                            jmpf: value.jmpf.into(),
553                            jmpb: value.jmpb.into(),
554                            jnzf: value.jnzf.into(),
555                            jnzb: value.jnzb.into(),
556                            jnef: value.jnef.into(),
557                            jneb: value.jneb.into(),
558                            lb: value.lb.into(),
559                            log: value.log.into(),
560                            lt: value.lt.into(),
561                            lw: value.lw.into(),
562                            mint: value.mint.into(),
563                            mlog: value.mlog.into(),
564                            mod_op: value.mod_op.into(),
565                            modi: value.modi.into(),
566                            move_op: value.move_op.into(),
567                            movi: value.movi.into(),
568                            mroo: value.mroo.into(),
569                            mul: value.mul.into(),
570                            muli: value.muli.into(),
571                            mldv: value.mldv.into(),
572                            niop: value.niop.map(Into::into).unwrap_or(0),
573                            noop: value.noop.into(),
574                            not: value.not.into(),
575                            or: value.or.into(),
576                            ori: value.ori.into(),
577                            poph: value.poph.into(),
578                            popl: value.popl.into(),
579                            pshh: value.pshh.into(),
580                            pshl: value.pshl.into(),
581                            ret: value.ret.into(),
582                            rvrt: value.rvrt.into(),
583                            sb: value.sb.into(),
584                            sll: value.sll.into(),
585                            slli: value.slli.into(),
586                            srl: value.srl.into(),
587                            srli: value.srli.into(),
588                            srw: value.srw.map(Into::into).unwrap_or(0),
589                            sub: value.sub.into(),
590                            subi: value.subi.into(),
591                            sw: value.sw.into(),
592                            sww: value.sww.map(Into::into).unwrap_or(0),
593                            time: value.time.into(),
594                            tr: value.tr.into(),
595                            tro: value.tro.into(),
596                            wdcm: value.wdcm.into(),
597                            wqcm: value.wqcm.into(),
598                            wdop: value.wdop.into(),
599                            wqop: value.wqop.into(),
600                            wdml: value.wdml.into(),
601                            wqml: value.wqml.into(),
602                            wddv: value.wddv.into(),
603                            wqdv: value.wqdv.into(),
604                            wdmd: value.wdmd.into(),
605                            wqmd: value.wqmd.into(),
606                            wdam: value.wdam.into(),
607                            wqam: value.wqam.into(),
608                            wdmm: value.wdmm.into(),
609                            wqmm: value.wqmm.into(),
610                            xor: value.xor.into(),
611                            xori: value.xori.into(),
612                            ecop: value.ecop.map(Into::into).unwrap_or(0),
613
614                            aloc: value.aloc_dependent_cost.into(),
615                            bsiz: value
616                                .bsiz
617                                .map(Into::into)
618                                .unwrap_or(DependentCost::free()),
619                            bldd: value
620                                .bldd
621                                .map(Into::into)
622                                .unwrap_or(DependentCost::free()),
623                            cfe: value.cfe.into(),
624                            cfei: value.cfei_dependent_cost.into(),
625                            call: value.call.into(),
626                            ccp: value.ccp.into(),
627                            croo: value.croo.into(),
628                            csiz: value.csiz.into(),
629                            ed19: value.ed19_dependent_cost.into(),
630                            k256: value.k256.into(),
631                            ldc: value.ldc.into(),
632                            logd: value.logd.into(),
633                            mcl: value.mcl.into(),
634                            mcli: value.mcli.into(),
635                            mcp: value.mcp.into(),
636                            mcpi: value.mcpi.into(),
637                            meq: value.meq.into(),
638                            retd: value.retd.into(),
639                            s256: value.s256.into(),
640                            scwq: value
641                                .scwq
642                                .map(Into::into)
643                                .unwrap_or(DependentCost::free()),
644                            smo: value.smo.into(),
645                            srwq: value
646                                .srwq
647                                .map(Into::into)
648                                .unwrap_or(DependentCost::free()),
649                            swwq: value
650                                .swwq
651                                .map(Into::into)
652                                .unwrap_or(DependentCost::free()),
653                            epar: value
654                                .epar
655                                .map(Into::into)
656                                .unwrap_or(DependentCost::free()),
657                            contract_root: value.contract_root.into(),
658                            state_root: value.state_root.into(),
659                            vm_initialization: value.vm_initialization.into(),
660                            new_storage_per_byte: value.new_storage_per_byte.into(),
661                        }
662                        .into(),
663                    ))
664                }
665            }
666            _ => Err(ConversionError::UnknownVariant("GasCostsVersion")),
667        }
668    }
669}
670
671#[derive(cynic::QueryFragment, Clone, Debug)]
672#[cynic(schema_path = "./assets/schema.sdl")]
673pub struct LightOperation {
674    pub base: U64,
675    pub units_per_gas: U64,
676}
677
678#[derive(cynic::QueryFragment, Clone, Debug)]
679#[cynic(schema_path = "./assets/schema.sdl")]
680pub struct HeavyOperation {
681    pub base: U64,
682    pub gas_per_unit: U64,
683}
684
685#[derive(cynic::InlineFragments, Clone, Debug)]
686#[cynic(schema_path = "./assets/schema.sdl")]
687pub enum DependentCost {
688    LightOperation(LightOperation),
689    HeavyOperation(HeavyOperation),
690    #[cynic(fallback)]
691    Unknown,
692}
693
694impl TryFrom<ConsensusParameters> for fuel_core_types::fuel_tx::ConsensusParameters {
695    type Error = ConversionError;
696
697    fn try_from(params: ConsensusParameters) -> Result<Self, Self::Error> {
698        match params.version {
699            ConsensusParametersVersion::V1 => Ok(
700                fuel_core_types::fuel_tx::consensus_parameters::ConsensusParametersV2 {
701                    tx_params: params.tx_params.try_into()?,
702                    predicate_params: params.predicate_params.try_into()?,
703                    script_params: params.script_params.try_into()?,
704                    contract_params: params.contract_params.try_into()?,
705                    fee_params: params.fee_params.try_into()?,
706                    base_asset_id: params.base_asset_id.into(),
707                    block_gas_limit: params.block_gas_limit.into(),
708                    block_transaction_size_limit: params
709                        .block_transaction_size_limit
710                        .into(),
711                    chain_id: params.chain_id.0.into(),
712                    gas_costs: params.gas_costs.try_into()?,
713                    privileged_address: params.privileged_address.into(),
714                }
715                .into(),
716            ),
717            _ => Err(ConversionError::UnknownVariant(
718                "ConsensusParametersVersion",
719            )),
720        }
721    }
722}
723
724#[derive(cynic::QueryFragment, Clone, Debug)]
725#[cynic(schema_path = "./assets/schema.sdl", graphql_type = "Query")]
726pub struct ChainQuery {
727    pub chain: ChainInfo,
728}
729
730#[derive(cynic::QueryFragment, Clone, Debug)]
731#[cynic(schema_path = "./assets/schema.sdl")]
732pub struct ChainInfo {
733    pub da_height: U64,
734    pub name: String,
735    pub latest_block: Block,
736    pub consensus_parameters: ConsensusParameters,
737}
738
739#[cfg(test)]
740mod tests {
741    use super::*;
742
743    #[test]
744    fn chain_gql_query_output() {
745        use cynic::QueryBuilder;
746        let operation = ChainQuery::build(());
747
748        let snapshot_name = if cfg!(feature = "fault-proving") {
749            "chain_gql_query_output_with_tx_id_commitment"
750        } else {
751            "chain_gql_query_output"
752        };
753
754        insta::assert_snapshot!(snapshot_name, operation.query)
755    }
756}