-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add a summary of the signed transaction #1526
Conversation
I will change a few things and make transactions generally printable. I converted the PR to draft. |
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.
Switched to ready to review. Please double-check that what I did makes sense.
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 looks good to me.
A nuclear option would be to generalise this with traits, roughly like this:
- Introduce a
Summarize
trait that has the same signature asstd::fmt::Display
but takes an extrachain_config
parameter - Introduce a wrapper type
Summary(T, &ChainConfig)
which implementsDisplay
ifT: Summarize
. It now works everywhere you can useDisplay
. - There could be even extension trait that makes the syntax even more convenient, changing from
Summary(my_tx, &cc)
tomy_tx.summary(&cc)
- The summary trait could be implemented for outputs, inputs, transactions, or whatever else needs to be summarized
The above reuses all the formatting machinery already in Rust and would integrate rather nicely with existing tools, for exmaple:
log::debug!("Summary of transaction: {}", my_tx.summary(&cc))
- same with
println!
,format!
,write!
and such my_tx.summary(&cc).to_string()
would work too
let s = match output { | ||
TxOutput::Transfer(val, dest) => { | ||
let val_str = fmt_val(val); | ||
format!("Transfer({}, {val_str})", fmt_dest(dest)) | ||
} |
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 output printout could be taken out to a separate function in case someone wants to print outputs separately. Similarly with inputs.
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 will do the separation in a separate PR.
Print out a summary of the singed transaction form the wallet CLI