Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bladyjoker committed May 17, 2022
1 parent 1736042 commit fcfb1bb
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 72 deletions.
4 changes: 1 addition & 3 deletions nix/purescript-bridge-typelib-spago/packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ let additions =
, "affjax"
, "argonaut"
, "argonaut-codecs"
, "argonaut-core"
, "arraybuffer-types"
, "arrays"
, "bifunctors"
Expand Down Expand Up @@ -150,7 +149,6 @@ let additions =
, "node-fs-aff"
, "node-path"
, "nonempty"
, "numbers"
, "ordered-collections"
, "partial"
, "prelude"
Expand All @@ -177,7 +175,7 @@ let additions =
, "variant"
]
, repo = "https://github.com/plutonomicon/cardano-transaction-lib.git"
, version = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1"
, version = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0"
}
, aeson =
{ dependencies =
Expand Down
6 changes: 3 additions & 3 deletions nix/purescript-bridge-typelib-spago/spago-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 2 additions & 3 deletions nix/purescript-bridge-typelib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion plutus-ledger-api-typelib/Plutus/V1/Ledger/Ada.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plutus-ledger-api-typelib/Plutus/V1/Ledger/Bytes.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
10 changes: 6 additions & 4 deletions plutus-ledger-api-typelib/Plutus/V1/Ledger/Crypto.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions plutus-ledger-api-typelib/Plutus/V1/Ledger/Scripts.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plutus-ledger-api-typelib/Plutus/V1/Ledger/Slot.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plutus-ledger-api-typelib/Plutus/V1/Ledger/Time.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions plutus-ledger-api-typelib/Plutus/V1/Ledger/TxId.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand Down
2 changes: 1 addition & 1 deletion plutus-ledger-api-typelib/Plutus/V1/Ledger/Value.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions src/Language/PureScript/Bridge/Printer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions test/RoundTrip/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -100,7 +99,6 @@ instance Arbitrary TestSum where
, NT <$> arbitrary
, NTRecord <$> arbitrary
, Map <$> arbitrary
, Set <$> arbitrary
, TwoFields <$> arbitrary
, pure $ Unit ()
, Pair <$> arbitrary
Expand Down
2 changes: 1 addition & 1 deletion test/RoundTrip/app/packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ let additions =
, "variant"
]
, repo = "https://github.com/plutonomicon/cardano-transaction-lib.git"
, version = "30f1fc2d7ab64406787e56c5b9399402ca6e6ae1"
, version = "9cc8b10a9b5f49897ca3533f32f54f009f6b67a0"
}
, aeson =
{ dependencies =
Expand Down
6 changes: 3 additions & 3 deletions test/RoundTrip/app/spago-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 5 additions & 1 deletion test/RoundTrip/app/spago.dhall
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading

0 comments on commit fcfb1bb

Please sign in to comment.