This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
wallet.tact
87 lines (69 loc) · 1.81 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
80
81
82
83
84
85
86
87
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) {
if (!context().bounced) {
self.seqno = self.seqno + 1;
}
}
receive() {
if (!context().bounced) {
self.seqno = self.seqno + 1;
}
}
receive("notify") {
if (!context().bounced) {
self.seqno = self.seqno + 1;
}
}
receive("слава україни") {
if (!context().bounced) {
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;
}
}