Skip to content

Commit

Permalink
renderTxWithUTxO: add collateral and fee lines
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Nov 26, 2024
1 parent 8582200 commit 32a241c
Showing 1 changed file with 47 additions and 21 deletions.
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

0 comments on commit 32a241c

Please sign in to comment.