@eosrio/node-abieos 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +4 -1
  2. package/dist/abieos.node +0 -0
  3. package/lib/abieos.d.ts +19 -0
  4. package/lib/abieos.d.ts.map +1 -0
  5. package/lib/abieos.js +100 -0
  6. package/lib/abieos.ts +107 -0
  7. package/package.json +13 -8
  8. package/.idea/modules.xml +0 -8
  9. package/.idea/node-abieos.iml +0 -12
  10. package/.idea/vcs.xml +0 -9
  11. package/.idea/workspace.xml +0 -66
  12. package/CMakeLists.txt +0 -35
  13. package/abieos.d.ts +0 -21
  14. package/abieos.js +0 -59
  15. package/eosio.json +0 -1596
  16. package/include/.clang-format +0 -76
  17. package/include/eosio/abi.hpp +0 -393
  18. package/include/eosio/asset.hpp +0 -458
  19. package/include/eosio/bytes.hpp +0 -27
  20. package/include/eosio/chain_conversions.hpp +0 -450
  21. package/include/eosio/chain_types.hpp +0 -14
  22. package/include/eosio/check.hpp +0 -178
  23. package/include/eosio/convert.hpp +0 -95
  24. package/include/eosio/crypto.hpp +0 -148
  25. package/include/eosio/eosio_outcome.hpp +0 -41
  26. package/include/eosio/fixed_bytes.hpp +0 -250
  27. package/include/eosio/float.hpp +0 -35
  28. package/include/eosio/for_each_field.hpp +0 -48
  29. package/include/eosio/fpconv.c +0 -336
  30. package/include/eosio/fpconv.h +0 -41
  31. package/include/eosio/fpconv.license +0 -23
  32. package/include/eosio/from_bin.hpp +0 -272
  33. package/include/eosio/from_json.hpp +0 -749
  34. package/include/eosio/from_string.hpp +0 -28
  35. package/include/eosio/map_macro.h +0 -64
  36. package/include/eosio/murmur.hpp +0 -55
  37. package/include/eosio/name.hpp +0 -178
  38. package/include/eosio/opaque.hpp +0 -184
  39. package/include/eosio/operators.hpp +0 -71
  40. package/include/eosio/powers.h +0 -76
  41. package/include/eosio/reflection.hpp +0 -61
  42. package/include/eosio/ship_protocol.hpp +0 -971
  43. package/include/eosio/stream.hpp +0 -235
  44. package/include/eosio/symbol.hpp +0 -300
  45. package/include/eosio/time.hpp +0 -264
  46. package/include/eosio/to_bin.hpp +0 -189
  47. package/include/eosio/to_json.hpp +0 -334
  48. package/include/eosio/to_key.hpp +0 -305
  49. package/include/eosio/types.hpp +0 -103
  50. package/include/eosio/varint.hpp +0 -452
  51. package/include/outcome-basic.hpp +0 -6836
  52. package/include/rapidjson/allocators.h +0 -284
  53. package/include/rapidjson/cursorstreamwrapper.h +0 -78
  54. package/include/rapidjson/document.h +0 -2646
  55. package/include/rapidjson/encodedstream.h +0 -299
  56. package/include/rapidjson/encodings.h +0 -716
  57. package/include/rapidjson/error/en.h +0 -74
  58. package/include/rapidjson/error/error.h +0 -161
  59. package/include/rapidjson/filereadstream.h +0 -99
  60. package/include/rapidjson/filewritestream.h +0 -104
  61. package/include/rapidjson/fwd.h +0 -151
  62. package/include/rapidjson/internal/biginteger.h +0 -290
  63. package/include/rapidjson/internal/diyfp.h +0 -271
  64. package/include/rapidjson/internal/dtoa.h +0 -245
  65. package/include/rapidjson/internal/ieee754.h +0 -78
  66. package/include/rapidjson/internal/itoa.h +0 -308
  67. package/include/rapidjson/internal/meta.h +0 -186
  68. package/include/rapidjson/internal/pow10.h +0 -55
  69. package/include/rapidjson/internal/regex.h +0 -732
  70. package/include/rapidjson/internal/stack.h +0 -231
  71. package/include/rapidjson/internal/strfunc.h +0 -69
  72. package/include/rapidjson/internal/strtod.h +0 -290
  73. package/include/rapidjson/internal/swap.h +0 -46
  74. package/include/rapidjson/istreamwrapper.h +0 -113
  75. package/include/rapidjson/memorybuffer.h +0 -70
  76. package/include/rapidjson/memorystream.h +0 -71
  77. package/include/rapidjson/msinttypes/inttypes.h +0 -316
  78. package/include/rapidjson/msinttypes/stdint.h +0 -300
  79. package/include/rapidjson/ostreamwrapper.h +0 -81
  80. package/include/rapidjson/pointer.h +0 -1357
  81. package/include/rapidjson/prettywriter.h +0 -277
  82. package/include/rapidjson/rapidjson.h +0 -654
  83. package/include/rapidjson/reader.h +0 -2230
  84. package/include/rapidjson/schema.h +0 -2494
  85. package/include/rapidjson/stream.h +0 -223
  86. package/include/rapidjson/stringbuffer.h +0 -121
  87. package/include/rapidjson/writer.h +0 -710
  88. package/src/abi.cpp +0 -274
  89. package/src/abieos.cpp +0 -334
  90. package/src/abieos.h +0 -91
  91. package/src/abieos.hpp +0 -1011
  92. package/src/abieos_exception.hpp +0 -89
  93. package/src/abieos_numeric.hpp +0 -94
  94. package/src/abieos_ripemd160.hpp +0 -417
  95. package/src/crypto.cpp +0 -215
  96. package/src/main.cpp +0 -242
  97. package/src/ship.abi.cpp +0 -695
  98. package/tools/CMakeLists.txt +0 -9
  99. package/tools/name.cpp +0 -86
