/
lib.rs
50 lines (44 loc) · 1.59 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::json_types::Base58PublicKey;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::serde_json::json;
use near_sdk::{env, near_bindgen, AccountId, Promise};
#[global_allocator]
static ALLOC: near_sdk::wee_alloc::WeeAlloc<'_> = near_sdk::wee_alloc::WeeAlloc::INIT;
const CODE: &[u8] = include_bytes!("../../multisig2/res/multisig2.wasm");
/// This gas spent on the call & account creation, the rest goes to the `new` call.
const CREATE_CALL_GAS: u64 = 50_000_000_000_000;
#[derive(Serialize, Deserialize)]
#[serde(crate = "near_sdk::serde", untagged)]
pub enum MultisigMember {
AccessKey { public_key: Base58PublicKey },
Account { account_id: AccountId },
}
#[near_bindgen]
#[derive(BorshSerialize, BorshDeserialize, Default)]
pub struct MultisigFactory {}
#[near_bindgen]
impl MultisigFactory {
#[payable]
pub fn create(
&mut self,
name: AccountId,
members: Vec<MultisigMember>,
num_confirmations: u64,
) -> Promise {
let account_id = format!("{}.{}", name, env::current_account_id());
Promise::new(account_id)
.create_account()
.deploy_contract(CODE.to_vec())
.transfer(env::attached_deposit())
.function_call(
b"new".to_vec(),
json!({ "members": members, "num_confirmations": num_confirmations })
.to_string()
.as_bytes()
.to_vec(),
0,
env::prepaid_gas() - CREATE_CALL_GAS,
)
}
}