Merge pull request #91 from ExodusMovement/estimate-fee

Add estimate_fee and estimate_tx_weight
pull/98/head
Paul Shapiro 5 years ago committed by GitHub
commit 2ea39ffe28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -246,10 +246,16 @@ decodeRct
decodeRctSimple
```
```
estimate_fee
```
```
estimated_tx_network_fee
```
```
estimate_tx_weight
```
```
estimate_rct_tx_size
```

@ -233,6 +233,26 @@ 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_tx_weight(args)
{
const args_str = JSON.stringify(args);
const ret_string = this.Module.estimate_tx_weight(args_str);
const ret = JSON.parse(ret_string);
if (typeof ret.err_msg !== 'undefined' && ret.err_msg) {
throw ret.err_msg;
}
return parseInt(ret.retVal, 10);
}
estimate_rct_tx_size(n_inputs, mixin, n_outputs, extra_size, bulletproof)
{
const args =

@ -183,6 +183,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 {
@ -281,6 +300,8 @@ 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_tx_weight", &estimate_tx_weight);
emscripten::function("estimate_rct_tx_size", &estimate_rct_tx_size);
//
emscripten::function("generate_key_image", &generate_key_image);

@ -181,5 +181,39 @@ describe("cryptonote_utils tests", function() {
"4501", // TODO: is this correct?
);
});
it("estimate_fee", async function() {
const monero_utils = await require("../monero_utils/MyMoneroCoreBridge")({})
var fee = monero_utils.estimate_fee({
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
});
assert.equal(
fee,
330050000
);
});
it("estimate_tx_weight", async function() {
const monero_utils = await require("../monero_utils/MyMoneroCoreBridge")({})
var weight = monero_utils.estimate_tx_weight({
use_rct: true,
n_inputs: 2,
mixin: 10,
n_outputs: 2,
extra_size: 0,
bulletproof: true,
});
assert.equal(
weight,
2677
);
});
});

Loading…
Cancel
Save