Skip to content

Commit

Permalink
Update transaction-builder to a CSL12-compatible version
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Aug 30, 2024
1 parent 35502bd commit be1ba08
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 34 deletions.
6 changes: 3 additions & 3 deletions packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ let additions =
]
, repo =
"https://github.com/mlabs-haskell/purescript-cardano-serialization-lib"
, version = "0062d27a87b2d27ddd87f2bf4aaf34e6413e5e7c"
, version = "v2.0.0"
}
, cardano-plutus-data-schema =
{ dependencies = [ "prelude" ]
Expand Down Expand Up @@ -372,7 +372,7 @@ let additions =
, "unsafe-coerce"
]
, repo = "https://github.com/mlabs-haskell/purescript-cardano-types"
, version = "8f9e5d0e0a465990024fac7c8e8db36fcd56ab8c"
, version = "b084f05e1cc8c4e99fce2c42cf988590555c0ca7"
}
, cardano-message-signing =
{ dependencies =
Expand Down Expand Up @@ -453,7 +453,7 @@ let additions =
]
, repo =
"https://github.com/mlabs-haskell/purescript-cardano-transaction-builder"
, version = "a9c033b9a2bb78b134ae5309209f73e47f3d5791"
, version = "5b428f619a35dd927456f9042314b586b8b7d117"
}
, mote-testplan =
{ dependencies =
Expand Down
18 changes: 9 additions & 9 deletions spago-packages.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions src/Internal/Types/Val.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import Cardano.Types
import Cardano.Types.AssetName (fromAssetName)
import Cardano.Types.BigNum as BigNum
import Cardano.Types.Int as Int
import Cardano.Types.Mint (Mint(Mint))
import Cardano.Types.Mint (Mint)
import Cardano.Types.Mint as Mint
import Cardano.Types.MultiAsset as MultiAsset
import Data.Array (cons)
import Data.Array (cons, foldr)
import Data.Bifunctor (bimap)
import Data.ByteArray (byteArrayToHex)
import Data.Foldable (all)
Expand All @@ -31,7 +32,7 @@ import Data.Map as Map
import Data.Maybe (Maybe, fromMaybe)
import Data.Newtype (unwrap, wrap)
import Data.Show.Generic (genericShow)
import Data.These (These(This, That, Both))
import Data.These (These(This, That, Both), these)
import Data.Traversable (traverse)
import Data.Tuple.Nested (type (/\), (/\))
import JS.BigInt as BigInt
Expand Down Expand Up @@ -171,7 +172,29 @@ fromMultiAsset :: MultiAsset -> Val
fromMultiAsset (MultiAsset ma) = Val zero $ map (map BigNum.toBigInt) ma

fromMint :: Mint -> Val
fromMint (Mint ma) = Val zero $ map (map Int.toBigInt) $ ma
fromMint mint =
Val zero $ foldr insert Map.empty $ Mint.flatten mint
where
insert
:: (ScriptHash /\ AssetName /\ Int.Int)
-> Map ScriptHash (Map AssetName BigInt)
-> Map ScriptHash (Map AssetName BigInt)
insert (scriptHash /\ assetName /\ amount) ma =
map joinAssets $
MultiAsset.union
ma
( Map.singleton scriptHash $ Map.singleton assetName $ Int.toBigInt
amount
)

joinAssets
:: These (Map AssetName BigInt) (Map AssetName BigInt)
-> Map AssetName BigInt
joinAssets = these identity identity
(\x y -> map unBoth $ MultiAsset.union x y)
unBoth (Both a b) = add a b
unBoth (This a) = a
unBoth (That b) = b

minus :: Val -> Val -> Val
minus (Val a ma) (Val b mb) = Val (a - b) (unionWithNonAda (-) ma mb)
Expand Down
4 changes: 2 additions & 2 deletions templates/ctl-scaffold/packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ let additions =
]
, repo =
"https://github.com/mlabs-haskell/purescript-cardano-serialization-lib"
, version = "v1.0.0"
, version = "v2.0.0"
}
, cardano-plutus-data-schema =
{ dependencies = [ "prelude" ]
Expand Down Expand Up @@ -372,7 +372,7 @@ let additions =
, "unsafe-coerce"
]
, repo = "https://github.com/mlabs-haskell/purescript-cardano-types"
, version = "v2.0.1"
, version = "b084f05e1cc8c4e99fce2c42cf988590555c0ca7"
}
, cardano-message-signing =
{ dependencies =
Expand Down
12 changes: 6 additions & 6 deletions templates/ctl-scaffold/spago-packages.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions test/Fixtures.purs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Test.Ctl.Fixtures
, ed25519KeyHashFixture1
, fullyAppliedScriptFixture
, int1
, mint0
, mint1
, mkSampleTx
, mkTxInput
Expand Down Expand Up @@ -346,15 +345,9 @@ txFixture1 =

mint1 :: Mint
mint1 = Mint $ Map.fromFoldable
[ currencySymbol1 /\ Map.fromFoldable
[ tokenName2 /\ Int.newPositive BigNum.one
]
]

mint0 :: Mint
mint0 = Mint $ Map.fromFoldable
[ currencySymbol1 /\ Map.fromFoldable
[ tokenName2 /\ Int.newPositive BigNum.zero
[ currencySymbol1 /\
[ Map.fromFoldable
[ tokenName2 /\ Int.newPositive BigNum.one ]
]
]

Expand Down

0 comments on commit be1ba08

Please sign in to comment.