Msig Contract

msigmultiple signature(多重簽名)的簡寫,顧名思義,就是讓多個賬戶對一起事務進行簽名。可以異步提出、批准、發佈經過多方同意的事務。多重簽名是根據賬戶或公鑰所擁有權限的權重來決定的,權重達到閾值才能簽名成功。

操作實例

dmc_client 對象是 dmc.js 的一個實例,它提供了一系列的方法,用於與區塊鏈進行交互。
以下代碼中的 dmc_client 均由下面的代碼創建,不再贅述。

1
2
3
4
5
6
7
8
9
10
var DMC = require('dmc.js');
var dmc_client = DMC({
chainId: 'c102a8115bef9e4a4e751559aac2cdc2859417e6476f8cb6054cd3f7dffe1ce4',
keyProvider: 'creator_priKey',
httpEndpoint: 'http://testnode.dmctech.io:8801',
logger: {
log: null,
error: null
}
});

propose

發起提案

參數

name type description
proposer string 提案人
proposal_name string 提案名
requested string 提案通過所需權限
trx string 提案具體執行的交易內容

示例

以下示例中,我們將使用 dmc.token 合約中的 extransfer 操作作為提案的交易內容。

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
let actions = [{
'account': 'dmc.token',
'name': 'extransfer',
'authorization': [{
"actor": from,
"permission": "active"
}],
'data': {
"from": from,
"to": to,
"quantity": quantity,
"memo": memo
}
}]
let serializeActions = dmc.serializeActions_sync(actions);
let r = dmc.transact_sync({
actions: [
{
account: 'dmc.msig',
name: 'propose',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
proposer: account,
proposal_name: proposal_name,
requested: [{
actor: account,
permission: 'active',
}],
trx: {
"expiration": expiration,
"ref_block_num": 0,
"ref_block_prefix": 0,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": serializeActions,
"transaction_extensions": []
}
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

approve

同意提案

參數

name type description
proposer string 提案人
proposal_name string 提案名
level string 使用哪個權限批准這個提案

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let r = dmc.transact_sync({
actions: [{
account: 'dmc.msig',
name: 'approve',
authorization: [
{
actor: account,
permission: 'active'
},
],
data: {
"proposer": proposer,
"proposal_name": proposal_name,
"level": {
"actor": account,
"permission": "active"
}
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

unapprove

不同意提案

參數

name type description
proposer string 提案人
proposal_name string 提案名
level string 使用哪個權限拒絕這個提案

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let r = dmc.transact_sync({
actions: [{
account: 'dmc.msig',
name: 'unapprove',
authorization: [
{
actor: account,
permission: 'active'
},
],
data: {
"proposer": proposer,
"proposal_name": proposal_name,
"level": {
"actor": account,
"permission": "active"
}
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

cancel

取消提案

參數

name type description
proposer string 提案人
proposal_name string 提案名
canceler string 取消賬戶

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let r = dmc.transact_sync({
actions: [{
account: 'dmc.msig',
name: 'cancel',
authorization: [
{
actor: account,
permission: 'active'
},
],
data: {
"proposer": proposer,
"proposal_name": proposal_name,
"canceler": account
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

exec

執行提案

參數

name type description
proposer string 提案人
proposal_name string 提案名
executer string 執行賬戶

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let r = dmc.transact_sync({
actions: [{
account: 'dmc.msig',
name: 'exec',
authorization: [
{
actor: account,
permission: 'active'
},
],
data: {
"proposer": proposer,
"proposal_name": proposal_name,
"executer": account
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);