Skip to content

Commit

Permalink
[CLI] Add multisig governance tooling, docs (#8346)
Browse files Browse the repository at this point in the history
  • Loading branch information
alnoki committed May 27, 2023
1 parent e0c6a8b commit fbc88b8
Show file tree
Hide file tree
Showing 20 changed files with 1,947 additions and 279 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 3 additions & 5 deletions aptos-move/move-examples/cli_args/Move.toml
Expand Up @@ -4,9 +4,7 @@ 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"
30 changes: 30 additions & 0 deletions aptos-move/move-examples/cli_args/entry_function_arguments.json
@@ -0,0 +1,30 @@
{
"function_id": "<test_account>::cli_args::set_vals",
"type_args": [
"0x1::account::Account",
"0x1::chain_id::ChainId"
],
"args": [
{
"type": "u8",
"value": 123
},
{
"type": "bool",
"value": [false, true, false, false]
},
{
"type": "address",
"value": [
[
"0xace",
"0xbee"
],
[
"0xcad"
],
[]
]
}
]
}
20 changes: 20 additions & 0 deletions aptos-move/move-examples/cli_args/script_function_arguments.json
@@ -0,0 +1,20 @@
{
"type_args": [
"0x1::account::Account",
"0x1::chain_id::ChainId"
],
"args": [
{
"type": "u8",
"value": 123
},
{
"type": "u8",
"value": [122, 123, 124, 125]
},
{
"type": "address",
"value": "0xace"
}
]
}
20 changes: 20 additions & 0 deletions aptos-move/move-examples/cli_args/scripts/set_vals.move
@@ -0,0 +1,20 @@
// :!:>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::map_ref(&u8_vec, |e_ref| *e_ref > u8_solo);
let addr_vec_vec = vector[vector[address_solo]];
cli_args::set_vals<T1, T2>(account, u8_solo, bool_vec, addr_vec_vec);
}
} // <:!:script
71 changes: 49 additions & 22 deletions aptos-move/move-examples/cli_args/sources/cli_args.move
@@ -1,37 +1,64 @@
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
struct RevealResult has drop {
u8_solo: u8,
bool_vec: vector<bool>,
address_vec_vec: vector<vector<address>>,
type_info_1_match: bool,
type_info_2_match: bool
}

#[view]
/// Pack into a `RevealResult` the first three fields in host's
/// `Holder`, as well as two `bool` flags denoting if `T1` & `T2`
/// respectively match `Holder.type_info_1` & `Holder.type_info_2`,
/// then return the `RevealResult`.
public fun reveal<T1, T2>(host: address): RevealResult acquires Holder {
let holder_ref = borrow_global<Holder>(host);
RevealResult {
u8_solo: holder_ref.u8_solo,
bool_vec: holder_ref.bool_vec,
address_vec_vec: holder_ref.address_vec_vec,
type_info_1_match:
type_info::type_of<T1>() == holder_ref.type_info_1,
type_info_2_match:
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
@@ -0,0 +1,13 @@
{
"function_id": "<test_account>::cli_args::reveal",
"type_args": [
"0x1::account::Account",
"0x1::account::Account"
],
"args": [
{
"type": "address",
"value": "<test_account>"
}
]
}
8 changes: 8 additions & 0 deletions crates/aptos/CHANGELOG.md
Expand Up @@ -6,6 +6,14 @@ All notable changes to the Aptos CLI will be captured in this file. This project
- Add nested vector arg support
- Updated DB bootstrap command with new DB restore features

## [1.0.14] - 2023/05/25

### Added
- Recursive nested vector parsing
- Multisig v2 governance support
- JSON support for both input files and CLI argument input
- **Breaking change**: You can no longer pass in a vector like this: `--arg vector<address>:0x1,0x2`, you must do it like this: `--arg 'address:["0x1", "0x2"]'`

## [1.0.13] - 2023/04/27
### Fixed
* Previously `--skip-fetch-latest-git-deps` would not actually do anything when used with `aptos move test`. This has been fixed.
Expand Down
1 change: 1 addition & 0 deletions crates/aptos/Cargo.toml
Expand Up @@ -69,6 +69,7 @@ move-prover-boogie-backend = { workspace = true }
move-symbol-pool = { workspace = true }
move-unit-test = { workspace = true, features = [ "debugging" ] }
move-vm-runtime = { workspace = true, features = [ "testing" ] }
once_cell = { workspace = true }
rand = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions crates/aptos/src/account/mod.rs
Expand Up @@ -52,7 +52,9 @@ pub enum MultisigAccountTool {
CreateTransaction(multisig_account::CreateTransaction),
Execute(multisig_account::Execute),
ExecuteReject(multisig_account::ExecuteReject),
ExecuteWithPayload(multisig_account::ExecuteWithPayload),
Reject(multisig_account::Reject),
VerifyProposal(multisig_account::VerifyProposal),
}

impl MultisigAccountTool {
Expand All @@ -63,7 +65,9 @@ impl MultisigAccountTool {
MultisigAccountTool::CreateTransaction(tool) => tool.execute_serialized().await,
MultisigAccountTool::Execute(tool) => tool.execute_serialized().await,
MultisigAccountTool::ExecuteReject(tool) => tool.execute_serialized().await,
MultisigAccountTool::ExecuteWithPayload(tool) => tool.execute_serialized().await,
MultisigAccountTool::Reject(tool) => tool.execute_serialized().await,
MultisigAccountTool::VerifyProposal(tool) => tool.execute_serialized().await,
}
}
}

0 comments on commit fbc88b8

Please sign in to comment.