Skip to content

Commit

Permalink
renderTxWithUTxO: add collateral and fee fields (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
noonio authored Jan 3, 2025
2 parents 7b36819 + 1dd1516 commit e0dc991
Showing 1 changed file with 48 additions and 22 deletions.
70 changes: 48 additions & 22 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Cardano.Ledger.SafeHash qualified as Ledger
import Data.Aeson qualified as Aeson
import Data.ByteString.Lazy qualified as BL
import Data.Function (on)
import Data.List (sort, sortBy)
import Data.List (intercalate, sort, sortBy)
import Data.Map.Strict qualified as Map
import Data.Text qualified as T
import GHC.IsList (IsList (..))
Expand All @@ -27,27 +27,24 @@ renderTx = renderTxWithUTxO mempty
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 @@ -66,6 +63,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 @@ -76,6 +82,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 @@ -97,6 +104,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 e0dc991

Please sign in to comment.