Skip to content

Commit

Permalink
WIP: transition to ps-csl
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Jan 11, 2024
1 parent 31b1392 commit bddb48e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 132 deletions.
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ You can edit this file as you like.
, "node-streams"
, "nonempty"
, "now"
, "nullable"
, "numbers"
, "optparse"
, "ordered-collections"
Expand Down
3 changes: 1 addition & 2 deletions src/Internal/Serialization.purs
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,7 @@ convertMint (T.Mint nonAdaAssets) = do
forWithIndex_ values \tokenName' bigIntValue -> do
let tokenName = TokenName.getTokenName tokenName'
assetName <- newAssetName tokenName
bigInt <- fromJustEff "convertMint: failed to convert BigInt" $
Serialization.convertBigInt bigIntValue
let bigInt = Serialization.convertBigInt bigIntValue
int <- fromJustEff "convertMint: numeric overflow or underflow" $
_bigIntToInt maybeFfiHelper bigInt
insertMintAsset assets assetName int
Expand Down
2 changes: 2 additions & 0 deletions src/Internal/Serialization/AuxiliaryData.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Ctl.Internal.Serialization.AuxiliaryData

import Prelude

import Cardano.Serialization.Lib.Internal (packMapContainerFromMap)
import Ctl.Internal.Cardano.Types.Transaction
( AuxiliaryData(AuxiliaryData)
, AuxiliaryDataHash
Expand Down Expand Up @@ -35,6 +36,7 @@ import Ctl.Internal.Types.TransactionMetadata
import Data.Map as Map
import Data.Newtype (unwrap, wrap)
import Data.Traversable (for, for_, traverse)
import Data.TraversableWithIndex (traverseWithIndex)
import Data.Tuple (Tuple(Tuple))
import Data.Tuple.Nested (type (/\), (/\))
import Effect (Effect)
Expand Down
11 changes: 0 additions & 11 deletions src/Internal/Serialization/BigInt.js

This file was deleted.

13 changes: 7 additions & 6 deletions src/Internal/Serialization/BigInt.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module Ctl.Internal.Serialization.BigInt

import Prelude

import Ctl.Internal.FfiHelpers (MaybeFfiHelper, maybeFfiHelper)
import Cardano.Serialization.Lib (bigInt_fromStr)
import Ctl.Internal.Serialization.Types (BigInt)
import Data.Maybe (Maybe)
import Data.Maybe (fromJust)
import Data.Nullable (toMaybe)
import JS.BigInt as BigInt
import Partial.Unsafe (unsafePartial)

convertBigInt :: BigInt.BigInt -> Maybe BigInt
convertBigInt = _BigInt_from_str maybeFfiHelper <<< BigInt.toString

foreign import _BigInt_from_str :: MaybeFfiHelper -> String -> Maybe BigInt
convertBigInt :: BigInt.BigInt -> BigInt
convertBigInt bi = unsafePartial $ fromJust $ toMaybe $ bigInt_fromStr $
BigInt.toString bi
13 changes: 0 additions & 13 deletions src/Internal/Serialization/PlutusScript.js

This file was deleted.

15 changes: 4 additions & 11 deletions src/Internal/Serialization/PlutusScript.purs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
module Ctl.Internal.Serialization.PlutusScript
( plutusScriptBytes
, convertPlutusScript
( convertPlutusScript
) where

import Prelude

import Cardano.Serialization.Lib (plutusScript_new, plutusScript_newV2)
import Ctl.Internal.Serialization.Types (PlutusScript)
import Ctl.Internal.Types.ByteArray (ByteArray)
import Ctl.Internal.Types.Scripts
( Language(PlutusV1, PlutusV2)
, PlutusScript(PlutusScript)
) as T
import Data.Tuple.Nested ((/\))

foreign import plutusScriptBytes :: PlutusScript -> ByteArray

foreign import newPlutusV1Script :: ByteArray -> PlutusScript

foreign import newPlutusV2Script :: ByteArray -> PlutusScript

convertPlutusScript :: T.PlutusScript -> PlutusScript
convertPlutusScript (T.PlutusScript (bytes /\ language)) =
bytes # case language of
T.PlutusV1 -> newPlutusV1Script
T.PlutusV2 -> newPlutusV2Script
T.PlutusV1 -> plutusScript_new
T.PlutusV2 -> plutusScript_newV2
91 changes: 5 additions & 86 deletions src/Internal/Serialization/Types.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Ctl.Internal.Serialization.Types
( module X
) where

import Cardano.Serialization.Lib
( AssetName
, Assets
, AuxiliaryData
Expand Down Expand Up @@ -83,89 +87,4 @@ module Ctl.Internal.Serialization.Types
, Vkeywitness
, Vkeywitnesses
, Withdrawals
) where

foreign import data AssetName :: Type
foreign import data Assets :: Type
foreign import data AuxiliaryData :: Type
foreign import data AuxiliaryDataHash :: Type
foreign import data BigInt :: Type
foreign import data Bip32PrivateKey :: Type
foreign import data Bip32PublicKey :: Type
foreign import data BootstrapWitness :: Type
foreign import data BootstrapWitnesses :: Type
foreign import data Certificate :: Type
foreign import data Certificates :: Type
foreign import data ConstrPlutusData :: Type
foreign import data CostModel :: Type
foreign import data Costmdls :: Type
foreign import data DataCost :: Type
foreign import data DataHash :: Type
foreign import data Ed25519KeyHashes :: Type
foreign import data Ed25519Signature :: Type
foreign import data ExUnitPrices :: Type
foreign import data ExUnits :: Type
foreign import data GeneralTransactionMetadata :: Type
foreign import data GenesisDelegateHash :: Type
foreign import data GenesisHash :: Type
foreign import data GenesisKeyDelegation :: Type
foreign import data Ipv4 :: Type
foreign import data Ipv6 :: Type
foreign import data Language :: Type
foreign import data MIRToStakeCredentials :: Type
foreign import data MetadataList :: Type
foreign import data MetadataMap :: Type
foreign import data Mint :: Type
foreign import data MintAssets :: Type
foreign import data MoveInstantaneousReward :: Type
foreign import data MultiAsset :: Type
foreign import data MultiHostName :: Type
foreign import data NativeScript :: Type
foreign import data NativeScripts :: Type
foreign import data NetworkId :: Type
foreign import data Nonce :: Type
foreign import data PlutusData :: Type
foreign import data PlutusList :: Type
foreign import data PlutusMap :: Type
foreign import data PlutusScript :: Type
foreign import data PlutusScripts :: Type
foreign import data PoolMetadata :: Type
foreign import data PoolMetadataHash :: Type
foreign import data PoolParams :: Type
foreign import data ProposedProtocolParameterUpdates :: Type
foreign import data ProtocolParamUpdate :: Type
foreign import data ProtocolVersion :: Type
foreign import data PublicKey :: Type
foreign import data PrivateKey :: Type
foreign import data Redeemer :: Type
foreign import data RedeemerTag :: Type
foreign import data Redeemers :: Type
foreign import data Relay :: Type
foreign import data Relays :: Type
foreign import data ScriptAll :: Type
foreign import data ScriptAny :: Type
foreign import data ScriptDataHash :: Type
foreign import data ScriptNOfK :: Type
foreign import data ScriptPubkey :: Type
foreign import data ScriptRef :: Type
foreign import data SingleHostAddr :: Type
foreign import data SingleHostName :: Type
foreign import data TimelockExpiry :: Type
foreign import data TimelockStart :: Type
foreign import data Transaction :: Type
foreign import data TransactionBody :: Type
foreign import data TransactionHash :: Type
foreign import data TransactionInput :: Type
foreign import data TransactionInputs :: Type
foreign import data TransactionMetadatum :: Type
foreign import data TransactionOutput :: Type
foreign import data TransactionOutputs :: Type
foreign import data TransactionUnspentOutput :: Type
foreign import data TransactionWitnessSet :: Type
foreign import data UnitInterval :: Type
foreign import data Update :: Type
foreign import data Value :: Type
foreign import data Vkey :: Type
foreign import data Vkeywitness :: Type
foreign import data Vkeywitnesses :: Type
foreign import data Withdrawals :: Type
) as X
3 changes: 1 addition & 2 deletions src/Internal/Types/BigNum.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Prelude

import Aeson (class DecodeAeson, class EncodeAeson, decodeAeson, encodeAeson)
import Aeson (JsonDecodeError(TypeMismatch)) as Aeson
import Cardano.Serialization.Lib (BigNum)
import Ctl.Internal.Deserialization.Error (FromCslRepError, fromCslRepError)
import Ctl.Internal.Error (E, noteE)
import Ctl.Internal.FfiHelpers (MaybeFfiHelper, maybeFfiHelper)
Expand All @@ -34,8 +35,6 @@ import JS.BigInt (fromString, toString) as BigInt
import Partial.Unsafe (unsafePartial)
import Type.Row (type (+))

foreign import data BigNum :: Type

instance Eq BigNum where
eq lhs rhs = bnCompare lhs rhs == 0

Expand Down
2 changes: 1 addition & 1 deletion test/Deserialization.purs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ suite = do
test "Deserialization is inverse to serialization" do
let bigInt = BigInt.fromInt 123
res <- errMaybe "Failed to serialize BigInt" do
DB.convertBigInt =<< SB.convertBigInt bigInt
DB.convertBigInt $ SB.convertBigInt bigInt
res `shouldEqual` bigInt
group "BigNum" do
test "Deserialization is inverse to serialization" do
Expand Down

0 comments on commit bddb48e

Please sign in to comment.