Skip to content

Commit 3434539

Browse files
committed
Done with parsing the sample.pd.cbor in Plutarch
1 parent 986260b commit 3434539

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

coop-plutus/resources/sample.json

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
{
2-
"array": [
3-
1,
4-
2,
5-
3
6-
],
7-
"boolean": true,
8-
"null": null,
9-
"integer": 123,
10-
"big_integer": 12300000000000000000000000,
11-
"real": 123.123,
12-
"big_real": 12300000000000000000000000.123,
13-
"object": {
14-
"a": "b",
15-
"c": "d"
16-
},
17-
"string": "Hello World"
2+
"array": [
3+
1,
4+
2,
5+
3
6+
],
7+
"boolean": true,
8+
"null": null,
9+
"integer": 123,
10+
"big_integer": 12300000000000000000000000,
11+
"real": 123.123,
12+
"big_real": 12300000000000000000000000.123,
13+
"string": "Hello World"
1814
}
-16 Bytes
Binary file not shown.

coop-plutus/src/Coop/Plutus.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Plutarch.Extra.Interval (pcontains)
2626
import Plutarch.List (pmap)
2727
import Plutarch.Monadic qualified as P
2828
import Plutarch.Num (PNum (pnegate, (#+)))
29-
import Plutarch.Prelude (ClosedTerm, PAsData, PBuiltinList, PByteString, PData, PEq ((#==)), PInteger, PListLike (pcons, phead, pnil), PMaybe (PJust), PPair (PPair), PPartialOrd ((#<), (#<=)), Term, pcon, pconsBS, pconstant, pdata, pfield, pfoldl, pfromData, phoistAcyclic, plam, plet, pletFields, ptrace, ptraceError, (#), (#$), type (:-->))
29+
import Plutarch.Prelude (ClosedTerm, PAsData, PBuiltinList, PByteString, PData, PEq ((#==)), PInteger, PListLike (pcons, phead, pnil), PMaybe (PJust), PPair (PPair), PPartialOrd ((#<), (#<=)), Term, pcon, pconsBS, pconstant, pfield, pfoldl, pfromData, phoistAcyclic, plam, plet, pletFields, ptrace, ptraceError, (#), (#$), type (:-->))
3030
import PlutusTx.Prelude (Group (inv))
3131
import Prelude (Monoid (mempty), Semigroup ((<>)), ($), (.))
3232

@@ -651,13 +651,18 @@ exampleConsumer = phoistAcyclic $
651651
_ <- plet $ pif ((pfstBuiltin # real'') #== 3) (popaque punit) (ptraceError "Expected a Plutus Constr 3 [123123, -3]")
652652
_ <- plet $ pif (real''' #== pconstant [123123, -3]) (popaque punit) (ptraceError "Expected a Plutus Constr 3 [123123, -3]")
653653

654-
-- Take the "big_real" field in the Fact Statement and assert that it is 123.123
654+
-- Take the "big_real" field in the Fact Statement and assert that it is 12300000000000000000000000.123
655655
PJust big_real' <- pmatch $ plookup # pconstant "big_real" # factStatement
656656
big_real'' :: Term s (PBuiltinPair PInteger (PBuiltinList PData)) <- plet $ pasConstr # big_real'
657657
big_real''' :: Term s (PBuiltinList PInteger) <- plet $ pmap # plam (pfromData . ptryFromData) # (psndBuiltin # big_real'')
658658
_ <- plet $ pif ((pfstBuiltin # big_real'') #== 3) (popaque punit) (ptraceError "Expected a Plutus Constr 3 [12300000000000000000000000123, -3]")
659659
_ <- plet $ pif (big_real''' #== pconstant [12300000000000000000000000123, -3]) (popaque punit) (ptraceError "Expected a Plutus Constr 3 [12300000000000000000000000123, -3]")
660660

661-
ptrace "exampleConsumer: Must have a Fact Statement reference input from a trusted COOP Oracle" $ popaque punit
661+
-- Take the "string" field in the Fact Statement and assert that it is "Hello World"
662+
PJust string' <- pmatch $ plookup # pconstant "string" # factStatement
663+
string'' :: Term s PByteString <- plet $ pfromData $ ptryFromData string'
664+
_ <- plet $ pif (string'' #== pconstant "Hello World") (popaque punit) (ptraceError "Expected a Plutus Bytestring \"Hello World\"")
665+
666+
ptrace "exampleConsumer: Everything worked!" $ popaque punit
662667
)
663668
(ptraceError "exampleConsumer: Must have a Fact Statement reference input from a trusted COOP Oracle")

0 commit comments

Comments
 (0)