updated estimated_tx_network_fee, and the step1 and step2 functions with fork_version support

pull/28/head
Paul Shapiro 5 years ago
parent bba8fff34c
commit bb3baad2ee

@ -272,6 +272,7 @@ Useful for displaying an estimated fee To obtain exact fees, see "Creating a
* Args:
* `fee_per_b: UInt64String`
* `priority: UInt32String`
* `fork_version: UInt8String`
* Returns: `retVal: UInt64String`
@ -318,6 +319,7 @@ The values which must be passed between functions have (almost entirely) consist
* `priority: UInt32String` of `1``4`
* `fee_per_b: UInt64String`
* `fee_mask: UInt64String`
* `fork_version: UInt8String`
* `unspent_outs: [UnspentOutput]` - fully parsed server response
* `payment_id_string: Optional<String>`
* `passedIn_attemptAt_fee: Optional<UInt64String>`
@ -356,6 +358,7 @@ The values which must be passed between functions have (almost entirely) consist
* `priority: UInt32String` of `1``4`
* `fee_per_b: UInt64String`
* `fee_mask: UInt64String`
* `fork_version: UInt8String`
* `using_outs: [UnspentOutput]` returned by step1
* `mix_outs: [MixAmountAndOuts]` defined below
* `unlock_time: UInt64String`

@ -311,13 +311,15 @@ string serial_bridge::estimated_tx_network_fee(const string &args_string)
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
uint8_t fork_version = 0; // if missing
optional<string> optl__fork_version_string = json_root.get_optional<string>("fork_version");
if (optl__fork_version_string != none) {
fork_version = stoul(*optl__fork_version_string);
}
uint64_t fee = monero_fee_utils::estimated_tx_network_fee(
stoull(json_root.get<string>("fee_per_b")),
stoul(json_root.get<string>("priority")),
[] (uint8_t version, int64_t early_blocks) -> bool
{
return lightwallet_hardcoded__use_fork_rules(version, early_blocks);
}
monero_fork_rules::make_use_fork_rules_fn(fork_version)
);
std::ostringstream o;
o << fee;
@ -417,6 +419,11 @@ string serial_bridge::send_step1__prepare_params_for_get_decoys(const string &ar
if (optl__passedIn_attemptAt_fee_string != none) {
optl__passedIn_attemptAt_fee = stoull(*optl__passedIn_attemptAt_fee_string);
}
uint8_t fork_version = 0; // if missing
optional<string> optl__fork_version_string = json_root.get_optional<string>("fork_version");
if (optl__fork_version_string != none) {
fork_version = stoul(*optl__fork_version_string);
}
Send_Step1_RetVals retVals;
monero_transfer_utils::send_step1__prepare_params_for_get_decoys(
retVals,
@ -425,10 +432,7 @@ string serial_bridge::send_step1__prepare_params_for_get_decoys(const string &ar
stoull(json_root.get<string>("sending_amount")),
json_root.get<bool>("is_sweeping"),
stoul(json_root.get<string>("priority")),
[] (uint8_t version, int64_t early_blocks) -> bool
{
return lightwallet_hardcoded__use_fork_rules(version, early_blocks);
},
monero_fork_rules::make_use_fork_rules_fn(fork_version),
unspent_outs,
stoull(json_root.get<string>("fee_per_b")), // per v8
stoull(json_root.get<string>("fee_mask")),
@ -511,6 +515,11 @@ string serial_bridge::send_step2__try_create_transaction(const string &args_stri
}
mix_outs.push_back(std::move(amountAndOuts));
}
uint8_t fork_version = 0; // if missing
optional<string> optl__fork_version_string = json_root.get_optional<string>("fork_version");
if (optl__fork_version_string != none) {
fork_version = stoul(*optl__fork_version_string);
}
Send_Step2_RetVals retVals;
monero_transfer_utils::send_step2__try_create_transaction(
retVals,
@ -528,10 +537,7 @@ string serial_bridge::send_step2__try_create_transaction(const string &args_stri
stoull(json_root.get<string>("fee_per_b")),
stoull(json_root.get<string>("fee_mask")),
mix_outs,
[] (uint8_t version, int64_t early_blocks) -> bool
{
return lightwallet_hardcoded__use_fork_rules(version, early_blocks);
},
monero_fork_rules::make_use_fork_rules_fn(fork_version),
stoull(json_root.get<string>("unlock_time")),
nettype_from_string(json_root.get<string>("nettype_string"))
);

@ -104,10 +104,8 @@ BOOST_AUTO_TEST_CASE(wallet)
#include "../src/monero_fork_rules.hpp"
BOOST_AUTO_TEST_CASE(transfers__fee)
{
monero_fork_rules::use_fork_rules_fn_type use_fork_rules_fn = [] (uint8_t version, int64_t early_blocks) -> bool
{
return monero_fork_rules::lightwallet_hardcoded__use_fork_rules(version, early_blocks);
};
uint8_t fork_version = 10;
auto use_fork_rules_fn = monero_fork_rules::make_use_fork_rules_fn(fork_version);
uint64_t fee_per_b = 24658;
uint32_t priority = 2;
uint64_t est_fee = monero_fee_utils::estimated_tx_network_fee(fee_per_b, priority, use_fork_rules_fn);
@ -177,6 +175,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__sweepDust)
root.put("sending_amount", "0");
root.put("fee_per_b", "24658");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("priority", "1");
root.add_child("unspent_outs", unspent_outs);
if (fee_actually_needed_string != none) {
@ -262,6 +261,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__sweepDust)
root.put("sec_spendKey_string", "4e6d43cd03812b803c6f3206689f5fcc910005fc7e91d50d79b0776dbefcd803");
root.put("fee_per_b", "24658");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("unlock_time", "0");
root.put("priority", "1");
root.add_child("mix_outs", mix_outs);
@ -327,6 +327,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__amountWOnlyDusty)
root.put("sending_amount", "1000000");
root.put("fee_per_b", "24658");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("priority", "1");
root.add_child("unspent_outs", unspent_outs);
@ -385,6 +386,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__amount)
root.put("sending_amount", "200000000");
root.put("fee_per_b", "24658");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("priority", "1");
root.add_child("unspent_outs", unspent_outs);
if (fee_actually_needed_string != none) {
@ -471,6 +473,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__amount)
root.put("sec_spendKey_string", "4e6d43cd03812b803c6f3206689f5fcc910005fc7e91d50d79b0776dbefcd803");
root.put("fee_per_b", "24658");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("unlock_time", "0");
root.put("priority", "1");
root.add_child("mix_outs", mix_outs);
@ -876,6 +879,7 @@ BOOST_AUTO_TEST_CASE(bridged__estimated_tx_network_fee)
boost::property_tree::ptree root;
root.put("fee_per_b", "24658");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("priority", "2");
//
auto ret_string = serial_bridge::estimated_tx_network_fee(args_string_from_root(root));
@ -1409,6 +1413,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send_stagenet_coinbase)
root.put("sending_amount", "1000000000000");
root.put("fee_per_b", "166333");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("priority", "1");
root.add_child("unspent_outs", unspent_outs);
if (fee_actually_needed_string != none) {
@ -1494,6 +1499,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send_stagenet_coinbase)
root.put("sec_spendKey_string", "4acde2a96d5085423fcc8713c878448b35e45900f4e9cf2c0b643eb4268e140e");
root.put("fee_per_b", "166333");
root.put("fee_mask", "10000");
root.put("fork_version", "10");
root.put("unlock_time", "0");
root.put("priority", "1");
root.add_child("mix_outs", mix_outs);

Loading…
Cancel
Save