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] Add nested vector arg support, docs (#7709) #7790

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions aptos-move/move-examples/cli_args/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "CliArgs"
version = "0.1.0"
upgrade_policy = "compatible"

[addresses]
deploy_address = "_"
std = "0x1"
aptos_framework = "0x1"

[dependencies]
AptosFramework = { local = "../../framework/aptos-framework" }
37 changes: 37 additions & 0 deletions aptos-move/move-examples/cli_args/sources/cli_args.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module deploy_address::cli_args {
use std::signer;

struct Holder has key {
u8_solo: u8,
bool_vec: vector<bool>,
address_vec_vec: vector<vector<address>>,
}


#[view]
public fun reveal(host: address): (u8, vector<bool>, vector<vector<address>>) acquires Holder {
let holder_ref = borrow_global<Holder>(host);
(holder_ref.u8_solo, holder_ref.bool_vec, holder_ref.address_vec_vec)
}

public entry fun set_vals(
account: signer,
u8_solo: u8,
bool_vec: vector<bool>,
address_vec_vec: vector<vector<address>>,
) acquires Holder {
let account_addr = signer::address_of(&account);
if (!exists<Holder>(account_addr)) {
move_to(&account, Holder {
u8_solo,
bool_vec,
address_vec_vec,
})
} else {
let old_holder = borrow_global_mut<Holder>(account_addr);
old_holder.u8_solo = u8_solo;
old_holder.bool_vec = bool_vec;
old_holder.address_vec_vec = address_vec_vec;
}
}
}
27 changes: 20 additions & 7 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,23 @@ pub struct RotationProofChallenge {
pub new_public_key: Vec<u8>,
}

#[derive(Debug, Parser)]
/// This is used for both entry functions and scripts.
pub struct ArgWithTypeVec {
/// Arguments combined with their type separated by spaces.
///
/// Supported types [address, bool, hex, string, u8, u16, u32, u64, u128, u256, raw]
///
/// Vectors may be specified using JSON array literal syntax (you may need to escape this with
/// quotes based on your shell interpreter)
///
/// Example: `address:0x1 bool:true u8:0 u256:1234 "bool:[true, false]" 'address:[["0xace", "0xbee"], []]'`
///
/// Vector is wrapped in a reusable struct for uniform CLI documentation.
#[clap(long, multiple_values = true)]
pub(crate) args: Vec<ArgWithType>,
}

/// Common options for constructing an entry function transaction payload.
#[derive(Debug, Parser)]
pub struct EntryFunctionArguments {
Expand All @@ -1681,13 +1698,8 @@ pub struct EntryFunctionArguments {
#[clap(long)]
pub function_id: MemberId,

/// Arguments combined with their type separated by spaces.
///
/// Supported types [u8, u16, u32, u64, u128, u256, bool, hex, string, address, raw, vector<inner_type>]
///
/// Example: `address:0x1 bool:true u8:0 u256:1234 'vector<u32>:a,b,c,d'`
#[clap(long, multiple_values = true)]
pub args: Vec<ArgWithType>,
#[clap(flatten)]
pub(crate) arg_vec: ArgWithTypeVec,

/// TypeTag arguments separated by spaces.
///
Expand All @@ -1700,6 +1712,7 @@ impl EntryFunctionArguments {
/// Construct and return an entry function payload from function_id, args, and type_args.
pub fn create_entry_function_payload(self) -> CliTypedResult<EntryFunction> {
let args: Vec<Vec<u8>> = self
.arg_vec
.args
.into_iter()
.map(|arg_with_type| arg_with_type.arg)
Expand Down