Skip to content

Commit

Permalink
Extend describeCardanoTx by printing inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jan 26, 2022
1 parent f315907 commit 5f5bd99
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions hydra-node/src/Hydra/Ledger/Cardano.hs
Expand Up @@ -311,35 +311,42 @@ fromLedgerTx (Ledger.Alonzo.ValidatedTx body wits isValid auxData) =
describeCardanoTx :: CardanoTx -> Text
describeCardanoTx (Tx body _wits) =
unlines $
[ show (getTxId body)
, " Inputs (" <> show (length inputs) <> ")"
, " Outputs (" <> show (length outputs) <> ")"
, " total number of assets: " <> show totalNumberOfAssets
, " Scripts (" <> show (length scripts) <> ")"
, " total size (bytes): " <> show totalScriptSize
]
<> datums
<> redeemers
[show (getTxId body)]
<> inputLines
<> [ " Outputs (" <> show (length outputs) <> ")"
, " total number of assets: " <> show totalNumberOfAssets
, " Scripts (" <> show (length scripts) <> ")"
, " total size (bytes): " <> show totalScriptSize
]
<> datumLines
<> redeemerLines
where
ShelleyTxBody _era lbody scripts scriptsData _auxData _validity = body
outputs = Ledger.Alonzo.outputs' lbody
TxBody bodyContent = body

inputLines =
" Input set (" <> show (length inputs) <> ")" :
((" " <>) . renderTxIn . fst <$> txIns bodyContent)

inputs = Ledger.Alonzo.inputs' lbody

totalScriptSize = sum $ BL.length . serialize <$> scripts
totalNumberOfAssets =
sum $
[ foldl' (\n inner -> n + Map.size inner) 0 outer
| Ledger.Alonzo.TxOut _ (Ledger.Mary.Value _ outer) _ <- toList outputs
]

datums = case scriptsData of
datumLines = case scriptsData of
TxBodyNoScriptData -> []
(TxBodyScriptData _ (Ledger.Alonzo.TxDats dats) _) ->
" Datums (" <> show (length dats) <> ")" :
((" " <>) . showDatumAndHash <$> Map.toList dats)

showDatumAndHash (k, v) = show k <> " -> " <> show v

redeemers = case scriptsData of
redeemerLines = case scriptsData of
TxBodyNoScriptData -> []
(TxBodyScriptData _ _ re) ->
let rdmrs = Map.elems $ Ledger.Alonzo.unRedeemers re
Expand Down

0 comments on commit 5f5bd99

Please sign in to comment.