Skip to content

Commit

Permalink
transaction id: do not tie implementation with default of parser
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jan 13, 2025
1 parent f8d55ee commit b83358e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ newtype TransactionHashScriptDataCmdArgs = TransactionHashScriptDataCmdArgs

data TransactionTxIdCmdArgs = TransactionTxIdCmdArgs
{ inputTxBodyOrTxFile :: InputTxBodyOrTxFile
, outputFormat :: !(Maybe OutputFormatJsonOrText)
, outputFormat :: !OutputFormatJsonOrText
}
deriving Show

Expand Down
6 changes: 2 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,10 +1727,8 @@ pOutputFormatJsonOrText kind =
-- to write @transaction txid@'s output on standard output.
pTxIdOutputFormatJsonOrText :: Parser OutputFormatJsonOrText
pTxIdOutputFormatJsonOrText =
asum
[ make OutputFormatJson "JSON" "json"
, make OutputFormatText "TEXT" "text"
]
asum [make OutputFormatJson "JSON" "json", make OutputFormatText "TEXT" "text"]
<|> pure default_
where
default_ = OutputFormatText
make format desc flag_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,4 @@ pTransactionId =
fmap TransactionTxIdCmd $
TransactionTxIdCmdArgs
<$> pInputTxOrTxBodyFile
<*> optional pTxIdOutputFormatJsonOrText
<*> pTxIdOutputFormatJsonOrText
8 changes: 2 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,15 +1748,11 @@ runTransactionTxIdCmd
return . InAnyShelleyBasedEra era $ getTxBody tx

let txId = getTxId txbody
bsToWrite = serialiseToRawBytesHex txId

liftIO $
case outputFormat of
Just OutputFormatJson -> LBS.putStrLn $ Aeson.encode $ TxSubmissionResult txId
Just OutputFormatText -> BS.putStrLn bsToWrite
Nothing ->
-- Stay compatible with output when there was no --output-format flag
BS.putStrLn bsToWrite
OutputFormatJson -> LBS.putStrLn $ Aeson.encode $ TxSubmissionResult txId
OutputFormatText -> BS.putStrLn $ serialiseToRawBytesHex txId

-- ----------------------------------------------------------------------------
-- Witness commands
Expand Down

0 comments on commit b83358e

Please sign in to comment.