Skip to content

Commit

Permalink
Print hash of submitted transaction as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Nov 7, 2024
1 parent 3d8aefa commit 1ee583f
Show file tree
Hide file tree
Showing 2 changed files with 16 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 @@ -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 (..))
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 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
, TxIdSubmission (..)
, TxTreasuryDonation (..)
, TxInCount (..)
, TxMempoolQuery (..)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1ee583f

Please sign in to comment.