Skip to content

Commit

Permalink
transaction submit: print transaction hash as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Nov 13, 2024
1 parent 31e628f commit 2e301c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.hPutStrLn IO.stderr "Transaction successfully submitted. Transaction hash is:"
liftIO $ LBS.putStrLn $ Aeson.encode $ TxSubmissionResult $ getTxId $ getTxBody tx
Net.Tx.SubmitFail reason ->
case reason of
TxValidationErrorInCardanoMode err -> left . TxCmdTxSubmitError . Text.pack $ show err
Expand Down
12 changes: 12 additions & 0 deletions cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
Expand Down Expand Up @@ -68,6 +69,7 @@ module Cardano.CLI.Types.Common
, TxBuildOutputOptions (..)
, TxByronWitnessCount (..)
, TxFile
, TxSubmissionResult (..)
, TxTreasuryDonation (..)
, TxInCount (..)
, TxMempoolQuery (..)
Expand Down Expand Up @@ -102,6 +104,7 @@ import Data.String (IsString)
import Data.Text (Text)
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
Expand Down Expand Up @@ -663,3 +666,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 TxSubmissionResult = TxSubmissionResult {txhash :: TxId}
deriving (Show, Generic)

instance FromJSON TxSubmissionResult

instance ToJSON TxSubmissionResult

0 comments on commit 2e301c2

Please sign in to comment.