Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderTxWithUTxO: add collateral and fee fields #1749

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
68 changes: 47 additions & 21 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,24 @@ renderTxs xs = intercalate "\n\n" (renderTx <$> xs)
renderTxWithUTxO :: UTxO -> Api.Tx -> String
renderTxWithUTxO utxo (Tx body _wits) =
unlines $
[show (getTxId body)]
<> [""]
<> inputLines
<> [""]
<> referenceInputLines
<> [""]
<> outputLines
<> [""]
<> validityLines
<> [""]
<> mintLines
<> [""]
<> scriptLines
<> [""]
<> datumLines
<> [""]
<> redeemerLines
<> [""]
<> requiredSignersLines
<> [""]
<> metadataLines
intercalate
[""]
[ pure $ show (getTxId body)
, inputLines
, collateralInputLines
, referenceInputLines
, outputLines
, totalCollateralLines
, returnCollateralLines
, feeLines
, validityLines
, mintLines
, scriptLines
, datumLines
, redeemerLines
, requiredSignersLines
, metadataLines
]
where
Api.ShelleyTxBody _lbody scripts scriptsData _auxData _validity = body
outs = txOuts content
Expand All @@ -69,6 +66,15 @@ renderTxWithUTxO utxo (Tx body _wits) =
Api.TxInsReferenceNone -> []
Api.TxInsReference refInputs -> refInputs

collateralInputLines =
"== COLLATERAL INPUTS (" <> show (length collateralInputs) <> ")"
: (("- " <>) . prettyTxIn <$> sort collateralInputs)

collateralInputs =
case txInsCollateral content of
Api.TxInsCollateralNone -> []
Api.TxInsCollateral refInputs -> refInputs

prettyTxIn i =
case UTxO.resolve i utxo of
Nothing -> T.unpack $ renderTxIn i
Expand All @@ -79,6 +85,7 @@ renderTxWithUTxO utxo (Tx body _wits) =
<> ("\n " <> prettyDatumUtxo (Api.txOutDatum o))
<> ("\n " <> prettyReferenceScript (Api.txOutReferenceScript o))

outputLines :: [String]
outputLines =
[ "== OUTPUTS (" <> show (length outs) <> ")"
, "Total number of assets: " <> show totalNumberOfAssets
Expand All @@ -100,6 +107,25 @@ renderTxWithUTxO utxo (Tx body _wits) =
let totalValue = foldMap Api.txOutValue outs
in length $ toList totalValue

totalCollateralLines :: [String]
totalCollateralLines =
[ "== TOTAL COLLATERAL"
, show $ txTotalCollateral content
]

returnCollateralLines :: [String]
returnCollateralLines =
[ "== RETURN COLLATERAL"
, show $ txReturnCollateral content
]

feeLines :: [String]
feeLines =
[ "== FEE"
, show $ txFee content
]

validityLines :: [String]
validityLines =
[ "== VALIDITY"
, show (txValidityLowerBound content)
Expand Down
Loading