From 3d8aefadd19504a04b9b8400b0f8b56850688c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 4 Oct 2024 16:27:11 +0200 Subject: [PATCH 1/2] transaction submit: print transaction hash --- cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index c59ace374..f90c8dba1 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -1483,7 +1483,9 @@ runTransactionSubmitCmd res <- liftIO $ submitTxToNodeLocal localNodeConnInfo txInMode case res of - Net.Tx.SubmitSuccess -> liftIO $ Text.putStrLn "Transaction successfully submitted." + Net.Tx.SubmitSuccess -> do + liftIO $ Text.putStrLn "Transaction successfully submitted. Transaction hash is:" + liftIO $ BS.putStrLn $ serialiseToRawBytesHex (getTxId $ getTxBody tx) Net.Tx.SubmitFail reason -> case reason of TxValidationErrorInCardanoMode err -> left . TxCmdTxSubmitError . Text.pack $ show err From 1ee583fccdaf42e67b8434e0f3dd2a8917bf0b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 7 Nov 2024 11:20:10 +0100 Subject: [PATCH 2/2] Print hash of submitted transaction as JSON --- .../src/Cardano/CLI/EraBased/Run/Transaction.hs | 4 +++- cardano-cli/src/Cardano/CLI/Types/Common.hs | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index f90c8dba1..5c65baf44 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -75,6 +75,7 @@ import Data.Maybe (catMaybes, fromMaybe, mapMaybe) import Data.Set (Set) import qualified Data.Set as Set import qualified Data.Text as Text +import qualified Data.Text.Encoding as T import qualified Data.Text.IO as Text import Data.Type.Equality (TestEquality (..)) import GHC.Exts (IsList (..)) @@ -1485,7 +1486,8 @@ runTransactionSubmitCmd case res of Net.Tx.SubmitSuccess -> do liftIO $ Text.putStrLn "Transaction successfully submitted. Transaction hash is:" - liftIO $ BS.putStrLn $ serialiseToRawBytesHex (getTxId $ getTxBody tx) + let hashText = T.decodeUtf8 $ serialiseToRawBytesHex (getTxId $ getTxBody tx) + liftIO $ LBS.putStrLn $ Aeson.encode $ TxIdSubmission hashText Net.Tx.SubmitFail reason -> case reason of TxValidationErrorInCardanoMode err -> left . TxCmdTxSubmitError . Text.pack $ show err diff --git a/cardano-cli/src/Cardano/CLI/Types/Common.hs b/cardano-cli/src/Cardano/CLI/Types/Common.hs index c765ac64a..70d092043 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Common.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Common.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralisedNewtypeDeriving #-} @@ -68,6 +69,7 @@ module Cardano.CLI.Types.Common , TxBuildOutputOptions (..) , TxByronWitnessCount (..) , TxFile + , TxIdSubmission (..) , TxTreasuryDonation (..) , TxInCount (..) , TxMempoolQuery (..) @@ -100,8 +102,10 @@ import Data.Aeson (FromJSON (..), ToJSON (..), object, pairs, (.=)) import qualified Data.Aeson as Aeson import Data.String (IsString) import Data.Text (Text) +import qualified Data.Text as T import qualified Data.Text as Text import Data.Word (Word64) +import GHC.Generics (Generic) -- | Determines the direction in which the MIR certificate will transfer ADA. data TransferDirection @@ -663,3 +667,12 @@ data PotentiallyCheckedAnchor anchorType anchor -- ^ Whether to check the hash or not (CheckHash for checking or TrustHash for not checking) } deriving (Eq, Show) + +-- | Type used for serialization when printing the hash of a transaction +-- after having submitted it. +newtype TxIdSubmission = TxIdSubmission {txhash :: T.Text} + deriving (Show, Generic) + +instance FromJSON TxIdSubmission + +instance ToJSON TxIdSubmission