Skip to content

Commit

Permalink
Improve multisig example (#962)
Browse files Browse the repository at this point in the history
* Allow payable transactions to be evaluated

* Rename `multisig_plain` ➔ `multisig`

* Fix comment syntax

* Fix case
  • Loading branch information
Michael Müller authored Oct 15, 2021
1 parent 284e4e5 commit 44951c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "multisig_plain"
name = "multisig"
version = "3.0.0-rc5"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
Expand All @@ -16,7 +16,7 @@ scale = { package = "parity-scale-codec", version = "2", default-features = fals
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }

[lib]
name = "multisig_plain"
name = "multisig"
path = "lib.rs"
crate-type = ["cdylib"]

Expand Down
30 changes: 15 additions & 15 deletions examples/multisig_plain/lib.rs → examples/multisig/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! # Plain Multisig Wallet
//! # Multisig Wallet
//!
//! This implements a plain multi owner wallet.
//!
Expand Down Expand Up @@ -55,15 +55,15 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use self::multisig_plain::{
pub use self::multisig::{
ConfirmationStatus,
MultisigPlain,
Multisig,
Transaction,
};
use ink_lang as ink;

#[ink::contract]
mod multisig_plain {
mod multisig {
use ink_env::call::{
build_call,
utils::ReturnType,
Expand Down Expand Up @@ -150,7 +150,7 @@ mod multisig_plain {
}

#[ink(storage)]
pub struct MultisigPlain {
pub struct Multisig {
/// Every entry in this map represents the confirmation of an owner for a
/// transaction. This is effectively a set rather than a map.
confirmations: StorageHashMap<(TransactionId, AccountId), ()>,
Expand Down Expand Up @@ -247,7 +247,7 @@ mod multisig_plain {
new_requirement: u32,
}

impl MultisigPlain {
impl Multisig {
/// The only constructor of the contract.
///
/// A list of owners must be supplied and a number of how many of them must
Expand Down Expand Up @@ -287,9 +287,9 @@ mod multisig_plain {
/// `Transaction` and dispatched through `submit_transaction` and `invoke_transaction`:
/// ```no_run
/// use ink_env::{DefaultEnvironment as Env, AccountId, call::{CallParams, Selector}, test::CallData};
/// use multisig_plain::{Transaction, ConfirmationStatus};
/// use multisig::{Transaction, ConfirmationStatus};
///
/// // address of an existing MultiSigPlain contract
/// // address of an existing `Multisig` contract
/// let wallet_id: AccountId = [7u8; 32].into();
///
/// // first create the transaction that adds `alice` through `add_owner`
Expand Down Expand Up @@ -506,7 +506,7 @@ mod multisig_plain {
/// Its return value indicates whether the called transaction was successful and contains
/// its output when successful.
/// This can be called by anyone.
#[ink(message)]
#[ink(message, payable)]
pub fn eval_transaction(
&mut self,
trans_id: TransactionId,
Expand Down Expand Up @@ -708,13 +708,13 @@ mod multisig_plain {
.expect("Test environment is expected to be initialized.")
}

fn build_contract() -> MultisigPlain {
fn build_contract() -> Multisig {
let accounts = default_accounts();
let owners = ink_prelude::vec![accounts.alice, accounts.bob, accounts.eve];
MultisigPlain::new(2, owners)
Multisig::new(2, owners)
}

fn submit_transaction() -> MultisigPlain {
fn submit_transaction() -> Multisig {
let mut contract = build_contract();
let accounts = default_accounts();
set_from_owner();
Expand Down Expand Up @@ -752,21 +752,21 @@ mod multisig_plain {
#[ink::test]
#[should_panic]
fn empty_owner_construction_fails() {
MultisigPlain::new(0, vec![]);
Multisig::new(0, vec![]);
}

#[ink::test]
#[should_panic]
fn zero_requirement_construction_fails() {
let accounts = default_accounts();
MultisigPlain::new(0, vec![accounts.alice, accounts.bob]);
Multisig::new(0, vec![accounts.alice, accounts.bob]);
}

#[ink::test]
#[should_panic]
fn too_large_requirement_construction_fails() {
let accounts = default_accounts();
MultisigPlain::new(3, vec![accounts.alice, accounts.bob]);
Multisig::new(3, vec![accounts.alice, accounts.bob]);
}

#[ink::test]
Expand Down

0 comments on commit 44951c9

Please sign in to comment.