@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.
- package/README.md +4 -1
- package/dist/abieos.node +0 -0
- package/lib/abieos.d.ts +19 -0
- package/lib/abieos.d.ts.map +1 -0
- package/lib/abieos.js +100 -0
- package/lib/abieos.ts +107 -0
- package/package.json +13 -8
- package/.idea/modules.xml +0 -8
- package/.idea/node-abieos.iml +0 -12
- package/.idea/vcs.xml +0 -9
- package/.idea/workspace.xml +0 -66
- package/CMakeLists.txt +0 -35
- package/abieos.d.ts +0 -21
- package/abieos.js +0 -59
- package/eosio.json +0 -1596
- package/include/.clang-format +0 -76
- package/include/eosio/abi.hpp +0 -393
- package/include/eosio/asset.hpp +0 -458
- package/include/eosio/bytes.hpp +0 -27
- package/include/eosio/chain_conversions.hpp +0 -450
- package/include/eosio/chain_types.hpp +0 -14
- package/include/eosio/check.hpp +0 -178
- package/include/eosio/convert.hpp +0 -95
- package/include/eosio/crypto.hpp +0 -148
- package/include/eosio/eosio_outcome.hpp +0 -41
- package/include/eosio/fixed_bytes.hpp +0 -250
- package/include/eosio/float.hpp +0 -35
- package/include/eosio/for_each_field.hpp +0 -48
- package/include/eosio/fpconv.c +0 -336
- package/include/eosio/fpconv.h +0 -41
- package/include/eosio/fpconv.license +0 -23
- package/include/eosio/from_bin.hpp +0 -272
- package/include/eosio/from_json.hpp +0 -749
- package/include/eosio/from_string.hpp +0 -28
- package/include/eosio/map_macro.h +0 -64
- package/include/eosio/murmur.hpp +0 -55
- package/include/eosio/name.hpp +0 -178
- package/include/eosio/opaque.hpp +0 -184
- package/include/eosio/operators.hpp +0 -71
- package/include/eosio/powers.h +0 -76
- package/include/eosio/reflection.hpp +0 -61
- package/include/eosio/ship_protocol.hpp +0 -971
- package/include/eosio/stream.hpp +0 -235
- package/include/eosio/symbol.hpp +0 -300
- package/include/eosio/time.hpp +0 -264
- package/include/eosio/to_bin.hpp +0 -189
- package/include/eosio/to_json.hpp +0 -334
- package/include/eosio/to_key.hpp +0 -305
- package/include/eosio/types.hpp +0 -103
- package/include/eosio/varint.hpp +0 -452
- package/include/outcome-basic.hpp +0 -6836
- package/include/rapidjson/allocators.h +0 -284
- package/include/rapidjson/cursorstreamwrapper.h +0 -78
- package/include/rapidjson/document.h +0 -2646
- package/include/rapidjson/encodedstream.h +0 -299
- package/include/rapidjson/encodings.h +0 -716
- package/include/rapidjson/error/en.h +0 -74
- package/include/rapidjson/error/error.h +0 -161
- package/include/rapidjson/filereadstream.h +0 -99
- package/include/rapidjson/filewritestream.h +0 -104
- package/include/rapidjson/fwd.h +0 -151
- package/include/rapidjson/internal/biginteger.h +0 -290
- package/include/rapidjson/internal/diyfp.h +0 -271
- package/include/rapidjson/internal/dtoa.h +0 -245
- package/include/rapidjson/internal/ieee754.h +0 -78
- package/include/rapidjson/internal/itoa.h +0 -308
- package/include/rapidjson/internal/meta.h +0 -186
- package/include/rapidjson/internal/pow10.h +0 -55
- package/include/rapidjson/internal/regex.h +0 -732
- package/include/rapidjson/internal/stack.h +0 -231
- package/include/rapidjson/internal/strfunc.h +0 -69
- package/include/rapidjson/internal/strtod.h +0 -290
- package/include/rapidjson/internal/swap.h +0 -46
- package/include/rapidjson/istreamwrapper.h +0 -113
- package/include/rapidjson/memorybuffer.h +0 -70
- package/include/rapidjson/memorystream.h +0 -71
- package/include/rapidjson/msinttypes/inttypes.h +0 -316
- package/include/rapidjson/msinttypes/stdint.h +0 -300
- package/include/rapidjson/ostreamwrapper.h +0 -81
- package/include/rapidjson/pointer.h +0 -1357
- package/include/rapidjson/prettywriter.h +0 -277
- package/include/rapidjson/rapidjson.h +0 -654
- package/include/rapidjson/reader.h +0 -2230
- package/include/rapidjson/schema.h +0 -2494
- package/include/rapidjson/stream.h +0 -223
- package/include/rapidjson/stringbuffer.h +0 -121
- package/include/rapidjson/writer.h +0 -710
- package/src/abi.cpp +0 -274
- package/src/abieos.cpp +0 -334
- package/src/abieos.h +0 -91
- package/src/abieos.hpp +0 -1011
- package/src/abieos_exception.hpp +0 -89
- package/src/abieos_numeric.hpp +0 -94
- package/src/abieos_ripemd160.hpp +0 -417
- package/src/crypto.cpp +0 -215
- package/src/main.cpp +0 -242
- package/src/ship.abi.cpp +0 -695
- package/tools/CMakeLists.txt +0 -9
- package/tools/name.cpp +0 -86
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "stream.hpp"
|
|
4
|
-
#include <string_view>
|
|
5
|
-
|
|
6
|
-
namespace eosio {
|
|
7
|
-
|
|
8
|
-
template <typename T, typename S>
|
|
9
|
-
T from_string(S& stream) {
|
|
10
|
-
T obj;
|
|
11
|
-
from_string(obj, stream);
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
template <typename T>
|
|
16
|
-
void convert_from_string(T& obj, std::string_view s) {
|
|
17
|
-
input_stream stream{ s };
|
|
18
|
-
from_string(obj, stream);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
template <typename T>
|
|
22
|
-
T convert_from_string(std::string_view s) {
|
|
23
|
-
T obj;
|
|
24
|
-
convert_from_string(obj, s);
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
} // namespace eosio
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2012 William Swanson
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person
|
|
5
|
-
* obtaining a copy of this software and associated documentation
|
|
6
|
-
* files (the "Software"), to deal in the Software without
|
|
7
|
-
* restriction, including without limitation the rights to use, copy,
|
|
8
|
-
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
-
* of the Software, and to permit persons to whom the Software is
|
|
10
|
-
* furnished to do so, subject to the following conditions:
|
|
11
|
-
*
|
|
12
|
-
* The above copyright notice and this permission notice shall be
|
|
13
|
-
* included in all copies or substantial portions of the Software.
|
|
14
|
-
*
|
|
15
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
|
19
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
20
|
-
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
*
|
|
23
|
-
* Except as contained in this notice, the names of the authors or
|
|
24
|
-
* their institutions shall not be used in advertising or otherwise to
|
|
25
|
-
* promote the sale, use or other dealings in this Software without
|
|
26
|
-
* prior written authorization from the authors.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
* This file has been modified by block.one
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
#ifndef EOSIO_MAP_MACRO_H_INCLUDED
|
|
34
|
-
#define EOSIO_MAP_MACRO_H_INCLUDED
|
|
35
|
-
|
|
36
|
-
#define EOSIO_EVAL0(...) __VA_ARGS__
|
|
37
|
-
#define EOSIO_EVAL1(...) EOSIO_EVAL0(EOSIO_EVAL0(EOSIO_EVAL0(__VA_ARGS__)))
|
|
38
|
-
#define EOSIO_EVAL2(...) EOSIO_EVAL1(EOSIO_EVAL1(EOSIO_EVAL1(__VA_ARGS__)))
|
|
39
|
-
#define EOSIO_EVAL3(...) EOSIO_EVAL2(EOSIO_EVAL2(EOSIO_EVAL2(__VA_ARGS__)))
|
|
40
|
-
#define EOSIO_EVAL4(...) EOSIO_EVAL3(EOSIO_EVAL3(EOSIO_EVAL3(__VA_ARGS__)))
|
|
41
|
-
#define EOSIO_EVAL(...) EOSIO_EVAL4(EOSIO_EVAL4(EOSIO_EVAL4(__VA_ARGS__)))
|
|
42
|
-
|
|
43
|
-
#define EOSIO_MAP_END(...)
|
|
44
|
-
#define EOSIO_MAP_OUT
|
|
45
|
-
|
|
46
|
-
#define EOSIO_MAP_GET_END2() 0, EOSIO_MAP_END
|
|
47
|
-
#define EOSIO_MAP_GET_END1(...) EOSIO_MAP_GET_END2
|
|
48
|
-
#define EOSIO_MAP_GET_END(...) EOSIO_MAP_GET_END1
|
|
49
|
-
#define EOSIO_MAP_NEXT0(test, next, ...) next EOSIO_MAP_OUT
|
|
50
|
-
#define EOSIO_MAP_NEXT1(test, next) EOSIO_MAP_NEXT0(test, next, 0)
|
|
51
|
-
#define EOSIO_MAP_NEXT(test, next) EOSIO_MAP_NEXT1(EOSIO_MAP_GET_END test, next)
|
|
52
|
-
|
|
53
|
-
// Macros below this point added by block.one
|
|
54
|
-
|
|
55
|
-
#define EOSIO_MAP_REUSE_ARG0_0(f, arg0, x, peek, ...) \
|
|
56
|
-
f(arg0, x) EOSIO_MAP_NEXT(peek, EOSIO_MAP_REUSE_ARG0_1)(f, arg0, peek, __VA_ARGS__)
|
|
57
|
-
#define EOSIO_MAP_REUSE_ARG0_1(f, arg0, x, peek, ...) \
|
|
58
|
-
f(arg0, x) EOSIO_MAP_NEXT(peek, EOSIO_MAP_REUSE_ARG0_0)(f, arg0, peek, __VA_ARGS__)
|
|
59
|
-
// Handle 0 arguments
|
|
60
|
-
#define EOSIO_MAP_REUSE_ARG0_I(f, arg0, peek, ...) \
|
|
61
|
-
EOSIO_MAP_NEXT(peek, EOSIO_MAP_REUSE_ARG0_1)(f, arg0, peek, __VA_ARGS__)
|
|
62
|
-
#define EOSIO_MAP_REUSE_ARG0(f, ...) EOSIO_EVAL(EOSIO_MAP_REUSE_ARG0_I(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
|
|
63
|
-
|
|
64
|
-
#endif
|
package/include/eosio/murmur.hpp
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
namespace eosio {
|
|
3
|
-
namespace {
|
|
4
|
-
inline constexpr uint64_t unaligned_load(const char* p)
|
|
5
|
-
{
|
|
6
|
-
uint64_t r = 0;
|
|
7
|
-
for( uint32_t i = 0; i < 8; ++i ) {
|
|
8
|
-
r |= p[i];
|
|
9
|
-
r <<= 8;
|
|
10
|
-
}
|
|
11
|
-
return r;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Loads n bytes, where 1 <= n < 8.
|
|
15
|
-
inline constexpr uint64_t load_bytes(const char* p, int n)
|
|
16
|
-
{
|
|
17
|
-
std::uint64_t result = 0;
|
|
18
|
-
--n;
|
|
19
|
-
do
|
|
20
|
-
result = (result << 8) + (unsigned char)(p[n]);
|
|
21
|
-
while (--n >= 0);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
inline constexpr uint64_t shift_mix(std::uint64_t v)
|
|
26
|
-
{ return v ^ (v >> 47);}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Implementation of Murmur hash for 64-bit size_t.
|
|
30
|
-
inline constexpr uint64_t murmur64(const char* ptr, uint64_t len, uint64_t seed = 0xbadd00d00)
|
|
31
|
-
{
|
|
32
|
-
const uint64_t mul = (((uint64_t) 0xc6a4a793UL) << 32UL)
|
|
33
|
-
+ (uint64_t) 0x5bd1e995UL;
|
|
34
|
-
const char* const buf = ptr;
|
|
35
|
-
|
|
36
|
-
// Remove the bytes not divisible by the sizeof(uint64_t). This
|
|
37
|
-
// allows the main loop to process the data as 64-bit integers.
|
|
38
|
-
const uint64_t len_aligned = len & ~(uint64_t)0x7;
|
|
39
|
-
const char* const end = buf + len_aligned;
|
|
40
|
-
uint64_t hash = seed ^ (len * mul);
|
|
41
|
-
for (const char* p = buf; p != end; p += 8) {
|
|
42
|
-
const uint64_t data = shift_mix(unaligned_load(p) * mul) * mul;
|
|
43
|
-
hash ^= data;
|
|
44
|
-
hash *= mul;
|
|
45
|
-
}
|
|
46
|
-
if ((len & 0x7) != 0) {
|
|
47
|
-
const uint64_t data = load_bytes(end, len & 0x7);
|
|
48
|
-
hash ^= data;
|
|
49
|
-
hash *= mul;
|
|
50
|
-
}
|
|
51
|
-
hash = shift_mix(hash) * mul;
|
|
52
|
-
hash = shift_mix(hash);
|
|
53
|
-
return hash;
|
|
54
|
-
}
|
|
55
|
-
} // namespace eosio
|
package/include/eosio/name.hpp
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "chain_conversions.hpp"
|
|
4
|
-
#include "check.hpp"
|
|
5
|
-
#include "operators.hpp"
|
|
6
|
-
#include "reflection.hpp"
|
|
7
|
-
#include "murmur.hpp"
|
|
8
|
-
#include <string>
|
|
9
|
-
|
|
10
|
-
namespace eosio {
|
|
11
|
-
|
|
12
|
-
struct name {
|
|
13
|
-
enum class raw : uint64_t {};
|
|
14
|
-
uint64_t value = 0;
|
|
15
|
-
|
|
16
|
-
constexpr name() = default;
|
|
17
|
-
constexpr explicit name(uint64_t value) : value{ value } {}
|
|
18
|
-
constexpr explicit name(name::raw value) : value{ static_cast<uint64_t>(value) } {}
|
|
19
|
-
constexpr explicit name(std::string_view str) : value{ string_to_name_strict(str) } { }
|
|
20
|
-
|
|
21
|
-
constexpr name(const name&) = default;
|
|
22
|
-
|
|
23
|
-
constexpr operator raw() const { return static_cast<raw>(value); }
|
|
24
|
-
explicit operator std::string() const { return eosio::name_to_string(value); }
|
|
25
|
-
std::string to_string() const { return std::string(*this); }
|
|
26
|
-
/**
|
|
27
|
-
* Explicit cast to bool of the uint64_t value of the name
|
|
28
|
-
*
|
|
29
|
-
* @return Returns true if the name is set to the default value of 0 else true.
|
|
30
|
-
*/
|
|
31
|
-
constexpr explicit operator bool() const { return value != 0; }
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Converts a %name Base32 symbol into its corresponding value
|
|
35
|
-
*
|
|
36
|
-
* @param c - Character to be converted
|
|
37
|
-
* @return constexpr char - Converted value
|
|
38
|
-
*/
|
|
39
|
-
static constexpr uint8_t char_to_value(char c) {
|
|
40
|
-
if (c == '.')
|
|
41
|
-
return 0;
|
|
42
|
-
else if (c >= '1' && c <= '5')
|
|
43
|
-
return (c - '1') + 1;
|
|
44
|
-
else if (c >= 'a' && c <= 'z')
|
|
45
|
-
return (c - 'a') + 6;
|
|
46
|
-
else
|
|
47
|
-
eosio::check(false, "character is not in allowed character set for names");
|
|
48
|
-
|
|
49
|
-
return 0; // control flow will never reach here; just added to suppress warning
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Returns the length of the %name
|
|
54
|
-
*/
|
|
55
|
-
constexpr uint8_t length() const {
|
|
56
|
-
constexpr uint64_t mask = 0xF800000000000000ull;
|
|
57
|
-
|
|
58
|
-
if (value == 0)
|
|
59
|
-
return 0;
|
|
60
|
-
|
|
61
|
-
uint8_t l = 0;
|
|
62
|
-
uint8_t i = 0;
|
|
63
|
-
for (auto v = value; i < 13; ++i, v <<= 5) {
|
|
64
|
-
if ((v & mask) > 0) {
|
|
65
|
-
l = i;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return l + 1;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the suffix of the %name
|
|
74
|
-
*/
|
|
75
|
-
constexpr name suffix() const {
|
|
76
|
-
uint32_t remaining_bits_after_last_actual_dot = 0;
|
|
77
|
-
uint32_t tmp = 0;
|
|
78
|
-
for (int32_t remaining_bits = 59; remaining_bits >= 4;
|
|
79
|
-
remaining_bits -= 5) { // Note: remaining_bits must remain signed integer
|
|
80
|
-
// Get characters one-by-one in name in order from left to right (not including the 13th character)
|
|
81
|
-
auto c = (value >> remaining_bits) & 0x1Full;
|
|
82
|
-
if (!c) { // if this character is a dot
|
|
83
|
-
tmp = static_cast<uint32_t>(remaining_bits);
|
|
84
|
-
} else { // if this character is not a dot
|
|
85
|
-
remaining_bits_after_last_actual_dot = tmp;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
uint64_t thirteenth_character = value & 0x0Full;
|
|
90
|
-
if (thirteenth_character) { // if 13th character is not a dot
|
|
91
|
-
remaining_bits_after_last_actual_dot = tmp;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (remaining_bits_after_last_actual_dot ==
|
|
95
|
-
0) // there is no actual dot in the %name other than potentially leading dots
|
|
96
|
-
return name{ value };
|
|
97
|
-
|
|
98
|
-
// At this point remaining_bits_after_last_actual_dot has to be within the range of 4 to 59 (and restricted to
|
|
99
|
-
// increments of 5).
|
|
100
|
-
|
|
101
|
-
// Mask for remaining bits corresponding to characters after last actual dot, except for 4 least significant bits
|
|
102
|
-
// (corresponds to 13th character).
|
|
103
|
-
uint64_t mask = (1ull << remaining_bits_after_last_actual_dot) - 16;
|
|
104
|
-
uint32_t shift = 64 - remaining_bits_after_last_actual_dot;
|
|
105
|
-
|
|
106
|
-
return name{ ((value & mask) << shift) + (thirteenth_character << (shift - 1)) };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Returns the prefix of the %name
|
|
111
|
-
*/
|
|
112
|
-
constexpr name prefix() const {
|
|
113
|
-
uint64_t result = value;
|
|
114
|
-
bool not_dot_character_seen = false;
|
|
115
|
-
uint64_t mask = 0xFull;
|
|
116
|
-
|
|
117
|
-
// Get characters one-by-one in name in order from right to left
|
|
118
|
-
for (int32_t offset = 0; offset <= 59;) {
|
|
119
|
-
auto c = (value >> offset) & mask;
|
|
120
|
-
|
|
121
|
-
if (!c) { // if this character is a dot
|
|
122
|
-
if (not_dot_character_seen) { // we found the rightmost dot character
|
|
123
|
-
result = (value >> offset) << offset;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
not_dot_character_seen = true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (offset == 0) {
|
|
131
|
-
offset += 4;
|
|
132
|
-
mask = 0x1Full;
|
|
133
|
-
} else {
|
|
134
|
-
offset += 5;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return name{ result };
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// TODO this seems weird and the name is misleading
|
|
143
|
-
// and I don't think this has ever been truly constexpr
|
|
144
|
-
inline constexpr uint64_t hash_name( std::string_view str ) {
|
|
145
|
-
auto r = try_string_to_name_strict(str);
|
|
146
|
-
if( r ) return r.value();
|
|
147
|
-
return murmur64( str.data(), str.size() );
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
EOSIO_REFLECT(name, value);
|
|
151
|
-
EOSIO_COMPARE(name);
|
|
152
|
-
|
|
153
|
-
template <typename S>
|
|
154
|
-
void from_json(name& obj, S& stream) {
|
|
155
|
-
auto r = stream.get_string();
|
|
156
|
-
obj = name(hash_name(r));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
template <typename S>
|
|
160
|
-
void to_json(const name& obj, S& stream) {
|
|
161
|
-
to_json(eosio::name_to_string(obj.value), stream);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
inline namespace literals {
|
|
165
|
-
#if defined(__clang__)
|
|
166
|
-
# pragma clang diagnostic push
|
|
167
|
-
# pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
|
|
168
|
-
#endif
|
|
169
|
-
template <typename T, T... Str>
|
|
170
|
-
inline constexpr name operator""_n() {
|
|
171
|
-
return name(string_to_name_strict<Str...>()); }
|
|
172
|
-
inline constexpr name operator""_h(const char* s, size_t) { return name( hash_name(s) ); }
|
|
173
|
-
#if defined(__clang__)
|
|
174
|
-
# pragma clang diagnostic pop
|
|
175
|
-
#endif
|
|
176
|
-
} // namespace literals
|
|
177
|
-
|
|
178
|
-
} // namespace eosio
|
package/include/eosio/opaque.hpp
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
#include "to_bin.hpp"
|
|
3
|
-
#include "from_bin.hpp"
|
|
4
|
-
#include "stream.hpp"
|
|
5
|
-
#include "types.hpp"
|
|
6
|
-
|
|
7
|
-
namespace eosio {
|
|
8
|
-
|
|
9
|
-
///
|
|
10
|
-
/// opaque<T> type provides a type safe alternative to input_stream to declare a field
|
|
11
|
-
/// to be skiped during deserialization of its containing data structure. Afterwards,
|
|
12
|
-
/// the underlying value can be restored with correct type information.
|
|
13
|
-
///
|
|
14
|
-
/// The serialization opaque<T> consists of a variable length byte count followed by the
|
|
15
|
-
/// serialized bytes for a value of type T. The purpose to serialized as opaque<T> as oppose
|
|
16
|
-
/// to T is to allow the client to delay deserialization until the value is actually needed and
|
|
17
|
-
/// thus saving some CPU cycles or memory requirement.
|
|
18
|
-
///
|
|
19
|
-
/// For example, given a foo_type,
|
|
20
|
-
///
|
|
21
|
-
/// <code>
|
|
22
|
-
/// struct foo_type {
|
|
23
|
-
/// uint32_t field1;
|
|
24
|
-
/// string field2;
|
|
25
|
-
/// opaque<std::vector<string>> field3;
|
|
26
|
-
/// };
|
|
27
|
-
/// </code>
|
|
28
|
-
///
|
|
29
|
-
/// the deserialization can be implemented as follows:
|
|
30
|
-
///
|
|
31
|
-
/// <code>
|
|
32
|
-
/// input_stream serialized_foo_stream(...);
|
|
33
|
-
/// foo_type foo_value;
|
|
34
|
-
/// from_bin(foo_value, serialized_foo_stream);
|
|
35
|
-
/// if (foo_value.field1 > 1 || foo_value.field2 == "meet_precondition") {
|
|
36
|
-
/// if(!foo_value.field3.empty()) {
|
|
37
|
-
/// loop_until(foo_value.field3, [](const auto& x) {
|
|
38
|
-
/// if (x.size() > 1) {
|
|
39
|
-
/// return true;
|
|
40
|
-
/// }
|
|
41
|
-
/// do_something(x);
|
|
42
|
-
/// return false;
|
|
43
|
-
/// });
|
|
44
|
-
/// }
|
|
45
|
-
/// }
|
|
46
|
-
/// </code>
|
|
47
|
-
|
|
48
|
-
template <typename T>
|
|
49
|
-
class opaque_base {
|
|
50
|
-
protected:
|
|
51
|
-
input_stream bin;
|
|
52
|
-
|
|
53
|
-
opaque_base(input_stream b) : bin(b) {}
|
|
54
|
-
|
|
55
|
-
public:
|
|
56
|
-
opaque_base() = default;
|
|
57
|
-
explicit opaque_base(const std::vector<char>& data) : bin(data) {}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @pre !this->empty()
|
|
61
|
-
*/
|
|
62
|
-
[[deprecated("Use unpack() free function instead.")]] void unpack(T& obj) { eosio::from_bin(obj, bin); }
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @pre !this->empty()
|
|
66
|
-
*/
|
|
67
|
-
[[deprecated("Use unpack() free function instead.")]] T unpack() {
|
|
68
|
-
T obj;
|
|
69
|
-
this->unpack(obj);
|
|
70
|
-
return obj;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
bool empty() const { return !bin.remaining(); }
|
|
74
|
-
size_t num_bytes() const { return bin.remaining(); }
|
|
75
|
-
|
|
76
|
-
template <typename S>
|
|
77
|
-
void from(S& stream) {
|
|
78
|
-
eosio::from_bin(this->bin, stream);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
template <typename S>
|
|
82
|
-
void to_bin(S& stream) const {
|
|
83
|
-
eosio::to_bin(this->bin, stream);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
input_stream get() const { return bin; }
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
template <typename T>
|
|
90
|
-
class opaque : public opaque_base<T> {
|
|
91
|
-
public:
|
|
92
|
-
using opaque_base<T>::opaque_base;
|
|
93
|
-
|
|
94
|
-
template <typename U, typename = std::enable_if_t<std::is_base_of_v<T, U>>>
|
|
95
|
-
opaque(opaque<U> other) : opaque_base<T>(other.bin) {}
|
|
96
|
-
|
|
97
|
-
template <typename U>
|
|
98
|
-
friend opaque<U> as_opaque(input_stream bin);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
template <typename T>
|
|
102
|
-
class opaque<std::vector<T>> : public opaque_base<std::vector<T>> {
|
|
103
|
-
public:
|
|
104
|
-
using opaque_base<std::vector<T>>::opaque_base;
|
|
105
|
-
|
|
106
|
-
/** Determine the size of the vector to be unpacked.
|
|
107
|
-
*
|
|
108
|
-
* @pre !this->empty()
|
|
109
|
-
*/
|
|
110
|
-
[[deprecated("Use for_each() or loop_until() free function instead.")]] uint64_t unpack_size() {
|
|
111
|
-
uint64_t num;
|
|
112
|
-
varuint64_from_bin(num, this->bin);
|
|
113
|
-
return num;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
[[deprecated("Use for_each() or loop_until() free function instead.")]] void unpack_next(T& obj) {
|
|
117
|
-
eosio::from_bin(obj, this->bin);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
[[deprecated("Use for_each() or loop_until() free function instead.")]] T unpack_next() {
|
|
121
|
-
T obj;
|
|
122
|
-
this->unpack_next(obj);
|
|
123
|
-
return obj;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
template <typename U>
|
|
127
|
-
friend opaque<U> as_opaque(input_stream bin);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
template <typename T>
|
|
131
|
-
constexpr const char* get_type_name(opaque<T>*) {
|
|
132
|
-
return "bytes";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
template <typename T, typename S>
|
|
136
|
-
void from_bin(opaque<T>& obj, S& stream) {
|
|
137
|
-
obj.from(stream);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
template <typename T, typename S>
|
|
141
|
-
void to_bin(const opaque<T>& obj, S& stream) {
|
|
142
|
-
obj.to_bin(stream);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
template <typename U>
|
|
146
|
-
opaque<U> as_opaque(input_stream bin) {
|
|
147
|
-
opaque<U> result;
|
|
148
|
-
result.bin = bin;
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
template <typename T, typename U>
|
|
153
|
-
std::enable_if_t<std::is_base_of_v<U, T>, bool> unpack(opaque<T> opq, U& obj) {
|
|
154
|
-
if (opq.empty())
|
|
155
|
-
return false;
|
|
156
|
-
input_stream bin = opq.get();
|
|
157
|
-
eosio::from_bin(obj, bin);
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
template <typename T, typename Predicate>
|
|
162
|
-
void loop_until(opaque<std::vector<T>> opq, Predicate&& f) {
|
|
163
|
-
if (opq.empty())
|
|
164
|
-
return;
|
|
165
|
-
input_stream bin = opq.get();
|
|
166
|
-
uint64_t num;
|
|
167
|
-
varuint64_from_bin(num, bin);
|
|
168
|
-
for (uint64_t i = 0; i < num; ++i) {
|
|
169
|
-
T obj;
|
|
170
|
-
eosio::from_bin(obj, bin);
|
|
171
|
-
if (f(std::move(obj)))
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
template <typename T, typename UnaryFunction>
|
|
177
|
-
void for_each(opaque<std::vector<T>> opq, UnaryFunction&& f) {
|
|
178
|
-
loop_until(opq, [&f](auto&& x) {
|
|
179
|
-
f(std::forward<decltype(x)>(x));
|
|
180
|
-
return false;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
} // namespace eosio
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "for_each_field.hpp"
|
|
4
|
-
|
|
5
|
-
namespace eosio { namespace operators {
|
|
6
|
-
|
|
7
|
-
// Defines comparison operators for a reflected struct
|
|
8
|
-
#define EOSIO_COMPARE(...) \
|
|
9
|
-
auto eosio_enable_comparison(const __VA_ARGS__&)->bool; \
|
|
10
|
-
using ::eosio::operators::operator==; \
|
|
11
|
-
using ::eosio::operators::operator!=; \
|
|
12
|
-
using ::eosio::operators::operator<; \
|
|
13
|
-
using ::eosio::operators::operator>; \
|
|
14
|
-
using ::eosio::operators::operator<=; \
|
|
15
|
-
using ::eosio::operators::operator>=; \
|
|
16
|
-
using ::eosio::operators::eosio_compare
|
|
17
|
-
|
|
18
|
-
template <typename T>
|
|
19
|
-
constexpr auto operator==(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) {
|
|
20
|
-
bool result = true;
|
|
21
|
-
for_each_field<T>([&](const char*, auto&& member) { result = result && (member(&lhs) == member(&rhs)); });
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
template <typename T>
|
|
25
|
-
constexpr auto operator!=(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) {
|
|
26
|
-
return !(lhs == rhs);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
namespace internal_use_do_not_use {
|
|
30
|
-
// This is a worse match than the user-visible overload
|
|
31
|
-
template <typename T, typename U>
|
|
32
|
-
constexpr int eosio_compare(const T& lhs, const U& rhs) {
|
|
33
|
-
if (lhs < rhs)
|
|
34
|
-
return -1;
|
|
35
|
-
else if (rhs < lhs)
|
|
36
|
-
return 1;
|
|
37
|
-
else
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
|
-
} // namespace internal_use_do_not_use
|
|
41
|
-
|
|
42
|
-
template <typename T>
|
|
43
|
-
constexpr auto eosio_compare(const T& lhs, const T& rhs) -> decltype((eosio_enable_comparison(lhs), 0)) {
|
|
44
|
-
int result = 0;
|
|
45
|
-
for_each_field<T>([&](const char*, auto&& member) {
|
|
46
|
-
if (!result) {
|
|
47
|
-
using internal_use_do_not_use::eosio_compare;
|
|
48
|
-
result = eosio_compare(member(&lhs), member(&rhs));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
template <typename T>
|
|
55
|
-
constexpr auto operator<(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) {
|
|
56
|
-
return eosio_compare(lhs, rhs) < 0;
|
|
57
|
-
}
|
|
58
|
-
template <typename T>
|
|
59
|
-
constexpr auto operator>(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) {
|
|
60
|
-
return eosio_compare(lhs, rhs) > 0;
|
|
61
|
-
}
|
|
62
|
-
template <typename T>
|
|
63
|
-
constexpr auto operator<=(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) {
|
|
64
|
-
return eosio_compare(lhs, rhs) <= 0;
|
|
65
|
-
}
|
|
66
|
-
template <typename T>
|
|
67
|
-
constexpr auto operator>=(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) {
|
|
68
|
-
return eosio_compare(lhs, rhs) >= 0;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}} // namespace eosio::operators
|
package/include/eosio/powers.h
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/// From https://github.com/night-shift/fpconv
|
|
2
|
-
/// Boost Software License 1.0
|
|
3
|
-
/// See accompanying license file
|
|
4
|
-
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include <stdint.h>
|
|
8
|
-
|
|
9
|
-
#define npowers 87
|
|
10
|
-
#define steppowers 8
|
|
11
|
-
#define firstpower -348 /* 10 ^ -348 */
|
|
12
|
-
|
|
13
|
-
#define expmax -32
|
|
14
|
-
#define expmin -60
|
|
15
|
-
|
|
16
|
-
typedef struct Fp {
|
|
17
|
-
uint64_t frac;
|
|
18
|
-
int exp;
|
|
19
|
-
} Fp;
|
|
20
|
-
|
|
21
|
-
static Fp powers_ten[] = {
|
|
22
|
-
{ 18054884314459144840U, -1220 }, { 13451937075301367670U, -1193 }, { 10022474136428063862U, -1166 },
|
|
23
|
-
{ 14934650266808366570U, -1140 }, { 11127181549972568877U, -1113 }, { 16580792590934885855U, -1087 },
|
|
24
|
-
{ 12353653155963782858U, -1060 }, { 18408377700990114895U, -1034 }, { 13715310171984221708U, -1007 },
|
|
25
|
-
{ 10218702384817765436U, -980 }, { 15227053142812498563U, -954 }, { 11345038669416679861U, -927 },
|
|
26
|
-
{ 16905424996341287883U, -901 }, { 12595523146049147757U, -874 }, { 9384396036005875287U, -847 },
|
|
27
|
-
{ 13983839803942852151U, -821 }, { 10418772551374772303U, -794 }, { 15525180923007089351U, -768 },
|
|
28
|
-
{ 11567161174868858868U, -741 }, { 17236413322193710309U, -715 }, { 12842128665889583758U, -688 },
|
|
29
|
-
{ 9568131466127621947U, -661 }, { 14257626930069360058U, -635 }, { 10622759856335341974U, -608 },
|
|
30
|
-
{ 15829145694278690180U, -582 }, { 11793632577567316726U, -555 }, { 17573882009934360870U, -529 },
|
|
31
|
-
{ 13093562431584567480U, -502 }, { 9755464219737475723U, -475 }, { 14536774485912137811U, -449 },
|
|
32
|
-
{ 10830740992659433045U, -422 }, { 16139061738043178685U, -396 }, { 12024538023802026127U, -369 },
|
|
33
|
-
{ 17917957937422433684U, -343 }, { 13349918974505688015U, -316 }, { 9946464728195732843U, -289 },
|
|
34
|
-
{ 14821387422376473014U, -263 }, { 11042794154864902060U, -236 }, { 16455045573212060422U, -210 },
|
|
35
|
-
{ 12259964326927110867U, -183 }, { 18268770466636286478U, -157 }, { 13611294676837538539U, -130 },
|
|
36
|
-
{ 10141204801825835212U, -103 }, { 15111572745182864684U, -77 }, { 11258999068426240000U, -50 },
|
|
37
|
-
{ 16777216000000000000U, -24 }, { 12500000000000000000U, 3 }, { 9313225746154785156U, 30 },
|
|
38
|
-
{ 13877787807814456755U, 56 }, { 10339757656912845936U, 83 }, { 15407439555097886824U, 109 },
|
|
39
|
-
{ 11479437019748901445U, 136 }, { 17105694144590052135U, 162 }, { 12744735289059618216U, 189 },
|
|
40
|
-
{ 9495567745759798747U, 216 }, { 14149498560666738074U, 242 }, { 10542197943230523224U, 269 },
|
|
41
|
-
{ 15709099088952724970U, 295 }, { 11704190886730495818U, 322 }, { 17440603504673385349U, 348 },
|
|
42
|
-
{ 12994262207056124023U, 375 }, { 9681479787123295682U, 402 }, { 14426529090290212157U, 428 },
|
|
43
|
-
{ 10748601772107342003U, 455 }, { 16016664761464807395U, 481 }, { 11933345169920330789U, 508 },
|
|
44
|
-
{ 17782069995880619868U, 534 }, { 13248674568444952270U, 561 }, { 9871031767461413346U, 588 },
|
|
45
|
-
{ 14708983551653345445U, 614 }, { 10959046745042015199U, 641 }, { 16330252207878254650U, 667 },
|
|
46
|
-
{ 12166986024289022870U, 694 }, { 18130221999122236476U, 720 }, { 13508068024458167312U, 747 },
|
|
47
|
-
{ 10064294952495520794U, 774 }, { 14996968138956309548U, 800 }, { 11173611982879273257U, 827 },
|
|
48
|
-
{ 16649979327439178909U, 853 }, { 12405201291620119593U, 880 }, { 9242595204427927429U, 907 },
|
|
49
|
-
{ 13772540099066387757U, 933 }, { 10261342003245940623U, 960 }, { 15290591125556738113U, 986 },
|
|
50
|
-
{ 11392378155556871081U, 1013 }, { 16975966327722178521U, 1039 }, { 12648080533535911531U, 1066 }
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
static Fp find_cachedpow10(int exp, int* k) {
|
|
54
|
-
const double one_log_ten = 0.30102999566398114;
|
|
55
|
-
|
|
56
|
-
int approx = -(exp + npowers) * one_log_ten;
|
|
57
|
-
int idx = (approx - firstpower) / steppowers;
|
|
58
|
-
|
|
59
|
-
while (1) {
|
|
60
|
-
int current = exp + powers_ten[idx].exp + 64;
|
|
61
|
-
|
|
62
|
-
if (current < expmin) {
|
|
63
|
-
idx++;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (current > expmax) {
|
|
68
|
-
idx--;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
*k = (firstpower + idx * steppowers);
|
|
73
|
-
|
|
74
|
-
return powers_ten[idx];
|
|
75
|
-
}
|
|
76
|
-
}
|