diff --git a/nix/purescript-bridge-typelib-spago/packages.dhall b/nix/purescript-bridge-typelib-spago/packages.dhall index f8516fdf..b83f460a 100644 --- a/nix/purescript-bridge-typelib-spago/packages.dhall +++ b/nix/purescript-bridge-typelib-spago/packages.dhall @@ -117,7 +117,6 @@ let additions = , "affjax" , "argonaut" , "argonaut-codecs" - , "argonaut-core" , "arraybuffer-types" , "arrays" , "bifunctors" @@ -150,7 +149,6 @@ let additions = , "node-fs-aff" , "node-path" , "nonempty" - , "numbers" , "ordered-collections" , "partial" , "prelude" @@ -177,7 +175,7 @@ let additions = , "variant" ] , repo = "https://github.com/plutonomicon/cardano-transaction-lib.git" - , version = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1" + , version = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0" } , aeson = { dependencies = diff --git a/nix/purescript-bridge-typelib-spago/spago-packages.nix b/nix/purescript-bridge-typelib-spago/spago-packages.nix index 263fb77c..42712654 100644 --- a/nix/purescript-bridge-typelib-spago/spago-packages.nix +++ b/nix/purescript-bridge-typelib-spago/spago-packages.nix @@ -199,11 +199,11 @@ let "cardano-transaction-lib" = pkgs.stdenv.mkDerivation { name = "cardano-transaction-lib"; - version = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1"; + version = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0"; src = pkgs.fetchgit { url = "https://github.com/plutonomicon/cardano-transaction-lib.git"; - rev = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1"; - sha256 = "0v0k7mm59s9hik77jmrisns5bxja5c2vxk0wcfzsjfw95w145j0k"; + rev = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0"; + sha256 = "1acm9yz4v9nv7drjdkfkbm2lrh3rqqy47n49dxmknq0n5hhqcck3"; }; phases = "installPhase"; installPhase = "ln -s $src $out"; diff --git a/nix/purescript-bridge-typelib.nix b/nix/purescript-bridge-typelib.nix index a3d79bd1..43bd7a1c 100644 --- a/nix/purescript-bridge-typelib.nix +++ b/nix/purescript-bridge-typelib.nix @@ -6,9 +6,8 @@ pkgs.stdenv.mkDerivation { buildInputs = [ purs installSpagoStyle buildFromNixStore ]; doCheck = true; buildPhase = '' - set -vox - mkdir src - cp -r ${pursDir} src/ + mkdir src + cp -r ${pursDir} src/ ''; checkPhase = '' install-spago-style diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Ada.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Ada.purs index 12bfbfe0..d5690c0a 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Ada.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Ada.purs @@ -46,7 +46,8 @@ derive newtype instance ToData Ada derive newtype instance FromData Ada instance EncodeAeson Ada where - encodeAeson x = E.encode (E.record { getLovelace: E.value :: _ (BigInt) }) + encodeAeson' x = pure $ E.encode + (E.record { getLovelace: E.value :: _ (BigInt) }) { getLovelace: unwrap x } instance DecodeAeson Ada where diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Bytes.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Bytes.purs index 8ca18e42..6bad708c 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Bytes.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Bytes.purs @@ -46,7 +46,7 @@ derive newtype instance ToData LedgerBytes derive newtype instance FromData LedgerBytes instance EncodeAeson LedgerBytes where - encodeAeson x = E.encode + encodeAeson' x = pure $ E.encode (E.record { getLedgerBytes: E.value :: _ (ByteArray) }) { getLedgerBytes: unwrap x } diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Crypto.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Crypto.purs index 8aa6fd26..c514ce59 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Crypto.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Crypto.purs @@ -47,7 +47,8 @@ derive newtype instance ToData PubKey derive newtype instance FromData PubKey instance EncodeAeson PubKey where - encodeAeson x = E.encode (E.record { getPubKey: E.value :: _ (LedgerBytes) }) + encodeAeson' x = pure $ E.encode + (E.record { getPubKey: E.value :: _ (LedgerBytes) }) { getPubKey: unwrap x } instance DecodeAeson PubKey where @@ -76,7 +77,7 @@ derive newtype instance ToData PubKeyHash derive newtype instance FromData PubKeyHash instance EncodeAeson PubKeyHash where - encodeAeson x = E.encode + encodeAeson' x = pure $ E.encode (E.record { getPubKeyHash: E.value :: _ (ByteArray) }) { getPubKeyHash: unwrap x } @@ -106,7 +107,7 @@ derive newtype instance ToData PrivateKey derive newtype instance FromData PrivateKey instance EncodeAeson PrivateKey where - encodeAeson x = E.encode + encodeAeson' x = pure $ E.encode (E.record { getPrivateKey: E.value :: _ (LedgerBytes) }) { getPrivateKey: unwrap x } @@ -136,7 +137,8 @@ derive newtype instance ToData Signature derive newtype instance FromData Signature instance EncodeAeson Signature where - encodeAeson x = E.encode (E.record { getSignature: E.value :: _ (ByteArray) }) + encodeAeson' x = pure $ E.encode + (E.record { getSignature: E.value :: _ (ByteArray) }) { getSignature: unwrap x } instance DecodeAeson Signature where diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Scripts.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Scripts.purs index 4a2cc205..d0e36c98 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Scripts.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Scripts.purs @@ -47,7 +47,8 @@ derive newtype instance ToData Redeemer derive newtype instance FromData Redeemer instance EncodeAeson Redeemer where - encodeAeson x = E.encode (E.record { getRedeemer: E.value :: _ (PlutusData) }) + encodeAeson' x = pure $ E.encode + (E.record { getRedeemer: E.value :: _ (PlutusData) }) { getRedeemer: unwrap x } instance DecodeAeson Redeemer where @@ -76,7 +77,8 @@ derive newtype instance ToData Datum derive newtype instance FromData Datum instance EncodeAeson Datum where - encodeAeson x = E.encode (E.record { getDatum: E.value :: _ (PlutusData) }) + encodeAeson' x = pure $ E.encode + (E.record { getDatum: E.value :: _ (PlutusData) }) { getDatum: unwrap x } instance DecodeAeson Datum where @@ -105,7 +107,7 @@ derive newtype instance ToData ScriptHash derive newtype instance FromData ScriptHash instance EncodeAeson ScriptHash where - encodeAeson x = E.encode + encodeAeson' x = pure $ E.encode (E.record { getScriptHash: E.value :: _ (ByteArray) }) { getScriptHash: unwrap x } @@ -135,7 +137,7 @@ derive newtype instance ToData ValidatorHash derive newtype instance FromData ValidatorHash instance EncodeAeson ValidatorHash where - encodeAeson = defer \_ -> E.encode $ unwrap >$< E.value + encodeAeson' x = pure $ (defer \_ -> E.encode $ unwrap >$< E.value) x instance DecodeAeson ValidatorHash where decodeAeson = defer \_ -> D.decode $ (ValidatorHash <$> D.value) @@ -161,7 +163,7 @@ derive newtype instance ToData DatumHash derive newtype instance FromData DatumHash instance EncodeAeson DatumHash where - encodeAeson = defer \_ -> E.encode $ unwrap >$< E.value + encodeAeson' x = pure $ (defer \_ -> E.encode $ unwrap >$< E.value) x instance DecodeAeson DatumHash where decodeAeson = defer \_ -> D.decode $ (DatumHash <$> D.value) @@ -187,7 +189,7 @@ derive newtype instance ToData MintingPolicyHash derive newtype instance FromData MintingPolicyHash instance EncodeAeson MintingPolicyHash where - encodeAeson = defer \_ -> E.encode $ unwrap >$< E.value + encodeAeson' x = pure $ (defer \_ -> E.encode $ unwrap >$< E.value) x instance DecodeAeson MintingPolicyHash where decodeAeson = defer \_ -> D.decode $ (MintingPolicyHash <$> D.value) @@ -213,7 +215,7 @@ derive newtype instance ToData StakeValidatorHash derive newtype instance FromData StakeValidatorHash instance EncodeAeson StakeValidatorHash where - encodeAeson = defer \_ -> E.encode $ unwrap >$< E.value + encodeAeson' x = pure $ (defer \_ -> E.encode $ unwrap >$< E.value) x instance DecodeAeson StakeValidatorHash where decodeAeson = defer \_ -> D.decode $ (StakeValidatorHash <$> D.value) diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Slot.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Slot.purs index 83de6f1f..7f462dc7 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Slot.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Slot.purs @@ -50,7 +50,7 @@ derive newtype instance ToData Slot derive newtype instance FromData Slot instance EncodeAeson Slot where - encodeAeson x = E.encode (E.record { getSlot: E.value :: _ (BigInt) }) + encodeAeson' x = pure $ E.encode (E.record { getSlot: E.value :: _ (BigInt) }) { getSlot: unwrap x } instance DecodeAeson Slot where diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Time.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Time.purs index 0aa5394b..62e258ab 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Time.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Time.purs @@ -49,7 +49,7 @@ derive newtype instance ToData DiffMilliSeconds derive newtype instance FromData DiffMilliSeconds instance EncodeAeson DiffMilliSeconds where - encodeAeson = defer \_ -> E.encode $ unwrap >$< E.value + encodeAeson' x = pure $ (defer \_ -> E.encode $ unwrap >$< E.value) x instance DecodeAeson DiffMilliSeconds where decodeAeson = defer \_ -> D.decode $ (DiffMilliSeconds <$> D.value) @@ -79,7 +79,7 @@ derive newtype instance ToData POSIXTime derive newtype instance FromData POSIXTime instance EncodeAeson POSIXTime where - encodeAeson = defer \_ -> E.encode $ unwrap >$< E.value + encodeAeson' x = pure $ (defer \_ -> E.encode $ unwrap >$< E.value) x instance DecodeAeson POSIXTime where decodeAeson = defer \_ -> D.decode $ (POSIXTime <$> D.value) diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/TxId.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/TxId.purs index 4332b374..3d0f0ddc 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/TxId.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/TxId.purs @@ -57,10 +57,12 @@ instance Show TxId where show a = genericShow a instance EncodeAeson TxId where - encodeAeson = defer \_ -> E.encode $ unwrap >$< - ( E.record - { getTxId: E.value :: _ ByteArray } - ) + encodeAeson' x = pure $ + ( defer \_ -> E.encode $ unwrap >$< + ( E.record + { getTxId: E.value :: _ ByteArray } + ) + ) x instance DecodeAeson TxId where decodeAeson = defer \_ -> D.decode $ diff --git a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Value.purs b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Value.purs index 2cd21dfe..0340dfb6 100644 --- a/plutus-ledger-api-typelib/Plutus/V1/Ledger/Value.purs +++ b/plutus-ledger-api-typelib/Plutus/V1/Ledger/Value.purs @@ -52,7 +52,7 @@ derive newtype instance ToData AssetClass derive newtype instance FromData AssetClass instance EncodeAeson AssetClass where - encodeAeson x = E.encode + encodeAeson' x = pure $ E.encode (E.record { unAssetClass: E.value :: _ (Tuple CurrencySymbol TokenName) }) { unAssetClass: unwrap x } diff --git a/src/Language/PureScript/Bridge/Printer.hs b/src/Language/PureScript/Bridge/Printer.hs index 2f021e13..439a724c 100644 --- a/src/Language/PureScript/Bridge/Printer.hs +++ b/src/Language/PureScript/Bridge/Printer.hs @@ -449,7 +449,7 @@ instances st@(SumType t cs is) = go <$> is [ mkInstance (mkType "EncodeAeson" [t]) encodeJsonConstraints - [ "encodeAeson x = E.encode (E.record {" + [ "encodeAeson' x = pure $ E.encode (E.record {" <> fname <> ": E.value :: _ " <> parens (signature_' tp) @@ -481,7 +481,7 @@ instances st@(SumType t cs is) = go <$> is [ mkInstance (mkType "EncodeAeson" [t]) encodeJsonConstraints - ["encodeAeson = defer \\_ ->" <+> sumTypeToEncode st] + ["encodeAeson' x = pure $ (defer \\_ -> " <+> sumTypeToEncode st <+> ") x"] , mkInstance (mkType "DecodeAeson" [t]) decodeJsonConstraints diff --git a/test/RoundTrip/Types.hs b/test/RoundTrip/Types.hs index 925a70e4..b0f36101 100644 --- a/test/RoundTrip/Types.hs +++ b/test/RoundTrip/Types.hs @@ -31,7 +31,6 @@ module RoundTrip.Types ( import Data.Aeson (FromJSON, ToJSON) import Data.Map (Map) -import Data.Set (Set) import GHC.Generics (Generic) import PlutusTx qualified as P import PlutusTx.Aux (unstableMakeIsData) @@ -57,7 +56,7 @@ instance Arbitrary TestData where data TestSum = Nullary | Bool Bool - | Int Bool -- FIXME: Conflict Argonaut vs PlutusTx (Int vs Integer) + | Int Integer | Number Double | String String | Array [Bool] @@ -68,13 +67,13 @@ data TestSum | NT TestNewtype | NTRecord TestNewtypeRecord | TwoFields TestTwoFields - | Set (Set Bool) - | Map (Map String Bool) + | -- | Set (Set Bool) + Map (Map String Bool) | Unit () | MyUnit MyUnit | Pair (Bool, Double) - | Triple (Bool, (), Bool) - | Quad (Bool, Double, Bool, Double) + | Triple (Bool, (), Integer) + | Quad (Bool, Double, Integer, Double) | QuadSimple Bool Double Bool Double | Recursive TestRecursiveA | Enum TestEnum @@ -100,7 +99,6 @@ instance Arbitrary TestSum where , NT <$> arbitrary , NTRecord <$> arbitrary , Map <$> arbitrary - , Set <$> arbitrary , TwoFields <$> arbitrary , pure $ Unit () , Pair <$> arbitrary diff --git a/test/RoundTrip/app/packages.dhall b/test/RoundTrip/app/packages.dhall index f8516fdf..34c1fff4 100644 --- a/test/RoundTrip/app/packages.dhall +++ b/test/RoundTrip/app/packages.dhall @@ -177,7 +177,7 @@ let additions = , "variant" ] , repo = "https://github.com/plutonomicon/cardano-transaction-lib.git" - , version = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1" + , version = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0" } , aeson = { dependencies = diff --git a/test/RoundTrip/app/spago-packages.nix b/test/RoundTrip/app/spago-packages.nix index 663d59be..4a32a330 100644 --- a/test/RoundTrip/app/spago-packages.nix +++ b/test/RoundTrip/app/spago-packages.nix @@ -199,11 +199,11 @@ let "cardano-transaction-lib" = pkgs.stdenv.mkDerivation { name = "cardano-transaction-lib"; - version = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1"; + version = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0"; src = pkgs.fetchgit { url = "https://github.com/plutonomicon/cardano-transaction-lib.git"; - rev = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1"; - sha256 = "0v0k7mm59s9hik77jmrisns5bxja5c2vxk0wcfzsjfw95w145j0k"; + rev = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0"; + sha256 = "1acm9yz4v9nv7drjdkfkbm2lrh3rqqy47n49dxmknq0n5hhqcck3"; }; phases = "installPhase"; installPhase = "ln -s $src $out"; diff --git a/test/RoundTrip/app/spago.dhall b/test/RoundTrip/app/spago.dhall index b60769fa..ba268e14 100644 --- a/test/RoundTrip/app/spago.dhall +++ b/test/RoundTrip/app/spago.dhall @@ -1,19 +1,23 @@ { name = "roundtip-test" , dependencies = [ "aeson" + , "aeson-helpers" + , "argonaut" + , "bigints" , "cardano-transaction-lib" , "console" + , "contravariant" , "control" , "effect" , "either" , "enums" - , "aeson-helpers" , "maybe" , "newtype" , "node-readline" , "ordered-collections" , "prelude" , "profunctor-lenses" + , "record" , "tuples" , "typelevel-prelude" , "untagged-union" diff --git a/test/RoundTrip/app/src/Main.purs b/test/RoundTrip/app/src/Main.purs index 5581655f..4f1e057a 100644 --- a/test/RoundTrip/app/src/Main.purs +++ b/test/RoundTrip/app/src/Main.purs @@ -2,19 +2,18 @@ module Main ( main ) where -import Prelude (Unit, bind, discard, pure, show, (#), ($), (<<<), (<>), (=<<)) -import Aeson (stringify) -import Aeson.Decode - ( JsonDecodeError - , decodeJson - , parseJson - , printJsonDecodeError - ) -import Aeson.Encode (encodeJson) +import Aeson (decodeJsonString, encodeAeson, stringifyAeson) +import Data.Argonaut (JsonDecodeError, printJsonDecodeError) import Data.Either (either, Either(Left, Right)) +import Data.Maybe (maybe, Maybe) +import Deserialization.FromBytes (fromBytes', FromBytesError) +import Deserialization.PlutusData as DeserPd import Effect (Effect) import Effect.Class.Console (error, log) +import Error (E) +import FromData (fromData) import Node.ReadLine (createConsoleInterface, noCompletion, question) +import Prelude (Unit, bind, discard, pure, show, (#), ($), (<<<), (<>)) import RoundTrip.Types ( TestData , TestPlutusData @@ -22,17 +21,12 @@ import RoundTrip.Types , Response(..) , RepType(..) ) -import ToData (toData) -import FromData (fromData) -import Deserialization.FromBytes (fromBytes', FromBytesError) -import Error (E) -import Data.Maybe (maybe, Maybe) +import Serialization (toBytes) +import Serialization.PlutusData as SerPd import Serialization.Types (PlutusData) +import ToData (toData) import Type.Row (type (+)) -import Deserialization.PlutusData as DeserPd -import Serialization.PlutusData as SerPd import Types.ByteArray (hexToByteArray, byteArrayToHex) -import Serialization (toBytes) import Untagged.Union (asOneOf) main :: Effect Unit @@ -45,7 +39,7 @@ main = do interface # question "" \input -> do let reqOrErr :: Either JsonDecodeError Request - reqOrErr = decodeJson =<< parseJson input + reqOrErr = decodeJsonString input case reqOrErr of Left err -> do error $ "ps> Wanted Request got error: " <> printJsonDecodeError err @@ -56,11 +50,11 @@ main = do either ( \err -> do error err - log $ stringify $ encodeJson $ RespError err + log $ stringifyAeson $ encodeAeson $ RespError err ) ( \resp -> do error "" - log $ stringify $ encodeJson $ resp + log $ stringifyAeson $ encodeAeson $ resp ) (handleReq req) go interface @@ -73,8 +67,8 @@ handleReq (Req RTJson str) = do <> str ) pure - (decodeJson =<< parseJson str :: Either JsonDecodeError TestData) - let payload = stringify $ encodeJson testData + (decodeJsonString str :: Either JsonDecodeError TestData) + let payload = stringifyAeson $ encodeAeson testData pure $ RespSuccess RTJson payload handleReq (Req RTPlutusData hex) = do -- Base16 -> ByteArray -> Cbor-> Foreign PlutusData -> CTL PlutusData -> TestPlutusData diff --git a/test/expected/plutus-codegen/RecordWithPlutusScripts.purs b/test/expected/plutus-codegen/RecordWithPlutusScripts.purs index cbe05ef7..6137b901 100644 --- a/test/expected/plutus-codegen/RecordWithPlutusScripts.purs +++ b/test/expected/plutus-codegen/RecordWithPlutusScripts.purs @@ -23,10 +23,10 @@ newtype RecordWithPlutusScripts = RecordWithPlutusScripts } instance EncodeAeson RecordWithPlutusScripts where - encodeAeson = defer \_ -> E.encode $ unwrap >$< (E.record - { mintingPolicy: E.value :: _ MintingPolicy - , validator: E.value :: _ Validator - }) + encodeAeson' x = pure $ (defer \_ -> E.encode $ unwrap >$< (E.record + { mintingPolicy: E.value :: _ MintingPolicy + , validator: E.value :: _ Validator + }) ) x instance DecodeAeson RecordWithPlutusScripts where decodeAeson = defer \_ -> D.decode $ (RecordWithPlutusScripts <$> D.record "RecordWithPlutusScripts" diff --git a/test/expected/plutus-codegen/TwoRecordsWithDataAndJson.purs b/test/expected/plutus-codegen/TwoRecordsWithDataAndJson.purs index 6bdb17a6..e93a6fee 100644 --- a/test/expected/plutus-codegen/TwoRecordsWithDataAndJson.purs +++ b/test/expected/plutus-codegen/TwoRecordsWithDataAndJson.purs @@ -33,7 +33,7 @@ data TwoRecords } instance EncodeAeson TwoRecords where - encodeAeson = defer \_ -> case _ of + encodeAeson' x = pure $ (defer \_ -> case _ of FirstRecord {_fra, _frb} -> encodeAeson { tag: "FirstRecord" , _fra: flip E.encode _fra E.value @@ -43,7 +43,7 @@ instance EncodeAeson TwoRecords where { tag: "SecondRecord" , _src: flip E.encode _src E.value , _srd: flip E.encode _srd E.value - } + } ) x instance DecodeAeson TwoRecords where decodeAeson = defer \_ -> D.decode