@@ -1,450 +0,0 @@
1
- #pragma once
2
-
3
- #include "stream.hpp"
4
- #include <chrono>
5
- #include <stdint.h>
6
- #include <string>
7
- #include <string_view>
8
- #include <vector>
9
- #include <optional>
10
-
11
- namespace eosio {
12
-
13
- // TODO remove in c++20
14
- namespace {
15
- using days = std::chrono::duration
16
- <int, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
17
-
18
- using weeks = std::chrono::duration
19
- <int, std::ratio_multiply<std::ratio<7>, days::period>>;
20
-
21
- using years = std::chrono::duration
22
- <int, std::ratio_multiply<std::ratio<146097, 400>, days::period>>;
23
-
24
- using months = std::chrono::duration
25
- <int, std::ratio_divide<years::period, std::ratio<12>>>;
26
-
27
- struct day {
28
- inline explicit day(uint32_t d) : d(d) {}
29
- uint32_t d;
30
- };
31
- struct month {
32
- inline explicit month(uint32_t m) : m(m) {}
33
- uint32_t m;
34
- };
35
- struct month_day {
36
- inline month_day( eosio::month m, eosio::day d ) : m(m), d(d) {}
37
- inline auto month() const { return m; }
38
- inline auto day() const { return d; }
39
- struct month m;
40
- struct day d;
41
- };
42
- struct year {
43
- inline explicit year( uint32_t y )
44
- : y(y) {}
45
- uint32_t y;
46
- };
47
-
48
- template <class Duration>
49
- using sys_time = std::chrono::time_point<std::chrono::system_clock, Duration>;
50
-
51
- using sys_days = sys_time<days>;
52
- using sys_seconds = sys_time<std::chrono::seconds>;
53
-
54
- typedef year year_t;
55
- typedef month month_t;
56
- typedef day day_t;
57
- struct year_month_day {
58
- inline auto from_days( days ds ) {
59
- const auto z = ds.count() + 719468;
60
- const auto era = (z >= 0 ? z : z - 146096) / 146097;
61
- const auto doe = static_cast<uint32_t>(z - era * 146097);
62
- const auto yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365;
63
- const auto y = static_cast<days::rep>(yoe) + era * 400;
64
- const auto doy = doe - (365 * yoe + yoe/4 - yoe/100);
65
- const auto mp = (5*doy + 2)/153;
66
- const auto d = doy - (153*mp+2)/5 + 1;
67
- const auto m = mp < 10 ? mp+3 : mp-9;
68
- return year_month_day{year_t{static_cast<uint32_t>(y + (m <= 2))}, month_t(m), day_t(d)};
69
- }
70
- inline auto to_days() const {
71
- const auto _y = static_cast<int>(y.y) - (m.m <= month_t{2}.m);
72
- const auto _m = static_cast<uint32_t>(m.m);
73
- const auto _d = static_cast<uint32_t>(d.d);
74
- const auto era = (_y >= 0 ? _y : _y-399) / 400;
75
- const auto yoe = static_cast<uint32_t>(_y - era * 400);
76
- const auto doy = (153*(_m > 2 ? _m-3 : _m+9) + 2)/5 + _d-1;
77
- const auto doe = yoe * 365 + yoe/4 -yoe/100 + doy;
78
- return days{era * 146097 + static_cast<int>(doe) - 719468};
79
- }
80
- inline year_month_day(const year_t& y, const month_t& m, const day_t& d)
81
- : y(y), m(m), d(d) {}
82
- inline year_month_day(const year_month_day&) = default;
83
- inline year_month_day(year_month_day&&) = default;
84
- inline year_month_day(sys_days ds)
85
- : year_month_day(from_days(ds.time_since_epoch())) {}
86
- inline auto year() const { return y.y; }
87
- inline auto month() const { return m.m; }
88
- inline auto day() const { return d.d; }
89
- year_t y;
90
- month_t m;
91
- day_t d;
92
- };
93
- }
94
-
95
- inline constexpr uint64_t char_to_name_digit(char c) {
96
- if (c >= 'a' && c <= 'z')
97
- return (c - 'a') + 6;
98
- if (c >= '1' && c <= '5')
99
- return (c - '1') + 1;
100
- return 0;
101
- }
102
-
103
- inline constexpr uint64_t string_to_name(const char* str, int size) {
104
- uint64_t name = 0;
105
- int i = 0;
106
- for (; i < size && i < 12; ++i) name |= (char_to_name_digit(str[i]) & 0x1f) << (64 - 5 * (i + 1));
107
- if (i < size)
108
- name |= char_to_name_digit(str[i]) & 0x0F;
109
- return name;
110
- }
111
-
112
- inline constexpr uint64_t string_to_name(const char* str) {
113
- int len = 0;
114
- while (str[len]) ++len;
115
- return string_to_name(str, len);
116
- }
117
-
118
- inline constexpr uint64_t string_to_name(std::string_view str) { return string_to_name(str.data(), str.size()); }
119
-
120
- inline uint64_t string_to_name(const std::string& str) { return string_to_name(str.data(), str.size()); }
121
-
122
- constexpr inline bool is_valid_char(char c) {
123
- return (c >= 'a' && c <= 'z') ||
124
- (c >= '1' && c <= '5') ||
125
- (c == '.');
126
- }
127
-
128
- template <char C>
129
- constexpr inline uint64_t char_to_name_digit_strict() {
130
- static_assert(is_valid_char(C), "character is not for an eosio name");
131
- if constexpr (C >= 'a' && C <= 'z')
132
- return (C - 'a') + 6;
133
- else if constexpr (C >= '1' && C <= '5')
134
- return (C - '1') + 1;
135
- else if constexpr (C == '.')
136
- return 0;
137
- }
138
-
139
- [[nodiscard]] inline constexpr bool char_to_name_digit_strict(char c, uint64_t& result) {
140
- if (c >= 'a' && c <= 'z') {
141
- result = (c - 'a') + 6;
142
- return true;
143
- }
144
- if (c >= '1' && c <= '5') {
145
- result = (c - '1') + 1;
146
- return true;
147
- }
148
- if (c == '.') {
149
- result = 0;
150
- return true;
151
- }
152
- else {
153
- return false;
154
- }
155
- }
156
-
157
- template <std::size_t N, uint64_t ValueSoFar, char C, char... Rest>
158
- constexpr inline uint64_t string_to_name_strict_impl() {
159
- if constexpr (N == 12)
160
- static_assert((char_to_name_digit_strict<C>() & 0xf) == char_to_name_digit_strict<C>(),
161
- "eosio name 13th character cannot be a letter after j");
162
- if constexpr (sizeof...(Rest) > 0)
163
- return string_to_name_strict_impl<N+1,
164
- ValueSoFar | (char_to_name_digit_strict<C>() & 0x1f) << (64 - 5 * (N+1)), Rest...>();
165
- else
166
- return ValueSoFar | (char_to_name_digit_strict<C>() & 0x1f) << (64 + (N == 12) - 5 * (N+1));
167
- }
168
-
169
- template <char... Str>
170
- constexpr inline uint64_t string_to_name_strict() {
171
- static_assert(sizeof...(Str) <= 13, "eosio name string is too long");
172
- if constexpr (sizeof...(Str) == 0)
173
- return 0;
174
- else
175
- return string_to_name_strict_impl<0, 0, Str...>();
176
- }
177
-
178
- // std::optional is killing constexpr'ness
179
- namespace detail {
180
- struct simple_optional {
181
- explicit constexpr inline simple_optional( stream_error e ) : valid(e) {}
182
- explicit constexpr inline simple_optional( uint64_t v ) : val(v) {}
183
- explicit constexpr inline operator bool() const { return valid == stream_error::no_error; }
184
- constexpr inline auto value() const { return val; }
185
- stream_error valid = stream_error::no_error;
186
- uint64_t val = 0;
187
- };
188
- }
189
-
190
- [[nodiscard]] constexpr inline detail::simple_optional try_string_to_name_strict(std::string_view str) {
191
- uint64_t name = 0;
192
- unsigned i = 0;
193
- for (; i < str.size() && i < 12; ++i) {
194
- uint64_t x = 0;
195
- if (!char_to_name_digit_strict(str[i], x)) return detail::simple_optional{stream_error::invalid_name_char};
196
- name |= (x & 0x1f) << (64 - 5 * (i + 1));
197
- }
198
- if (i < str.size() && i == 12) {
199
- uint64_t x = 0;
200
- if (!char_to_name_digit_strict(str[i], x)) return detail::simple_optional{stream_error::invalid_name_char};
201
-
202
- if(x != (x & 0xf)) return detail::simple_optional{stream_error::invalid_name_char13};
203
- name |= x;
204
- ++i;
205
- }
206
- if(i < str.size()) return detail::simple_optional{stream_error::name_too_long};
207
- return detail::simple_optional{name};
208
- }
209
-
210
- constexpr inline uint64_t string_to_name_strict(std::string_view str) {
211
- if(auto r = try_string_to_name_strict(str)) return r.val;
212
- else check(false, convert_stream_error(r.valid));
213
- __builtin_unreachable();
214
- }
215
-
216
- inline std::string name_to_string(uint64_t name) {
217
- static const char* charmap = ".12345abcdefghijklmnopqrstuvwxyz";
218
- std::string str(13, '.');
219
-
220
- uint64_t tmp = name;
221
- for (uint32_t i = 0; i <= 12; ++i) {
222
- char c = charmap[tmp & (i == 0 ? 0x0f : 0x1f)];
223
- str[12 - i] = c;
224
- tmp >>= (i == 0 ? 4 : 5);
225
- }
226
-
227
- const auto last = str.find_last_not_of('.');
228
- return str.substr(0, last + 1);
229
- }
230
-
231
- inline std::string microseconds_to_str(uint64_t microseconds) {
232
- std::string result;
233
-
234
- auto append_uint = [&result](uint32_t value, int digits) {
235
- char s[20];
236
- char* ch = s;
237
- while (digits--) {
238
- *ch++ = '0' + (value % 10);
239
- value /= 10;
240
- };
241
- std::reverse(s, ch);
242
- result.insert(result.end(), s, ch);
243
- };
244
-
245
- std::chrono::microseconds us{ microseconds };
246
- sys_days sd(std::chrono::floor<days>(us));
247
- auto ymd = year_month_day{ sd };
248
- uint32_t ms = (std::chrono::floor<std::chrono::milliseconds>(us) - sd.time_since_epoch()).count();
249
- us -= sd.time_since_epoch();
250
- append_uint((int)ymd.year(), 4);
251
- result.push_back('-');
252
- append_uint((unsigned)ymd.month(), 2);
253
- result.push_back('-');
254
- append_uint((unsigned)ymd.day(), 2);
255
- result.push_back('T');
256
- append_uint(ms / 3600000 % 60, 2);
257
- result.push_back(':');
258
- append_uint(ms / 60000 % 60, 2);
259
- result.push_back(':');
260
- append_uint(ms / 1000 % 60, 2);
261
- result.push_back('.');
262
- append_uint(ms % 1000, 3);
263
- return result;
264
- }
265
-
266
- [[nodiscard]] inline bool string_to_utc_seconds(uint32_t& result, const char*& s, const char* end, bool eat_fractional,
267
- bool require_end) {
268
- auto parse_uint = [&](uint32_t& result, int digits) {
269
- result = 0;
270
- while (digits--) {
271
- if (s != end && *s >= '0' && *s <= '9')
272
- result = result * 10 + *s++ - '0';
273
- else
274
- return false;
275
- }
276
- return true;
277
- };
278
- uint32_t y, m, d, h, min, sec;
279
- if (!parse_uint(y, 4))
280
- return false;
281
- if (s == end || *s++ != '-')
282
- return false;
283
- if (!parse_uint(m, 2))
284
- return false;
285
- if (s == end || *s++ != '-')
286
- return false;
287
- if (!parse_uint(d, 2))
288
- return false;
289
- if (s == end || *s++ != 'T')
290
- return false;
291
- if (!parse_uint(h, 2))
292
- return false;
293
- if (s == end || *s++ != ':')
294
- return false;
295
- if (!parse_uint(min, 2))
296
- return false;
297
- if (s == end || *s++ != ':')
298
- return false;
299
- if (!parse_uint(sec, 2))
300
- return false;
301
- result = sys_days(year_month_day{year_t{y}, month_t{m}, day_t{d}}.to_days()).time_since_epoch().count() * 86400 + h * 3600 + min * 60 + sec;
302
- if (eat_fractional && s != end && *s == '.') {
303
- ++s;
304
- while (s != end && *s >= '0' && *s <= '9') ++s;
305
- }
306
- return s == end || !require_end;
307
- }
308
-
309
- [[nodiscard]] inline bool string_to_utc_seconds(uint32_t& result, const char* s, const char* end) {
310
- return string_to_utc_seconds(result, s, end, true, true);
311
- }
312
-
313
- [[nodiscard]] inline bool string_to_utc_microseconds(uint64_t& result, const char*& s, const char* end,
314
- bool require_end) {
315
- uint32_t sec;
316
- if (!string_to_utc_seconds(sec, s, end, false, false))
317
- return false;
318
- result = sec * 1000000ull;
319
- if (s == end)
320
- return true;
321
- if (*s != '.')
322
- return !require_end;
323
- ++s;
324
- uint32_t scale = 100000;
325
- while (scale >= 1 && s != end && *s >= '0' && *s <= '9') {
326
- result += (*s++ - '0') * scale;
327
- scale /= 10;
328
- }
329
- return s == end || !require_end;
330
- }
331
-
332
- [[nodiscard]] inline bool string_to_utc_microseconds(uint64_t& result, const char* s, const char* end) {
333
- return string_to_utc_microseconds(result, s, end, true);
334
- }
335
-
336
- [[nodiscard]] inline bool string_to_symbol_code(uint64_t& result, const char*& pos, const char* end, bool require_end) {
337
- while (pos != end && *pos == ' ') ++pos;
338
- result = 0;
339
- uint32_t i = 0;
340
- while (pos != end && *pos >= 'A' && *pos <= 'Z') {
341
- if (i >= 7)
342
- return false;
343
- result |= uint64_t(*pos++) << (8 * i++);
344
- }
345
- return i && (pos == end || !require_end);
346
- }
347
-
348
- [[nodiscard]] inline bool string_to_symbol_code(uint64_t& result, const char* pos, const char* end) {
349
- return string_to_symbol_code(result, pos, end, true);
350
- }
351
-
352
- inline std::string symbol_code_to_string(uint64_t v) {
353
- std::string result;
354
- while (v > 0) {
355
- result += char(v & 0xFF);
356
- v >>= 8;
357
- }
358
- return result;
359
- }
360
-
361
- [[nodiscard]] inline bool string_to_symbol(uint64_t& result, uint8_t precision, const char*& pos, const char* end,
362
- bool require_end) {
363
- if (!eosio::string_to_symbol_code(result, pos, end, require_end))
364
- return false;
365
- result = (result << 8) | precision;
366
- return true;
367
- }
368
-
369
- [[nodiscard]] inline bool string_to_symbol(uint64_t& result, const char*& pos, const char* end, bool require_end) {
370
- uint8_t precision = 0;
371
- bool found = false;
372
- while (pos != end && *pos >= '0' && *pos <= '9') {
373
- precision = precision * 10 + (*pos - '0');
374
- found = true;
375
- ++pos;
376
- }
377
- if (!found || pos == end || *pos++ != ',')
378
- return false;
379
- return string_to_symbol(result, precision, pos, end, require_end);
380
- }
381
-
382
- [[nodiscard]] inline bool string_to_symbol(uint64_t& result, const char* pos, const char* end) {
383
- return string_to_symbol(result, pos, end, true);
384
- }
385
-
386
- inline std::string symbol_to_string(uint64_t v) {
387
- return std::to_string(v & 0xff) + "," + eosio::symbol_code_to_string(v >> 8);
388
- }
389
-
390
- [[nodiscard]] inline bool string_to_asset(int64_t& amount, uint64_t& symbol, const char*& s, const char* end,
391
- bool expect_end) {
392
- // todo: check overflow
393
- while (s != end && *s == ' ') //
394
- ++s;
395
- uint64_t uamount = 0;
396
- uint8_t precision = 0;
397
- bool negative = false;
398
- if (s != end && *s == '-') {
399
- ++s;
400
- negative = true;
401
- }
402
- while (s != end && *s >= '0' && *s <= '9') //
403
- uamount = uamount * 10 + (*s++ - '0');
404
- if (s != end && *s == '.') {
405
- ++s;
406
- while (s != end && *s >= '0' && *s <= '9') {
407
- uamount = uamount * 10 + (*s++ - '0');
408
- ++precision;
409
- }
410
- }
411
- if (negative)
412
- uamount = -uamount;
413
- amount = uamount;
414
- uint64_t code;
415
- if (!eosio::string_to_symbol_code(code, s, end, expect_end))
416
- return false;
417
- symbol = (code << 8) | precision;
418
- return true;
419
- }
420
-
421
- [[nodiscard]] inline bool string_to_asset(int64_t& amount, uint64_t& symbol, const char* s, const char* end) {
422
- return string_to_asset(amount, symbol, s, end, true);
423
- }
424
-
425
- inline std::string asset_to_string(int64_t amount, uint64_t symbol) {
426
- std::string result;
427
- uint64_t uamount;
428
- if (amount < 0)
429
- uamount = -amount;
430
- else
431
- uamount = amount;
432
- uint8_t precision = symbol;
433
- if (precision) {
434
- while (precision--) {
435
- result += '0' + uamount % 10;
436
- uamount /= 10;
437
- }
438
- result += '.';
439
- }
440
- do {
441
- result += '0' + uamount % 10;
442
- uamount /= 10;
443
- } while (uamount);
444
- if (amount < 0)
445
- result += '-';
446
- std::reverse(result.begin(), result.end());
447
- return result + ' ' + eosio::symbol_code_to_string(symbol >> 8);
448
- }
449
-
450
- } // namespace eosio
@@ -1,14 +0,0 @@
1
- #pragma once
2
- #include "ship_protocol.hpp"
3
-
4
- namespace chain_types {
5
- using namespace eosio::ship_protocol;
6
-
7
- struct block_info {
8
- uint32_t block_num = {};
9
- eosio::checksum256 block_id = {};
10
- eosio::block_timestamp timestamp;
11
- };
12
-
13
- EOSIO_REFLECT(block_info, block_num, block_id, timestamp);
14
- }; // namespace chain_types
@@ -1,178 +0,0 @@
1
- /**
2
- * @file
3
- * @copyright defined in eos/LICENSE
4
- */
5
- #pragma once
6
-
7
- #ifdef __eosio_cdt__
8
- #include <cstdint>
9
- namespace eosio {
10
- namespace internal_use_do_not_use {
11
- extern "C" {
12
- __attribute__((eosio_wasm_import, noreturn))
13
- void eosio_assert_message(uint32_t, const char*, uint32_t);
14
- __attribute__((eosio_wasm_import, noreturn))
15
- void eosio_assert(uint32_t, const char*);
16
- __attribute__((eosio_wasm_import, noreturn))
17
- void eosio_assert_code(uint32_t, uint64_t);
18
- }
19
- }
20
- }
21
- #else
22
- #include <stdexcept>
23
- #endif
24
-
25
- #include <string>
26
- #include <string_view>
27
-
28
- namespace eosio {
29
-
30
- /**
31
- * @defgroup system System
32
- * @ingroup core
33
- * @brief Defines wrappers over eosio_assert
34
- */
35
-
36
-
37
- struct eosio_error : std::exception {
38
- explicit eosio_error(uint64_t code) {}
39
- };
40
-
41
- namespace detail {
42
- [[noreturn]] inline void assert_or_throw(std::string_view msg) {
43
- #ifdef __eosio_cdt__
44
- internal_use_do_not_use::eosio_assert_message(false, msg.data(), msg.size());
45
- #else
46
- throw std::runtime_error(std::string(msg));
47
- #endif
48
- }
49
- [[noreturn]] inline void assert_or_throw(const char* msg) {
50
- #ifdef __eosio_cdt__
51
- internal_use_do_not_use::eosio_assert(false, msg);
52
- #else
53
- throw std::runtime_error(msg);
54
- #endif
55
- }
56
- [[noreturn]] inline void assert_or_throw(std::string&& msg) {
57
- #ifdef __eosio_cdt__
58
- internal_use_do_not_use::eosio_assert_message(false, msg.c_str(), msg.size());
59
- #else
60
- throw std::runtime_error(std::move(msg));
61
- #endif
62
- }
63
- [[noreturn]] inline void assert_or_throw(uint64_t code) {
64
- #ifdef __eosio_cdt__
65
- internal_use_do_not_use::eosio_assert_code(false, code);
66
- #else
67
- throw std::runtime_error(std::to_string(code));
68
- #endif
69
- }
70
- } // ns eosio::detail
71
-
72
- /**
73
- * Assert if the predicate fails and use the supplied message.
74
- *
75
- * @ingroup system
76
- *
77
- * Example:
78
- * @code
79
- * eosio::check(a == b, "a does not equal b");
80
- * @endcode
81
- */
82
- inline void check(bool pred, std::string_view msg) {
83
- if (!pred)
84
- eosio::detail::assert_or_throw(msg);
85
- }
86
-
87
- /**
88
- * Assert if the predicate fails and use the supplied message.
89
- *
90
- * @ingroup system
91
- *
92
- * Example:
93
- * @code
94
- * eosio::check(a == b, "a does not equal b");
95
- * @endcode
96
- */
97
- inline void check(bool pred, const char* msg) {
98
- if (!pred)
99
- eosio::detail::assert_or_throw(msg);
100
- }
101
-
102
- /**
103
- * Assert if the predicate fails and use the supplied message.
104
- *
105
- * @ingroup system
106
- *
107
- * Example:
108
- * @code
109
- * eosio::check(a == b, "a does not equal b");
110
- * @endcode
111
- */
112
- inline void check(bool pred, const std::string& msg) {
113
- if (!pred)
114
- eosio::detail::assert_or_throw(std::string_view{msg.c_str(), msg.size()});
115
- }
116
-
117
- /**
118
- * Assert if the predicate fails and use the supplied message.
119
- *
120
- * @ingroup system
121
- *
122
- * Example:
123
- * @code
124
- * eosio::check(a == b, "a does not equal b");
125
- * @endcode
126
- */
127
- inline void check(bool pred, std::string&& msg) {
128
- if (!pred)
129
- eosio::detail::assert_or_throw(std::move(msg));
130
- }
131
-
132
- /**
133
- * Assert if the predicate fails and use a subset of the supplied message.
134
- *
135
- * @ingroup system
136
- *
137
- * Example:
138
- * @code
139
- * const char* msg = "a does not equal b b does not equal a";
140
- * eosio::check(a == b, "a does not equal b", 18);
141
- * @endcode
142
- */
143
- inline void check(bool pred, const char* msg, size_t n) {
144
- if (!pred)
145
- eosio::detail::assert_or_throw(std::string_view{msg, n});
146
- }
147
-
148
- /**
149
- * Assert if the predicate fails and use a subset of the supplied message.
150
- *
151
- * @ingroup system
152
- *
153
- * Example:
154
- * @code
155
- * std::string msg = "a does not equal b b does not equal a";
156
- * eosio::check(a == b, msg, 18);
157
- * @endcode
158
- */
159
- inline void check(bool pred, const std::string& msg, size_t n) {
160
- if (!pred)
161
- eosio::detail::assert_or_throw(msg.substr(0, n));
162
- }
163
-
164
- /**
165
- * Assert if the predicate fails and use the supplied error code.
166
- *
167
- * @ingroup system
168
- *
169
- * Example:
170
- * @code
171
- * eosio::check(a == b, 13);
172
- * @endcode
173
- */
174
- inline void check(bool pred, uint64_t code) {
175
- if (!pred)
176
- eosio::detail::assert_or_throw(code);
177
- }
178
- } // namespace eosio