Skip to content

Commit

Permalink
cardano-api 10.6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Jan 21, 2025
1 parent dbff9d5 commit bd9c48d
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 243 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Build dependencies for integration test
run: |
cabal update
cabal install -j cardano-node-10.1.1 cardano-cli-10.1.0.0 --overwrite-policy=always
cabal install -j cardano-node-10.1.4 cardano-cli-10.3.0.0 --overwrite-policy=always
cabal install -j convex-wallet --overwrite-policy=always
echo "/home/runner/.cabal/bin" >> $GITHUB_PATH
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ The `main` branch uses the following versions of its major dependencies:

|Name|Version|
|--|--|
|`cardano-node`|[10.1.1](https://github.com/IntersectMBO/cardano-node/releases/tag/10.1.1)|
|`cardano-api`|[10.1.0.0](https://chap.intersectmbo.org/package/cardano-api-10.1.0.0/)|
|`cardano-node`|[10.1.4](https://github.com/IntersectMBO/cardano-node/releases/tag/10.1.4)|
|`cardano-api`|[10.6.0.0](https://chap.intersectmbo.org/package/cardano-api-10.6.0.0/)|
|`ghc`|9.6.6|
|`cabal`|3.10.3.0|

Expand Down
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ repository cardano-haskell-packages

with-compiler: ghc-9.6.6
index-state:
, hackage.haskell.org 2024-10-10T00:52:24Z
, cardano-haskell-packages 2024-10-24T10:49:32Z
, hackage.haskell.org 2025-01-20T00:52:24Z
, cardano-haskell-packages 2025-01-20T10:49:32Z

multi-repl: true

Expand Down
61 changes: 22 additions & 39 deletions flake.lock

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

2 changes: 1 addition & 1 deletion src/base/convex-base.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ library
build-depends:
, base16-bytestring
, bytestring
, cardano-api ==10.1.0.0
, cardano-api ==10.6.0.0
, cardano-binary
, cardano-crypto-class
, cardano-crypto-wrapper
Expand Down
48 changes: 25 additions & 23 deletions src/base/lib/Convex/BuildTx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Here, we want to get the index into the on-chain map, but instead index into the
These two indexes should be the same by construction, but it is possible to violate this invariant when building a tx.
-}
lookupIndexMinted :: (C.IsMaryBasedEra era) => C.PolicyId -> TxBody era -> Maybe Int
lookupIndexMinted policy = Map.lookupIndex policy . view (L.txMintValue . L._TxMintValue . _2)
lookupIndexMinted policy = Map.lookupIndex policy . view (L.txMintValue . L._TxMintValue)

-- | Look up the index of the @PolicyId@ in the transaction mint. Throws an error if the @PolicyId@ is not present.
findIndexMinted :: (C.IsMaryBasedEra era) => C.PolicyId -> TxBody era -> Int
Expand Down Expand Up @@ -340,8 +340,8 @@ addInputWithTxBody txIn f = addTxBuilder (TxBuilder $ \body -> over L.txIns ((tx

addMintWithTxBody :: (MonadBuildTx era m, C.IsMaryBasedEra era) => C.PolicyId -> C.AssetName -> C.Quantity -> (TxBody era -> C.ScriptWitness C.WitCtxMint era) -> m ()
addMintWithTxBody policy assetName quantity f =
let v = assetValue (C.unPolicyId policy) assetName quantity
in addTxBuilder (TxBuilder $ \body -> over (L.txMintValue . L._TxMintValue) (over _1 (<> v) . over _2 (Map.insert policy (f body))))
let entry body = (assetName, quantity, C.BuildTxWith $ f body)
in addTxBuilder (TxBuilder $ \body -> over (L.txMintValue . L._TxMintValue . at policy . L.anon [] null) ((entry body) :))

addWithdrawalWithTxBody :: (MonadBuildTx era m, C.IsShelleyBasedEra era) => C.StakeAddress -> C.Quantity -> (TxBody era -> C.Witness C.WitCtxStake era) -> m ()
addWithdrawalWithTxBody address amount f =
Expand Down Expand Up @@ -383,6 +383,7 @@ addStakeScriptWitnessRef
, Plutus.ToData redeemer
, C.IsShelleyBasedEra era
, C.HasScriptLanguageInEra lang era
, C.IsPlutusScriptLanguage lang
)
=> C.StakeCredential
-> C.TxIn
Expand All @@ -392,7 +393,7 @@ addStakeScriptWitnessRef
addStakeScriptWitnessRef credential txIn plutusScriptVersion redeemer = do
let scriptWitness = buildRefScriptWitness txIn plutusScriptVersion C.NoScriptDatumForStake redeemer
let witness = C.ScriptWitness C.ScriptWitnessForStakeAddr scriptWitness
addBtx (over (L.txCertificates . L._TxCertificates . _2) ((:) (credential, witness)))
addBtx (over (L.txCertificates . L._TxCertificates . _2) ((credential, witness) :))

{- | Like @addStakeWitness@ but uses a function that takes a @TxBody@ to build the witness.
TODO Give an example of why this is useful. We should just remove it.
Expand Down Expand Up @@ -426,7 +427,7 @@ buildScriptWitness script datum redeemer =

-- | Utility function to build a reference script witness
buildRefScriptWitness
:: (Plutus.ToData redeemer, C.HasScriptLanguageInEra lang era)
:: (Plutus.ToData redeemer, C.HasScriptLanguageInEra lang era, C.IsPlutusScriptLanguage lang)
=> C.TxIn
-> C.PlutusScriptVersion lang
-> C.ScriptDatum witctx
Expand All @@ -436,7 +437,7 @@ buildRefScriptWitness refTxIn scrVer datum redeemer =
C.PlutusScriptWitness
C.scriptLanguageInEra
scrVer
(C.PReferenceScript refTxIn Nothing)
(C.PReferenceScript refTxIn)
datum
(toHashableScriptData redeemer)
(C.ExecutionUnits 0 0)
Expand All @@ -463,7 +464,7 @@ can depend on the index of the @TxIn@ in the inputs of the final transaction.
-}
spendPlutusRefBase
:: forall redeemer lang era m
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsAlonzoBasedEra era, C.HasScriptLanguageInEra lang era)
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsAlonzoBasedEra era, C.HasScriptLanguageInEra lang era, C.IsPlutusScriptLanguage lang)
=> C.TxIn -> C.TxIn -> C.PlutusScriptVersion lang -> C.ScriptDatum C.WitCtxTxIn -> (Int -> redeemer) -> m ()
spendPlutusRefBase txIn refTxIn scrVer dat red =
let wit txBody = C.BuildTxWith $ C.ScriptWitness C.ScriptWitnessForSpending $ buildRefScriptWitness refTxIn scrVer dat (red $ findIndexSpending txIn txBody)
Expand All @@ -472,20 +473,20 @@ spendPlutusRefBase txIn refTxIn scrVer dat red =
-- | Spend an output locked by a Plutus V2 validator using the redeemer
spendPlutusRefBaseWithInRef
:: forall redeemer lang era m
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra lang era)
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra lang era, C.IsPlutusScriptLanguage lang)
=> C.TxIn -> C.TxIn -> C.PlutusScriptVersion lang -> C.ScriptDatum C.WitCtxTxIn -> redeemer -> m ()
spendPlutusRefBaseWithInRef txIn refTxIn scrVer dat red = inBabbage @era $ spendPlutusRefBase txIn refTxIn scrVer dat (const red) >> addReference refTxIn

spendPlutusRef
:: forall datum redeemer lang era m
. (MonadBuildTx era m, Plutus.ToData datum, Plutus.ToData redeemer, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra lang era)
. (MonadBuildTx era m, Plutus.ToData datum, Plutus.ToData redeemer, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra lang era, C.IsPlutusScriptLanguage lang)
=> C.TxIn -> C.TxIn -> C.PlutusScriptVersion lang -> datum -> redeemer -> m ()
spendPlutusRef txIn refTxIn scrVer (toHashableScriptData -> dat) = spendPlutusRefBaseWithInRef txIn refTxIn scrVer (C.ScriptDatumForTxIn $ Just dat)

-- | same as spendPlutusV2Ref but considers inline datum at the spent utxo
spendPlutusRefWithInlineDatum
:: forall redeemer lang era m
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra lang era)
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsBabbageBasedEra era, C.HasScriptLanguageInEra lang era, C.IsPlutusScriptLanguage lang)
=> C.TxIn -> C.TxIn -> C.PlutusScriptVersion lang -> redeemer -> m ()
spendPlutusRefWithInlineDatum txIn refTxIn scrVer = spendPlutusRefBaseWithInRef txIn refTxIn scrVer C.InlineScriptDatum

