Skip to content

Commit 1dd1516

Browse files
renderTxWithUTxO: add collateral and fee lines
1 parent 8e637ff commit 1dd1516

File tree

1 file changed

+48
-22
lines changed
  • hydra-cardano-api/src/Hydra/Cardano/Api

1 file changed

+48
-22
lines changed

hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Cardano.Ledger.SafeHash qualified as Ledger
1313
import Data.Aeson qualified as Aeson
1414
import Data.ByteString.Lazy qualified as BL
1515
import Data.Function (on)
16-
import Data.List (sort, sortBy)
16+
import Data.List (intercalate, sort, sortBy)
1717
import Data.Map.Strict qualified as Map
1818
import Data.Text qualified as T
1919
import GHC.IsList (IsList (..))
@@ -27,27 +27,24 @@ renderTx = renderTxWithUTxO mempty
2727
renderTxWithUTxO :: UTxO -> Api.Tx -> String
2828
renderTxWithUTxO utxo (Tx body _wits) =
2929
unlines $
30-
[show (getTxId body)]
31-
<> [""]
32-
<> inputLines
33-
<> [""]
34-
<> referenceInputLines
35-
<> [""]
36-
<> outputLines
37-
<> [""]
38-
<> validityLines
39-
<> [""]
40-
<> mintLines
41-
<> [""]
42-
<> scriptLines
43-
<> [""]
44-
<> datumLines
45-
<> [""]
46-
<> redeemerLines
47-
<> [""]
48-
<> requiredSignersLines
49-
<> [""]
50-
<> metadataLines
30+
intercalate
31+
[""]
32+
[ pure $ show (getTxId body)
33+
, inputLines
34+
, collateralInputLines
35+
, referenceInputLines
36+
, outputLines
37+
, totalCollateralLines
38+
, returnCollateralLines
39+
, feeLines
40+
, validityLines
41+
, mintLines
42+
, scriptLines
43+
, datumLines
44+
, redeemerLines
45+
, requiredSignersLines
46+
, metadataLines
47+
]
5148
where
5249
Api.ShelleyTxBody _lbody scripts scriptsData _auxData _validity = body
5350
outs = txOuts content
@@ -66,6 +63,15 @@ renderTxWithUTxO utxo (Tx body _wits) =
6663
Api.TxInsReferenceNone -> []
6764
Api.TxInsReference refInputs -> refInputs
6865

66+
collateralInputLines =
67+
"== COLLATERAL INPUTS (" <> show (length collateralInputs) <> ")"
68+
: (("- " <>) . prettyTxIn <$> sort collateralInputs)
69+
70+
collateralInputs =
71+
case txInsCollateral content of
72+
Api.TxInsCollateralNone -> []
73+
Api.TxInsCollateral refInputs -> refInputs
74+
6975
prettyTxIn i =
7076
case UTxO.resolve i utxo of
7177
Nothing -> T.unpack $ renderTxIn i
@@ -76,6 +82,7 @@ renderTxWithUTxO utxo (Tx body _wits) =
7682
<> ("\n " <> prettyDatumUtxo (Api.txOutDatum o))
7783
<> ("\n " <> prettyReferenceScript (Api.txOutReferenceScript o))
7884

85+
outputLines :: [String]
7986
outputLines =
8087
[ "== OUTPUTS (" <> show (length outs) <> ")"
8188
, "Total number of assets: " <> show totalNumberOfAssets
@@ -97,6 +104,25 @@ renderTxWithUTxO utxo (Tx body _wits) =
97104
let totalValue = foldMap Api.txOutValue outs
98105
in length $ toList totalValue
99106

107+
totalCollateralLines :: [String]
108+
totalCollateralLines =
109+
[ "== TOTAL COLLATERAL"
110+
, show $ txTotalCollateral content
111+
]
112+
113+
returnCollateralLines :: [String]
114+
returnCollateralLines =
115+
[ "== RETURN COLLATERAL"
116+
, show $ txReturnCollateral content
117+
]
118+
119+
feeLines :: [String]
120+
feeLines =
121+
[ "== FEE"
122+
, show $ txFee content
123+
]
124+
125+
validityLines :: [String]
100126
validityLines =
101127
[ "== VALIDITY"
102128
, show (txValidityLowerBound content)

0 commit comments

Comments
 (0)