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

[CLI] Use tabled to convert JSON to table format #2887

Merged
merged 15 commits into from
Nov 14, 2024

Conversation

baicaiyihao
Copy link
Contributor

Summary

I added a new file, crates/rooch-rpc-api/src/jsonrpc_types/json_to_table_display.rs, which is used to convert transaction JSON data into table format. I've tried my best to optimize, but it still seems like there's a lot of data. Do you have any better suggestions?
Currently, I've applied this functionality only to the rooch account transfer command. By default, the output is in table format, and the --json option can be used to retrieve the output in JSON format. Here’s an example of the output:

rooch account transfer --to rooch15un9ky539eume4qsjpt7d73wft53tsewlvyyzgzfpyyywyk4mw2qv28808 --coin-type 0x3::gas_coin::RGas --amount 100
╭──────────────────────────────────────────────────────────────────────────────────╮
│ Execution Info                                                                   │
├──────────────────────────────────────────────────────────────────────────────────┤
│ tx_hash: "0xeb2572df5251d50856289d5e5bee6230d4458d38d1d6d42f9646b45eff555273"    │
│ state_root: "0xb7da8a2a67faf6a9e9a16eee0212bc5c920b2907cb3b88acb8706f4f4ba3cec3" │
│ event_root: "0x5c24e3d98f4939271ebfe0a8bdc37ac6c2cb75e879e19b03cd9b0d07ad8de599" │
│ gas_used: "777350"                                                               │
│ [status]                                                                         │
│ type: "executed"                                                                 │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ Changeset                                                                                    │
├──────────────────────────────────────────────────────────────────────────────────────────────┤
│ [metadata]                                                                                   │
│ id: "0x1058d2e1fbda447b44d76980712ad902a234f61ab3c3e78105a1fbd4c5301a12"                     │
│ owner: "rooch1l6y2sn6u9dggxv28ttj4yfvazvvlsul9dq94lht9p3qhxrww6erqxfvmxt"                    │
│ owner_bitcoin_address: null                                                                  │
│ flag: 0                                                                                      │
│ state_root: "0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000"             │
│ size: "0"                                                                                    │
│ created_at: "1730174364000"                                                                  │
│ updated_at: "1731402037364"                                                                  │
│ object_type: "0x3::coin_store::CoinStore<0x3::gas_coin::RGas>"                               │
│ [value]                                                                                      │
│ modify: "0xc5132c090000000000000000000000000000000000000000000000000000000000"               │
│ ─────────────────────                                                                        │
│ [metadata]                                                                                   │
│ id: "0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca"                     │
│ owner: "rooch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhxqaen"                    │
│ owner_bitcoin_address: null                                                                  │
│ flag: 1                                                                                      │
│ state_root: "0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000"             │
│ size: "0"                                                                                    │
│ created_at: "1725416189000"                                                                  │
│ updated_at: "1731402037364"                                                                  │
│ object_type: "0x2::timestamp::Timestamp"                                                     │
│ [value]                                                                                      │
│ modify: "0x74789a1f93010000"                                                                 │
│ ─────────────────────                                                                        │
│ [metadata]                                                                                   │
│ id: "0x9f56f080b27183553618a84b573b30d79b3b0fcfb2fecf9be4b95308cd0e221e"                     │
│ owner: "rooch15un9ky539eume4qsjpt7d73wft53tsewlvyyzgzfpyyywyk4mw2qv28808"                    │
│ owner_bitcoin_address: null                                                                  │
│ flag: 0                                                                                      │
│ state_root: "0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000"             │
│ size: "0"                                                                                    │
│ created_at: "1731293019092"                                                                  │
│ updated_at: "1731402037364"                                                                  │
│ object_type: "0x3::coin_store::CoinStore<0x3::gas_coin::RGas>"                               │
│ [value]                                                                                      │
│ modify: "0x280a00000000000000000000000000000000000000000000000000000000000000"               │
│ ─────────────────────                                                                        │
│ [metadata]                                                                                   │
│ id: "0xa2df14d377e38f7ac5e73396163cd9e5110faa5d199244aaa0c36f97b5fa2559"                     │
│ owner: "rooch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhxqaen"                    │
│ owner_bitcoin_address: null                                                                  │
│ flag: 0                                                                                      │
│ state_root: "0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000"             │
│ size: "0"                                                                                    │
│ created_at: "1725416189000"                                                                  │
│ updated_at: "1731402037364"                                                                  │
│ object_type: "0x3::coin_store::CoinStore<0x3::gas_coin::RGas>"                               │
│ [value]                                                                                      │
│ modify: "0x48f3fb706100000000000000000000000000000000000000000000000000000000"               │
│ ─────────────────────                                                                        │
│ [metadata]                                                                                   │
│ id: "0xfe88a84f5c2b508331475ae552259d1319f873e5680b5fdd650c41730dced646"                     │
│ owner: "rooch1l6y2sn6u9dggxv28ttj4yfvazvvlsul9dq94lht9p3qhxrww6erqxfvmxt"                    │
│ owner_bitcoin_address: null                                                                  │
│ flag: 0                                                                                      │
│ state_root: "0x3f4cbb9ac9e955dee4421a1a0bdd9de5d093777e15e5748d3140b106a4e16b65"             │
│ size: "1"                                                                                    │
│ created_at: "1730174364000"                                                                  │
│ updated_at: "1731402037364"                                                                  │
│ object_type: "0x2::account::Account"                                                         │
│ [value]                                                                                      │
│ modify: "0xfe88a84f5c2b508331475ae552259d1319f873e5680b5fdd650c41730dced6462700000000000000" │
│ ─────────────────────                                                                        │
│ state_root: "0xb7da8a2a67faf6a9e9a16eee0212bc5c920b2907cb3b88acb8706f4f4ba3cec3"             │
│ global_size: "2164"                                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Events                                                                                          │
├─────────────────────────────────────────────────────────────────────────────────────────────────┤
│ [event_id]                                                                                      │
│ event_handle_id: "0x18e4e7d4ead4c9a9be261bbe4c140e06c12a6e9bd7cad46a9f44caa4acc4174c"           │
│ event_seq: "1926904"                                                                            │
│ event_type: "0x3::coin_store::WithdrawEvent"                                                    │
│ event_index: "0"                                                                                │
│ [decoded_event_data]                                                                            │
│ abilities: 7                                                                                    │
│ type: "0x3::coin_store::WithdrawEvent"                                                          │
│ [value]                                                                                         │
│ amount: "100000000"                                                                             │
│ coin_store_id: "0x1058d2e1fbda447b44d76980712ad902a234f61ab3c3e78105a1fbd4c5301a12"             │
│ coin_type: "0x0000000000000000000000000000000000000000000000000000000000000003::gas_coin::RGas" │
│ ─────────────────────                                                                           │
│ [event_id]                                                                                      │
│ event_handle_id: "0xb853393e53406be49dfd6325e65de25eae00c348cbe0b2cec8ea56513fa2c26a"           │
│ event_seq: "1927670"                                                                            │
│ event_type: "0x3::coin_store::DepositEvent"                                                     │
│ event_index: "1"                                                                                │
│ [decoded_event_data]                                                                            │
│ abilities: 7                                                                                    │
│ type: "0x3::coin_store::DepositEvent"                                                           │
│ [value]                                                                                         │
│ amount: "100000000"                                                                             │
│ coin_store_id: "0xa2df14d377e38f7ac5e73396163cd9e5110faa5d199244aaa0c36f97b5fa2559"             │
│ coin_type: "0x0000000000000000000000000000000000000000000000000000000000000003::gas_coin::RGas" │
│ ─────────────────────                                                                           │
│ [event_id]                                                                                      │
│ event_handle_id: "0x18e4e7d4ead4c9a9be261bbe4c140e06c12a6e9bd7cad46a9f44caa4acc4174c"           │
│ event_seq: "1926905"                                                                            │
│ event_type: "0x3::coin_store::WithdrawEvent"                                                    │
│ event_index: "2"                                                                                │
│ [decoded_event_data]                                                                            │
│ abilities: 7                                                                                    │
│ type: "0x3::coin_store::WithdrawEvent"                                                          │
│ [value]                                                                                         │
│ amount: "100"                                                                                   │
│ coin_store_id: "0x1058d2e1fbda447b44d76980712ad902a234f61ab3c3e78105a1fbd4c5301a12"             │
│ coin_type: "0x0000000000000000000000000000000000000000000000000000000000000003::gas_coin::RGas" │
│ ─────────────────────                                                                           │
│ [event_id]                                                                                      │
│ event_handle_id: "0xb853393e53406be49dfd6325e65de25eae00c348cbe0b2cec8ea56513fa2c26a"           │
│ event_seq: "1927671"                                                                            │
│ event_type: "0x3::coin_store::DepositEvent"                                                     │
│ event_index: "3"                                                                                │
│ [decoded_event_data]                                                                            │
│ abilities: 7                                                                                    │
│ type: "0x3::coin_store::DepositEvent"                                                           │
│ [value]                                                                                         │
│ amount: "100"                                                                                   │
│ coin_store_id: "0x9f56f080b27183553618a84b573b30d79b3b0fcfb2fecf9be4b95308cd0e221e"             │
│ coin_type: "0x0000000000000000000000000000000000000000000000000000000000000003::gas_coin::RGas" │
│ ─────────────────────                                                                           │
│ [event_id]                                                                                      │
│ event_handle_id: "0x18e4e7d4ead4c9a9be261bbe4c140e06c12a6e9bd7cad46a9f44caa4acc4174c"           │
│ event_seq: "1926906"                                                                            │
│ event_type: "0x3::coin_store::WithdrawEvent"                                                    │
│ event_index: "4"                                                                                │
│ [decoded_event_data]                                                                            │
│ abilities: 7                                                                                    │
│ type: "0x3::coin_store::WithdrawEvent"                                                          │
│ [value]                                                                                         │
│ amount: "99222650"                                                                              │
│ coin_store_id: "0xa2df14d377e38f7ac5e73396163cd9e5110faa5d199244aaa0c36f97b5fa2559"             │
│ coin_type: "0x0000000000000000000000000000000000000000000000000000000000000003::gas_coin::RGas" │
│ ─────────────────────                                                                           │
│ [event_id]                                                                                      │
│ event_handle_id: "0xb853393e53406be49dfd6325e65de25eae00c348cbe0b2cec8ea56513fa2c26a"           │
│ event_seq: "1927672"                                                                            │
│ event_type: "0x3::coin_store::DepositEvent"                                                     │
│ event_index: "5"                                                                                │
│ [decoded_event_data]                                                                            │
│ abilities: 7                                                                                    │
│ type: "0x3::coin_store::DepositEvent"                                                           │
│ [value]                                                                                         │
│ amount: "99222650"                                                                              │
│ coin_store_id: "0x1058d2e1fbda447b44d76980712ad902a234f61ab3c3e78105a1fbd4c5301a12"             │
│ coin_type: "0x0000000000000000000000000000000000000000000000000000000000000003::gas_coin::RGas" │
│ ─────────────────────                                                                           │
╰─────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────╮
│ Output Status             │
├───────────────────────────┤
│ [status]                  │
│ type: "executed"          │
│ changeset: [complex data] │
│ events: [complex data]    │
│ gas_used: "777350"        │
│ is_upgrade: false         │
╰───────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Sequence Info                                                                                    │
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
│ tx_order: "101730878"                                                                            │
│ tx_order_signature:                                                                              │
│ 0x0179c92ff3d8fd080783388dece832069ceaf1cb40ab9b72fb000359bb69c4e9a534d067c586cc52034abdd5553ac6 │
│ 72149fd6f28d24286410f9aa54a8898a0940026c9e5a00643a706d3826424f766bbbb08adada4dc357c1b279ad4662d2 │
│ fd1e2e                                                                                           │
│ tx_accumulator_root: "0xbc8453c4a8e382ff3ba5cd00a06c886b351a3ddcd139806da89c5355ec1a9633"        │
│ tx_timestamp: "1731402037364"                                                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

I’ve also modified the rooch session-key list command so that it defaults to table display, with the option to use --json for JSON format.

References #2864

Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rooch-portal-v2.1 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 11:05am
test-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 11:05am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
rooch ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 11:05am

@jolestar jolestar merged commit 30ef683 into rooch-network:main Nov 14, 2024
9 checks passed
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.

2 participants