Expand All @@ -494,14 +495,14 @@ This is to cover the case whereby the reference script utxo is expected to be co
-}
spendPlutusRefWithoutInRef
:: forall datum redeemer lang era m
. (MonadBuildTx era m, Plutus.ToData datum, Plutus.ToData redeemer, C.IsAlonzoBasedEra era, C.HasScriptLanguageInEra lang era)
. (MonadBuildTx era m, Plutus.ToData datum, Plutus.ToData redeemer, C.IsAlonzoBasedEra era, C.HasScriptLanguageInEra lang era, C.IsPlutusScriptLanguage lang)
=> C.TxIn -> C.TxIn -> C.PlutusScriptVersion lang -> datum -> redeemer -> m ()
spendPlutusRefWithoutInRef txIn refTxIn scrVer (toHashableScriptData -> dat) red = spendPlutusRefBase txIn refTxIn scrVer (C.ScriptDatumForTxIn $ Just dat) (const red)

-- | same as spendPlutusV2RefWithoutInRef but considers inline datum at the spent utxo
spendPlutusRefWithoutInRefInlineDatum
:: forall redeemer lang era m
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsAlonzoBasedEra era, C.HasScriptLanguageInEra lang era)
. (MonadBuildTx era m, Plutus.ToData redeemer, C.IsAlonzoBasedEra era, C.HasScriptLanguageInEra lang era, C.IsPlutusScriptLanguage lang)
=> C.TxIn -> C.TxIn -> C.PlutusScriptVersion lang -> redeemer -> m ()
spendPlutusRefWithoutInRefInlineDatum txIn refTxIn scrVer red = spendPlutusRefBase txIn refTxIn scrVer C.InlineScriptDatum (const red)

