Skip to content

Commit

Permalink
[cli]list resource support filter struct_type and start_idx max_size (#…
Browse files Browse the repository at this point in the history
…3639)

* [cli]list resource support filter struct_type and start_idx max_size
  • Loading branch information
YouNeedWork authored Aug 11, 2022
1 parent 098adf0 commit 81d32a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmd/starcoin/src/state/list_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +38,15 @@ pub enum ListDataOpt {
#[clap(long, short = 'n')]
/// Get state at a special block height.
block_number: Option<u64>,

#[clap(long, short = 't')]
resource_type: Option<StructTagView>,

#[clap(long, short = 'i')]
start_index: Option<usize>,

#[clap(long, short = 's')]
max_size: Option<usize>,
},
}

Expand Down Expand Up @@ -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
Expand All @@ -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()]),
)?,
))
}
Expand Down
2 changes: 2 additions & 0 deletions testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 81d32a9

Please sign in to comment.