-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transaction submit: print transaction hash #925
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't add more print statements here. A more principled approach would be to query the mempool to confirm that tx has been submitted and we can derive the txid from the tx itself. Why are we printing the txid here in the first place?
This PR is an answer to this ask by a user: #896. Design has been validated by @CarlosLopezDeLara. |
Responded. We need to know what they intend to do with the information and that will inform what changes we should make, if any. |
I believe this feature adds good value. After submitting a transaction, it's common to share the transaction ID (txid) with the recipient or check it in a blockchain explorer. Including the txid in the output seems like a natural addition, as it's the key information needed for any follow-up. Of course, one can compute the tx-id with |
7799011
to
feffd34
Compare
feffd34
to
1ee583f
Compare
newtype TxIdSubmission = TxIdSubmission {txhash :: T.Text} | ||
deriving (Show, Generic) | ||
|
||
instance FromJSON TxIdSubmission |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put the FromJSON
instance too, in case independent Haskell tooling wants to use it.
liftIO $ Text.putStrLn "Transaction successfully submitted. Transaction hash is:" | ||
let hashText = T.decodeUtf8 $ serialiseToRawBytesHex (getTxId $ getTxBody tx) | ||
liftIO $ LBS.putStrLn $ Aeson.encode $ TxIdSubmission hashText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message should go to stderr, the hash should go to stdout. Otherwise it'll be a hassle to separate one from the other.
|
||
-- | Type used for serialization when printing the hash of a transaction | ||
-- after having submitted it. | ||
newtype TxIdSubmission = TxIdSubmission {txhash :: T.Text} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The name should be
TxSubmissionResult
or something similar, it's a result of a submitting a transaction and not tx id. - Why not use
TxId
? It has a JSON instance already. I mean:
newtype TxSubmissionResult = TxSubmissionResult {txhash :: TxId}
Net.Tx.SubmitSuccess -> liftIO $ Text.putStrLn "Transaction successfully submitted." | ||
Net.Tx.SubmitSuccess -> do | ||
liftIO $ Text.putStrLn "Transaction successfully submitted. Transaction hash is:" | ||
let hashText = T.decodeUtf8 $ serialiseToRawBytesHex (getTxId $ getTxBody tx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates the ToJSON TxId
instance. Can we avoid that?
Changelog
Context
Fixes #896
How to trust this PR
We added a test in
cardano-testnet
: IntersectMBO/cardano-node#6003Checklist