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 JSON input file support, docs (#7709) #8054

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


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

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

[dependencies]
AptosFramework = { local = "../../framework/aptos-framework" }
[dependencies.AptosFramework]
local = "../../framework/aptos-framework" # <:!:manifest
30 changes: 30 additions & 0 deletions aptos-move/move-examples/cli_args/entry_function_arguments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"function_id": "<test_account>::cli_args::set_vals",
"type_args": [
"0x1::account::Account",
"0x1::chain_id::ChainId"
],
"args": [
{
"arg_type": "u8",
"arg_value": 123
},
{
"arg_type": "bool",
"arg_value": [false, true, false, false]
},
{
"arg_type": "address",
"arg_value": [
[
"0xace",
"0xbee"
],
[
"0xcad"
],
[]
]
}
]
}
20 changes: 20 additions & 0 deletions aptos-move/move-examples/cli_args/script_function_arguments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type_args": [
"0x1::account::Account",
"0x1::chain_id::ChainId"
],
"args": [
{
"arg_type": "u8",
"arg_value": 123
},
{
"arg_type": "u8",
"arg_value": [122, 123, 124, 125]
},
{
"arg_type": "address",
"arg_value": "0xace"
}
]
}
28 changes: 28 additions & 0 deletions aptos-move/move-examples/cli_args/scripts/set_vals.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// :!:>script
script {
use test_account::cli_args;
use std::vector;

/// Get a `bool` vector where each element indicates `true` if the
/// corresponding element in `u8_vec` is greater than `u8_solo`.
/// Then pack `address_solo` in a `vector<vector<<address>>` and
/// pass resulting argument set to public entry function.
fun set_vals<T1, T2>(
account: signer,
u8_solo: u8,
u8_vec: vector<u8>,
address_solo: address,
) {
let bool_vec = vector[];
let i = 0;
while (i < vector::length(&u8_vec)) {
vector::push_back(
&mut bool_vec,
*vector::borrow(&u8_vec, i) > u8_solo
);
i = i + 1;
};
let addr_vec_vec = vector[vector[address_solo]];
cli_args::set_vals<T1, T2>(account, u8_solo, bool_vec, addr_vec_vec);
}
} // <:!:script
66 changes: 43 additions & 23 deletions aptos-move/move-examples/cli_args/sources/cli_args.move
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
module deploy_address::cli_args {
// :!:>resource
module test_account::cli_args {
use std::signer;
use aptos_std::type_info::{Self, TypeInfo};

struct Holder has key {

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

type_info_1: TypeInfo,
type_info_2: TypeInfo,
} //<:!:resource

#[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(
// :!:>setter
/// Set values in a `Holder` under `account`.
public entry fun set_vals<T1, T2>(
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;
}
if (exists<Holder>(account_addr)) {
move_from<Holder>(account_addr);
};
move_to(&account, Holder {
u8_solo,
bool_vec,
address_vec_vec,
type_info_1: type_info::type_of<T1>(),
type_info_2: type_info::type_of<T2>(),
});
} //<:!:setter

// :!:>view
#[view]
/// Reveal first three fields in host's `Holder`, as well as two
/// `bool` flags denoting if `T1` and `T2` respectively match
/// `Holder.type_info_1` and `Holder.type_info_2`.
public fun reveal<T1, T2>(host: address): (
u8,
vector<bool>,
vector<vector<address>>,
bool,
bool
) acquires Holder {
let holder_ref = borrow_global<Holder>(host);
(holder_ref.u8_solo,
holder_ref.bool_vec,
holder_ref.address_vec_vec,
type_info::type_of<T1>() == holder_ref.type_info_1,
type_info::type_of<T2>() == holder_ref.type_info_2)
}
}

} //<:!:view
13 changes: 13 additions & 0 deletions aptos-move/move-examples/cli_args/view_function_arguments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"function_id": "<test_account>::cli_args::reveal",
"type_args": [
"0x1::account::Account",
"0x1::account::Account"
],
"args": [
{
"arg_type": "address",
"arg_value": "<test_account>"
}
]
}
5 changes: 2 additions & 3 deletions crates/aptos/src/account/multisig_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ impl CliCommand<TransactionSummary> for CreateTransaction {
}

async fn execute(self) -> CliTypedResult<TransactionSummary> {
let payload = MultisigTransactionPayload::EntryFunction(
self.entry_function_args.create_entry_function_payload()?,
);
let payload =
MultisigTransactionPayload::EntryFunction(self.entry_function_args.try_into()?);
self.txn_options
.submit_transaction(aptos_stdlib::multisig_account_create_transaction(
self.multisig_account.multisig_address,
Expand Down
Loading