Skip to content

Commit

Permalink
Fix transaction era - node era mismatch failure when using the transa…
Browse files Browse the repository at this point in the history
…ction build

command to construct transactions from prior eras
  • Loading branch information
Jimbo4350 committed Sep 27, 2022
1 parent 844e83f commit 0f61c86
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -501,33 +501,53 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
validatedTxUpProp
validatedMintValue
validatedTxScriptValidity

eInMode <- case toEraInMode era CardanoMode of
Just result -> return result
Nothing ->
left (ShelleyTxCmdEraConsensusModeMismatchTxBalance outputOptions
(AnyConsensusMode CardanoMode) (AnyCardanoEra era))

let allTxInputs = inputsThatRequireWitnessing ++ allReferenceInputs ++ txinsc
SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError
$ newExceptT readEnvSocketPath

(utxo, pparams, eraHistory, systemStart, stakePools) <-
let allTxInputs = inputsThatRequireWitnessing ++ allReferenceInputs ++ txinsc
localNodeConnInfo = LocalNodeConnectInfo
{ localConsensusModeParams = CardanoModeParams $ EpochSlots 21600
, localNodeNetworkId = networkId
, localNodeSocketPath = sockPath
}
AnyCardanoEra nodeEra
<- firstExceptT (ShelleyTxCmdQueryConvenienceError . AcqFailure)
. newExceptT $ determineEra cModeParams localNodeConnInfo

(nodeEraUTxO, pparams, eraHistory, systemStart, stakePools) <-
firstExceptT ShelleyTxCmdQueryConvenienceError . newExceptT
$ queryStateForBalancedTx era networkId allTxInputs
$ queryStateForBalancedTx nodeEra networkId allTxInputs

firstExceptT ShelleyTxCmdTxInsDoNotExist
. hoistEither $ txInsExistInUTxO allTxInputs utxo
. hoistEither $ txInsExistInUTxO allTxInputs nodeEraUTxO
firstExceptT ShelleyTxCmdQueryNotScriptLocked
. hoistEither $ notScriptLockedTxIns txinsc utxo
. hoistEither $ notScriptLockedTxIns txinsc nodeEraUTxO

let cAddr = case anyAddressInEra era changeAddr of
Just addr -> addr
Nothing -> error $ "runTxBuild: Byron address used: " <> show changeAddr

-- Why do we cast the era? The user can specify an era prior to the era that the node is currently in.
-- We cannot use the user specified era to construct a query against a node because it may differ
-- from the node's era and this will result in the 'QueryEraMismatch' failure.
txEraUtxo <- case first ShelleyTxCmdTxEraCastErr (eraCast era nodeEraUTxO) of
Right txEraUtxo -> return txEraUtxo
Left e -> left e

(BalancedTxBody balancedTxBody _ fee) <-
firstExceptT ShelleyTxCmdBalanceTxBody
. hoistEither
$ makeTransactionBodyAutoBalance eInMode systemStart eraHistory
pparams stakePools utxo txBodyContent
pparams stakePools txEraUtxo txBodyContent
cAddr mOverrideWits

putStrLn $ "Estimated transaction fee: " <> (show fee :: String)

case outputOptions of
Expand All @@ -537,10 +557,10 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
scriptExecUnitsMap <- firstExceptT ShelleyTxCmdTxExecUnitsErr $ hoistEither
$ evaluateTransactionExecutionUnits
eInMode systemStart eraHistory
pparams utxo balancedTxBody
pparams txEraUtxo balancedTxBody
scriptCostOutput <- firstExceptT ShelleyTxCmdPlutusScriptCostErr $ hoistEither
$ renderScriptCosts
utxo
txEraUtxo
executionUnitPrices
(collectTxBodyScriptWitnesses txBodyContent)
scriptExecUnitsMap
Expand Down

0 comments on commit 0f61c86

Please sign in to comment.