Skip to content
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

[fastx CLI] Improve demo wallet's UX and add option to choose between pretty print or json output #536

Merged
merged 5 commits into from
Feb 23, 2022

Conversation

patrickkuo
Copy link
Contributor

@patrickkuo patrickkuo commented Feb 23, 2022

  • new --json flag for json output
  • WalletCommand now returns WalletCommandResult
  • implemented Display and Debug for WalletCommandResult, for pretty print and json output
  • implemented Display for CertifiedTransaction
  • --no-shell and --json flag is now a global flag
  • object --deep is now replace by --json

Todo: Update docs

Call :

sui>-$ call --package 0x2 --module ObjectBasics --function create --gas 1159FC75BA09271060103B037531C62FB65BCEF2 --pure-args 100u64 x\"1076355727bdc26bfc8424d473c5ccd44f81b566b0b48d4822d5d5eced5d8c12\" --gas-budget 100
----- Certificate ----
Signed Authorities : [k#2c08e9e1e0f1f52ed343d5283406e405a1d970392c904d1ba0757e73364b8c67, k#9b13cdc18677c0bc7e489243c2c8e9aa4f213cda09e4e01181e587e1a575a941, k#39da0e4306c28d3ee0731e311f01b6ea8d6a0e3d06a3645d80ccd077c3c0d13e]
Transaction Kind : Call
Gas Budget : 100
Package ID : 0000000000000000000000000000000000000002
Module : ObjectBasics
Function : create
Object Arguments : []
Pure Arguments : [[100, 0, 0, 0, 0, 0, 0, 0], [32, 16, 118, 53, 87, 39, 189, 194, 107, 252, 132, 36, 212, 115, 197, 204, 212, 79, 129, 181, 102, 176, 180, 141, 72, 34, 213, 213, 236, 237, 93, 140, 18]]
Type Arguments : []
Gas Budget : []
----- Transaction Effects ----
Status : Success { gas_used: 62 }
Created Objects:
597526E9B2A26130DC97B9094E9B854EA8C2CA28 SequenceNumber(1) o#9f268c5751a0b81499e1a7b07076a87535f18385d55134166cc087e34a1afd32
Mutated Objects:
1159FC75BA09271060103B037531C62FB65BCEF2 SequenceNumber(6) o#597ca6c10f80bd8eee583fec930a1a4340704d512f5b2c08a735523f9825b6e8

Transfer:

sui>-$ transfer --to 1A6CB47D2EA575A071F47F273D0B1BB50401E9A6B6A465F8227FF03FD8926A2A --object-id 325AAC55013A3F760AB78404E9271B83A9F03AD2 --gas A5E66F3DD6F262AC2C97C93580C6DA13158C369C 
Transfer confirmed after 11115 us
----- Certificate ----
Signed Authorities : [k#2c08e9e1e0f1f52ed343d5283406e405a1d970392c904d1ba0757e73364b8c67, k#9b13cdc18677c0bc7e489243c2c8e9aa4f213cda09e4e01181e587e1a575a941, k#39da0e4306c28d3ee0731e311f01b6ea8d6a0e3d06a3645d80ccd077c3c0d13e]
Transaction Kind : Transfer
Recipient : 1A6CB47D2EA575A071F47F273D0B1BB50401E9A6B6A465F8227FF03FD8926A2A
Object ID : 325AAC55013A3F760AB78404E9271B83A9F03AD2
Sequence Number : SequenceNumber(0)
Object Digest : 25b362dc1a41516464eba1fec8fdc5a4494e0bcce100f06cbb41320e18051d23
----- Transaction Effects ----
Status : Success { gas_used: 18 }
Mutated Objects:
325AAC55013A3F760AB78404E9271B83A9F03AD2 SequenceNumber(1) o#2e70c346726f30c20afd14d8e85a61037642617a40cfac0564a268110933867b
A5E66F3DD6F262AC2C97C93580C6DA13158C369C SequenceNumber(1) o#9c3efe5f0de99a4340f7cb638b33124f185092fa7e40b4d3d35c44bed87bd507

Example json output:

sui>-$ transfer --to 1076355727BDC26BFC8424D473C5CCD44F81B566B0B48D4822D5D5ECED5D8C12 --object-id AD8A79A077BC9CF683DF1C14BA07EE4E8D12CBD0 --gas 724BD7026794302C4D0C5079615FD0A0D1B1BEC7 --json
[{"transaction":{"data":{"kind":{"Transfer":{"recipient":[16,118,53,87,39,189,194,107,252,132,36,212,115,197,204,212,79,129,181,102,176,180,141,72,34,213,213,236,237,93,140,18],"object_ref":["ad8a79a077bc9cf683df1c14ba07ee4e8d12cbd0",0,[212,84,69,158,191,157,195,190,14,180,2,91,235,187,254,216,184,109,222,123,203,248,157,76,156,102,237,203,13,149,248,51]]}},"sender":[81,179,231,143,215,24,214,246,38,114,125,244,47,172,24,46,157,175,115,104,145,142,253,200,250,217,13,204,95,80,95,151],"gas_payment":["724bd7026794302c4d0c5079615fd0a0d1b1bec7",0,[206,224,197,2,119,190,249,159,215,196,52,166,183,193,193,42,134,21,67,200,174,112,122,118,43,102,68,159,171,105,105,243]]},"signature":[30,119,103,148,79,61,140,108,164,254,28,139,240,179,56,220,58,137,141,17,196,197,250,45,186,211,34,161,106,180,15,172,112,78,37,251,135,189,154,158,22,178,112,220,126,64,173,68,193,198,182,84,142,40,130,214,44,91,203,225,71,109,239,11,23,125,161,213,168,248,156,144,27,253,8,155,114,13,91,80,76,197,100,120,2,177,195,155,154,164,2,67,201,225,25,118]},"signatures":[[[98,137,209,38,132,3,70,160,255,198,170,122,66,177,60,65,226,184,121,172,94,90,132,141,192,253,150,105,61,19,162,158],[119,64,36,175,59,41,71,193,130,161,143,164,118,198,130,142,175,198,98,16,222,38,155,173,201,230,116,130,186,40,69,129,6,58,254,227,219,175,63,193,250,145,31,251,30,43,227,62,92,23,55,55,124,3,6,193,126,117,111,59,185,144,71,8]],[[44,8,233,225,224,241,245,46,211,67,213,40,52,6,228,5,161,217,112,57,44,144,77,27,160,117,126,115,54,75,140,103],[129,10,126,15,210,57,5,49,192,172,159,190,117,187,226,189,197,71,104,87,241,23,167,241,222,64,165,150,165,24,152,40,143,127,90,12,165,190,93,58,130,205,141,68,118,138,123,151,240,75,153,253,189,82,210,106,12,221,213,103,39,246,116,15]],[[57,218,14,67,6,194,141,62,224,115,30,49,31,1,182,234,141,106,14,61,6,163,100,93,128,204,208,119,195,192,209,62],[189,238,129,73,211,78,225,44,202,254,8,84,12,74,141,131,93,170,230,26,206,223,132,251,67,213,47,166,45,236,83,16,235,72,70,26,7,50,86,204,2,170,40,90,35,238,75,231,17,184,153,238,79,226,34,177,132,37,158,199,108,24,24,9]]]},{"status":{"Success":{"gas_used":18}},"transaction_digest":[88,185,19,42,239,202,202,97,56,209,9,204,79,63,84,91,193,228,81,110,48,173,49,235,36,81,197,23,245,239,112,132],"created":[],"mutated":[[["724bd7026794302c4d0c5079615fd0a0d1b1bec7",1,[108,195,174,243,203,194,79,220,232,233,88,147,59,36,81,55,202,173,145,207,32,207,126,119,222,82,156,136,162,28,255,142]],[81,179,231,143,215,24,214,246,38,114,125,244,47,172,24,46,157,175,115,104,145,142,253,200,250,217,13,204,95,80,95,151]],[["ad8a79a077bc9cf683df1c14ba07ee4e8d12cbd0",1,[5,8,37,8,86,31,179,131,110,29,167,78,170,83,38,180,242,18,96,71,137,139,104,68,117,102,245,131,60,158,247,188]],[16,118,53,87,39,189,194,107,252,132,36,212,115,197,204,212,79,129,181,102,176,180,141,72,34,213,213,236,237,93,140,18]]],"deleted":[],"gas_object":[["724bd7026794302c4d0c5079615fd0a0d1b1bec7",1,[108,195,174,243,203,194,79,220,232,233,88,147,59,36,81,55,202,173,145,207,32,207,126,119,222,82,156,136,162,28,255,142]],[81,179,231,143,215,24,214,246,38,114,125,244,47,172,24,46,157,175,115,104,145,142,253,200,250,217,13,204,95,80,95,151]],"events":[],"dependencies":[]}]

@patrickkuo patrickkuo changed the title [fastx CLI] Improve demo wallet's UX and add option to choose between pretty print or json output #403 [fastx CLI] Improve demo wallet's UX and add option to choose between pretty print or json output Feb 23, 2022
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s = match self {
WalletCommandResult::Publish(cert, effects) => {
if matches!(effects.status, ExecutionStatus::Failure { .. }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as if let ExecutionStatus::Failure {..} = effects.status right? I think if let is more readable, but this is just a really small thing

effects.status
)));
}
vec![
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code pattern is repeated a lot, might want to make a quick fn out of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just changed these to use fmt:write instead

Copy link
Contributor

@velvia velvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great set of changes @patrickkuo !

* WalletCommand now returns WalletCommandResult
* implement Display and Debug for WalletCommandResult, for pretty print and json output
* --no-shell and --json flag is now a global flag
fix gas command
@patrickkuo patrickkuo requested a review from velvia February 23, 2022 19:37
@patrickkuo
Copy link
Contributor Author

rebased and made Gas command work with the new WalletCommandResult

writeln!(writer, "Object Arguments : {:?}", c.object_arguments)?;
writeln!(writer, "Pure Arguments : {:?}", c.pure_arguments)?;
writeln!(writer, "Type Arguments : {:?}", c.type_arguments)?;
writeln!(writer, "Gas Budget : {:?}", c.object_arguments)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Gas Budget

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! good spot

Copy link
Contributor

@velvia velvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @patrickkuo love the latest set of changes, much more compact and easier to read!

@patrickkuo patrickkuo merged commit 871500f into main Feb 23, 2022
@patrickkuo patrickkuo deleted the pat/cli-json-output branch February 23, 2022 20:34
mwtian pushed a commit that referenced this pull request Sep 12, 2022
…536)

* Rename field 'batch' to 'transaction_list'

* Remove concept of batches in client facing code

* update example docs
mwtian pushed a commit to mwtian/sui that referenced this pull request Sep 29, 2022
…ystenLabs#536)

* Rename field 'batch' to 'transaction_list'

* Remove concept of batches in client facing code

* update example docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fastx CLI] Improve demo wallet's UX and add option to choose between pretty print or json output
4 participants