forked from tact-lang/tact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.tact
79 lines (61 loc) · 1.59 KB
/
wallet.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
struct Transfer {
seqno: Int as uint32;
mode: Int as uint8;
to: Address;
amount: Int as coins;
body: Cell?;
}
message(123) TransferMessage {
signature: Slice;
transfer: Transfer;
}
contract Wallet {
seqno: Int as uint32 = 0;
key: Int as uint256;
walletId: Int as uint64;
init(key: Int, walletId: Int) {
self.key = key;
self.walletId = walletId;
}
receive("Deploy") {
// Do nothing
}
receive(msg: TransferMessage) {
// Check Signature
let op_hash: Int = msg.transfer.toCell().hash();
require(checkSignature(op_hash, msg.signature, self.key), "Invalid signature");
require(msg.transfer.seqno == self.seqno, "Invalid seqno");
// Increment seqno
self.seqno = self.seqno + 1;
// Send message
send(SendParameters{value: msg.transfer.amount, to: msg.transfer.to, mode: msg.transfer.mode, body: msg.transfer.body});
}
receive(msg: Slice) {
self.seqno = self.seqno + 1;
}
receive() {
self.seqno = self.seqno + 1;
}
receive("notify") {
self.seqno = self.seqno + 1;
}
receive("你好ж") {
self.seqno = self.seqno + 1;
}
receive("duplicate") {
// Create new wallet
let walletInit: StateInit = initOf Wallet(self.key, self.walletId + 1);
}
bounced(msg: Slice) {
// TODO: Handle
}
get fun publicKey(): Int {
return self.key;
}
get fun walletId(): Int {
return self.walletId;
}
get fun seqno(): Int {
return self.seqno;
}
}