@@ -24,10 +24,10 @@ import Plutarch.Internal.Term (
2424import Plutarch.LedgerApi.V1 (PCurrencySymbol (PCurrencySymbol ), PTokenName (PTokenName ), pposixTime )
2525import Plutarch.LedgerApi.Value (PAssetClass (PAssetClass ))
2626import Plutarch.Maybe qualified as Scott
27- import Plutarch.Prelude (ClosedTerm , PAsData , PBool (PFalse , PTrue ), PBuiltinList , PByteString , PDataNewtype ( PDataNewtype ), PEq ((#==) ), PIsData , PlutusType , Term , pcon , pconstant , pdata , perror , pfind , pfromData , pif , plam , pletC , pmatch , pmatchC , ppairDataBuiltin , pshow , ptraceInfo , unTermCont , (#) , (#&&) , (:-->) )
27+ import Plutarch.Prelude (ClosedTerm , PAsData , PBool (PFalse , PTrue ), PBuiltinList , PByteString , PEq ((#==) ), PIsData , PlutusType , Term , pcon , pconstant , pdata , perror , pfind , pfromData , pif , plam , pletC , pmatch , pmatchC , ppairDataBuiltin , pshow , ptraceInfo , unTermCont , (#) , (#&&) , (:-->) )
2828
2929userRef :: Text -> Term s (Ref User )
30- userRef userName = userRef' (pfromData $ name userName)
30+ userRef userName = userRef' (textToBytes userName)
3131
3232userRef' :: Term s Bytes -> Term s (Ref User )
3333userRef' userName = pcon $ Ref (pdata (userRefAssetClass userName))
@@ -36,24 +36,17 @@ userRefAssetClass :: Term s Bytes -> Term s PAssetClass
3636userRefAssetClass userName =
3737 pcon $
3838 PAssetClass
39- ( pcon $
40- PDataNewtype
41- ( pdata $
42- ppairDataBuiltin
43- # pcon' (PCurrencySymbol $ pcon $ PDataNewtype $ name " users" )
44- # pcon' (PTokenName $ pcon $ PDataNewtype $ pdata userName)
45- )
39+ ( ppairDataBuiltin
40+ # pcon' (PCurrencySymbol $ textToBytes " users" )
41+ # pcon' (PTokenName userName)
4642 )
4743
4844activeUser :: Text -> [Term s (Ref User )] -> Integer -> Term s User
49- activeUser n friends since = pcon $ User (name n) (pdata $ activeSince since) (pdata $ Lb. plistFrom friends)
45+ activeUser n friends since = pcon $ User (pdata $ textToBytes n) (pdata $ activeSince since) (pdata $ Lb. plistFrom friends)
5046
5147activeSince :: Integer -> Term s Status
5248activeSince since = pcon (Status'Active (pdata (pposixTime (pconstantInteger since))))
5349
54- name :: Text -> Term s (PAsData PByteString )
55- name = textToBytes
56-
5750message :: Term s POSIXTime -> Term s (Ref User ) -> Term s (Ref User ) -> Term s Content -> Term s Message
5851message at from to content = pcon $ Message (pdata at) (pdata from) (pdata to) (pdata content)
5952
@@ -68,7 +61,7 @@ isFriendly = plam $ \users msg -> unTermCont $ do
6861 pif
6962 ( (isFriend # fromFriends # toName)
7063 #== (isFriend # toFriends # fromName)
71- #&& (content #== pcon' (Content'Text (textToBytes " 'sup" )))
64+ #&& (content #== pcon' (Content'Text (pdata $ textToBytes " 'sup" )))
7265 )
7366 (pcon PTrue )
7467 (ptraceInfo (" This wasn't a friendly message :(" <> pshow msg) perror)
@@ -102,8 +95,8 @@ isFriendly = plam $ \users msg -> unTermCont $ do
10295pcon' :: PIsData a => PlutusType a => a s -> Term s (PAsData a )
10396pcon' = pdata . pcon
10497
105- textToBytes :: Text -> Term s ( PAsData PByteString )
106- textToBytes = pdata . pconstant . Text. encodeUtf8
98+ textToBytes :: Text -> Term s PByteString
99+ textToBytes = pconstant . Text. encodeUtf8
107100
108101toBuiltinList :: Term s (Lb. PList a :--> PBuiltinList (PAsData a ))
109102toBuiltinList = plam $ \ xs -> pmatch xs (\ (Lb. PList xs') -> xs')
@@ -127,7 +120,7 @@ jared :: Term s User
127120jared = activeUser " Jared Pon" [userRef " Gergely Szabó" , userRef " Drazen Popovic" ] 2
128121
129122supJaredSaidGergo :: Term s Message
130- supJaredSaidGergo = message (pposixTime (pconstantInteger 10 )) (userRef " Gergely Szabó" ) (userRef " Jared Pon" ) (pcon $ Content'Text (textToBytes " 'sup" ))
123+ supJaredSaidGergo = message (pposixTime (pconstantInteger 10 )) (userRef " Gergely Szabó" ) (userRef " Jared Pon" ) (pcon $ Content'Text (pdata $ textToBytes " 'sup" ))
131124
132125main :: IO ()
133126main = evalBool $ isFriendly # Lb. plistFrom [drazen, gergo, jared] # supJaredSaidGergo
0 commit comments