forked from tonkeeper/tongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulator-extern.h
238 lines (214 loc) · 8.48 KB
/
emulator-extern.h
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
236
237
238
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "emulator_export.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Creates TransactionEmulator object
* @param config_params_boc Base64 encoded BoC serialized Config dictionary (Hashmap 32 ^Cell)
* @param vm_log_verbosity Verbosity level of VM log. 0 - log truncated to last 256 characters. 1 - unlimited length log.
* 2 - for each command prints its cell hash and offset. 3 - for each command log prints all stack values.
* @return Pointer to TransactionEmulator or nullptr in case of error
*/
EMULATOR_EXPORT void *transaction_emulator_create(const char *config_params_boc, int vm_log_verbosity);
/**
* @brief Creates Config object from base64 encoded BoC
* @param config_params_boc Base64 encoded BoC serialized Config dictionary (Hashmap 32 ^Cell)
* @return Pointer to Config object or nullptr in case of error
*/
EMULATOR_EXPORT void *emulator_config_create(const char *config_params_boc);
/**
* @brief Set unixtime for emulation
* @param transaction_emulator Pointer to TransactionEmulator object
* @param unixtime Unix timestamp
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool transaction_emulator_set_unixtime(void *transaction_emulator, uint32_t unixtime);
/**
* @brief Set lt for emulation
* @param transaction_emulator Pointer to TransactionEmulator object
* @param lt Logical time
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool transaction_emulator_set_lt(void *transaction_emulator, uint64_t lt);
/**
* @brief Set rand seed for emulation
* @param transaction_emulator Pointer to TransactionEmulator object
* @param rand_seed_hex Hex string of length 64
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool transaction_emulator_set_rand_seed(void *transaction_emulator, const char* rand_seed_hex);
/**
* @brief Set ignore_chksig flag for emulation
* @param transaction_emulator Pointer to TransactionEmulator object
* @param ignore_chksig Whether emulation should always succeed on CHKSIG operation
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool transaction_emulator_set_ignore_chksig(void *transaction_emulator, bool ignore_chksig);
/**
* @brief Set config for emulation
* @param transaction_emulator Pointer to TransactionEmulator object
* @param config_boc Base64 encoded BoC serialized Config dictionary (Hashmap 32 ^Cell)
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool transaction_emulator_set_config(void *transaction_emulator, const char* config_boc);
/**
* @brief Set unixtime for emulation
* @param transaction_emulator Pointer to TransactionEmulator object
* @param libs_boc Base64 encoded BoC serialized shared libraries dictionary (HashmapE 256 ^Cell).
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool transaction_emulator_set_libs(void *transaction_emulator, const char* libs_boc);
/**
* @brief Emulate transaction
* @param transaction_emulator Pointer to TransactionEmulator object
* @param shard_account_boc Base64 encoded BoC serialized ShardAccount
* @param message_boc Base64 encoded BoC serialized inbound Message (internal or external)
* @return Json object with error:
* {
* "success": false,
* "error": "Error description"
* // and optional fields "vm_exit_code" and "vm_log" in case external message was not accepted.
* }
* Or success:
* {
* "success": true,
* "transaction": "Base64 encoded Transaction boc",
* "shard_account": "Base64 encoded new ShardAccount boc",
* "vm_log": "execute DUP...",
* "actions": "Base64 encoded compute phase actions boc (OutList n)"
* }
*/
EMULATOR_EXPORT const char *transaction_emulator_emulate_transaction(void *transaction_emulator, const char *shard_account_boc, const char *message_boc);
/**
* @brief Destroy TransactionEmulator object
* @param transaction_emulator Pointer to TransactionEmulator object
*/
EMULATOR_EXPORT void transaction_emulator_destroy(void *transaction_emulator);
/**
* @brief Set global verbosity level of the library
* @param verbosity_level New verbosity level (0 - never, 1 - error, 2 - warning, 3 - info, 4 - debug)
*/
EMULATOR_EXPORT bool emulator_set_verbosity_level(int verbosity_level);
/**
* @brief Create TVM emulator
* @param code_boc Base64 encoded BoC serialized smart contract code cell
* @param data_boc Base64 encoded BoC serialized smart contract data cell
* @param vm_log_verbosity Verbosity level of VM log
* @return Pointer to TVM emulator object
*/
EMULATOR_EXPORT void *tvm_emulator_create(const char *code_boc, const char *data_boc, int vm_log_verbosity);
/**
* @brief Set libraries for TVM emulator
* @param libs_boc Base64 encoded BoC serialized libraries dictionary (HashmapE 256 ^Cell).
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool tvm_emulator_set_libraries(void *tvm_emulator, const char *libs_boc);
/**
* @brief Set c7 parameters
* @param tvm_emulator Pointer to TVM emulator
* @param address Adress of smart contract
* @param unixtime Unix timestamp
* @param balance Smart contract balance
* @param rand_seed_hex Random seed as hex string of length 64
* @param config Base64 encoded BoC serialized Config dictionary (Hashmap 32 ^Cell)
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool tvm_emulator_set_c7(void *tvm_emulator, const char *address, uint32_t unixtime, uint64_t balance, const char *rand_seed_hex, const char *config);
/**
* @brief Set config for TVM emulator
* @param tvm_emulator Pointer to TVM emulator
* @param config Pointer to Config object
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool tvm_emulator_set_config_object(void* tvm_emulator, void* config);
/**
* @brief Set TVM gas limit
* @param tvm_emulator Pointer to TVM emulator
* @param gas_limit Gas limit
* @return true in case of success, false in case of error
*/
EMULATOR_EXPORT bool tvm_emulator_set_gas_limit(void *tvm_emulator, int64_t gas_limit);
/**
* @brief Run get method
* @param tvm_emulator Pointer to TVM emulator
* @param method_id Integer method id
* @param stack_boc Base64 encoded BoC serialized stack (VmStack)
* @return Json object with error:
* {
* "success": false,
* "error": "Error description"
* }
* Or success:
* {
* "success": true
* "vm_log": "...",
* "vm_exit_code": 0,
* "stack": "Base64 encoded BoC serialized stack (VmStack)",
* "missing_library": null,
* "gas_used": 1212
* }
*/
EMULATOR_EXPORT const char *tvm_emulator_run_get_method(void *tvm_emulator, int method_id, const char *stack_boc);
/**
* @brief Send external message
* @param tvm_emulator Pointer to TVM emulator
* @param message_body_boc Base64 encoded BoC serialized message body cell.
* @return Json object with error:
* {
* "success": false,
* "error": "Error description"
* }
* Or success:
* {
* "success": true,
* "new_code": "Base64 boc decoded new code cell",
* "new_data": "Base64 boc decoded new data cell",
* "accepted": true,
* "vm_exit_code": 0,
* "vm_log": "...",
* "missing_library": null,
* "gas_used": 1212,
* "actions": "Base64 boc decoded actions cell of type (OutList n)"
* }
*/
EMULATOR_EXPORT const char *tvm_emulator_send_external_message(void *tvm_emulator, const char *message_body_boc);
/**
* @brief Send internal message
* @param tvm_emulator Pointer to TVM emulator
* @param message_body_boc Base64 encoded BoC serialized message body cell.
* @param amount Amount of nanograms attached with internal message.
* @return Json object with error:
* {
* "success": false,
* "error": "Error description"
* }
* Or success:
* {
* "success": true,
* "new_code": "Base64 boc decoded new code cell",
* "new_data": "Base64 boc decoded new data cell",
* "accepted": true,
* "vm_exit_code": 0,
* "vm_log": "...",
* "missing_library": null,
* "gas_used": 1212,
* "actions": "Base64 boc decoded actions cell of type (OutList n)"
* }
*/
EMULATOR_EXPORT const char *tvm_emulator_send_internal_message(void *tvm_emulator, const char *message_body_boc, uint64_t amount);
/**
* @brief Destroy TVM emulator object
* @param tvm_emulator Pointer to TVM emulator object
*/
EMULATOR_EXPORT void tvm_emulator_destroy(void *tvm_emulator);
/**
* @brief Destroy Config object
* @param tvm_emulator Pointer to Config object
*/
EMULATOR_EXPORT void emulator_config_destroy(void *config);
#ifdef __cplusplus
} // extern "C"
#endif