Skip to content

Commit 9fbd897

Browse files
committed
transaction submit: print transaction hash as JSON
1 parent 808d843 commit 9fbd897

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,9 @@ runTransactionSubmitCmd
14831483

14841484
res <- liftIO $ submitTxToNodeLocal localNodeConnInfo txInMode
14851485
case res of
1486-
Net.Tx.SubmitSuccess -> liftIO $ Text.putStrLn "Transaction successfully submitted."
1486+
Net.Tx.SubmitSuccess -> do
1487+
liftIO $ Text.putStrLn "Transaction successfully submitted. Transaction hash is:"
1488+
liftIO $ LBS.putStrLn $ Aeson.encode $ TxIdSubmission (getTxId $ getTxBody tx)
14871489
Net.Tx.SubmitFail reason ->
14881490
case reason of
14891491
TxValidationErrorInCardanoMode err -> left . TxCmdTxSubmitError . Text.pack $ show err

cardano-cli/src/Cardano/CLI/Types/Common.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DeriveGeneric #-}
23
{-# LANGUAGE DerivingStrategies #-}
34
{-# LANGUAGE GADTs #-}
45
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
@@ -68,6 +69,7 @@ module Cardano.CLI.Types.Common
6869
, TxBuildOutputOptions (..)
6970
, TxByronWitnessCount (..)
7071
, TxFile
72+
, TxIdSubmission (..)
7173
, TxTreasuryDonation (..)
7274
, TxInCount (..)
7375
, TxMempoolQuery (..)
@@ -102,6 +104,7 @@ import Data.String (IsString)
102104
import Data.Text (Text)
103105
import qualified Data.Text as Text
104106
import Data.Word (Word64)
107+
import GHC.Generics (Generic)
105108

106109
-- | Determines the direction in which the MIR certificate will transfer ADA.
107110
data TransferDirection
@@ -663,3 +666,12 @@ data PotentiallyCheckedAnchor anchorType anchor
663666
-- ^ Whether to check the hash or not (CheckHash for checking or TrustHash for not checking)
664667
}
665668
deriving (Eq, Show)
669+
670+
-- | Type used for serialization when printing the hash of a transaction
671+
-- after having submitted it.
672+
newtype TxIdSubmission = TxIdSubmission {txhash :: TxId}
673+
deriving (Show, Generic)
674+
675+
instance FromJSON TxIdSubmission
676+
677+
instance ToJSON TxIdSubmission

0 commit comments

Comments
 (0)