Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project: cardano-cli
pr: 1408
kind:
- feature
description: |
Adapt compatible transaction building to the new cardano-api CompatibleTxBodyContent record API, add missing Bech32InvalidUtf8 error handling in KES key parsing, and add --protocol-params-file and --tx-in-collateral options to `compatible transaction signed-transaction` so transactions with plutus witnesses can be built.
8 changes: 8 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ write-ghc-environment-files: always
-- 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.git
tag: 26aaf4a878a46bf398a2e88e8bd88f307dd20587
--sha256: sha256-yiKKAY4Uru3nAJBeZy/c3kES8vwcq/vU3xSPx2Z4+i8=
subdir:
cardano-api

-- cabal-allow-newer begin
if impl(ghc >= 9.14)
allow-newer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ data CompatibleTransactionCmds era
= CreateCompatibleSignedTransaction
(ShelleyBasedEra era)
[TxIn]
[TxIn]
-- ^ Collateral inputs
[TxOutAnyEra]
!(Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile)))
!( Maybe
Expand All @@ -37,6 +39,8 @@ data CompatibleTransactionCmds era
-- ^ Tx fee
![(CertificateFile, Maybe AnyNonAssetScript)]
-- ^ stake registering certs
!(Maybe ProtocolParamsFile)
-- ^ Needed to compute the script integrity hash when plutus witnesses are present.
!(File () Out)

renderCompatibleTransactionCmd :: CompatibleTransactionCmds era -> Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pCompatibleSignedTransaction
pCompatibleSignedTransaction env sbe =
CreateCompatibleSignedTransaction sbe
<$> many pTxInOnly
<*> many pTxInCollateral
<*> many (pTxOutEraAware sbe)
<*> pFeatured (toCardanoEra sbe) (optional pUpdateProposalFile)
<*> pFeatured (toCardanoEra sbe) (many (pProposalFile ManualBalance))
Expand All @@ -58,6 +59,7 @@ pCompatibleSignedTransaction env sbe =
<*> optional (pNetworkId env)
<*> pTxFee
<*> many (pCertificateFile ManualBalance)
<*> optional pProtocolParamsFile
<*> pOutputFile

pTxInOnly :: Parser TxIn
Expand Down
38 changes: 37 additions & 1 deletion cardano-cli/src/Cardano/CLI/Compatible/Transaction/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ import Cardano.CLI.EraBased.Script.Vote.Read
import Cardano.CLI.EraBased.Transaction.Run
import Cardano.CLI.Read
import Cardano.CLI.Type.Common
import Cardano.CLI.Type.Error.ProtocolParamsError

import Control.Monad
import Data.Aeson qualified as A
import Data.ByteString.Lazy.Char8 qualified as LBS
import Data.Map.Ordered.Strict qualified as OMap
import Data.Map.Strict qualified as Map
import Data.Text qualified as Text
import Lens.Micro

runCompatibleTransactionCmd
Expand All @@ -49,6 +53,7 @@ runCompatibleTransactionCmd
( CreateCompatibleSignedTransaction
sbe
ins
insCollateral
outs
mUpdateProposal
mProposalProcedure
Expand All @@ -57,6 +62,7 @@ runCompatibleTransactionCmd
mNetworkId
fee
certificates
mProtocolParamsFile
outputFp
) = shelleyBasedEraConstraints sbe $ do
sks <- mapM (fromEitherIOCli . readWitnessSigningData) witnesses
Expand Down Expand Up @@ -107,9 +113,22 @@ runCompatibleTransactionCmd

let txCerts = mkTxCertificatesSbe sbe certsAndMaybeScriptWits

protocolParams <- mapM (readCompatibleProtocolParams sbe) mProtocolParamsFile

transaction@(ShelleyTx _ ledgerTx) <-
fromEitherCli $
createCompatibleTx sbe ins allOuts extraDatums fee protocolUpdates votes txCerts
createCompatibleTx sbe $
(defaultCompatibleTxBodyContent sbe)
{ compatibleTxIns = map (,Exp.AnyKeyWitnessPlaceholder) ins
, compatibleTxOuts = allOuts
, compatibleTxSupplementalDatums = extraDatums
, compatibleTxFee = fee
, compatibleTxProtocolUpdate = protocolUpdates
, compatibleTxVotingProcedures = votes
, compatibleTxCertificates = txCerts
, compatibleTxInsCollateral = insCollateral
, compatibleTxProtocolParams = protocolParams
}

let txBody = ledgerTx ^. L.bodyTxL

Expand All @@ -127,6 +146,23 @@ runCompatibleTransactionCmd
fromEitherIOCli $
writeTxFileTextEnvelope sbe outputFp signedTx

-- | Read protocol parameters from a JSON file, in whatever Shelley-based era
-- is currently in scope. Needed by 'createCompatibleTx' to compute the script
-- integrity hash when plutus witnesses (e.g. a plutus-witnessed certificate)
-- are present.
readCompatibleProtocolParams
:: ShelleyBasedEra era
-> ProtocolParamsFile
-> CIO e (L.PParams (ShelleyLedgerEra era))
readCompatibleProtocolParams sbe (ProtocolParamsFile fpath) =
fromExceptTCli $ do
bytes <-
handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $
LBS.readFile fpath
firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $
shelleyBasedEraConstraints sbe $
A.eitherDecode' bytes

readCertificateScriptWitnesses'
:: ShelleyBasedEra era
-> [(CertificateFile, Maybe AnyNonAssetScript)]
Expand Down
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,7 @@ pKesVerificationKey =
Left err@(Bech32DataPartToBytesError _) -> Left $ displayError err
Left err@(Bech32DeserialiseFromBytesError _) -> Left $ displayError err
Left err@(Bech32WrongPrefix _ _) -> Left $ displayError err
Left err@(Bech32InvalidUtf8 _) -> Left $ displayError err
-- The input was not valid Bech32. Attempt to deserialise it as hex.
Left (Bech32DecodingError _) ->
first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Cardano.Api.Experimental.Certificate
( KESPeriod (..)
, OperationalCertificateIssueCounter (..)
)
import Cardano.Api.Ledger (StandardCrypto, StrictMaybe (SNothing))
import Cardano.Api.Ledger (StrictMaybe (SNothing))
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.Byron.Genesis (NewDirectory (NewDirectory))
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Type/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ instance ToJSON QueryTipLocalStateOutput where
. ("syncProgress" ..=? mSyncProgress a)
)
[]
ChainTip slotNo blockHeader blockNo ->
ChainTip slotNo blockHeader blockNumber ->
object $
( ("slot" ..= slotNo)
. ("hash" ..= serialiseToRawBytesHexText blockHeader)
. ("block" ..= blockNo)
. ("block" ..= blockNumber)
. ("era" ..=? mEra a)
. ("epoch" ..=? mEpoch a)
. ("slotInEpoch" ..=? mSlotInEpoch a)
Expand All @@ -241,12 +241,12 @@ instance ToJSON QueryTipLocalStateOutput where
. ("syncProgress" ..=? mSyncProgress a)
)
[]
ChainTip slotNo blockHeader blockNo ->
ChainTip slotNo blockHeader blockNumber ->
pairs $
mconcat $
( ("slot" ..= slotNo)
. ("hash" ..= serialiseToRawBytesHexText blockHeader)
. ("block" ..= blockNo)
. ("block" ..= blockNumber)
. ("era" ..=? mEra a)
. ("epoch" ..=? mEpoch a)
. ("slotInEpoch" ..=? mSlotInEpoch a)
Expand Down
12 changes: 12 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -5908,6 +5908,7 @@ Usage: cardano-cli compatible shelley transaction signed-transaction

Usage: cardano-cli compatible shelley transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE]
[--update-proposal-file FILEPATH]
[--signing-key-file FILEPATH
Expand Down Expand Up @@ -5935,6 +5936,7 @@ Usage: cardano-cli compatible shelley transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.
Expand Down Expand Up @@ -6119,6 +6121,7 @@ Usage: cardano-cli compatible allegra transaction signed-transaction

Usage: cardano-cli compatible allegra transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE]
[--update-proposal-file FILEPATH]
[--signing-key-file FILEPATH
Expand Down Expand Up @@ -6146,6 +6149,7 @@ Usage: cardano-cli compatible allegra transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.
Expand Down Expand Up @@ -6330,6 +6334,7 @@ Usage: cardano-cli compatible mary transaction signed-transaction

Usage: cardano-cli compatible mary transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE]
[--update-proposal-file FILEPATH]
[--signing-key-file FILEPATH
Expand Down Expand Up @@ -6357,6 +6362,7 @@ Usage: cardano-cli compatible mary transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.
Expand Down Expand Up @@ -6541,6 +6547,7 @@ Usage: cardano-cli compatible alonzo transaction signed-transaction

Usage: cardano-cli compatible alonzo transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE
[ --tx-out-datum-hash HASH
| --tx-out-datum-hash-cbor-file CBOR_FILE
Expand Down Expand Up @@ -6576,6 +6583,7 @@ Usage: cardano-cli compatible alonzo transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.
Expand Down Expand Up @@ -6767,6 +6775,7 @@ Usage: cardano-cli compatible babbage transaction signed-transaction

Usage: cardano-cli compatible babbage transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE
[ --tx-out-datum-hash HASH
| --tx-out-datum-hash-cbor-file CBOR_FILE
Expand Down Expand Up @@ -6805,6 +6814,7 @@ Usage: cardano-cli compatible babbage transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.
Expand Down Expand Up @@ -6993,6 +7003,7 @@ Usage: cardano-cli compatible conway transaction signed-transaction

Usage: cardano-cli compatible conway transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE
[ --tx-out-datum-hash HASH
| --tx-out-datum-hash-cbor-file CBOR_FILE
Expand Down Expand Up @@ -7063,6 +7074,7 @@ Usage: cardano-cli compatible conway transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Usage: cardano-cli compatible allegra transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE]
[--update-proposal-file FILEPATH]
[--signing-key-file FILEPATH
Expand Down Expand Up @@ -27,12 +28,14 @@ Usage: cardano-cli compatible allegra transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.

Available options:
--tx-in TX_IN TxId#TxIx
--tx-in-collateral TX_IN TxId#TxIx
--tx-out ADDRESS VALUE The transaction output as ADDRESS VALUE where ADDRESS
is the Bech32-encoded address followed by the value
in the multi-asset syntax (including simply
Expand Down Expand Up @@ -86,5 +89,7 @@ Available options:
top-level strings and numbers.
--certificate-reference-tx-in-execution-units (INT, INT)
The time and space units needed by the script.
--protocol-params-file FILEPATH
Filepath of the JSON-encoded protocol parameters file
--out-file FILEPATH The output file.
-h,--help Show this help text
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Usage: cardano-cli compatible alonzo transaction signed-transaction
[--tx-in TX_IN]
[--tx-in-collateral TX_IN]
[--tx-out ADDRESS VALUE
[ --tx-out-datum-hash HASH
| --tx-out-datum-hash-cbor-file CBOR_FILE
Expand Down Expand Up @@ -35,12 +36,14 @@ Usage: cardano-cli compatible alonzo transaction signed-transaction
)
--certificate-reference-tx-in-execution-units (INT, INT)
]]
[--protocol-params-file FILEPATH]
--out-file FILEPATH

Create a simple signed transaction.

Available options:
--tx-in TX_IN TxId#TxIx
--tx-in-collateral TX_IN TxId#TxIx
--tx-out ADDRESS VALUE The transaction output as ADDRESS VALUE where ADDRESS
is the Bech32-encoded address followed by the value
in the multi-asset syntax (including simply
Expand Down Expand Up @@ -121,5 +124,7 @@ Available options:
top-level strings and numbers.
--certificate-reference-tx-in-execution-units (INT, INT)
The time and space units needed by the script.
--protocol-params-file FILEPATH
Filepath of the JSON-encoded protocol parameters file
--out-file FILEPATH The output file.
-h,--help Show this help text
Loading