-
Notifications
You must be signed in to change notification settings - Fork 720
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2348: Add `cardano-cli transaction view` r=cblp a=cblp Co-authored-by: Yuriy Syrovetskiy <yuriy.syrovetskiy@iohk.io>
- Loading branch information
Showing
5 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{-# LANGUAGE DisambiguateRecordFields #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Cardano.CLI.Shelley.Run.Pretty (prettyTx) where | ||
|
||
import Cardano.Api | ||
(ShelleyBasedEra (ShelleyBasedEraAllegra, ShelleyBasedEraMary, ShelleyBasedEraShelley)) | ||
import Cardano.Api.Byron (TxBody (ByronTxBody)) | ||
import Cardano.Api.Shelley (TxBody (ShelleyTxBody)) | ||
import Cardano.CLI.Helpers (textShow) | ||
import qualified Cardano.Ledger.ShelleyMA.TxBody as ShelleyMA | ||
import Cardano.Prelude | ||
import Data.Aeson as JSON (Value, object, (.=)) | ||
import Data.Aeson.Encode.Pretty (Config (confCompare), defConfig, encodePretty') | ||
import qualified Shelley.Spec.Ledger.API as Shelley | ||
|
||
prettyTx :: TxBody era -> LByteString | ||
prettyTx body0 = | ||
encodePretty' defConfig{confCompare = compare} $ | ||
object $ | ||
case body0 of | ||
ByronTxBody tx -> ["era" .= ("Byron" :: Text), "tx" .= tx] | ||
ShelleyTxBody ShelleyBasedEraShelley body aux -> | ||
[ "era" .= ("Shelley" :: Text) | ||
, "inputs" .= _inputs | ||
, "outputs" .= _outputs | ||
, "certificates" .= fmap textShow _certs | ||
, "withdrawals" .= withdrawals | ||
, "fee" .= _txfee | ||
, "timetolive" .= _ttl | ||
, "update" .= fmap textShow _txUpdate | ||
, "metadata_hash" .= fmap textShow _mdHash | ||
, "auxiliary_data" .= fmap textShow aux | ||
] | ||
where | ||
Shelley.TxBody | ||
{ _inputs | ||
, _outputs | ||
, _certs | ||
, _wdrls | ||
, _txfee | ||
, _ttl | ||
, _txUpdate | ||
, _mdHash | ||
} = | ||
body | ||
Shelley.Wdrl withdrawals = _wdrls | ||
ShelleyTxBody ShelleyBasedEraAllegra body aux -> | ||
[ "era" .= ("Allegra" :: Text) | ||
, "inputs" .= inputs | ||
, "outputs" .= outputs | ||
, "certificates" .= fmap textShow certificates | ||
, "withdrawals" .= withdrawals | ||
, "fee" .= txfee | ||
, "validity_interval" .= prettyValidityInterval validity | ||
, "update" .= fmap textShow update | ||
, "auxiliary_data_hash" .= fmap textShow adHash | ||
, "mint" .= mint | ||
, "auxiliary_data" .= fmap textShow aux | ||
] | ||
where | ||
ShelleyMA.TxBody | ||
inputs | ||
outputs | ||
certificates | ||
(Shelley.Wdrl withdrawals) | ||
txfee | ||
validity | ||
update | ||
adHash | ||
mint = | ||
body | ||
ShelleyTxBody ShelleyBasedEraMary body aux -> | ||
[ "era" .= ("Mary" :: Text) | ||
, "inputs" .= inputs | ||
, "outputs" .= outputs | ||
, "certificates" .= fmap textShow certificates | ||
, "withdrawals" .= withdrawals | ||
, "fee" .= txfee | ||
, "validity_interval" .= prettyValidityInterval validity | ||
, "update" .= fmap textShow update | ||
, "auxiliary_data_hash" .= fmap textShow adHash | ||
, "mint" .= mint | ||
, "auxiliary_data" .= fmap textShow aux | ||
] | ||
where | ||
ShelleyMA.TxBody | ||
inputs | ||
outputs | ||
certificates | ||
(Shelley.Wdrl withdrawals) | ||
txfee | ||
validity | ||
update | ||
adHash | ||
mint = | ||
body | ||
|
||
prettyValidityInterval :: ShelleyMA.ValidityInterval -> JSON.Value | ||
prettyValidityInterval | ||
ShelleyMA.ValidityInterval{invalidBefore, invalidHereafter} = | ||
object | ||
[ "invalid_before" .= invalidBefore | ||
, "invalid_hereafter" .= invalidHereafter | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters