use alloc::{
collections::BTreeSet,
vec::Vec,
};
use fuel_tx::{
ContractId,
PanicReason,
};
use crate::{
error::PanicOrBug,
interpreter::PanicContext,
};
trait Seal {}
#[allow(private_bounds)] pub trait Verifier
where
Self: Sized + Seal,
{
#[allow(private_interfaces)] fn check_contract_in_inputs(
&mut self,
panic_context: &mut PanicContext,
input_contracts: &BTreeSet<ContractId>,
contract_id: &ContractId,
) -> Result<(), PanicOrBug>;
}
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
pub struct Normal;
impl Verifier for Normal
where
Self: Sized,
{
#[allow(private_interfaces)]
fn check_contract_in_inputs(
&mut self,
panic_context: &mut PanicContext,
input_contracts: &BTreeSet<ContractId>,
contract_id: &ContractId,
) -> Result<(), PanicOrBug> {
if input_contracts.contains(contract_id) {
Ok(())
} else {
*panic_context = PanicContext::ContractId(*contract_id);
Err(PanicReason::ContractNotInInputs.into())
}
}
}
impl Seal for Normal {}
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub struct AttemptContinue {
pub missing_contract_inputs: Vec<ContractId>,
}
impl Verifier for AttemptContinue
where
Self: Sized,
{
#[allow(private_interfaces)]
fn check_contract_in_inputs(
&mut self,
_panic_context: &mut PanicContext,
input_contracts: &BTreeSet<ContractId>,
contract_id: &ContractId,
) -> Result<(), PanicOrBug> {
if !input_contracts.contains(contract_id) {
self.missing_contract_inputs.push(*contract_id);
}
Ok(())
}
}
impl Seal for AttemptContinue {}