@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
package/src/crypto.cpp
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
#include <algorithm>
|
|
2
|
-
#include <array>
|
|
3
|
-
#include <cstdint>
|
|
4
|
-
#include "../include/eosio/crypto.hpp"
|
|
5
|
-
#include "../include/eosio/from_bin.hpp"
|
|
6
|
-
#include "../include/eosio/from_json.hpp"
|
|
7
|
-
#include "../include/eosio/to_bin.hpp"
|
|
8
|
-
#include "../include/eosio/to_json.hpp"
|
|
9
|
-
#include <string>
|
|
10
|
-
#include <string_view>
|
|
11
|
-
|
|
12
|
-
#include "abieos_ripemd160.hpp"
|
|
13
|
-
|
|
14
|
-
using namespace eosio;
|
|
15
|
-
|
|
16
|
-
namespace {
|
|
17
|
-
|
|
18
|
-
enum key_type : uint8_t {
|
|
19
|
-
k1 = 0,
|
|
20
|
-
r1 = 1,
|
|
21
|
-
wa = 2,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
constexpr char base58_chars[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
25
|
-
|
|
26
|
-
constexpr auto create_base58_map() {
|
|
27
|
-
std::array<int8_t, 256> base58_map{{0}};
|
|
28
|
-
for (unsigned i = 0; i < base58_map.size(); ++i)
|
|
29
|
-
base58_map[i] = -1;
|
|
30
|
-
for (unsigned i = 0; i < sizeof(base58_chars); ++i)
|
|
31
|
-
base58_map[base58_chars[i]] = i;
|
|
32
|
-
return base58_map;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
constexpr auto base58_map = create_base58_map();
|
|
36
|
-
|
|
37
|
-
template <typename Container>
|
|
38
|
-
void base58_to_binary(Container& result, std::string_view s) {
|
|
39
|
-
std::size_t offset = result.size();
|
|
40
|
-
for (auto& src_digit : s) {
|
|
41
|
-
int carry = base58_map[static_cast<uint8_t>(src_digit)];
|
|
42
|
-
check(carry >= 0,
|
|
43
|
-
::eosio::convert_json_error(::eosio::from_json_error::expected_key));
|
|
44
|
-
for (std::size_t i = offset; i < result.size(); ++i) {
|
|
45
|
-
auto& result_byte = result[i];
|
|
46
|
-
int x = static_cast<uint8_t>(result_byte) * 58 + carry;
|
|
47
|
-
result_byte = x;
|
|
48
|
-
carry = x >> 8;
|
|
49
|
-
}
|
|
50
|
-
if (carry)
|
|
51
|
-
result.push_back(static_cast<uint8_t>(carry));
|
|
52
|
-
}
|
|
53
|
-
for (auto& src_digit : s)
|
|
54
|
-
if (src_digit == '1')
|
|
55
|
-
result.push_back(0);
|
|
56
|
-
else
|
|
57
|
-
break;
|
|
58
|
-
std::reverse(result.begin() + offset, result.end());
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
template <typename Container>
|
|
62
|
-
std::string binary_to_base58(const Container& bin) {
|
|
63
|
-
std::string result("");
|
|
64
|
-
for (auto byte : bin) {
|
|
65
|
-
static_assert(sizeof(byte) == 1);
|
|
66
|
-
int carry = static_cast<uint8_t>(byte);
|
|
67
|
-
for (auto& result_digit : result) {
|
|
68
|
-
int x = (base58_map[result_digit] << 8) + carry;
|
|
69
|
-
result_digit = base58_chars[x % 58];
|
|
70
|
-
carry = x / 58;
|
|
71
|
-
}
|
|
72
|
-
while (carry) {
|
|
73
|
-
result.push_back(base58_chars[carry % 58]);
|
|
74
|
-
carry = carry / 58;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
for (auto byte : bin)
|
|
78
|
-
if (byte)
|
|
79
|
-
break;
|
|
80
|
-
else
|
|
81
|
-
result.push_back('1');
|
|
82
|
-
std::reverse(result.begin(), result.end());
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
template <typename... Container>
|
|
87
|
-
std::array<unsigned char, 20> digest_suffix_ripemd160(const Container&... data) {
|
|
88
|
-
std::array<unsigned char, 20> digest;
|
|
89
|
-
abieos_ripemd160::ripemd160_state self;
|
|
90
|
-
abieos_ripemd160::ripemd160_init(&self);
|
|
91
|
-
(abieos_ripemd160::ripemd160_update(&self, data.data(), data.size()), ...);
|
|
92
|
-
check( abieos_ripemd160::ripemd160_digest(&self, digest.data()),
|
|
93
|
-
convert_json_error(eosio::from_json_error::invalid_signature) );
|
|
94
|
-
return digest;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
template <typename Key>
|
|
99
|
-
Key string_to_key(std::string_view s, key_type type, std::string_view suffix) {
|
|
100
|
-
std::vector<char> whole;
|
|
101
|
-
whole.push_back(uint8_t{type});
|
|
102
|
-
base58_to_binary(whole, s);
|
|
103
|
-
check(whole.size() > 5,
|
|
104
|
-
convert_json_error(eosio::from_json_error::expected_key));
|
|
105
|
-
auto ripe_digest = digest_suffix_ripemd160(std::string_view(whole.data() + 1, whole.size() - 5), suffix);
|
|
106
|
-
check(memcmp(ripe_digest.data(), whole.data() + whole.size() - 4, 4)==0,
|
|
107
|
-
convert_json_error(from_json_error::expected_key));
|
|
108
|
-
whole.erase(whole.end() - 4, whole.end());
|
|
109
|
-
return convert_from_bin<Key>(whole);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
template <typename Key>
|
|
113
|
-
std::string key_to_string(const Key& key, std::string_view suffix, const char* prefix) {
|
|
114
|
-
auto whole = convert_to_bin(key);
|
|
115
|
-
auto ripe_digest = digest_suffix_ripemd160(std::string_view(whole.data() + 1, whole.size() - 1), suffix);
|
|
116
|
-
whole.insert(whole.end(), ripe_digest.data(), ripe_digest.data() + 4);
|
|
117
|
-
return prefix + binary_to_base58(std::string_view(whole.data() + 1, whole.size() - 1));
|
|
118
|
-
}
|
|
119
|
-
} // namespace
|
|
120
|
-
|
|
121
|
-
std::string eosio::public_key_to_string(const public_key& key) {
|
|
122
|
-
if (key.index() == key_type::k1) {
|
|
123
|
-
return key_to_string(key, "K1", "PUB_K1_");
|
|
124
|
-
} else if (key.index() == key_type::r1) {
|
|
125
|
-
return key_to_string(key, "R1", "PUB_R1_");
|
|
126
|
-
} else if (key.index() == key_type::wa) {
|
|
127
|
-
return key_to_string(key, "WA", "PUB_WA_");
|
|
128
|
-
} else {
|
|
129
|
-
check(false, convert_json_error(eosio::from_json_error::expected_public_key));
|
|
130
|
-
__builtin_unreachable();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public_key eosio::public_key_from_string(std::string_view s) {
|
|
135
|
-
public_key result;
|
|
136
|
-
if (s.substr(0, 3) == "EOS") {
|
|
137
|
-
return string_to_key<public_key>(s.substr(3), key_type::k1, "");
|
|
138
|
-
} else if (s.substr(0, 7) == "PUB_K1_") {
|
|
139
|
-
return string_to_key<public_key>(s.substr(7), key_type::k1, "K1");
|
|
140
|
-
} else if (s.substr(0, 7) == "PUB_R1_") {
|
|
141
|
-
return string_to_key<public_key>(s.substr(7), key_type::r1, "R1");
|
|
142
|
-
} else if (s.substr(0, 7) == "PUB_WA_") {
|
|
143
|
-
return string_to_key<public_key>(s.substr(7), key_type::wa, "WA");
|
|
144
|
-
} else {
|
|
145
|
-
check(false, convert_json_error(from_json_error::expected_public_key));
|
|
146
|
-
__builtin_unreachable();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
std::string eosio::private_key_to_string(const private_key& private_key) {
|
|
151
|
-
if (private_key.index() == key_type::k1)
|
|
152
|
-
return key_to_string(private_key, "K1", "PVT_K1_");
|
|
153
|
-
else if (private_key.index() == key_type::r1)
|
|
154
|
-
return key_to_string(private_key, "R1", "PVT_R1_");
|
|
155
|
-
else {
|
|
156
|
-
check(false, convert_json_error(from_json_error::expected_private_key));
|
|
157
|
-
__builtin_unreachable();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
private_key eosio::private_key_from_string(std::string_view s) {
|
|
162
|
-
if (s.substr(0, 7) == "PVT_K1_")
|
|
163
|
-
return string_to_key<private_key>(s.substr(7), key_type::k1, "K1");
|
|
164
|
-
else if (s.substr(0, 7) == "PVT_R1_")
|
|
165
|
-
return string_to_key<private_key>(s.substr(7), key_type::r1, "R1");
|
|
166
|
-
else if (s.substr(0, 4) == "PVT_") {
|
|
167
|
-
check(false, convert_json_error(from_json_error::expected_private_key));
|
|
168
|
-
__builtin_unreachable();
|
|
169
|
-
} else {
|
|
170
|
-
std::vector<char> whole;
|
|
171
|
-
base58_to_binary(whole, s);
|
|
172
|
-
check(whole.size() >= 5, convert_json_error(from_json_error::expected_private_key));
|
|
173
|
-
whole[0] = key_type::k1;
|
|
174
|
-
whole.erase(whole.end() - 4, whole.end());
|
|
175
|
-
return convert_from_bin<private_key>(whole);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
std::string eosio::signature_to_string(const eosio::signature& signature) {
|
|
180
|
-
if (signature.index() == key_type::k1)
|
|
181
|
-
return key_to_string(signature, "K1", "SIG_K1_");
|
|
182
|
-
else if (signature.index() == key_type::r1)
|
|
183
|
-
return key_to_string(signature, "R1", "SIG_R1_");
|
|
184
|
-
else if (signature.index() == key_type::wa)
|
|
185
|
-
return key_to_string(signature, "WA", "SIG_WA_");
|
|
186
|
-
else {
|
|
187
|
-
check(false, convert_json_error(eosio::from_json_error::expected_signature));
|
|
188
|
-
__builtin_unreachable();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
signature eosio::signature_from_string(std::string_view s) {
|
|
193
|
-
if (s.size() >= 7 && s.substr(0, 7) == "SIG_K1_")
|
|
194
|
-
return string_to_key<signature>(s.substr(7), key_type::k1, "K1");
|
|
195
|
-
else if (s.size() >= 7 && s.substr(0, 7) == "SIG_R1_")
|
|
196
|
-
return string_to_key<signature>(s.substr(7), key_type::r1, "R1");
|
|
197
|
-
else if (s.size() >= 7 && s.substr(0, 7) == "SIG_WA_")
|
|
198
|
-
return string_to_key<signature>(s.substr(7), key_type::wa, "WA");
|
|
199
|
-
else {
|
|
200
|
-
check(false, convert_json_error(eosio::from_json_error::expected_signature));
|
|
201
|
-
__builtin_unreachable();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
namespace eosio {
|
|
206
|
-
std::string to_base58(const char* d, size_t s ) {
|
|
207
|
-
return binary_to_base58( std::string_view(d,s) );
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
std::vector<char> from_base58(const std::string_view& s) {
|
|
211
|
-
std::vector<char> ret;
|
|
212
|
-
base58_to_binary(ret, s);
|
|
213
|
-
return ret;
|
|
214
|
-
}
|
|
215
|
-
}
|
package/src/main.cpp
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
#include <napi.h>
|
|
2
|
-
#include <napi-inl.h>
|
|
3
|
-
|
|
4
|
-
#include "abieos.h"
|
|
5
|
-
#include "abieos.hpp"
|
|
6
|
-
#include <cstdio>
|
|
7
|
-
#include <string>
|
|
8
|
-
#include <iostream>
|
|
9
|
-
|
|
10
|
-
using namespace std;
|
|
11
|
-
|
|
12
|
-
abieos_context* global_context;
|
|
13
|
-
|
|
14
|
-
std::string json_to_hex(const char *contract_name, const char *type, const char *json)
|
|
15
|
-
{
|
|
16
|
-
if(global_context == nullptr) {
|
|
17
|
-
global_context = abieos_create();
|
|
18
|
-
}
|
|
19
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
20
|
-
bool status = abieos_json_to_bin(global_context, contract, type, json);
|
|
21
|
-
if(!status)
|
|
22
|
-
{
|
|
23
|
-
std::cout << abieos_get_error(global_context) << "\n";
|
|
24
|
-
return "PARSING_ERROR";
|
|
25
|
-
}
|
|
26
|
-
auto results = abieos_get_bin_hex(global_context);
|
|
27
|
-
if(results == nullptr)
|
|
28
|
-
{
|
|
29
|
-
std::cout << abieos_get_error(global_context) << "\n";
|
|
30
|
-
return "ERROR";
|
|
31
|
-
}
|
|
32
|
-
std::string hexValue = &results[0u];
|
|
33
|
-
return hexValue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
std::string hex_to_json(const char *contract_name, const char *type, const char *hex)
|
|
37
|
-
{
|
|
38
|
-
if(global_context == nullptr) {
|
|
39
|
-
global_context = abieos_create();
|
|
40
|
-
}
|
|
41
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
42
|
-
auto results = abieos_hex_to_json(global_context, contract, type, hex);
|
|
43
|
-
if(results == nullptr)
|
|
44
|
-
{
|
|
45
|
-
return abieos_get_error(global_context);
|
|
46
|
-
}
|
|
47
|
-
return results;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
std::string bin_to_json(const char *contract_name, const char *type, const char *bin, int size)
|
|
51
|
-
{
|
|
52
|
-
if(global_context == nullptr) {
|
|
53
|
-
global_context = abieos_create();
|
|
54
|
-
}
|
|
55
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
56
|
-
auto results = abieos_bin_to_json(global_context, contract, type, bin, size);
|
|
57
|
-
if(results == nullptr)
|
|
58
|
-
{
|
|
59
|
-
return abieos_get_error(global_context);
|
|
60
|
-
}
|
|
61
|
-
return results;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
Napi::String JsonToHexWrapped(const Napi::CallbackInfo &info)
|
|
65
|
-
{
|
|
66
|
-
Napi::Env env = info.Env();
|
|
67
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
68
|
-
std::string type = info[1].As<Napi::String>().Utf8Value();
|
|
69
|
-
std::string json = info[2].As<Napi::String>().Utf8Value();
|
|
70
|
-
auto returnValue = json_to_hex(&contract_name[0u], &type[0u], &json[0u]);
|
|
71
|
-
return Napi::String::New(env, returnValue);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
Napi::String HexToJsonWrapped(const Napi::CallbackInfo &info)
|
|
75
|
-
{
|
|
76
|
-
Napi::Env env = info.Env();
|
|
77
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
78
|
-
std::string type = info[1].As<Napi::String>().Utf8Value();
|
|
79
|
-
std::string hex = info[2].As<Napi::String>().Utf8Value();
|
|
80
|
-
auto returnValue = hex_to_json(&contract_name[0u], &type[0u], &hex[0u]);
|
|
81
|
-
return Napi::String::New(env, returnValue);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
Napi::String BinToJsonWrapped(const Napi::CallbackInfo &info)
|
|
85
|
-
{
|
|
86
|
-
Napi::Env env = info.Env();
|
|
87
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
88
|
-
std::string type = info[1].As<Napi::String>().Utf8Value();
|
|
89
|
-
Napi::Buffer buf = info[2].As<Napi::Buffer<char>>();
|
|
90
|
-
auto returnValue = bin_to_json(&contract_name[0u], &type[0u], buf.Data(), buf.Length());
|
|
91
|
-
return Napi::String::New(env, returnValue);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
uint64_t string_to_name(const char *str)
|
|
95
|
-
{
|
|
96
|
-
if(global_context == nullptr) {
|
|
97
|
-
global_context = abieos_create();
|
|
98
|
-
}
|
|
99
|
-
uint64_t result = abieos_string_to_name(global_context, str);
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
Napi::BigInt StringToNameWrapped(const Napi::CallbackInfo &info)
|
|
104
|
-
{
|
|
105
|
-
Napi::Env env = info.Env();
|
|
106
|
-
// name string
|
|
107
|
-
std::string str_input = info[0].As<Napi::String>().Utf8Value();
|
|
108
|
-
uint64_t returnValue = string_to_name(&str_input[0u]);
|
|
109
|
-
return Napi::BigInt::New(env, returnValue);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
bool load_abi(const char *contract_name, const char *abi)
|
|
113
|
-
{
|
|
114
|
-
if(global_context == nullptr) {
|
|
115
|
-
global_context = abieos_create();
|
|
116
|
-
}
|
|
117
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
118
|
-
bool abi_status = abieos_set_abi(global_context, contract, abi);
|
|
119
|
-
if(!abi_status) {
|
|
120
|
-
std::cout << "load_abi error on [" << contract_name << "] - " << abieos_get_error(global_context) << "\n";
|
|
121
|
-
return false;
|
|
122
|
-
} else {
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
Napi::Boolean LoadAbiWrapped(const Napi::CallbackInfo &info)
|
|
128
|
-
{
|
|
129
|
-
Napi::Env env = info.Env();
|
|
130
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
131
|
-
std::string abi = info[1].As<Napi::String>().Utf8Value();
|
|
132
|
-
auto returnValue = load_abi(&contract_name[0u], &abi[0u]);
|
|
133
|
-
return Napi::Boolean::New(env, returnValue);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
bool load_abi_hex(const char *contract_name, const char *hex)
|
|
137
|
-
{
|
|
138
|
-
if(global_context == nullptr) {
|
|
139
|
-
global_context = abieos_create();
|
|
140
|
-
}
|
|
141
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
142
|
-
bool abi_status = abieos_set_abi_hex(global_context, contract, hex);
|
|
143
|
-
if(!abi_status)
|
|
144
|
-
{
|
|
145
|
-
std::cout << "load_abi_hex error on [" << contract_name << "] - " << abieos_get_error(global_context) << "\n";
|
|
146
|
-
return false;
|
|
147
|
-
} else {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
Napi::Boolean LoadAbiHexWrapped(const Napi::CallbackInfo &info)
|
|
153
|
-
{
|
|
154
|
-
Napi::Env env = info.Env();
|
|
155
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
156
|
-
std::string abihex = info[1].As<Napi::String>().Utf8Value();
|
|
157
|
-
auto returnValue = load_abi_hex(&contract_name[0u], &abihex[0u]);
|
|
158
|
-
return Napi::Boolean::New(env, returnValue);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
string get_type_for_action(const char *contract_name, const char *action_name)
|
|
162
|
-
{
|
|
163
|
-
if(global_context != nullptr) {
|
|
164
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
165
|
-
uint64_t action = abieos_string_to_name(global_context, action_name);
|
|
166
|
-
auto result = abieos_get_type_for_action(global_context, contract, action);
|
|
167
|
-
if(result == nullptr) {
|
|
168
|
-
return "NOT_FOUND";
|
|
169
|
-
} else {
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
return "NO_CONTEXT";
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
string get_type_for_table(const char *contract_name, const char *table_name)
|
|
178
|
-
{
|
|
179
|
-
if(global_context != nullptr) {
|
|
180
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
181
|
-
uint64_t table = abieos_string_to_name(global_context, table_name);
|
|
182
|
-
auto result = abieos_get_type_for_table(global_context,contract, table);
|
|
183
|
-
if(result == nullptr) {
|
|
184
|
-
return "NOT_FOUND";
|
|
185
|
-
} else {
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
return "NO_CONTEXT";
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
Napi::String GetTypeWrapped(const Napi::CallbackInfo &info)
|
|
194
|
-
{
|
|
195
|
-
Napi::Env env = info.Env();
|
|
196
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
197
|
-
std::string action_name = info[1].As<Napi::String>().Utf8Value();
|
|
198
|
-
auto returnValue = get_type_for_action(&contract_name[0u], &action_name[0u]);
|
|
199
|
-
return Napi::String::New(env, returnValue);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
Napi::String GetTableTypeWrapped(const Napi::CallbackInfo &info)
|
|
203
|
-
{
|
|
204
|
-
Napi::Env env = info.Env();
|
|
205
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
206
|
-
std::string table_name = info[1].As<Napi::String>().Utf8Value();
|
|
207
|
-
auto returnValue = get_type_for_table(&contract_name[0u], &table_name[0u]);
|
|
208
|
-
return Napi::String::New(env, returnValue);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
bool delete_contract(const char *contract_name) {
|
|
212
|
-
if(global_context != nullptr) {
|
|
213
|
-
uint64_t contract = abieos_string_to_name(global_context, contract_name);
|
|
214
|
-
return abieos_delete_contract(global_context, contract);
|
|
215
|
-
} else {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
Napi::Boolean DeleteContractWrapped(const Napi::CallbackInfo &info)
|
|
221
|
-
{
|
|
222
|
-
Napi::Env env = info.Env();
|
|
223
|
-
std::string contract_name = info[0].As<Napi::String>().Utf8Value();
|
|
224
|
-
auto returnValue = delete_contract(&contract_name[0u]);
|
|
225
|
-
return Napi::Boolean::New(env, returnValue);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
Napi::Object Init(Napi::Env env, Napi::Object exports)
|
|
229
|
-
{
|
|
230
|
-
exports.Set("string_to_name", Napi::Function::New(env, StringToNameWrapped));
|
|
231
|
-
exports.Set("json_to_hex", Napi::Function::New(env, JsonToHexWrapped));
|
|
232
|
-
exports.Set("hex_to_json", Napi::Function::New(env, HexToJsonWrapped));
|
|
233
|
-
exports.Set("bin_to_json", Napi::Function::New(env, BinToJsonWrapped));
|
|
234
|
-
exports.Set("load_abi", Napi::Function::New(env, LoadAbiWrapped));
|
|
235
|
-
exports.Set("load_abi_hex", Napi::Function::New(env, LoadAbiHexWrapped));
|
|
236
|
-
exports.Set("get_type_for_action", Napi::Function::New(env, GetTypeWrapped));
|
|
237
|
-
exports.Set("get_type_for_table", Napi::Function::New(env, GetTableTypeWrapped));
|
|
238
|
-
exports.Set("delete_contract", Napi::Function::New(env, DeleteContractWrapped));
|
|
239
|
-
return exports;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
NODE_API_MODULE(abieos,Init);
|