diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f3a04f..d62c546 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,10 +1,5 @@
-cmake_minimum_required (VERSION 3.24)
-project(node_abieos VERSION 2.2 LANGUAGES CXX C)
-
-add_definitions(-DNAPI_VERSION=8)
-# add_definitions(-DNAPI_EXPERIMENTAL)
-
-include_directories(${CMAKE_JS_INC})
+cmake_minimum_required (VERSION 3.21.4)
+project(deno_abieos VERSION 2.2 LANGUAGES CXX C)
set(default_build_type "Release")
set(CMAKE_CXX_STANDARD 17)
@@ -15,6 +10,8 @@ option(ABIEOS_NO_INT128 "disable use of __int128" OFF)
find_package(Threads)
+include_directories(include)
+
add_library(abieos STATIC src/abi.cpp src/crypto.cpp include/eosio/fpconv.c)
target_include_directories(abieos PUBLIC include)
@@ -25,11 +22,6 @@ endif()
set_target_properties(abieos PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_library(${PROJECT_NAME} SHARED src/main.cpp src/abieos.cpp)
-set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
-target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB};abieos;${CMAKE_THREAD_LIBS_INIT})
+set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".so")
+target_link_libraries(${PROJECT_NAME} abieos;${CMAKE_THREAD_LIBS_INIT})
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-unused-parameter)
-
-execute_process(COMMAND node -p "require('node-addon-api').include" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE NODE_ADDON_API_DIR)
-string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
-string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
-target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
diff --git a/deno_dist/README.md b/deno_dist/README.md
new file mode 100644
index 0000000..f613674
--- /dev/null
+++ b/deno_dist/README.md
@@ -0,0 +1,46 @@
+# node-abieos
+
+Node.js native binding for [abieos](https://github.com/EOSIO/abieos), with some improvements:
+
+- Contracts can be directly updated on the map
+- Added `abieos_delete_contract`
+
+Made with ♥ by [EOS Rio](https://eosrio.io/)
+
+----
+**Only Linux is supported for now, import will be null on others**
+
+- Typescript typings included
+- Prebuilt binary included (Clang 9.0.0 required to build)
+
+### Install
+
+```shell script
+npm i @eosrio/node-abieos --save
+```
+
+### Usage
+
+CommonJS
+```js
+const nodeAbieos = require('@eosrio/node-abieos');
+```
+
+ES Modules
+```typescript
+import * as nodeAbieos from "@eosrio/node-abieos";
+```
+
+Check the [/examples](https://github.com/eosrio/node-abieos/tree/master/examples) folder for implementation examples
+
+### Building
+
+env setup instructions soon
+```shell script
+git clone https://github.com/eosrio/node-abieos.git
+cd node-abieos
+# linux
+npm run build:linux
+# windows
+npm run build:win
+```
diff --git a/deno_dist/abieos.d.ts b/deno_dist/abieos.d.ts
new file mode 100644
index 0000000..9cbe0c4
--- /dev/null
+++ b/deno_dist/abieos.d.ts
@@ -0,0 +1,20 @@
+import { Buffer } from "node:buffer";
+///
+declare let abieos: any | null;
+export declare class Abieos {
+ private static instance;
+ static native: typeof abieos;
+ private constructor();
+ static getInstance(): Abieos;
+ stringToName(nameString: string): BigInteger;
+ jsonToHex(contractName: string, type: string, json: string | object): string;
+ hexToJson(contractName: string, type: string, hex: string): any;
+ binToJson(contractName: string, type: string, buffer: Buffer): any;
+ loadAbi(contractName: string, abi: string | object): boolean;
+ loadAbiHex(contractName: string, abihex: string): boolean;
+ getTypeForAction(contractName: string, actionName: string): string;
+ getTypeForTable(contractName: string, table_name: string): string;
+ deleteContract(contractName: string): boolean;
+}
+export {};
+//# sourceMappingURL=abieos.d.ts.map
\ No newline at end of file
diff --git a/deno_dist/abieos.d.ts.map b/deno_dist/abieos.d.ts.map
new file mode 100644
index 0000000..761def5
--- /dev/null
+++ b/deno_dist/abieos.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"abieos.d.ts","sourceRoot":"","sources":["abieos.ts"],"names":[],"mappings":";AAKA,QAAA,IAAI,MAAM,EAAE,GAAG,GAAG,IAAW,CAAC;AAQ9B,qBAAa,MAAM;IACf,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAc,MAAM,EAAE,OAAO,MAAM,CAAC;IAEpC,OAAO;WAIO,WAAW,IAAI,MAAM;IAO5B,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;IAI5C,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAU5E,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG;IAa/D,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG;IAalE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAY5D,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAIzD,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IASlE,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IASjE,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;CAGvD"}
\ No newline at end of file
diff --git a/deno_dist/abieos.js b/deno_dist/abieos.js
new file mode 100644
index 0000000..d0037da
--- /dev/null
+++ b/deno_dist/abieos.js
@@ -0,0 +1,100 @@
+import { createRequire } from 'node:module';
+const require = createRequire(import.meta.url);
+let modulePath = "../dist/abieos.node";
+let abieos = null;
+if (process.platform === 'linux') {
+ abieos = require(modulePath);
+}
+else if (process.platform === 'win32') {
+ // throw new Error(`${process.platform} is not supported by node-abieos`);
+ abieos = null;
+}
+export class Abieos {
+ constructor() {
+ Abieos.native = abieos;
+ }
+ static getInstance() {
+ if (!Abieos.instance) {
+ Abieos.instance = new Abieos();
+ }
+ return Abieos.instance;
+ }
+ stringToName(nameString) {
+ return Abieos.native.string_to_name(nameString);
+ }
+ jsonToHex(contractName, type, json) {
+ const jsonData = typeof json === 'object' ? JSON.stringify(json) : json;
+ const data = Abieos.native.json_to_hex(contractName, type, jsonData);
+ if (data === 'PARSING_ERROR') {
+ throw new Error('failed to parse data');
+ }
+ else {
+ return data;
+ }
+ }
+ hexToJson(contractName, type, hex) {
+ const data = Abieos.native.hex_to_json(contractName, type, hex);
+ if (data) {
+ try {
+ return JSON.parse(data);
+ }
+ catch (e) {
+ throw new Error('failed to parse json string: ' + data);
+ }
+ }
+ else {
+ throw new Error('failed to parse hex data');
+ }
+ }
+ binToJson(contractName, type, buffer) {
+ const data = Abieos.native.bin_to_json(contractName, type, buffer);
+ if (data[0] === '{' || data[0] === '[') {
+ try {
+ return JSON.parse(data);
+ }
+ catch (e) {
+ throw new Error('json parse error');
+ }
+ }
+ else {
+ throw new Error(data);
+ }
+ }
+ loadAbi(contractName, abi) {
+ if (typeof abi === 'string') {
+ return Abieos.native.load_abi(contractName, abi);
+ }
+ else {
+ if (typeof abi === 'object') {
+ return Abieos.native.load_abi(contractName, JSON.stringify(abi));
+ }
+ else {
+ throw new Error('ABI must be a String or Object');
+ }
+ }
+ }
+ loadAbiHex(contractName, abihex) {
+ return Abieos.native.load_abi_hex(contractName, abihex);
+ }
+ getTypeForAction(contractName, actionName) {
+ const result = Abieos.native.get_type_for_action(contractName, actionName);
+ if (result === 'NOT_FOUND') {
+ throw new Error('action ' + actionName + ' not found on contract ' + contractName);
+ }
+ else {
+ return result;
+ }
+ }
+ getTypeForTable(contractName, table_name) {
+ const result = Abieos.native.get_type_for_table(contractName, table_name);
+ if (result === 'NOT_FOUND') {
+ throw new Error('table ' + table_name + ' not found on contract ' + contractName);
+ }
+ else {
+ return result;
+ }
+ }
+ deleteContract(contractName) {
+ return Abieos.native.delete_contract(contractName);
+ }
+}
diff --git a/deno_dist/abieos.ts b/deno_dist/abieos.ts
new file mode 100644
index 0000000..3895ee0
--- /dev/null
+++ b/deno_dist/abieos.ts
@@ -0,0 +1,114 @@
+import { createRequire } from "https://deno.land/std@0.107.0/node/module.ts"
+let modulePath = '';
+let metaUrl = '';
+if (import.meta.url.startsWith('file://')) {
+ metaUrl = `${import.meta.url}`;
+ modulePath = `../dist/abieos.node`;
+} else {
+ metaUrl = `${Deno.mainModule}`;
+ modulePath = `../../bin/abieos.node`;
+const require = createRequire(metaUrl);
+
+const paths = ['abieos.node', '../abieos.node', '../../abieos.node', '../../bin/abieos.node', '../bin/abieos.node', './bin/abieos.node'];
+for (const maybePath of paths) {
+ try {
+ require(maybePath);
+ modulePath = maybePath;
+ console.log('gotcha', maybePath)
+ break;
+ } catch (e) {
+ console.log('wrong', e);
+ }
+}
+}
+const require = createRequire(metaUrl);
+let abieos = require(modulePath);
+export class Abieos {
+ constructor() {
+ Abieos.native = abieos;
+ }
+ static getInstance() {
+ if (!Abieos.instance) {
+ Abieos.instance = new Abieos();
+ }
+ return Abieos.instance;
+ }
+ stringToName(nameString) {
+ return Abieos.native.string_to_name(nameString);
+ }
+ jsonToHex(contractName, type, json) {
+ const jsonData = typeof json === 'object' ? JSON.stringify(json) : json;
+ const data = Abieos.native.json_to_hex(contractName, type, jsonData);
+ if (data === 'PARSING_ERROR') {
+ throw new Error('failed to parse data');
+ }
+ else {
+ return data;
+ }
+ }
+ hexToJson(contractName, type, hex) {
+ const data = Abieos.native.hex_to_json(contractName, type, hex);
+ if (data) {
+ try {
+ return JSON.parse(data);
+ }
+ catch (e) {
+ throw new Error('failed to parse json string: ' + data);
+ }
+ }
+ else {
+ throw new Error('failed to parse hex data');
+ }
+ }
+ binToJson(contractName, type, buffer) {
+ const data = Abieos.native.bin_to_json(contractName, type, buffer);
+ if (data[0] === '{' || data[0] === '[') {
+ try {
+ return JSON.parse(data);
+ }
+ catch (e) {
+ throw new Error('json parse error');
+ }
+ }
+ else {
+ throw new Error(data);
+ }
+ }
+ loadAbi(contractName, abi) {
+ if (typeof abi === 'string') {
+ return Abieos.native.load_abi(contractName, abi);
+ }
+ else {
+ if (typeof abi === 'object') {
+ return Abieos.native.load_abi(contractName, JSON.stringify(abi));
+ }
+ else {
+ throw new Error('ABI must be a String or Object');
+ }
+ }
+ }
+ loadAbiHex(contractName, abihex) {
+ return Abieos.native.load_abi_hex(contractName, abihex);
+ }
+ getTypeForAction(contractName, actionName) {
+ const result = Abieos.native.get_type_for_action(contractName, actionName);
+ if (result === 'NOT_FOUND') {
+ throw new Error('action ' + actionName + ' not found on contract ' + contractName);
+ }
+ else {
+ return result;
+ }
+ }
+ getTypeForTable(contractName, table_name) {
+ const result = Abieos.native.get_type_for_table(contractName, table_name);
+ if (result === 'NOT_FOUND') {
+ throw new Error('table ' + table_name + ' not found on contract ' + contractName);
+ }
+ else {
+ return result;
+ }
+ }
+ deleteContract(contractName) {
+ return Abieos.native.delete_contract(contractName);
+ }
+}
diff --git a/deno_dist/mod.ts b/deno_dist/mod.ts
new file mode 100644
index 0000000..c16f1e3
--- /dev/null
+++ b/deno_dist/mod.ts
@@ -0,0 +1 @@
+export * from "./abieos.ts";
\ No newline at end of file
diff --git a/dist/abieos.so b/dist/abieos.so
new file mode 100755
index 0000000..073ff06
Binary files /dev/null and b/dist/abieos.so differ
diff --git a/lib/abieos.deno.ts b/lib/abieos.deno.ts
new file mode 100644
index 0000000..3895ee0
--- /dev/null
+++ b/lib/abieos.deno.ts
@@ -0,0 +1,114 @@
+import { createRequire } from "https://deno.land/std@0.107.0/node/module.ts"
+let modulePath = '';
+let metaUrl = '';
+if (import.meta.url.startsWith('file://')) {
+ metaUrl = `${import.meta.url}`;
+ modulePath = `../dist/abieos.node`;
+} else {
+ metaUrl = `${Deno.mainModule}`;
+ modulePath = `../../bin/abieos.node`;
+const require = createRequire(metaUrl);
+
+const paths = ['abieos.node', '../abieos.node', '../../abieos.node', '../../bin/abieos.node', '../bin/abieos.node', './bin/abieos.node'];
+for (const maybePath of paths) {
+ try {
+ require(maybePath);
+ modulePath = maybePath;
+ console.log('gotcha', maybePath)
+ break;
+ } catch (e) {
+ console.log('wrong', e);
+ }
+}
+}
+const require = createRequire(metaUrl);
+let abieos = require(modulePath);
+export class Abieos {
+ constructor() {
+ Abieos.native = abieos;
+ }
+ static getInstance() {
+ if (!Abieos.instance) {
+ Abieos.instance = new Abieos();
+ }
+ return Abieos.instance;
+ }
+ stringToName(nameString) {
+ return Abieos.native.string_to_name(nameString);
+ }
+ jsonToHex(contractName, type, json) {
+ const jsonData = typeof json === 'object' ? JSON.stringify(json) : json;
+ const data = Abieos.native.json_to_hex(contractName, type, jsonData);
+ if (data === 'PARSING_ERROR') {
+ throw new Error('failed to parse data');
+ }
+ else {
+ return data;
+ }
+ }
+ hexToJson(contractName, type, hex) {
+ const data = Abieos.native.hex_to_json(contractName, type, hex);
+ if (data) {
+ try {
+ return JSON.parse(data);
+ }
+ catch (e) {
+ throw new Error('failed to parse json string: ' + data);
+ }
+ }
+ else {
+ throw new Error('failed to parse hex data');
+ }
+ }
+ binToJson(contractName, type, buffer) {
+ const data = Abieos.native.bin_to_json(contractName, type, buffer);
+ if (data[0] === '{' || data[0] === '[') {
+ try {
+ return JSON.parse(data);
+ }
+ catch (e) {
+ throw new Error('json parse error');
+ }
+ }
+ else {
+ throw new Error(data);
+ }
+ }
+ loadAbi(contractName, abi) {
+ if (typeof abi === 'string') {
+ return Abieos.native.load_abi(contractName, abi);
+ }
+ else {
+ if (typeof abi === 'object') {
+ return Abieos.native.load_abi(contractName, JSON.stringify(abi));
+ }
+ else {
+ throw new Error('ABI must be a String or Object');
+ }
+ }
+ }
+ loadAbiHex(contractName, abihex) {
+ return Abieos.native.load_abi_hex(contractName, abihex);
+ }
+ getTypeForAction(contractName, actionName) {
+ const result = Abieos.native.get_type_for_action(contractName, actionName);
+ if (result === 'NOT_FOUND') {
+ throw new Error('action ' + actionName + ' not found on contract ' + contractName);
+ }
+ else {
+ return result;
+ }
+ }
+ getTypeForTable(contractName, table_name) {
+ const result = Abieos.native.get_type_for_table(contractName, table_name);
+ if (result === 'NOT_FOUND') {
+ throw new Error('table ' + table_name + ' not found on contract ' + contractName);
+ }
+ else {
+ return result;
+ }
+ }
+ deleteContract(contractName) {
+ return Abieos.native.delete_contract(contractName);
+ }
+}
diff --git a/lib/mod.ts b/lib/mod.ts
new file mode 100644
index 0000000..c3156d6
--- /dev/null
+++ b/lib/mod.ts
@@ -0,0 +1 @@
+export * from "./abieos";
\ No newline at end of file
diff --git a/package.json b/package.json
index 11ede7f..f8e8916 100644
--- a/package.json
+++ b/package.json
@@ -8,8 +8,9 @@
"install": "node -e 'process.exit(0)'",
"test": "cd examples && node basic.js",
"tsc:watch": "tsc --watch",
- "build:linux": "cmake-js compile --cc /usr/bin/clang --cxx /usr/bin/clang++ && cp build/Release/node_abieos.node dist/abieos.node",
- "build:win": "cmake-js"
+ "build:linux": "cmake-js compile --cc /usr/bin/clang --cxx /usr/bin/clang++ && cp build/Release/deno_abieos.so dist/abieos.so",
+ "build:win": "cmake-js",
+ "build:deno": "npx denoify --src lib --out deno_dist"
},
"type": "module",
"repository": {
@@ -23,10 +24,11 @@
},
"homepage": "https://github.com/eosrio/node-abieos#readme",
"devDependencies": {
- "node-addon-api": "^5.0.0",
- "cmake-js": "^7.0.0",
"@types/node": "^18.11.13",
- "typescript": "^4.9.4"
+ "cmake-js": "^7.0.0",
+ "node-addon-api": "^5.0.0",
+ "typescript": "^4.9.4",
+ "denoify": "^1.5.3"
},
"cmake-js": {
"runtime": "node",
diff --git a/src/main.cpp b/src/main.cpp
index 614d2af..52f1080 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,17 +1,15 @@
-#include
-#include
-
#include "abieos.h"
-#include "abieos.hpp"
#include
#include
#include
+#include
+#include
using namespace std;
abieos_context* global_context;
-std::string json_to_hex(const char *contract_name, const char *type, const char *json)
+extern "C" const char* json_to_hex(const char *contract_name, const char *type, const char *json)
{
if(global_context == nullptr) {
global_context = abieos_create();
@@ -21,19 +19,28 @@ std::string json_to_hex(const char *contract_name, const char *type, const char
if(!status)
{
std::cout << abieos_get_error(global_context) << "\n";
- return "PARSING_ERROR";
- }
+char* result = static_cast(std::malloc(strlen("PARSING_ERROR") + 1));
+std::strcpy(result, "PARSING_ERROR");
+return result;
+ }
auto results = abieos_get_bin_hex(global_context);
if(results == nullptr)
{
std::cout << abieos_get_error(global_context) << "\n";
- return "ERROR";
- }
+char* result = static_cast(std::malloc(strlen("ERROR") + 1));
+std::strcpy(result, "ERROR");
+return result;
+
+ }
std::string hexValue = &results[0u];
- return hexValue;
+// Replace strdup(hexValue.c_str()) with:
+char* result = static_cast(std::malloc(hexValue.length() + 1));
+std::strcpy(result, hexValue.c_str());
+return result;
+
}
-std::string hex_to_json(const char *contract_name, const char *type, const char *hex)
+extern "C" const char* hex_to_json(const char *contract_name, const char *type, const char *hex)
{
if(global_context == nullptr) {
global_context = abieos_create();
@@ -47,7 +54,7 @@ std::string hex_to_json(const char *contract_name, const char *type, const char
return results;
}
-std::string bin_to_json(const char *contract_name, const char *type, const char *bin, int size)
+extern "C" const char* bin_to_json(const char *contract_name, const char *type, const char *bin, int size)
{
if(global_context == nullptr) {
global_context = abieos_create();
@@ -58,58 +65,19 @@ std::string bin_to_json(const char *contract_name, const char *type, const char
{
return abieos_get_error(global_context);
}
- return results;
-}
-
-Napi::String JsonToHexWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- std::string type = info[1].As().Utf8Value();
- std::string json = info[2].As().Utf8Value();
- auto returnValue = json_to_hex(&contract_name[0u], &type[0u], &json[0u]);
- return Napi::String::New(env, returnValue);
-}
-
-Napi::String HexToJsonWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- std::string type = info[1].As().Utf8Value();
- std::string hex = info[2].As().Utf8Value();
- auto returnValue = hex_to_json(&contract_name[0u], &type[0u], &hex[0u]);
- return Napi::String::New(env, returnValue);
-}
-
-Napi::String BinToJsonWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- std::string type = info[1].As().Utf8Value();
- Napi::Buffer buf = info[2].As>();
- auto returnValue = bin_to_json(&contract_name[0u], &type[0u], buf.Data(), buf.Length());
- return Napi::String::New(env, returnValue);
+ return results;
}
-uint64_t string_to_name(const char *str)
+extern "C" uint64_t string_to_name(const char *str)
{
if(global_context == nullptr) {
global_context = abieos_create();
}
uint64_t result = abieos_string_to_name(global_context, str);
- return result;
+ return result;
}
-Napi::BigInt StringToNameWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- // name string
- std::string str_input = info[0].As().Utf8Value();
- uint64_t returnValue = string_to_name(&str_input[0u]);
- return Napi::BigInt::New(env, returnValue);
-}
-
-bool load_abi(const char *contract_name, const char *abi)
+extern "C" bool load_abi(const char *contract_name, const char *abi)
{
if(global_context == nullptr) {
global_context = abieos_create();
@@ -121,19 +89,10 @@ bool load_abi(const char *contract_name, const char *abi)
return false;
} else {
return true;
- }
+ }
}
-Napi::Boolean LoadAbiWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- std::string abi = info[1].As().Utf8Value();
- auto returnValue = load_abi(&contract_name[0u], &abi[0u]);
- return Napi::Boolean::New(env, returnValue);
-}
-
-bool load_abi_hex(const char *contract_name, const char *hex)
+extern "C" bool load_abi_hex(const char *contract_name, const char *hex)
{
if(global_context == nullptr) {
global_context = abieos_create();
@@ -149,16 +108,7 @@ bool load_abi_hex(const char *contract_name, const char *hex)
}
}
-Napi::Boolean LoadAbiHexWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- std::string abihex = info[1].As().Utf8Value();
- auto returnValue = load_abi_hex(&contract_name[0u], &abihex[0u]);
- return Napi::Boolean::New(env, returnValue);
-}
-
-string get_type_for_action(const char *contract_name, const char *action_name)
+extern "C" const char* get_type_for_action(const char *contract_name, const char *action_name)
{
if(global_context != nullptr) {
uint64_t contract = abieos_string_to_name(global_context, contract_name);
@@ -174,7 +124,7 @@ string get_type_for_action(const char *contract_name, const char *action_name)
}
}
-string get_type_for_table(const char *contract_name, const char *table_name)
+extern "C" const char* get_type_for_table(const char *contract_name, const char *table_name)
{
if(global_context != nullptr) {
uint64_t contract = abieos_string_to_name(global_context, contract_name);
@@ -190,25 +140,8 @@ string get_type_for_table(const char *contract_name, const char *table_name)
}
}
-Napi::String GetTypeWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- std::string action_name = info[1].As().Utf8Value();
- auto returnValue = get_type_for_action(&contract_name[0u], &action_name[0u]);
- return Napi::String::New(env, returnValue);
-}
-
-Napi::String GetTableTypeWrapped(const Napi::CallbackInfo &info)
+extern "C" bool delete_contract(const char *contract_name)
{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- std::string table_name = info[1].As().Utf8Value();
- auto returnValue = get_type_for_table(&contract_name[0u], &table_name[0u]);
- return Napi::String::New(env, returnValue);
-}
-
-bool delete_contract(const char *contract_name) {
if(global_context != nullptr) {
uint64_t contract = abieos_string_to_name(global_context, contract_name);
return abieos_delete_contract(global_context, contract);
@@ -216,27 +149,3 @@ bool delete_contract(const char *contract_name) {
return false;
}
}
-
-Napi::Boolean DeleteContractWrapped(const Napi::CallbackInfo &info)
-{
- Napi::Env env = info.Env();
- std::string contract_name = info[0].As().Utf8Value();
- auto returnValue = delete_contract(&contract_name[0u]);
- return Napi::Boolean::New(env, returnValue);
-}
-
-Napi::Object Init(Napi::Env env, Napi::Object exports)
-{
- exports.Set("string_to_name", Napi::Function::New(env, StringToNameWrapped));
- exports.Set("json_to_hex", Napi::Function::New(env, JsonToHexWrapped));
- exports.Set("hex_to_json", Napi::Function::New(env, HexToJsonWrapped));
- exports.Set("bin_to_json", Napi::Function::New(env, BinToJsonWrapped));
- exports.Set("load_abi", Napi::Function::New(env, LoadAbiWrapped));
- exports.Set("load_abi_hex", Napi::Function::New(env, LoadAbiHexWrapped));
- exports.Set("get_type_for_action", Napi::Function::New(env, GetTypeWrapped));
- exports.Set("get_type_for_table", Napi::Function::New(env, GetTableTypeWrapped));
- exports.Set("delete_contract", Napi::Function::New(env, DeleteContractWrapped));
- return exports;
-}
-
-NODE_API_MODULE(abieos,Init);