Skip to content

Commit

Permalink
New transaction submit --error-detail-out option
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 15, 2022
1 parent 2b7b0d4 commit 92ce3c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -240,7 +240,7 @@ data TransactionCmd
| TxSign InputTxBodyOrTxFile [WitnessSigningData] (Maybe NetworkId) TxFile
| TxCreateWitness TxBodyFile WitnessSigningData (Maybe NetworkId) OutputFile
| TxAssembleTxBodyWitness TxBodyFile [WitnessFile] OutputFile
| TxSubmit AnyConsensusModeParams NetworkId FilePath
| TxSubmit AnyConsensusModeParams NetworkId FilePath (Maybe FilePath)
| TxMintedPolicyId ScriptFile
| TxCalculateMinFee
TxBodyFile
Expand Down
10 changes: 10 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -753,6 +753,7 @@ pTransaction =
pTransactionSubmit = TxSubmit <$> pConsensusModeParams
<*> pNetworkId
<*> pTxSubmitFile
<*> optional pErrorDetailJsonFile

pTransactionPolicyId :: Parser TransactionCmd
pTransactionPolicyId = TxMintedPolicyId <$> pScript
Expand Down Expand Up @@ -1968,6 +1969,15 @@ pTestnetMagic =
<> Opt.help "Specify a testnet magic id."
)

pErrorDetailJsonFile :: Parser FilePath
pErrorDetailJsonFile =
Opt.strOption
( Opt.long "error-detail-out"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of output file to which error detail should be written."
<> Opt.completer (Opt.bashCompleter "file")
)

pTxSubmitFile :: Parser FilePath
pTxSubmitFile =
Opt.strOption
Expand Down
16 changes: 9 additions & 7 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Expand Up @@ -88,7 +88,7 @@ data ShelleyTxCmdError
| ShelleyTxCmdMetaDecodeError !FilePath !CBOR.DecoderError
| ShelleyTxCmdBootstrapWitnessError !ShelleyBootstrapWitnessError
| ShelleyTxCmdSocketEnvError !EnvSocketError
| ShelleyTxCmdTxSubmitError !Text Aeson.Value
| ShelleyTxCmdTxSubmitError !Text
| ShelleyTxCmdTxSubmitErrorByron !(ApplyTxErr ByronBlock)
| ShelleyTxCmdTxSubmitErrorShelley !(ApplyTxErr (ShelleyBlock StandardShelley))
| ShelleyTxCmdTxSubmitErrorAllegra !(ApplyTxErr (ShelleyBlock StandardAllegra))
Expand Down Expand Up @@ -168,7 +168,7 @@ renderShelleyTxCmdError err =
ShelleyTxCmdAesonDecodeProtocolParamsError fp decErr ->
"Error while decoding the protocol parameters at: " <> show fp
<> " Error: " <> show decErr
ShelleyTxCmdTxSubmitError res _ -> "Error while submitting tx: " <> res
ShelleyTxCmdTxSubmitError res -> "Error while submitting tx: " <> res
ShelleyTxCmdTxSubmitErrorByron res ->
"Error while submitting tx: " <> Text.pack (show res)
ShelleyTxCmdTxSubmitErrorShelley res ->
Expand Down Expand Up @@ -319,8 +319,8 @@ runTransactionCmd cmd =
scriptFiles metadataFiles mpparams mUpProp outputFormat out
TxSign txinfile skfiles network txoutfile ->
runTxSign txinfile skfiles network txoutfile
TxSubmit anyConensusModeParams network txFp ->
runTxSubmit anyConensusModeParams network txFp
TxSubmit anyConensusModeParams network txFp errorDetailFp ->
runTxSubmit anyConensusModeParams network txFp errorDetailFp
TxCalculateMinFee txbody mnw pGenesisOrParamsFile nInputs nOutputs
nShelleyKeyWitnesses nByronKeyWitnesses ->
runTxCalculateMinFee txbody mnw pGenesisOrParamsFile nInputs nOutputs
Expand Down Expand Up @@ -1183,8 +1183,9 @@ runTxSubmit
:: AnyConsensusModeParams
-> NetworkId
-> FilePath
-> Maybe FilePath
-> ExceptT ShelleyTxCmdError IO ()
runTxSubmit (AnyConsensusModeParams cModeParams) network txFile = do
runTxSubmit (AnyConsensusModeParams cModeParams) network txFile mErrorDetailFp = do
SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError readEnvSocketPath

InAnyCardanoEra era tx <- readFileTx txFile
Expand All @@ -1206,8 +1207,9 @@ runTxSubmit (AnyConsensusModeParams cModeParams) network txFile = do
case reason of
TxValidationErrorInMode err _eraInMode -> do
let errorAsText = Text.pack (show err)
let errorAsJson = Aeson.toJSON err
left $ ShelleyTxCmdTxSubmitError errorAsText errorAsJson
forM_ mErrorDetailFp $ \errorDetailFp ->
liftIO $ LBS.writeFile errorDetailFp (Aeson.encode err)
left $ ShelleyTxCmdTxSubmitError errorAsText

TxValidationEraMismatch mismatchErr -> left $ ShelleyTxCmdTxSubmitErrorEraMismatch mismatchErr

Expand Down

0 comments on commit 92ce3c8

Please sign in to comment.