Expand All @@ -520,11 +521,11 @@ mintPlutus
-> m ()
mintPlutus script red assetName quantity =
let sh = C.hashScript (C.PlutusScript C.plutusScriptVersion script)
v = assetValue sh assetName quantity
policyId = C.PolicyId sh
wit = buildScriptWitness @era script C.NoScriptDatumForMint red
entry = (assetName, quantity, C.BuildTxWith wit)
in inAlonzo @era $
setScriptsValid >> addBtx (over (L.txMintValue . L._TxMintValue) (over _1 (<> v) . over _2 (Map.insert policyId wit)))
setScriptsValid >> addBtx (over (L.txMintValue . L._TxMintValue . at policyId . L.anon [] null) (entry :))

-- | A value containing the given amount of the native asset
assetValue :: ScriptHash -> C.AssetName -> C.Quantity -> C.Value
Expand All @@ -537,6 +538,7 @@ mintPlutusRef
, MonadBuildTx era m
, C.HasScriptLanguageInEra lang era
, C.IsBabbageBasedEra era
, C.IsPlutusScriptLanguage lang
)
=> C.TxIn
-> C.PlutusScriptVersion lang
Expand All @@ -547,11 +549,11 @@ mintPlutusRef
-> m ()
mintPlutusRef refTxIn scrVer sh red assetName quantity =
inBabbage @era $
let v = assetValue sh assetName quantity
wit = buildRefScriptWitness refTxIn scrVer C.NoScriptDatumForMint red
let wit = buildRefScriptWitness refTxIn scrVer C.NoScriptDatumForMint red
entry = (assetName, quantity, C.BuildTxWith wit)
policyId = C.PolicyId sh
in setScriptsValid
>> addBtx (over (L.txMintValue . L._TxMintValue) (over _1 (<> v) . over _2 (Map.insert policyId wit)))
>> addBtx (over (L.txMintValue . L._TxMintValue . at policyId . L.anon [] null) (entry :))
>> addReference refTxIn

mintSimpleScriptAssets :: forall era m. (MonadBuildTx era m, C.IsMaryBasedEra era) => C.SimpleScript -> [(C.AssetName, C.Quantity)] -> m ()
Expand Down Expand Up @@ -589,22 +591,22 @@ payToAddress addr vl = addBtx $ over L.txOuts (payToAddressTxOut addr vl :)
payToPublicKey :: (MonadBuildTx era m, C.IsMaryBasedEra era) => NetworkId -> Hash PaymentKey -> C.Value -> m ()
payToPublicKey network pk vl =
let val = mkTxOutValue vl
addr = C.makeShelleyAddressInEra (C.maryEraOnwardsToShelleyBasedEra C.maryBasedEra) network (C.PaymentCredentialByKey pk) C.NoStakeAddress
addr = C.makeShelleyAddressInEra (C.convert C.maryBasedEra) network (C.PaymentCredentialByKey pk) C.NoStakeAddress
txo = C.TxOut addr val C.TxOutDatumNone C.ReferenceScriptNone
in addOutput txo

