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 multisig governance tooling, docs #8346

Merged
merged 8 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
alnoki marked this conversation as resolved.
Show resolved Hide resolved
[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 @@
{
alnoki marked this conversation as resolved.
Show resolved Hide resolved
"function_id": "<test_account>::cli_args::set_vals",
"type_args": [
"0x1::account::Account",
"0x1::chain_id::ChainId"
],
"args": [
{
"arg_type": "u8",
"arg_value": 123
alnoki marked this conversation as resolved.
Show resolved Hide resolved
},
{
"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)) {
alnoki marked this conversation as resolved.
Show resolved Hide resolved
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): (
alnoki marked this conversation as resolved.
Show resolved Hide resolved
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>"
}
]
}
2 changes: 2 additions & 0 deletions crates/aptos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ self_update = { version = "0.34.0", features = ["archive-zip", "compression-zip-
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
sha2 = { workspace = true }
sha3 = { workspace = true }
shadow-rs = { workspace = true }
tempfile = { workspace = true }
termcolor = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/aptos/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl AccountTool {
pub enum MultisigAccountTool {
Approve(multisig_account::Approve),
Create(multisig_account::Create),
CheckTransaction(multisig_account::CheckTransaction),
CreateTransaction(multisig_account::CreateTransaction),
Execute(multisig_account::Execute),
ExecuteReject(multisig_account::ExecuteReject),
Expand All @@ -60,6 +61,7 @@ impl MultisigAccountTool {
match self {
MultisigAccountTool::Approve(tool) => tool.execute_serialized().await,
MultisigAccountTool::Create(tool) => tool.execute_serialized().await,
MultisigAccountTool::CheckTransaction(tool) => tool.execute_serialized().await,
MultisigAccountTool::CreateTransaction(tool) => tool.execute_serialized().await,
MultisigAccountTool::Execute(tool) => tool.execute_serialized().await,
MultisigAccountTool::ExecuteReject(tool) => tool.execute_serialized().await,
Expand Down
Loading