-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathaccount.masm
235 lines (209 loc) · 5.51 KB
/
account.masm
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#! Returns the account id.
#!
#! Stack: []
#! Output: [acct_id]
#!
#! - acct_id is the account id.
export.get_id
push.0
# => [0]
syscall.get_account_id
# => [acct_id]
end
#! Returns the account nonce.
#!
#! Stack: []
#! Output: [nonce]
#!
#! - nonce is the account nonce.
export.get_nonce
push.0
# => [0]
syscall.get_account_nonce
# => [nonce]
end
#! Returns the initial account hash.
#!
#! Stack: []
#! Output: [H]
#!
#! - H is the initial account hash.
export.get_initial_hash
padw
# => [0, 0, 0, 0]
syscall.get_initial_account_hash
# => [H]
end
#! Computes and returns the account hash from account data stored in memory.
#!
#! Stack: []
#! Output: [ACCT_HASH]
#!
#! - ACCT_HASH is the hash of the account data.
export.get_current_hash
padw
# => [0, 0, 0, 0]
syscall.get_current_account_hash
# => [ACCT_HASH]
end
#! Increments the account nonce by the provided value.
#!
#! Stack: [value]
#! Output: []
#!
#! - value is the value to increment the nonce by. value can be at most 2^32 - 1 otherwise this
#! procedure panics.
export.incr_nonce
syscall.incr_account_nonce
# => [0]
drop
# => []
end
#! Gets an item from the account storage. Panics if the index is out of bounds.
#!
#! Stack: [index]
#! Output: [VALUE]
#!
#! - index is the index of the item to get.
#! - VALUE is the value of the item.
export.get_item
push.0.0.0 movup.3
# => [index, 0, 0, 0]
syscall.get_account_item
# => [VALUE]
end
#! Sets an item in the account storage. Panics if the index is out of bounds.
#!
#! Stack: [index, V']
#! Output: [R', V]
#!
#! - index is the index of the item to set.
#! - V' is the value to set.
#! - V is the previous value of the item.
#! - R' is the new storage root.
export.set_item
push.0 movdn.5 push.0 movdn.5 push.0 movdn.5
# => [index, V', 0, 0, 0]
syscall.set_account_item
# => [R', V]
end
#! Gets a map item from the account storage. Panics if
#! - the index for the map is out of bounds, means >255
#! - the slot item at index is not a map
#!
#! Stack: [index, KEY]
#! Output: [VALUE]
#!
#! - index is the index of the map where the KEY VALUE should be read.
#! - KEY is the key of the item to get.
#! - VALUE is the value of the item.
export.get_map_item
syscall.get_account_map_item
# => [VALUE]
# prepare stack for return
movup.5 drop
# => [VALUE, 0]
end
#! Sets a map item in the account storage. Panics if
#! - the index for the map is out of bounds, means >255
#! - the slot item at index is not a map
#!
#! Stack: [index, KEY, VALUE]
#! Output: [OLD_MAP_ROOT, OLD_MAP_VALUE, 0]
#!
#! - index is the index of the map where the KEY VALUE should be set.
#! - KEY is the key to set at VALUE.
#! - VALUE is the value to set at KEY.
#! - OLD_MAP_ROOT is the old map root.
#! - OLD_MAP_VALUE is the old value at KEY.
export.set_map_item
syscall.set_account_map_item
# => [OLD_MAP_ROOT, OLD_MAP_VALUE]
# prepare stack for return
push.0 movdn.9
# => [OLD_MAP_ROOT, OLD_MAP_VALUE, 0]
end
#! Sets the code of the account the transaction is being executed against. This procedure can only
#! executed on regular accounts with updatable code. Otherwise, this procedure fails.
#!
#! Stack: [CODE_ROOT]
#! Output: []
#!
#! - CODE_ROOT is the hash of the code to set.
export.set_code
syscall.set_account_code
# => [0, 0, 0, 0]
dropw
# => []
end
#! Returns the balance of a fungible asset associated with a faucet_id.
#! Panics if the asset is not a fungible asset.
#!
#! Stack: [faucet_id]
#! Output: [balance]
#!
#! - faucet_id is the faucet id of the fungible asset of interest.
#! - balance is the vault balance of the fungible asset.
export.get_balance
syscall.account_vault_get_balance
# => [balance]
end
#! Returns a boolean indicating whether the non-fungible asset is present in the vault.
#! Panics if the ASSET is a fungible asset.
#!
#! Stack: [ASSET]
#! Output: [has_asset]
#!
#! - ASSET is the non-fungible asset of interest
#! - has_asset is a boolean indicating whether the account vault has the asset of interest
export.has_non_fungible_asset
syscall.account_vault_has_non_fungible_asset
# => [has_asset, 0, 0, 0]
swap drop swap drop swap drop
# => [has_asset]
end
#! Add the specified asset to the vault.
#!
#! Panics:
#! - If the asset is not valid.
#! - If the total value of two fungible assets is greater than or equal to 2^63.
#! - If the vault already contains the same non-fungible asset.
#!
#! Stack: [ASSET]
#! Output: [ASSET']
#!
#! - ASSET' final asset in the account vault defined as follows:
#! - If ASSET is a non-fungible asset, then ASSET' is the same as ASSET.
#! - If ASSET is a fungible asset, then ASSET' is the total fungible asset in the account vault
#! after ASSET was added to it.
export.add_asset
syscall.account_vault_add_asset
end
#! Remove the specified asset from the vault.
#!
#! Panics:
#! - The fungible asset is not found in the vault.
#! - The amount of the fungible asset in the vault is less than the amount to be removed.
#! - The non-fungible asset is not found in the vault.
#!
#! Stack: [ASSET]
#! Output: [ASSET]
#!
#! - ASSET is the asset to remove from the vault.
export.remove_asset
syscall.account_vault_remove_asset
end
#! Returns a commitment to the account vault.
#!
#! Stack: []
#! Output: [COM]
#!
#! - COM is a commitment to the account vault.
export.get_vault_commitment
# pad the stack for syscall invocation
padw
# => [0, 0, 0, 0]
# invoke the syscall
syscall.get_account_vault_commitment
# => [COM]
end