1use alloc::{
7 collections::BTreeSet,
8 vec::Vec,
9};
10
11use fuel_tx::{
12 ContractId,
13 PanicReason,
14};
15
16use crate::{
17 error::PanicOrBug,
18 interpreter::PanicContext,
19};
20
21trait Seal {}
24
25#[allow(private_bounds)] pub trait Verifier
28where
29 Self: Sized + Seal,
30{
31 #[allow(private_interfaces)] fn check_contract_in_inputs(
34 &mut self,
35 panic_context: &mut PanicContext,
36 input_contracts: &BTreeSet<ContractId>,
37 contract_id: &ContractId,
38 ) -> Result<(), PanicOrBug>;
39}
40
41#[derive(Debug, Copy, Clone, Default)]
44pub struct Normal;
45
46impl Verifier for Normal
47where
48 Self: Sized,
49{
50 #[allow(private_interfaces)]
51 fn check_contract_in_inputs(
52 &mut self,
53 panic_context: &mut PanicContext,
54 input_contracts: &BTreeSet<ContractId>,
55 contract_id: &ContractId,
56 ) -> Result<(), PanicOrBug> {
57 if input_contracts.contains(contract_id) {
58 Ok(())
59 } else {
60 *panic_context = PanicContext::ContractId(*contract_id);
61 Err(PanicReason::ContractNotInInputs.into())
62 }
63 }
64}
65
66impl Seal for Normal {}
67
68#[derive(Debug, Clone, Default)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72#[non_exhaustive]
73pub struct AttemptContinue {
74 pub missing_contract_inputs: Vec<ContractId>,
76}
77
78impl Verifier for AttemptContinue
79where
80 Self: Sized,
81{
82 #[allow(private_interfaces)]
83 fn check_contract_in_inputs(
84 &mut self,
85 _panic_context: &mut PanicContext,
86 input_contracts: &BTreeSet<ContractId>,
87 contract_id: &ContractId,
88 ) -> Result<(), PanicOrBug> {
89 if !input_contracts.contains(contract_id) {
90 self.missing_contract_inputs.push(*contract_id);
91 }
92 Ok(())
93 }
94}
95
96impl Seal for AttemptContinue {}