-
Notifications
You must be signed in to change notification settings - Fork 112
/
multisig.tact
132 lines (110 loc) · 3.41 KB
/
multisig.tact
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
message Request {
requested: Address;
to: Address;
value: Int as coins;
timeout: Int as uint32;
bounce: Bool;
mode: Int as uint8;
body: Cell?;
}
message Signed {
request: Request;
}
contract MultisigSigner {
master: Address;
// Voting state
members: map<Address, Int>;
weight: Int = 0;
requiredWeight: Int;
completed: Bool;
// Request
request: Request;
init(master: Address, members: map<Address, Int>, requiredWeight: Int, request: Request) {
self.master = master;
self.members = members;
self.requiredWeight = requiredWeight;
self.completed = false;
self.request = request;
}
receive() {
// Do nothing
}
receive("YES") {
// Checks
require(self.request.timeout > now(), "Timeout");
require(!self.completed, "Completed");
// Load weight
let sender: Address = sender();
let weight: Int = self.members.get(sender)!!;
self.members.set(sender, null);
// Update weight
self.weight = self.weight + weight;
if (self.weight >= self.requiredWeight) {
self.completed = true;
send(SendParameters{
value: 0,
to: self.master,
mode: SendRemainingBalance | SendIgnoreErrors,
bounce: false,
body: Signed{ request: self.request }.toCell()
});
}
}
get fun request(): Request {
return self.request;
}
}
contract Multisig {
seqno: Int;
members: map<Address, Int>;
totalWeight: Int;
requiredWeight: Int;
init(members: map<Address, Int>, totalWeight: Int, requiredWeight: Int) {
self.members = members;
self.requiredWeight = requiredWeight;
self.totalWeight = totalWeight;
self.totalWeight = 0;
self.seqno = 0;
}
// Request new pending transaction
receive(msg: Request) {
// Check sender
let sender: Address = sender();
let weight: Int = self.members.get(sender)!!;
require(weight > 0, "Not a member");
// Create message
let opInit: StateInit = initOf MultisigSigner(myAddress(), self.members, self.requiredWeight, msg);
let opAddress: Address = contractAddress(opInit);
send(SendParameters{
value: 0,
to: opAddress,
mode: SendRemainingValue | SendIgnoreErrors,
bounce: true,
code: opInit.code,
data: opInit.data
});
}
receive(msg: Signed) {
// Check parameters
// NOTE: this will check members, required weight, master address
let sender: Address = sender();
let opInit: StateInit = initOf MultisigSigner(myAddress(), self.members, self.requiredWeight, msg.request);
let opAddress: Address = contractAddress(opInit);
require(opAddress == sender, "Invalid sender");
require(msg.request.timeout > now(), "Timeout");
// Send operation
send(SendParameters{
to: msg.request.to,
value: msg.request.value,
mode: msg.request.mode,
bounce: msg.request.bounce,
body: msg.request.body
});
}
get fun member(address: Address): Int? {
return self.members.get(address);
}
get fun members(): map<Address, Int> {
return self.members;
}
}