Skip to content

Commit

Permalink
Upgrade to cardano-api-8.27.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Oct 19, 2023
1 parent cc24e2e commit f16c63b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 64 deletions.
8 changes: 7 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2023-08-08T19:56:09Z
, cardano-haskell-packages 2023-10-18T12:25:04Z
, cardano-haskell-packages 2023-10-05T18:49:55Z

packages:
cardano-cli
Expand Down Expand Up @@ -43,3 +43,9 @@ write-ghc-environment-files: always
-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-api
tag: c08769a19d39c28bd3edb6885247201ea34d7949
subdir: cardano-api
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.26.0.0
, cardano-api ^>= 8.27.0.0
, cardano-binary
, cardano-crypto
, cardano-crypto-class ^>= 2.1.2
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Byron/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ txSpendGenesisUTxOByronPBFT gc nId sk (ByronAddress bAddr) outs = do
, txFee = TxFeeImplicit ByronEraOnlyByron
, txValidityRange =
( TxValidityNoLowerBound
, defaultTxValidityUpperBound
, defaultTxValidityUpperBound ByronEra
)
, txMetadata = TxMetadataNone
, txAuxScripts = TxAuxScriptsNone
Expand All @@ -175,7 +175,7 @@ txSpendGenesisUTxOByronPBFT gc nId sk (ByronAddress bAddr) outs = do
, txVotingProcedures = Nothing
}

case createAndValidateTransactionBody txBodyCont of
case createAndValidateTransactionBody ByronEra txBodyCont of
Left err -> error $ "Error occurred while creating a Byron genesis based UTxO transaction: " <> show err
Right txBody -> let bWit = fromByronWitness sk nId txBody
in makeSignedTransaction [bWit] txBody
Expand Down Expand Up @@ -209,7 +209,7 @@ txSpendUTxOByronPBFT nId sk txIns outs = do
, txFee = TxFeeImplicit ByronEraOnlyByron
, txValidityRange =
( TxValidityNoLowerBound
, defaultTxValidityUpperBound
, defaultTxValidityUpperBound ByronEra
)
, txMetadata = TxMetadataNone
, txAuxScripts = TxAuxScriptsNone
Expand All @@ -224,7 +224,7 @@ txSpendUTxOByronPBFT nId sk txIns outs = do
, txVotingProcedures = Nothing
}

case createAndValidateTransactionBody txBodyCont of
case createAndValidateTransactionBody ByronEra txBodyCont of
Left err -> error $ "Error occurred while creating a Byron genesis based UTxO transaction: " <> show err
Right txBody -> let bWit = fromByronWitness sk nId txBody
in makeSignedTransaction [bWit] txBody
Expand Down
6 changes: 3 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ runGenesisCreateStakedCmd