payToScriptHash :: forall era m. (MonadBuildTx era m, C.IsAlonzoBasedEra era) => NetworkId -> ScriptHash -> HashableScriptData -> C.StakeAddressReference -> C.Value -> m ()
payToScriptHash :: forall era m. (MonadBuildTx era m, C.IsBabbageBasedEra era) => NetworkId -> ScriptHash -> HashableScriptData -> C.StakeAddressReference -> C.Value -> m ()
payToScriptHash network script datum stakeAddress vl =
inAlonzo @era $
let val = mkTxOutValue vl
addr = C.makeShelleyAddressInEra C.shelleyBasedEra network (C.PaymentCredentialByScript script) stakeAddress
dat = C.TxOutDatumInTx C.alonzoBasedEra datum
dat = C.TxOutDatumInline C.babbageBasedEra datum
txo = C.TxOut addr val dat C.ReferenceScriptNone
in addOutput txo

payToScriptDatumHash
:: forall a lang era m
. (MonadBuildTx era m, Plutus.ToData a, C.IsAlonzoBasedEra era)
. (MonadBuildTx era m, Plutus.ToData a, C.IsBabbageBasedEra era)
=> NetworkId -> C.Script lang -> a -> C.StakeAddressReference -> C.Value -> m ()
payToScriptDatumHash network s datum stakeRef vl =
let sh = C.hashScript s
Expand Down Expand Up @@ -639,7 +641,7 @@ createRefScriptDatumHash
. (MonadBuildTx era m, Plutus.ToData a, C.IsBabbageBasedEra era, C.IsScriptLanguage lang)
=> C.AddressInEra era -> C.Script lang -> a -> C.Value -> m ()
createRefScriptDatumHash addr script datum vl =
let dat = C.TxOutDatumInTx (C.babbageEraOnwardsToAlonzoEraOnwards C.babbageBasedEra) (toHashableScriptData datum)
let dat = C.TxOutDatumInline C.babbageBasedEra (toHashableScriptData datum)
in createRefScriptBase addr script dat vl

payToScriptInlineDatum :: forall a era m. (MonadBuildTx era m, Plutus.ToData a, C.IsBabbageBasedEra era) => NetworkId -> C.ScriptHash -> a -> C.StakeAddressReference -> C.Value -> m ()
Expand Down Expand Up @@ -675,7 +677,7 @@ minAdaDeposit (C.LedgerProtocolParameters params) txOut =
-- set the Ada value to a dummy amount to ensure that it is not 0 (if it was 0, the size of the output
-- would be smaller, causing 'calculateMinimumUTxO' to compute an amount that is a little too small)
& over (L._TxOut . _2 . L._TxOutValue . L._Value . at C.AdaAssetId) (maybe (Just minAdaValue) (Just . max minAdaValue))
in C.lovelaceToQuantity $ C.calculateMinimumUTxO (C.maryEraOnwardsToShelleyBasedEra C.maryBasedEra) txo params
in C.lovelaceToQuantity $ C.calculateMinimumUTxO (C.convert C.maryBasedEra) txo params

-- | Apply 'setMinAdaDeposit' to all outputs
setMinAdaDepositAll :: (MonadBuildTx era m, C.IsMaryBasedEra era) => C.LedgerProtocolParameters era -> m ()
Expand Down
2 changes: 1 addition & 1 deletion src/base/lib/Convex/Utxos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ txOutToLatestEra (C.TxOut addrInEra txOutValue txOutDatum ref) =
convertDatumToLatestEra :: C.TxOutDatum C.CtxTx era1 -> C.TxOutDatum C.CtxTx era
convertDatumToLatestEra C.TxOutDatumNone = C.TxOutDatumNone
convertDatumToLatestEra (C.TxOutDatumHash _ h) = inBabbage @era $ C.TxOutDatumHash C.alonzoBasedEra h
convertDatumToLatestEra (C.TxOutDatumInTx _ d) = inBabbage @era $ C.TxOutDatumInTx C.alonzoBasedEra d
convertDatumToLatestEra (C.TxOutDatumInline _ d) = C.TxOutDatumInline C.babbageBasedEra d
convertDatumToLatestEra (C.TxOutSupplementalDatum _ datum) = inBabbage @era $ C.TxOutSupplementalDatum C.alonzoBasedEra datum

convertRefScriptToLatestEra :: CS.ReferenceScript era1 -> CS.ReferenceScript era
convertRefScriptToLatestEra CS.ReferenceScriptNone = CS.ReferenceScriptNone
Expand Down
1 change: 1 addition & 0 deletions src/coin-selection/convex-coin-selection.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ test-suite convex-coin-selection-test
, cardano-api
, cardano-ledger-api
, cardano-ledger-conway
, cardano-ledger-core
, cardano-ledger-shelley
, containers
, convex-base
Expand Down
Loading

0 comments on commit bd9c48d

Please sign in to comment.