Skip to content

Commit 1b741b1

Browse files
committed
Done with boolean and null
1 parent 9902bb2 commit 1b741b1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

coop-plutus/src/Coop/Plutus.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import Plutarch.Api.V1.Value (passertPositive, pnormalize, pvalueOf)
1919
import Plutarch.Api.V1.Value qualified as PValue
2020
import Plutarch.Api.V2 (AmountGuarantees (NonZero, Positive), KeyGuarantees (Sorted, Unsorted), PCurrencySymbol, PMap, PMaybeData, PMintingPolicy, PTokenName (PTokenName), PTuple, PTxInInfo, PTxOut, PValidator, PValue)
2121
import Plutarch.Api.V2.Contexts (PScriptContext)
22-
import Plutarch.Bool (pif)
22+
import Plutarch.Bool (PBool, pif)
23+
import Plutarch.Builtin (PBuiltinPair, pasConstr, pfstBuiltin, psndBuiltin)
2324
import Plutarch.Crypto (pblake2b_256)
2425
import Plutarch.Extra.Interval (pcontains)
2526
import Plutarch.List (pmap)
@@ -613,12 +614,23 @@ exampleConsumer = phoistAcyclic $
613614
factStatement :: Term s (PMap 'Unsorted PByteString PData) <- plet $ pfromData $ ptryFromData fsDatum.fd'fs
614615

615616
-- Take the "array" field in the Fact Statement and assert that it is [1,2,3]
616-
PJust arrayNumbersPd <- pmatch $ plookup # pconstant "array" # factStatement
617+
PJust arrayNumbers''' <- pmatch $ plookup # pconstant "array" # factStatement
617618
-- Parse it as Plutus List
618-
arrayNumbers :: Term s (PBuiltinList (PAsData PInteger)) <- plet $ pfromData $ ptryFromData arrayNumbersPd
619+
arrayNumbers' :: Term s (PBuiltinList (PAsData PInteger)) <- plet $ pfromData $ ptryFromData arrayNumbers'''
619620
-- Parse the elements within as Plutus Integer
620-
arrayNumbers' <- plet $ pmap # plam pfromData # arrayNumbers
621-
_ <- plet $ pif (arrayNumbers' #== pconstant [1, 2, 3]) (popaque punit) (ptraceError "Expected a Plutus List [1,2,3]")
621+
arrayNumbers <- plet $ pmap # plam pfromData # arrayNumbers'
622+
_ <- plet $ pif (arrayNumbers #== pconstant [1, 2, 3]) (popaque punit) (ptraceError "Expected a Plutus List [1,2,3]")
623+
624+
-- Take the "boolean" field in the Fact Statement and assert that it is true
625+
PJust boolean' <- pmatch $ plookup # pconstant "boolean" # factStatement
626+
boolean :: Term s PBool <- plet $ pfromData $ ptryFromData boolean'
627+
_ <- plet $ pif boolean (popaque punit) (ptraceError "Expected a Plutus Boolean true")
628+
629+
-- Take the "null" field in the Fact Statement and assert that it is null
630+
PJust null' <- pmatch $ plookup # pconstant "null" # factStatement
631+
null'' :: Term s (PBuiltinPair PInteger (PBuiltinList PData)) <- plet $ pasConstr # null'
632+
_ <- plet $ pif ((pfstBuiltin # null'') #== 2) (popaque punit) (ptraceError "Expected a Plutus Boolean type (Constr 2 [])")
633+
_ <- plet $ pif ((psndBuiltin # null'') #== pconstant []) (popaque punit) (ptraceError "Expected a Plutus Boolean type (Constr 2 [])")
622634

623635
ptrace "exampleConsumer: Must have a Fact Statement reference input from a trusted COOP Oracle" $ popaque punit
624636
)

0 commit comments

Comments
 (0)