use crate::executor::*;
use crate::predicates::*;
pub struct EqualPredicate<'a, Ext: ExternalCall> {
pub ext: &'a Ext,
}
impl<Ext: ExternalCall> AtomicPredicateInterface<AddressOf<Ext>> for EqualPredicate<'_, Ext> {
fn decide(&self, inputs: Vec<Vec<u8>>) -> ExecResult<AddressOf<Ext>> {
require!(inputs.len() > 1);
require_with_message!(inputs[0] == inputs[1], "2 inputs must be equal");
Ok(true)
}
}
impl<Ext: ExternalCall> AtomicHelperInterface<AddressOf<Ext>> for EqualPredicate<'_, Ext> {
type Hash = HashOf<Ext>;
fn ext_address(&self) -> AddressOf<Ext> {
self.ext.ext_address()
}
fn ext_set_predicate_decision(
&self,
game_id: Self::Hash,
decision: bool,
) -> ExecResult<AddressOf<Ext>> {
self.ext.ext_set_predicate_decision(game_id, decision)
}
fn ext_get_property_id(&self, property: &Property<AddressOf<Ext>>) -> Self::Hash {
self.ext.ext_get_property_id(property)
}
}
impl<Ext: ExternalCall> DecidablePredicateInterface<AddressOf<Ext>> for EqualPredicate<'_, Ext> {
fn decide_with_witness(
&self,
inputs: Vec<Vec<u8>>,
_witness: Vec<Vec<u8>>,
) -> ExecResult<AddressOf<Ext>> {
Self::decide(self, inputs)
}
}
impl<Ext: ExternalCall> BaseAtomicPredicateInterface<AddressOf<Ext>> for EqualPredicate<'_, Ext> {}