From 81d32a92055a9cda2ae7388f493bf3c2a1fe3d2b Mon Sep 17 00:00:00 2001 From: yusong wang Date: Fri, 12 Aug 2022 01:08:07 +0800 Subject: [PATCH] [cli]list resource support filter struct_type and start_idx max_size (#3639) * [cli]list resource support filter struct_type and start_idx max_size --- cmd/starcoin/src/state/list_cmd.rs | 21 +++++++++++++++++---- testsuite/features/cmd.feature | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/starcoin/src/state/list_cmd.rs b/cmd/starcoin/src/state/list_cmd.rs index dcc5ebc34e..0e0d955214 100644 --- a/cmd/starcoin/src/state/list_cmd.rs +++ b/cmd/starcoin/src/state/list_cmd.rs @@ -8,7 +8,7 @@ use clap::Parser; use scmd::{CommandAction, ExecContext}; use serde::{Serialize, Serializer}; use starcoin_abi_resolver::ABIResolver; -use starcoin_rpc_api::types::{ListCodeView, ListResourceView}; +use starcoin_rpc_api::types::{ListCodeView, ListResourceView, StructTagView}; use starcoin_rpc_client::StateRootOption; use starcoin_vm_types::account_address::AccountAddress; use starcoin_vm_types::language_storage::ModuleId; @@ -38,6 +38,15 @@ pub enum ListDataOpt { #[clap(long, short = 'n')] /// Get state at a special block height. block_number: Option, + + #[clap(long, short = 't')] + resource_type: Option, + + #[clap(long, short = 'i')] + start_index: Option, + + #[clap(long, short = 's')] + max_size: Option, }, } @@ -98,6 +107,9 @@ impl CommandAction for ListCmd { ListDataOpt::Resource { address, block_number, + resource_type, + start_index, + max_size, } => { let state_root = match block_number { Some(block_number) => ctx @@ -110,15 +122,16 @@ impl CommandAction for ListCmd { let state_reader = ctx.state().client().state_reader( state_root.map_or(StateRootOption::Latest, StateRootOption::BlockHash), )?; + ListDataResult::Resource(decode_resource( &state_reader, ctx.state().client().state_list_resource( *address, false, state_root, - 0, - std::usize::MAX, - None, + start_index.unwrap_or_default(), + max_size.unwrap_or_else(|| std::usize::MAX), + resource_type.as_ref().map(|a| vec![a.clone()]), )?, )) } diff --git a/testsuite/features/cmd.feature b/testsuite/features/cmd.feature index ff4f96709c..77ca5c252a 100644 --- a/testsuite/features/cmd.feature +++ b/testsuite/features/cmd.feature @@ -106,6 +106,8 @@ Feature: cmd integration test Then assert: "{{$.state[-1].ok.json.sequence_number}} == 0" Then cmd: "account show" Then cmd: "state list resource {{$.account[0].ok.account.address}}" + Then cmd: "state list resource -t 0x1::Account::Balance {{$.account[0].ok.account.address}}" + Then cmd: "state list resource -s 5 -i 0 {{$.account[0].ok.account.address}}" Then cmd: "account show" Then cmd: "state list code {{$.account[0].ok.account.address}}" Then stop