Skip to main content

ovmi/predicates/
is_contained.rs

1use crate::executor::*;
2use crate::predicates::*;
3use crate::Range;
4
5pub struct IsContainedPredicate<'a, Ext: ExternalCall> {
6    pub ext: &'a Ext,
7}
8
9impl<Ext: ExternalCall> AtomicPredicateInterface<AddressOf<Ext>> for IsContainedPredicate<'_, Ext> {
10    fn decide(&self, inputs: Vec<Vec<u8>>) -> ExecResult<AddressOf<Ext>> {
11        require!(inputs.len() > 1);
12        let range: Range = Ext::bytes_to_range(&inputs[0])?;
13        let sub_range: Range = Ext::bytes_to_range(&inputs[1])?;
14        require_with_message!(
15            range.start <= sub_range.start && sub_range.end <= range.end,
16            "range must contain subrange"
17        );
18        Ok(true)
19    }
20}
21
22impl<Ext: ExternalCall> AtomicHelperInterface<AddressOf<Ext>> for IsContainedPredicate<'_, Ext> {
23    type Hash = HashOf<Ext>;
24    fn ext_address(&self) -> AddressOf<Ext> {
25        self.ext.ext_address()
26    }
27    fn ext_set_predicate_decision(
28        &self,
29        game_id: Self::Hash,
30        decision: bool,
31    ) -> ExecResult<AddressOf<Ext>> {
32        self.ext.ext_set_predicate_decision(game_id, decision)
33    }
34    fn ext_get_property_id(&self, property: &Property<AddressOf<Ext>>) -> Self::Hash {
35        self.ext.ext_get_property_id(property)
36    }
37}
38
39impl<Ext: ExternalCall> DecidablePredicateInterface<AddressOf<Ext>>
40    for IsContainedPredicate<'_, Ext>
41{
42    fn decide_with_witness(
43        &self,
44        inputs: Vec<Vec<u8>>,
45        _witness: Vec<Vec<u8>>,
46    ) -> ExecResult<AddressOf<Ext>> {
47        Self::decide(self, inputs)
48    }
49}
50
51impl<Ext: ExternalCall> BaseAtomicPredicateInterface<AddressOf<Ext>>
52    for IsContainedPredicate<'_, Ext>
53{
54}