forked from tact-lang/tact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.tact
167 lines (130 loc) · 3.04 KB
/
maps.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
message SetIntMap1 {
key: Int;
value: Int?;
}
message SetIntMap2 {
key: Int;
value: Bool?;
}
message SetIntMap3 {
key: Int;
value: Cell?;
}
message SetIntMap4 {
key: Int;
value: SomeStruct?;
}
message SetAddrMap1 {
key: Address;
value: Int?;
}
message SetAddrMap2 {
key: Address;
value: Bool?;
}
message SetAddrMap3 {
key: Address;
value: Cell?;
}
message SetAddrMap4 {
key: Address;
value: SomeStruct?;
}
struct SomeStruct {
value: Int;
}
struct SomeStruct2 {
value: Int;
intMap1: map<Int as uint8, Int as uint8>;
}
contract MapTestContract {
init() {
// Nothing to do
}
//
// Int Maps
//
intMap1: map<Int as uint8, Int as uint8>;
intMap2: map<Int, Bool>;
intMap3: map<Int, Cell>;
intMap4: map<Int, SomeStruct>;
receive(msg: SetIntMap1) {
self.intMap1.set(msg.key, msg.value);
}
receive(msg: SetIntMap2) {
self.intMap2.set(msg.key, msg.value);
}
receive(msg: SetIntMap3) {
self.intMap3.set(msg.key, msg.value);
}
receive(msg: SetIntMap4) {
self.intMap4.set(msg.key, msg.value);
}
get fun intMap1(): map<Int as uint8, Int as uint8> {
return self.intMap1;
}
get fun intMap1Value(key: Int): Int? {
return self.intMap1.get(key);
}
get fun intMap2(): map<Int, Bool> {
return self.intMap2;
}
get fun intMap2Value(key: Int): Bool? {
return self.intMap2.get(key);
}
get fun intMap3(): map<Int, Cell> {
return self.intMap3;
}
get fun intMap3Value(key: Int): Cell? {
return self.intMap3.get(key);
}
get fun intMap4(): map<Int, SomeStruct> {
return self.intMap4;
}
get fun intMap4Value(key: Int): SomeStruct? {
return self.intMap4.get(key);
}
//
// Address Keys
//
addrMap1: map<Address, Int>;
addrMap2: map<Address, Bool>;
addrMap3: map<Address, Cell>;
addrMap4: map<Address, SomeStruct>;
receive(msg: SetAddrMap1) {
self.addrMap1.set(msg.key, msg.value);
}
receive(msg: SetAddrMap2) {
self.addrMap2.set(msg.key, msg.value);
}
receive(msg: SetAddrMap3) {
self.addrMap3.set(msg.key, msg.value);
}
receive(msg: SetAddrMap4) {
self.addrMap4.set(msg.key, msg.value);
}
get fun addrMap1(): map<Address, Int> {
return self.addrMap1;
}
get fun addrMap1Value(key: Address): Int? {
return self.addrMap1.get(key);
}
get fun addrMap2(): map<Address, Bool> {
return self.addrMap2;
}
get fun addrMap2Value(key: Address): Bool? {
return self.addrMap2.get(key);
}
get fun addrMap3(): map<Address, Cell> {
return self.addrMap3;
}
get fun addrMap3Value(key: Address): Cell? {
return self.addrMap3.get(key);
}
get fun addrMap4(): map<Address, SomeStruct> {
return self.addrMap4;
}
get fun addrMap4Value(key: Address): SomeStruct? {
return self.addrMap4.get(key);
}
}