@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,95 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "for_each_field.hpp"
|
|
4
|
-
#include "stream.hpp"
|
|
5
|
-
#include <optional>
|
|
6
|
-
#include <type_traits>
|
|
7
|
-
#include <utility>
|
|
8
|
-
#include <variant>
|
|
9
|
-
#include <vector>
|
|
10
|
-
|
|
11
|
-
namespace eosio {
|
|
12
|
-
struct no_conversion {
|
|
13
|
-
using reverse = no_conversion;
|
|
14
|
-
};
|
|
15
|
-
struct widening_conversion;
|
|
16
|
-
// Fields must match exactly
|
|
17
|
-
struct strict_conversion {
|
|
18
|
-
using reverse = strict_conversion;
|
|
19
|
-
};
|
|
20
|
-
// Can discard some fields
|
|
21
|
-
struct narrowing_conversion {
|
|
22
|
-
using reverse = widening_conversion;
|
|
23
|
-
};
|
|
24
|
-
// Can default construct some fields
|
|
25
|
-
struct widening_conversion {
|
|
26
|
-
using reverse = narrowing_conversion;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
no_conversion conversion_kind(...);
|
|
30
|
-
void serialize_as(...);
|
|
31
|
-
|
|
32
|
-
template <typename T>
|
|
33
|
-
using serialization_type = decltype(serialize_as(std::declval<T>()));
|
|
34
|
-
|
|
35
|
-
template <typename T, typename U>
|
|
36
|
-
using conversion_kind_t =
|
|
37
|
-
std::conditional_t<std::is_same_v<decltype(conversion_kind(std::declval<T>(), std::declval<U>())), no_conversion>,
|
|
38
|
-
typename decltype(conversion_kind(std::declval<U>(), std::declval<T>()))::reverse,
|
|
39
|
-
decltype(conversion_kind(std::declval<T>(), std::declval<U>()))>;
|
|
40
|
-
|
|
41
|
-
template <typename Field, typename T, typename U, typename F>
|
|
42
|
-
auto convert_impl(Field field, const T& src, U& dst, F&& f, int)
|
|
43
|
-
-> std::void_t<decltype(field(&src)), decltype(field(&dst))> {
|
|
44
|
-
convert(field(&src), field(&dst), f);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
template <typename Field, typename T, typename U, typename F>
|
|
48
|
-
auto convert_impl(Field field, const T& src, U& dst, F&& f, long) {
|
|
49
|
-
static_assert(!std::is_same_v<conversion_kind_t<T, U>, strict_conversion>, "Member not found");
|
|
50
|
-
static_assert(!std::is_same_v<conversion_kind_t<T, U>, widening_conversion>, "Member not found");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
inline constexpr auto choose_first = [](auto src, auto dest) { return src; };
|
|
54
|
-
inline constexpr auto choose_second = [](auto src, auto dest) { return dest; };
|
|
55
|
-
|
|
56
|
-
// TODO: add some validation
|
|
57
|
-
|
|
58
|
-
template <typename T, typename U, typename F>
|
|
59
|
-
void convert(const T& src, U& dst, F&& chooser) {
|
|
60
|
-
if constexpr (std::is_same_v<T, U>) {
|
|
61
|
-
dst = src;
|
|
62
|
-
} else {
|
|
63
|
-
static_assert(!std::is_same_v<conversion_kind_t<T, U>, no_conversion>, "Conversion not defined");
|
|
64
|
-
for_each_field<std::decay_t<decltype(*chooser((T*)nullptr, (U*)nullptr))>>(
|
|
65
|
-
[&](const char*, auto field) { convert_impl(field, src, dst, chooser, 0); });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
template <typename... T, typename U, typename F>
|
|
70
|
-
void convert(const std::variant<T...>& src, U& dst, F&& chooser) {
|
|
71
|
-
std::visit([&](auto& src) { return convert(src, dst, chooser); }, src);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
template <typename T, typename U, typename F>
|
|
75
|
-
void convert(const std::vector<T>& src, std::vector<U>& dst, F&& chooser) {
|
|
76
|
-
dst.resize(src.size());
|
|
77
|
-
for (std::size_t i = 0; i < src.size(); ++i) { convert(src[i], dst[i], chooser); }
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
template <typename T, typename U, typename F>
|
|
81
|
-
void convert(const std::optional<T>& src, std::optional<U>& dst, F&& chooser) {
|
|
82
|
-
if (src) {
|
|
83
|
-
dst.emplace();
|
|
84
|
-
convert(*src, *dst, chooser);
|
|
85
|
-
} else {
|
|
86
|
-
dst = std::nullopt;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
struct stream;
|
|
91
|
-
template <typename F>
|
|
92
|
-
void convert(const input_stream& src, std::vector<char>& dst, F&& chooser) {
|
|
93
|
-
dst.assign(src.pos, src.end);
|
|
94
|
-
}
|
|
95
|
-
} // namespace eosio
|
package/include/eosio/crypto.hpp
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <cstdint>
|
|
4
|
-
#include "operators.hpp"
|
|
5
|
-
#include "reflection.hpp"
|
|
6
|
-
#include <string>
|
|
7
|
-
#include <variant>
|
|
8
|
-
#include <vector>
|
|
9
|
-
#include <array>
|
|
10
|
-
|
|
11
|
-
namespace eosio {
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @defgroup public_key Public Key Type
|
|
15
|
-
* @ingroup core
|
|
16
|
-
* @ingroup types
|
|
17
|
-
* @brief Specifies public key type
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* EOSIO ECC public key data
|
|
22
|
-
*
|
|
23
|
-
* Fixed size representation of either a K1 or R1 compressed public key
|
|
24
|
-
|
|
25
|
-
* @ingroup public_key
|
|
26
|
-
*/
|
|
27
|
-
using ecc_public_key = std::array<char, 33>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* EOSIO WebAuthN public key
|
|
31
|
-
*
|
|
32
|
-
* @ingroup public_key
|
|
33
|
-
*/
|
|
34
|
-
struct webauthn_public_key {
|
|
35
|
-
/**
|
|
36
|
-
* Enumeration of the various results of a Test of User Presence
|
|
37
|
-
* @see https://w3c.github.io/webauthn/#test-of-user-presence
|
|
38
|
-
*/
|
|
39
|
-
enum class user_presence_t : uint8_t { USER_PRESENCE_NONE, USER_PRESENCE_PRESENT, USER_PRESENCE_VERIFIED };
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The ECC key material
|
|
43
|
-
*/
|
|
44
|
-
ecc_public_key key;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* expected result of the test of user presence for a valid signature
|
|
48
|
-
* @see https://w3c.github.io/webauthn/#test-of-user-presence
|
|
49
|
-
*/
|
|
50
|
-
user_presence_t user_presence;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* the Relying Party Identifier for WebAuthN
|
|
54
|
-
* @see https://w3c.github.io/webauthn/#relying-party-identifier
|
|
55
|
-
*/
|
|
56
|
-
std::string rpid;
|
|
57
|
-
};
|
|
58
|
-
EOSIO_REFLECT(webauthn_public_key, key, user_presence, rpid);
|
|
59
|
-
EOSIO_COMPARE(webauthn_public_key);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* EOSIO Public Key
|
|
63
|
-
*
|
|
64
|
-
* A public key is a variant of
|
|
65
|
-
* 0 : a ECC K1 public key
|
|
66
|
-
* 1 : a ECC R1 public key
|
|
67
|
-
* 2 : a WebAuthN public key (requires the host chain to activate the WEBAUTHN_KEY consensus upgrade)
|
|
68
|
-
*
|
|
69
|
-
* @ingroup public_key
|
|
70
|
-
*/
|
|
71
|
-
using public_key = std::variant<ecc_public_key, ecc_public_key, webauthn_public_key>;
|
|
72
|
-
|
|
73
|
-
using ecc_private_key = std::array<char, 32>;
|
|
74
|
-
using private_key = std::variant<ecc_private_key, ecc_private_key>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* EOSIO ECC signature data
|
|
78
|
-
*
|
|
79
|
-
* Fixed size representation of either a K1 or R1 ECC compact signature
|
|
80
|
-
|
|
81
|
-
* @ingroup signature
|
|
82
|
-
*/
|
|
83
|
-
using ecc_signature = std::array<char, 65>;
|
|
84
|
-
|
|
85
|
-
struct webauthn_signature {
|
|
86
|
-
/**
|
|
87
|
-
* The ECC signature data
|
|
88
|
-
*/
|
|
89
|
-
ecc_signature compact_signature;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* The Encoded Authenticator Data returned from WebAuthN ceremony
|
|
93
|
-
* @see https://w3c.github.io/webauthn/#sctn-authenticator-data
|
|
94
|
-
*/
|
|
95
|
-
std::vector<std::uint8_t> auth_data;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* the JSON encoded Collected Client Data from a WebAuthN ceremony
|
|
99
|
-
* @see https://w3c.github.io/webauthn/#dictdef-collectedclientdata
|
|
100
|
-
*/
|
|
101
|
-
std::string client_json;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
EOSIO_REFLECT(webauthn_signature, compact_signature, auth_data, client_json);
|
|
105
|
-
EOSIO_COMPARE(webauthn_signature);
|
|
106
|
-
|
|
107
|
-
using signature = std::variant<ecc_signature, ecc_signature, webauthn_signature>;
|
|
108
|
-
constexpr const char* get_type_name(public_key*) { return "public_key"; }
|
|
109
|
-
constexpr const char* get_type_name(private_key*) { return "private_key"; }
|
|
110
|
-
constexpr const char* get_type_name(signature*) { return "signature"; }
|
|
111
|
-
|
|
112
|
-
std::string public_key_to_string(const public_key& obj);
|
|
113
|
-
public_key public_key_from_string(std::string_view s);
|
|
114
|
-
std::string private_key_to_string(const private_key& obj);
|
|
115
|
-
private_key private_key_from_string(std::string_view s);
|
|
116
|
-
std::string signature_to_string(const signature& obj);
|
|
117
|
-
signature signature_from_string(std::string_view s);
|
|
118
|
-
|
|
119
|
-
template <typename S>
|
|
120
|
-
void to_json(const public_key& obj, S& stream) {
|
|
121
|
-
to_json(public_key_to_string(obj), stream);
|
|
122
|
-
}
|
|
123
|
-
template <typename S>
|
|
124
|
-
void from_json(public_key& obj, S& stream) {
|
|
125
|
-
auto s = stream.get_string();
|
|
126
|
-
obj = public_key_from_string(s);
|
|
127
|
-
}
|
|
128
|
-
template <typename S>
|
|
129
|
-
void to_json(const private_key& obj, S& stream) {
|
|
130
|
-
to_json(private_key_to_string(obj), stream);
|
|
131
|
-
}
|
|
132
|
-
template <typename S>
|
|
133
|
-
void from_json(private_key& obj, S& stream) {
|
|
134
|
-
obj = private_key_from_string(stream.get_string());
|
|
135
|
-
}
|
|
136
|
-
template <typename S>
|
|
137
|
-
void to_json(const signature& obj, S& stream) {
|
|
138
|
-
return to_json(signature_to_string(obj), stream);
|
|
139
|
-
}
|
|
140
|
-
template <typename S>
|
|
141
|
-
void from_json(signature& obj, S& stream) {
|
|
142
|
-
obj = signature_from_string(stream.get_string());
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
std::string to_base58(const char* d, size_t s );
|
|
146
|
-
std::vector<char> from_base58(const std::string_view& s);
|
|
147
|
-
|
|
148
|
-
} // namespace eosio
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#if defined(__eosio_cdt__)
|
|
4
|
-
# define OUTCOME_DISABLE_EXECINFO
|
|
5
|
-
# include <eosio/check.hpp>
|
|
6
|
-
#else
|
|
7
|
-
# include <stdexcept>
|
|
8
|
-
#endif
|
|
9
|
-
|
|
10
|
-
#include <outcome-basic.hpp>
|
|
11
|
-
#include <system_error>
|
|
12
|
-
|
|
13
|
-
namespace eosio {
|
|
14
|
-
namespace outcome = OUTCOME_V2_NAMESPACE;
|
|
15
|
-
|
|
16
|
-
template <typename T>
|
|
17
|
-
using result = outcome::basic_result<T, std::error_code, outcome::policy::all_narrow>;
|
|
18
|
-
|
|
19
|
-
#if defined(__eosio_cdt__)
|
|
20
|
-
[[noreturn]] inline void check(std::error_code ec) {
|
|
21
|
-
check(false, ec.message());
|
|
22
|
-
__builtin_unreachable();
|
|
23
|
-
}
|
|
24
|
-
#else
|
|
25
|
-
[[noreturn]] inline void check(std::error_code ec) { throw std::runtime_error(ec.message()); }
|
|
26
|
-
#endif
|
|
27
|
-
|
|
28
|
-
template <typename T>
|
|
29
|
-
result<T> check(result<T> r) {
|
|
30
|
-
if (!r)
|
|
31
|
-
check(r.error());
|
|
32
|
-
return r;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
template <typename T>
|
|
36
|
-
void check_discard(result<T> r) {
|
|
37
|
-
if (!r)
|
|
38
|
-
check(r.error());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
} // namespace eosio
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <cstddef>
|
|
4
|
-
#include <cstdint>
|
|
5
|
-
#include <cstring>
|
|
6
|
-
#include "from_json.hpp"
|
|
7
|
-
#include "operators.hpp"
|
|
8
|
-
#include "reflection.hpp"
|
|
9
|
-
#include "to_json.hpp"
|
|
10
|
-
#include <type_traits>
|
|
11
|
-
|
|
12
|
-
namespace eosio {
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @defgroup fixed_bytes Fixed Size Byte Array
|
|
16
|
-
* @ingroup core
|
|
17
|
-
* @ingroup types
|
|
18
|
-
* @brief Fixed size array of bytes sorted lexicographically
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Fixed size byte array sorted lexicographically
|
|
23
|
-
*
|
|
24
|
-
* @ingroup fixed_bytes
|
|
25
|
-
* @tparam Size - Size of the fixed_bytes object
|
|
26
|
-
* @tparam Word - Type to use for storage
|
|
27
|
-
*/
|
|
28
|
-
template <std::size_t Size, typename Word = std::uint64_t>
|
|
29
|
-
class fixed_bytes {
|
|
30
|
-
private:
|
|
31
|
-
// Returns the minimum number of objects of type T required to hold at least Size bytes.
|
|
32
|
-
// T must be an unsigned integer type.
|
|
33
|
-
template <typename T>
|
|
34
|
-
static constexpr std::size_t count_words() {
|
|
35
|
-
return (Size + sizeof(T) - 1) / sizeof(T);
|
|
36
|
-
}
|
|
37
|
-
// Divides a value into words and writes the highest words first.
|
|
38
|
-
// If U is 1 byte, this is equivalent to big-endian encoding.
|
|
39
|
-
// sizeof(T) must be divisible by sizeof(U).
|
|
40
|
-
// Writes up to sizeof(T)/sizeof(U) elements to the range [ptr, end)
|
|
41
|
-
// Returns the end of the range written.
|
|
42
|
-
template <typename U, typename T>
|
|
43
|
-
static constexpr U* write_be(U* ptr, U* end, T t) {
|
|
44
|
-
constexpr std::size_t words = sizeof(T) / sizeof(U);
|
|
45
|
-
for (std::size_t i = 0; i < words && ptr < end; ++i) {
|
|
46
|
-
*ptr++ = static_cast<U>(t >> std::numeric_limits<U>::digits * (words - i - 1));
|
|
47
|
-
}
|
|
48
|
-
return ptr;
|
|
49
|
-
}
|
|
50
|
-
// The opposite of write_be. If there are insufficient elements in [ptr, end),
|
|
51
|
-
// fills `out` as if the missing elements were 0.
|
|
52
|
-
template <typename U, typename T>
|
|
53
|
-
static constexpr const U* read_be(const U* ptr, const U* end, T& out) {
|
|
54
|
-
constexpr std::size_t words = sizeof(T) / sizeof(U);
|
|
55
|
-
T result = 0;
|
|
56
|
-
for (std::size_t i = 0; i < words && ptr < end; ++i, ++ptr) {
|
|
57
|
-
result |= static_cast<T>(*ptr) << (std::numeric_limits<U>::digits * (words - i - 1));
|
|
58
|
-
}
|
|
59
|
-
out = result;
|
|
60
|
-
return ptr;
|
|
61
|
-
}
|
|
62
|
-
// Either splits or combines words depending on whether
|
|
63
|
-
// T is larger than U.
|
|
64
|
-
// Both arrays must hold the minimum number of elements
|
|
65
|
-
// required to store Size bytes.
|
|
66
|
-
template <typename T, typename U>
|
|
67
|
-
static constexpr void convert_array(const T* t, U* u) {
|
|
68
|
-
constexpr std::size_t t_elems = count_words<T>();
|
|
69
|
-
constexpr std::size_t u_elems = count_words<U>();
|
|
70
|
-
if constexpr (sizeof(T) > sizeof(U)) {
|
|
71
|
-
U* const end = u + u_elems;
|
|
72
|
-
for (std::size_t i = 0; i < t_elems; ++i) { u = write_be(u, end, t[i]); }
|
|
73
|
-
} else {
|
|
74
|
-
const T* const end = t + t_elems;
|
|
75
|
-
for (std::size_t i = 0; i < u_elems; ++i) { t = read_be(t, end, u[i]); }
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
template <typename T, typename U>
|
|
80
|
-
static constexpr std::array<T, count_words<T>()> convert_array(const U* u) {
|
|
81
|
-
std::array<T, count_words<T>()> result{0};
|
|
82
|
-
convert_array(u, result.data());
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
template <typename T, typename U>
|
|
87
|
-
static constexpr std::array<T, count_words<T>()> convert_array(const U* u, const U* end) {
|
|
88
|
-
std::array<U, count_words<U>()> tmp{0};
|
|
89
|
-
std::size_t count = std::min(static_cast<std::size_t>(end - u), tmp.size());
|
|
90
|
-
for (std::size_t i = 0; i < count; ++i) { tmp[i] = u[i]; }
|
|
91
|
-
return convert_array<T>(tmp.data());
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
template <typename T>
|
|
95
|
-
using require_word = std::enable_if_t<std::is_unsigned_v<T>>;
|
|
96
|
-
|
|
97
|
-
public:
|
|
98
|
-
using word_t = Word;
|
|
99
|
-
/**
|
|
100
|
-
* Get number of words contained in this fixed_bytes object. A word is defined to be 16 bytes in size
|
|
101
|
-
*/
|
|
102
|
-
static constexpr std::size_t num_words() { return count_words<Word>(); }
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Get number of padded bytes contained in this fixed_bytes object. Padded bytes are the remaining bytes
|
|
106
|
-
* inside the fixed_bytes object after all the words are allocated
|
|
107
|
-
*/
|
|
108
|
-
static constexpr size_t padded_bytes() { return num_words() * sizeof(Word) - Size; }
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Default constructor to fixed_bytes object which initializes all bytes to zero
|
|
112
|
-
*/
|
|
113
|
-
constexpr fixed_bytes() = default;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Constructor to fixed_bytes object from initializer list of bytes.
|
|
117
|
-
*/
|
|
118
|
-
constexpr fixed_bytes(std::initializer_list<std::uint8_t> il) : value(convert_array<Word>(il.begin(), il.end())) {}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Constructor to fixed_bytes object from std::array of num_words() word_t types
|
|
122
|
-
*
|
|
123
|
-
* @param arr data
|
|
124
|
-
*/
|
|
125
|
-
constexpr fixed_bytes(const std::array<Word, num_words()>& arr) : value(arr) {}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Constructor to fixed_bytes object from std::array of unsigned integral types.
|
|
129
|
-
*
|
|
130
|
-
* @param arr - Source data. arr cannot hold more words than are required to fill Size bytes. If it contains
|
|
131
|
-
* fewer than Size bytes, the remaining bytes will be zero-filled.
|
|
132
|
-
*/
|
|
133
|
-
template <typename T, std::size_t N,
|
|
134
|
-
typename Enable = std::enable_if_t<std::is_unsigned_v<T> && N <= count_words<T>()>>
|
|
135
|
-
constexpr fixed_bytes(const std::array<T, N>& arr) : value(convert_array<Word>(arr.begin(), arr.end())) {}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Constructor to fixed_bytes object from fixed-sized C array of unsigned integral types.
|
|
139
|
-
*
|
|
140
|
-
* @param arr - Source data. arr cannot hold more words than are required to fill Size bytes. If it contains
|
|
141
|
-
* fewer than Size bytes, the remaining bytes will be zero-filled.
|
|
142
|
-
*/
|
|
143
|
-
template <typename T, std::size_t N,
|
|
144
|
-
typename Enable = std::enable_if_t<std::is_unsigned_v<T> && N <= count_words<T>()>>
|
|
145
|
-
constexpr fixed_bytes(const T (&arr)[N]) : value(convert_array<Word>(&arr[0], &arr[0] + N)) {}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Create a new fixed_bytes object from a sequence of words
|
|
149
|
-
*
|
|
150
|
-
* @tparam T - The type of the words. T must be specified explicitly.
|
|
151
|
-
* @param a - The words in the sequence. All the parameters must have type T. The number of parameters must
|
|
152
|
-
* be equal to the number of values of type T required to fill Size bytes.
|
|
153
|
-
*/
|
|
154
|
-
template <typename T, typename... A,
|
|
155
|
-
typename Enable = std::enable_if_t<(std::is_unsigned_v<T> && (std::is_same_v<T, A> && ...) &&
|
|
156
|
-
(count_words<T>() == sizeof...(A)))>>
|
|
157
|
-
static constexpr fixed_bytes make_from_word_sequence(A... a) {
|
|
158
|
-
T args[count_words<T>()] = { a... };
|
|
159
|
-
return fixed_bytes(args);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Extract the contained data as an array of words
|
|
163
|
-
*
|
|
164
|
-
* @tparam T - The word type to return. T must be an unsigned integral type.
|
|
165
|
-
*/
|
|
166
|
-
template <typename T>
|
|
167
|
-
constexpr auto extract_as_word_array() const {
|
|
168
|
-
return convert_array<T>(data());
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Extract the contained data as an array of bytes
|
|
172
|
-
*
|
|
173
|
-
* @return - the extracted data as array of bytes
|
|
174
|
-
*/
|
|
175
|
-
constexpr std::array<std::uint8_t, Size> extract_as_byte_array() const {
|
|
176
|
-
return extract_as_word_array<std::uint8_t>();
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Get the underlying data of the contained std::array
|
|
180
|
-
*/
|
|
181
|
-
constexpr Word* data() { return value.data(); }
|
|
182
|
-
/**
|
|
183
|
-
* Get the underlying data of the contained std::array
|
|
184
|
-
*/
|
|
185
|
-
constexpr const Word* data() const { return value.data(); }
|
|
186
|
-
constexpr std::size_t size() const { return value.size(); }
|
|
187
|
-
/**
|
|
188
|
-
* Get the Word storing capacity in the underlying data of the contained std::array
|
|
189
|
-
*/
|
|
190
|
-
constexpr std::size_t capacity() const { return Size; }
|
|
191
|
-
/**
|
|
192
|
-
* Get the contained std::array
|
|
193
|
-
*/
|
|
194
|
-
constexpr const auto& get_array() const { return value; }
|
|
195
|
-
std::array<Word, count_words<Word>()> value{0};
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
// This is only needed to make eosio.cdt/tests/unit/fixed_bytes_tests.cpp pass.
|
|
199
|
-
// Everything else should be using one of the typedefs below.
|
|
200
|
-
template <std::size_t Size, typename Word, typename F>
|
|
201
|
-
void eosio_for_each_field(fixed_bytes<Size, Word>*, F&& f) {
|
|
202
|
-
f("value",
|
|
203
|
-
[](auto* p) -> decltype(&std::decay_t<decltype(*p)>::value) { return &std::decay_t<decltype(*p)>::value; });
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
template <std::size_t Size, typename Word>
|
|
207
|
-
EOSIO_COMPARE(fixed_bytes<Size, Word>);
|
|
208
|
-
|
|
209
|
-
using checksum160 = fixed_bytes<20,uint32_t>;
|
|
210
|
-
using checksum256 = fixed_bytes<32>;
|
|
211
|
-
using checksum512 = fixed_bytes<64>;
|
|
212
|
-
|
|
213
|
-
EOSIO_REFLECT(checksum160, value);
|
|
214
|
-
EOSIO_REFLECT(checksum256, value);
|
|
215
|
-
EOSIO_REFLECT(checksum512, value);
|
|
216
|
-
|
|
217
|
-
template <typename T, std::size_t Size, typename S>
|
|
218
|
-
void from_bin(fixed_bytes<Size, T>& obj, S& stream) {
|
|
219
|
-
std::array<std::uint8_t, Size> bytes;
|
|
220
|
-
from_bin(bytes, stream);
|
|
221
|
-
obj = fixed_bytes<Size, T>(bytes);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
template <typename T, std::size_t Size, typename S>
|
|
225
|
-
void to_bin(const fixed_bytes<Size, T>& obj, S& stream) {
|
|
226
|
-
to_bin(obj.extract_as_byte_array(), stream);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
template <typename T, std::size_t Size, typename S>
|
|
230
|
-
void to_key(const fixed_bytes<Size, T>& obj, S& stream) {
|
|
231
|
-
to_bin(obj.extract_as_byte_array(), stream);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
template <typename T, std::size_t Size, typename S>
|
|
235
|
-
void from_json(fixed_bytes<Size, T>& obj, S& stream) {
|
|
236
|
-
std::vector<char> v;
|
|
237
|
-
eosio::from_json_hex(v, stream);
|
|
238
|
-
check(v.size() == Size, convert_json_error(eosio::from_json_error::hex_string_incorrect_length));
|
|
239
|
-
std::array<uint8_t, Size> bytes;
|
|
240
|
-
std::memcpy(bytes.data(), v.data(), Size);
|
|
241
|
-
obj = fixed_bytes<Size, T>(bytes);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
template <typename T, std::size_t Size, typename S>
|
|
245
|
-
void to_json(const fixed_bytes<Size, T>& obj, S& stream) {
|
|
246
|
-
auto bytes = obj.extract_as_byte_array();
|
|
247
|
-
eosio::to_json_hex((const char*)bytes.data(), bytes.size(), stream);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
} // namespace eosio
|
package/include/eosio/float.hpp
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#ifdef __eosio_cdt__
|
|
4
|
-
|
|
5
|
-
namespace eosio {
|
|
6
|
-
|
|
7
|
-
using float32 = float;
|
|
8
|
-
using float64 = double;
|
|
9
|
-
using float128 = long double;
|
|
10
|
-
|
|
11
|
-
} // namespace eosio
|
|
12
|
-
|
|
13
|
-
#else
|
|
14
|
-
|
|
15
|
-
# include <eosio/fixed_bytes.hpp>
|
|
16
|
-
# include <limits>
|
|
17
|
-
|
|
18
|
-
namespace eosio {
|
|
19
|
-
|
|
20
|
-
using float32 = float;
|
|
21
|
-
using float64 = double;
|
|
22
|
-
using float128 = fixed_bytes<16>;
|
|
23
|
-
|
|
24
|
-
static_assert(sizeof(float32) == 4 && std::numeric_limits<float32>::is_iec559 &&
|
|
25
|
-
std::numeric_limits<float32>::digits == 24,
|
|
26
|
-
"Unexpected float representation");
|
|
27
|
-
static_assert(sizeof(float64) == 8 && std::numeric_limits<float64>::is_iec559 &&
|
|
28
|
-
std::numeric_limits<float64>::digits == 53,
|
|
29
|
-
"Unexpected double representation");
|
|
30
|
-
|
|
31
|
-
EOSIO_REFLECT(float128, value);
|
|
32
|
-
|
|
33
|
-
} // namespace eosio
|
|
34
|
-
|
|
35
|
-
#endif
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "reflection.hpp"
|
|
4
|
-
#include <utility>
|
|
5
|
-
|
|
6
|
-
#if __has_include(<boost/pfr/precise/core.hpp>)
|
|
7
|
-
|
|
8
|
-
# include <boost/pfr/precise/core.hpp>
|
|
9
|
-
|
|
10
|
-
namespace eosio {
|
|
11
|
-
template <typename T, typename F>
|
|
12
|
-
constexpr auto for_each_field(T&& t, F&& f) -> std::enable_if_t<!reflection::has_for_each_field_v<std::decay_t<T>>> {
|
|
13
|
-
return boost::pfr::for_each_field(static_cast<T&&>(t), static_cast<F&&>(f));
|
|
14
|
-
}
|
|
15
|
-
} // namespace eosio
|
|
16
|
-
#endif
|
|
17
|
-
|
|
18
|
-
namespace eosio {
|
|
19
|
-
|
|
20
|
-
template <typename T, typename F>
|
|
21
|
-
constexpr auto for_each_field(T&& t, F&& f) -> std::enable_if_t<reflection::has_for_each_field_v<std::decay_t<T>>> {
|
|
22
|
-
eosio_for_each_field((std::decay_t<T>*)nullptr, [&](const char*, auto member) {
|
|
23
|
-
if constexpr (std::is_member_object_pointer_v<decltype(member(&t))>) {
|
|
24
|
-
f(t.*member(&t));
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
template <typename T, typename F>
|
|
30
|
-
constexpr void for_each_field(F&& f) {
|
|
31
|
-
eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) {
|
|
32
|
-
if constexpr (std::is_member_object_pointer_v<decltype(member((T*)nullptr))>) {
|
|
33
|
-
f(name, [member](auto p) -> decltype((p->*member(p))) { return p->*member(p); });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Calls f(#fn_name, &T::fn_name) for every reflected member function of T.
|
|
39
|
-
template <typename T, typename F>
|
|
40
|
-
constexpr void for_each_method(F&& f) {
|
|
41
|
-
eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) {
|
|
42
|
-
if constexpr (std::is_member_function_pointer_v<decltype(member((T*)nullptr))>) {
|
|
43
|
-
f(name, member((T*)nullptr));
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
} // namespace eosio
|