-
Notifications
You must be signed in to change notification settings - Fork 114
/
wallet-opt.tact
48 lines (37 loc) · 1.07 KB
/
wallet-opt.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
message TransferMessage {
signature: Slice as bytes64;
transfer: Slice as remaining;
}
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(msg: TransferMessage) {
// Check Signature
let op_hash: Int = msg.transfer.hash();
require(checkSignature(op_hash, msg.signature, self.key), "Invalid signature");
// Check parameters
let pkg: Slice = msg.transfer;
let seqno: Int = pkg.loadInt(32);
let mode: Int = pkg.loadInt(8);
let body: Cell = pkg.loadRef();
require(seqno == self.seqno, "Invalid seqno");
// Increment seqno
self.seqno = (self.seqno + 1) % 65536;
// Send message
nativeSendMessage(body, mode);
}
get fun publicKey(): Int {
return self.key;
}
get fun walletId(): Int {
return self.walletId;
}
get fun seqno(): Int {
return self.seqno;
}
}