genStuffedAddress :: IO (AddressInEra ShelleyEra)
genStuffedAddress =
shelleyAddressInEra <$>
shelleyAddressInEra ShelleyBasedEraShelley <$>
(ShelleyAddress
<$> pure Ledger.Testnet
<*> (Ledger.KeyHashObj . mkKeyHash . read64BitInt
Expand Down Expand Up @@ -946,7 +946,7 @@ computeInsecureDelegation g0 nw pool = do
let initialUtxoAddr = makeShelleyAddress nw (PaymentCredentialByKey (verificationKeyHash paymentVK)) stakeAddressReference

delegation <- pure $ force Delegation
{ dInitialUtxoAddr = shelleyAddressInEra initialUtxoAddr
{ dInitialUtxoAddr = shelleyAddressInEra ShelleyBasedEraShelley initialUtxoAddr
, dDelegStaking = Ledger.hashKey (unStakeVerificationKey stakeVK)
, dPoolParams = pool
}
Expand Down Expand Up @@ -1290,7 +1290,7 @@ readInitialFundAddresses utxodir nw = do
, takeExtension file == ".vkey" ]
return [ addr | vkey <- vkeys
, let vkh = verificationKeyHash (castVerificationKey vkey)
addr = makeShelleyAddressInEra nw (PaymentCredentialByKey vkh)
addr = makeShelleyAddressInEra ShelleyBasedEraShelley nw (PaymentCredentialByKey vkh)
NoStakeAddress
]

Expand Down
112 changes: 57 additions & 55 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ runTransactionBuildCmd
certsAndMaybeScriptWits <-
case cardanoEraStyle eon of
LegacyByronEra -> return []
ShelleyBasedEra{} ->
sequence
[ fmap (,mSwit) (firstExceptT TxCmdReadTextViewFileError . newExceptT $
readFileTextEnvelope AsCertificate (File certFile))
| (CertificateFile certFile, mSwit) <- certFilesAndMaybeScriptWits
]
ShelleyBasedEra sbe ->
shelleyBasedEraConstraints sbe $
sequence
[ fmap (,mSwit) (firstExceptT TxCmdReadTextViewFileError . newExceptT $
readFileTextEnvelope AsCertificate (File certFile))
| (CertificateFile certFile, mSwit) <- certFilesAndMaybeScriptWits
]
withdrawalsAndMaybeScriptWits <- firstExceptT TxCmdScriptWitnessError $
readScriptWitnessFilesThruple eon withdrawals
txMetadata <- firstExceptT TxCmdMetadataError . newExceptT $
Expand Down Expand Up @@ -241,7 +242,7 @@ runTransactionBuildCmd

OutputTxBodyOnly fpath ->
let noWitTx = makeSignedTransaction [] balancedTxBody
in lift (cardanoEraConstraints eon $ writeTxFileTextEnvelopeCddl fpath noWitTx)
in lift (cardanoEraConstraints eon $ writeTxFileTextEnvelopeCddl eon fpath noWitTx)
& onLeft (left . TxCmdWriteFileError)

getExecutionUnitPrices :: CardanoEra era -> LedgerProtocolParameters era -> Maybe Ledger.Prices
Expand Down Expand Up @@ -293,12 +294,13 @@ runTransactionBuildRawCmd
certsAndMaybeScriptWits <-
case cardanoEraStyle eon of
LegacyByronEra -> return []
ShelleyBasedEra{} ->
sequence
[ fmap (,mSwit) (firstExceptT TxCmdReadTextViewFileError . newExceptT $
readFileTextEnvelope AsCertificate (File certFile))
| (CertificateFile certFile, mSwit) <- certFilesAndMaybeScriptWits
]
ShelleyBasedEra sbe ->
shelleyBasedEraConstraints sbe $
sequence
[ fmap (,mSwit) (firstExceptT TxCmdReadTextViewFileError . newExceptT $
readFileTextEnvelope AsCertificate (File certFile))
| (CertificateFile certFile, mSwit) <- certFilesAndMaybeScriptWits
]

withdrawalsAndMaybeScriptWits <- firstExceptT TxCmdScriptWitnessError
$ readScriptWitnessFilesThruple eon withdrawals
Expand Down Expand Up @@ -349,7 +351,7 @@ runTransactionBuildRawCmd
txMetadata mLedgerPParams mProp votingProcedures proposals

let noWitTx = makeSignedTransaction [] txBody
lift (cardanoEraConstraints eon $ writeTxFileTextEnvelopeCddl txBodyOutFile noWitTx)
lift (cardanoEraConstraints eon $ writeTxFileTextEnvelopeCddl eon txBodyOutFile noWitTx)
& onLeft (left . TxCmdWriteFileError)


Expand Down Expand Up @@ -454,7 +456,7 @@ runTxBuildRaw era
}

first TxCmdTxBodyError $
cardanoEraConstraints era $ createAndValidateTransactionBody txBodyContent
cardanoEraConstraints era $ createAndValidateTransactionBody era txBodyContent

runTxBuild :: ()
=> CardanoEra era
Expand Down Expand Up @@ -501,7 +503,7 @@ runTxBuild
inputsAndMaybeScriptWits readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts
(TxOutChangeAddress changeAddr) valuesWithScriptWits mLowerBound mUpperBound
certsAndMaybeScriptWits withdrawals reqSigners txAuxScripts txMetadata
mUpdatePropF mOverrideWits votingProcedures proposals outputOptions = do
mUpdatePropF mOverrideWits votingProcedures proposals outputOptions = cardanoEraConstraints era $ do

let consensusMode = consensusModeOnly cModeParams
dummyFee = Just $ Lovelace 0
Expand Down Expand Up @@ -531,7 +533,7 @@ runTxBuild
validatedTxScriptValidity <- hoistEither (first TxCmdScriptValidityValidationError $ validateTxScriptValidity era mScriptValidity)

case (consensusMode, cardanoEraStyle era) of
(CardanoMode, ShelleyBasedEra _) -> do
(CardanoMode, ShelleyBasedEra sbe) -> do
_ <- toEraInMode era CardanoMode
& hoistMaybe (TxCmdEraConsensusModeMismatchTxBalance outputOptions (AnyConsensusMode CardanoMode) (AnyCardanoEra era))

Expand Down Expand Up @@ -598,7 +600,7 @@ runTxBuild
balancedTxBody@(BalancedTxBody _ _ _ fee) <-
firstExceptT TxCmdBalanceTxBody
. hoistEither
$ makeTransactionBodyAutoBalance systemStart (toLedgerEpochInfo eraHistory)
$ makeTransactionBodyAutoBalance sbe systemStart (toLedgerEpochInfo eraHistory)
pparams stakePools stakeDelegDeposits drepDelegDeposits
txEraUtxo txBodyContent cAddr mOverrideWits

Expand Down Expand Up @@ -896,20 +898,20 @@ runTransactionSignCmd
inputTxFile <- liftIO $ fileOrPipe inputTxFilePath
anyTx <- lift (readFileTx inputTxFile) & onLeft (left . TxCmdCddlError)

InAnyShelleyBasedEra _era tx <-
InAnyShelleyBasedEra sbe tx <-
onlyInShelleyBasedEras "sign for Byron era transactions" anyTx

let (txbody, existingTxKeyWits) = getTxBodyAndWitnesses tx

byronWitnesses <-
pure (mkShelleyBootstrapWitnesses mNetworkId txbody sksByron)
pure (mkShelleyBootstrapWitnesses sbe mNetworkId txbody sksByron)
& onLeft (left . TxCmdBootstrapWitnessError)

let newShelleyKeyWits = map (makeShelleyKeyWitness txbody) sksShelley
let newShelleyKeyWits = map (makeShelleyKeyWitness sbe txbody) sksShelley
allKeyWits = existingTxKeyWits ++ newShelleyKeyWits ++ byronWitnesses
signedTx = makeSignedTransaction allKeyWits txbody

lift (writeTxFileTextEnvelopeCddl outTxFile signedTx)
lift (writeTxFileTextEnvelopeCddl (shelleyBasedToCardanoEra sbe) outTxFile signedTx)
& onLeft (left . TxCmdWriteFileError)

InputTxBodyFile (File txbodyFilePath) -> do
Expand All @@ -919,33 +921,33 @@ runTransactionSignCmd

case unwitnessed of
IncompleteCddlFormattedTx anyTx -> do
InAnyShelleyBasedEra _era unwitTx <-
InAnyShelleyBasedEra sbe unwitTx <-
onlyInShelleyBasedEras "sign for Byron era transactions" anyTx

let txbody = getTxBody unwitTx
-- Byron witnesses require the network ID. This can either be provided
-- directly or derived from a provided Byron address.
byronWitnesses <- firstExceptT TxCmdBootstrapWitnessError
. hoistEither
$ mkShelleyBootstrapWitnesses mNetworkId txbody sksByron
$ mkShelleyBootstrapWitnesses sbe mNetworkId txbody sksByron

let shelleyKeyWitnesses = map (makeShelleyKeyWitness txbody) sksShelley
let shelleyKeyWitnesses = map (makeShelleyKeyWitness sbe txbody) sksShelley
tx = makeSignedTransaction (byronWitnesses ++ shelleyKeyWitnesses) txbody

lift (writeTxFileTextEnvelopeCddl outTxFile tx)
lift (writeTxFileTextEnvelopeCddl (shelleyBasedToCardanoEra sbe) outTxFile tx)
& onLeft (left . TxCmdWriteFileError)

UnwitnessedCliFormattedTxBody anyTxbody -> do
InAnyShelleyBasedEra _era txbody <-
InAnyShelleyBasedEra sbe txbody <-
--TODO: in principle we should be able to support Byron era txs too
onlyInShelleyBasedEras "sign for Byron era transactions" anyTxbody
-- Byron witnesses require the network ID. This can either be provided
-- directly or derived from a provided Byron address.
byronWitnesses <- firstExceptT TxCmdBootstrapWitnessError
. hoistEither
$ mkShelleyBootstrapWitnesses mNetworkId txbody sksByron
$ mkShelleyBootstrapWitnesses sbe mNetworkId txbody sksByron

let shelleyKeyWitnesses = map (makeShelleyKeyWitness txbody) sksShelley
let shelleyKeyWitnesses = map (makeShelleyKeyWitness sbe txbody) sksShelley
tx = makeSignedTransaction (byronWitnesses ++ shelleyKeyWitnesses) txbody

firstExceptT TxCmdWriteFileError . newExceptT
Expand Down Expand Up @@ -1010,11 +1012,11 @@ runTransactionCalculateMinFeeCmd
pparams <- firstExceptT TxCmdProtocolParamsError $ readProtocolParameters protocolParamsFile
case unwitnessed of
IncompleteCddlFormattedTx anyTx -> do
InAnyShelleyBasedEra _era unwitTx <-
InAnyShelleyBasedEra sbe unwitTx <-
onlyInShelleyBasedEras "sign for Byron era transactions" anyTx
let txbody = getTxBody unwitTx
let tx = makeSignedTransaction [] txbody
Lovelace fee = estimateTransactionFee
Lovelace fee = estimateTransactionFee sbe
networkId
(protocolParamTxFeeFixed pparams)
(protocolParamTxFeePerByte pparams)
Expand All @@ -1025,12 +1027,12 @@ runTransactionCalculateMinFeeCmd
liftIO $ putStrLn $ (show fee :: String) <> " Lovelace"

UnwitnessedCliFormattedTxBody anyTxBody -> do
InAnyShelleyBasedEra _era txbody <-
InAnyShelleyBasedEra sbe txbody <-
--TODO: in principle we should be able to support Byron era txs too
onlyInShelleyBasedEras "calculate-min-fee for Byron era transactions" anyTxBody

let tx = makeSignedTransaction [] txbody
Lovelace fee = estimateTransactionFee
Lovelace fee = estimateTransactionFee sbe
networkId
(protocolParamTxFeeFixed pparams)
(protocolParamTxFeePerByte pparams)
Expand Down Expand Up @@ -1094,29 +1096,29 @@ partitionSomeWitnesses = reversePartitionedWits . foldl' go mempty

-- | Construct a Shelley bootstrap witness (i.e. a Byron key witness in the
-- Shelley era).
mkShelleyBootstrapWitness
:: IsShelleyBasedEra era
=> Maybe NetworkId
mkShelleyBootstrapWitness :: ()
=> ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness Nothing _ (ShelleyBootstrapWitnessSigningKeyData _ Nothing) =
mkShelleyBootstrapWitness _ Nothing _ (ShelleyBootstrapWitnessSigningKeyData _ Nothing) =
Left MissingNetworkIdOrByronAddressError
mkShelleyBootstrapWitness (Just nw) txBody (ShelleyBootstrapWitnessSigningKeyData skey Nothing) =
Right $ makeShelleyBootstrapWitness (WitnessNetworkId nw) txBody skey
mkShelleyBootstrapWitness _ txBody (ShelleyBootstrapWitnessSigningKeyData skey (Just addr)) =
Right $ makeShelleyBootstrapWitness (WitnessByronAddress addr) txBody skey
mkShelleyBootstrapWitness sbe (Just nw) txBody (ShelleyBootstrapWitnessSigningKeyData skey Nothing) =
Right $ makeShelleyBootstrapWitness sbe (WitnessNetworkId nw) txBody skey
mkShelleyBootstrapWitness sbe _ txBody (ShelleyBootstrapWitnessSigningKeyData skey (Just addr)) =
Right $ makeShelleyBootstrapWitness sbe (WitnessByronAddress addr) txBody skey

-- | Attempt to construct Shelley bootstrap witnesses until an error is
-- encountered.
mkShelleyBootstrapWitnesses
:: IsShelleyBasedEra era
=> Maybe NetworkId
mkShelleyBootstrapWitnesses :: ()
=> ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either BootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses mnw txBody =
mapM (mkShelleyBootstrapWitness mnw txBody)
mkShelleyBootstrapWitnesses sbe mnw txBody =
mapM (mkShelleyBootstrapWitness sbe mnw txBody)


-- ----------------------------------------------------------------------------
Expand Down Expand Up @@ -1226,15 +1228,15 @@ runTransactionWitnessCmd
AByronWitness bootstrapWitData ->
firstExceptT TxCmdBootstrapWitnessError
. hoistEither
$ mkShelleyBootstrapWitness mNetworkId txbody bootstrapWitData
$ mkShelleyBootstrapWitness sbe mNetworkId txbody bootstrapWitData
AShelleyKeyWitness skShelley ->
pure $ makeShelleyKeyWitness txbody skShelley
pure $ makeShelleyKeyWitness sbe txbody skShelley

firstExceptT TxCmdWriteFileError . newExceptT
$ writeTxWitnessFileTextEnvelopeCddl sbe outFile witness

UnwitnessedCliFormattedTxBody anyTxbody -> do
InAnyShelleyBasedEra _era txbody <-
InAnyShelleyBasedEra sbe txbody <-
onlyInShelleyBasedEras "sign for Byron era transactions" anyTxbody

someWit <- firstExceptT TxCmdReadWitnessSigningDataError
Expand All @@ -1247,9 +1249,9 @@ runTransactionWitnessCmd
AByronWitness bootstrapWitData ->
firstExceptT TxCmdBootstrapWitnessError
. hoistEither
$ mkShelleyBootstrapWitness mNetworkId txbody bootstrapWitData
$ mkShelleyBootstrapWitness sbe mNetworkId txbody bootstrapWitData
AShelleyKeyWitness skShelley ->
pure $ makeShelleyKeyWitness txbody skShelley
pure $ makeShelleyKeyWitness sbe txbody skShelley

firstExceptT TxCmdWriteFileError . newExceptT
$ writeLazyByteStringFile outFile
Expand All @@ -1267,15 +1269,15 @@ runTransactionSignWitnessCmd
txbodyFile <- liftIO $ fileOrPipe txbodyFilePath
unwitnessed <- lift (readFileTxBody txbodyFile) & onLeft (left . TxCmdCddlError)
case unwitnessed of
UnwitnessedCliFormattedTxBody (InAnyCardanoEra era txbody) -> do
UnwitnessedCliFormattedTxBody (InAnyCardanoEra era txbody) -> cardanoEraConstraints era $ do
witnesses <-
sequence
[ do
InAnyCardanoEra era' witness <-
lift (readFileTxKeyWitness file) & onLeft (left . TxCmdCddlWitnessError)

case testEquality era era' of
Nothing -> left $ TxCmdWitnessEraMismatch (AnyCardanoEra era) (AnyCardanoEra era') witnessFile
Nothing -> cardanoEraConstraints era' $ left $ TxCmdWitnessEraMismatch (AnyCardanoEra era) (AnyCardanoEra era') witnessFile
Just Refl -> return witness
| witnessFile@(WitnessFile file) <- witnessFiles
]
Expand All @@ -1301,7 +1303,7 @@ runTransactionSignWitnessCmd

let tx = makeSignedTransaction witnesses txbody

lift (writeTxFileTextEnvelopeCddl outFile tx) & onLeft (left . TxCmdWriteFileError)
lift (writeTxFileTextEnvelopeCddl era outFile tx) & onLeft (left . TxCmdWriteFileError)

-- | Constrain the era to be Shelley based. Fail for the Byron era.
onlyInShelleyBasedEras :: ()
Expand All @@ -1311,4 +1313,4 @@ onlyInShelleyBasedEras :: ()
onlyInShelleyBasedEras notImplMsg (InAnyCardanoEra era x) =
case cardanoEraStyle era of
LegacyByronEra -> left (TxCmdNotImplemented notImplMsg)
ShelleyBasedEra sbe -> return (InAnyShelleyBasedEra sbe x)
ShelleyBasedEra sbe -> shelleyBasedEraConstraints sbe $ return (InAnyShelleyBasedEra sbe x)

0 comments on commit f16c63b

Please sign in to comment.