From bb3baad2eef0d56854d154fa008b674cf8140d03 Mon Sep 17 00:00:00 2001 From: Paul Shapiro Date: Fri, 8 Mar 2019 14:14:19 -0600 Subject: [PATCH] updated estimated_tx_network_fee, and the step1 and step2 functions with fork_version support --- README.md | 3 +++ src/serial_bridge_index.cpp | 30 ++++++++++++++++++------------ test/test_all.cpp | 14 ++++++++++---- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a574749..5fe2132 100644 --- a/README.md +++ b/README.md @@ -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` * `passedIn_attemptAt_fee: Optional` @@ -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` diff --git a/src/serial_bridge_index.cpp b/src/serial_bridge_index.cpp index 001bae2..5154880 100644 --- a/src/serial_bridge_index.cpp +++ b/src/serial_bridge_index.cpp @@ -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 optl__fork_version_string = json_root.get_optional("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("fee_per_b")), stoul(json_root.get("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 optl__fork_version_string = json_root.get_optional("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("sending_amount")), json_root.get("is_sweeping"), stoul(json_root.get("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("fee_per_b")), // per v8 stoull(json_root.get("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 optl__fork_version_string = json_root.get_optional("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("fee_per_b")), stoull(json_root.get("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("unlock_time")), nettype_from_string(json_root.get("nettype_string")) ); diff --git a/test/test_all.cpp b/test/test_all.cpp index 0491ce8..169dcd7 100644 --- a/test/test_all.cpp +++ b/test/test_all.cpp @@ -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);