From 2526c66094e78344b1d4844f784941402f08bb13 Mon Sep 17 00:00:00 2001 From: Guten Ye Date: Fri, 22 Mar 2019 14:27:12 +0800 Subject: [PATCH] Add estimate_fee --- monero_utils/MyMoneroCoreBridgeClass.js | 10 ++++++++++ src/index.cpp | 20 ++++++++++++++++++++ tests/MyMoneroCoreCpp.node.js | 7 +++++++ 3 files changed, 37 insertions(+) diff --git a/monero_utils/MyMoneroCoreBridgeClass.js b/monero_utils/MyMoneroCoreBridgeClass.js index b09d1b4..870ca91 100644 --- a/monero_utils/MyMoneroCoreBridgeClass.js +++ b/monero_utils/MyMoneroCoreBridgeClass.js @@ -217,6 +217,16 @@ class MyMoneroCoreBridgeClass extends MyMoneroCoreBridgeEssentialsClass mask: ret.mask, }; } + estimate_fee(args) + { + const args_str = JSON.stringify(args); + const ret_string = this.Module.estimate_fee(args_str); + const ret = JSON.parse(ret_string); + if (typeof ret.err_msg !== 'undefined' && ret.err_msg) { + throw ret.err_msg; + } + return ret.retVal; + } estimate_rct_tx_size(n_inputs, mixin, n_outputs, extra_size, bulletproof) { const args = diff --git a/src/index.cpp b/src/index.cpp index 4b0f487..b695c5b 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -175,6 +175,25 @@ string estimated_tx_network_fee(const string &args_string) return serial_bridge_utils::error_ret_json_from_message(e.what()); } } +// +string estimate_fee(const string &args_string) +{ + try { + return serial_bridge::estimate_fee(args_string); + } catch (std::exception &e) { + return serial_bridge_utils::error_ret_json_from_message(e.what()); + } +} +// +string estimate_tx_weight(const string &args_string) +{ + try { + return serial_bridge::estimate_tx_weight(args_string); + } catch (std::exception &e) { + return serial_bridge_utils::error_ret_json_from_message(e.what()); + } +} +// string estimate_rct_tx_size(const string &args_string) { try { @@ -272,6 +291,7 @@ EMSCRIPTEN_BINDINGS(my_module) emscripten::function("address_and_keys_from_seed", &address_and_keys_from_seed); // emscripten::function("estimated_tx_network_fee", &estimated_tx_network_fee); + emscripten::function("estimate_fee", &estimate_fee); emscripten::function("estimate_rct_tx_size", &estimate_rct_tx_size); // emscripten::function("generate_key_image", &generate_key_image); diff --git a/tests/MyMoneroCoreCpp.node.js b/tests/MyMoneroCoreCpp.node.js index 6a4daa8..7a6b3f9 100644 --- a/tests/MyMoneroCoreCpp.node.js +++ b/tests/MyMoneroCoreCpp.node.js @@ -133,6 +133,13 @@ function tests(Module) console.timeEnd("estimated_tx_network_fee") console.log("estimated_tx_network_fee ret", ret_string) } + { + console.time("estimate_fee") + const args = {"use_per_byte_fee": "true", "use_rct": "true", "n_inputs": "2", "mixin": "10", "n_outputs": "2","extra_size": "0", "bulletproof": "true", "base_fee": "24658", "fee_quantization_mask": "10000", "priority": "2", "fork_version": "10"} + const ret_string = Module.estimate_fee(JSON.stringify(args)) + console.timeEnd("estimate_fee") + console.log("estimate_fee ret", ret_string) + } { console.time("estimate_rct_tx_size") const args_str = '{"n_inputs":1,"mixin":10,"n_outputs":2,"extra_size":0,"bulletproof":true}'