diff --git a/src/monero_fork_rules.hpp b/src/monero_fork_rules.hpp index 7a8ab6a..12916c5 100644 --- a/src/monero_fork_rules.hpp +++ b/src/monero_fork_rules.hpp @@ -36,7 +36,8 @@ #ifndef monero_fork_rules_hpp #define monero_fork_rules_hpp -#include "crypto.h" +#include +#include namespace monero_fork_rules { @@ -44,6 +45,18 @@ namespace monero_fork_rules // bool lightwallet_hardcoded__use_fork_rules(uint8_t version, int64_t early_blocks); // convenience - to be called by a use_fork_rules_fn_type implementation // + // The fork_version should be the actual current network fork version. + // If zero, it is ignored and the resulting functor always returns true. + inline use_fork_rules_fn_type make_use_fork_rules_fn(uint8_t fork_version) + { + return 0 != fork_version ? + [fork_version](uint8_t desired_version, int64_t/*early_blocks is ignored*/) + { + return desired_version <= fork_version; + } + : use_fork_rules_fn_type(lightwallet_hardcoded__use_fork_rules); + } + // uint32_t fixed_ringsize(); // not mixinsize, which would be ringsize-1 uint32_t fixed_mixinsize(); // not ringsize, which would be mixinsize+1 // diff --git a/src/monero_send_routine.cpp b/src/monero_send_routine.cpp index 54282fe..ef8a41b 100644 --- a/src/monero_send_routine.cpp +++ b/src/monero_send_routine.cpp @@ -242,9 +242,11 @@ LightwalletAPI_Res_GetUnspentOuts monero_send_routine::new__parsed_res__get_unsp unspent_outs.push_back(std::move(out)); } } + auto fork_version = res.get_optional("fork_version"); return LightwalletAPI_Res_GetUnspentOuts{ none, - final__per_byte_fee, fee_mask, unspent_outs + final__per_byte_fee, fee_mask, unspent_outs, + fork_version ? *fork_version : static_cast(0) }; } LightwalletAPI_Res_GetRandomOuts monero_send_routine::new__parsed_res__get_random_outs( @@ -312,6 +314,7 @@ struct _SendFunds_ConstructAndSendTx_Args const vector &unspent_outs; uint64_t fee_per_b; uint64_t fee_quantization_mask; + uint8_t fork_version; // // cached const secret_key &sec_viewKey; @@ -329,6 +332,8 @@ void _reenterable_construct_and_send_tx( ) { args.status_update_fn(calculatingFee); // + auto use_fork_rules = monero_fork_rules::make_use_fork_rules_fn(args.fork_version); + // Send_Step1_RetVals step1_retVals; monero_transfer_utils::send_step1__prepare_params_for_get_decoys( step1_retVals, @@ -337,10 +342,7 @@ void _reenterable_construct_and_send_tx( args.sending_amount, args.is_sweeping, args.simple_priority, - [] (uint8_t version, int64_t early_blocks) -> bool - { - return lightwallet_hardcoded__use_fork_rules(version, early_blocks); - }, + use_fork_rules, args.unspent_outs, args.fee_per_b, args.fee_quantization_mask, @@ -358,7 +360,8 @@ void _reenterable_construct_and_send_tx( api_fetch_cb_fn get_random_outs_fn__cb_fn = [ args, step1_retVals, - constructionAttempt + constructionAttempt, + use_fork_rules ] ( const property_tree::ptree &res ) -> void { @@ -386,10 +389,7 @@ void _reenterable_construct_and_send_tx( args.fee_per_b, args.fee_quantization_mask, *(parsed_res.mix_outs), - [] (uint8_t version, int64_t early_blocks) -> bool - { - return lightwallet_hardcoded__use_fork_rules(version, early_blocks); - }, + std::move(use_fork_rules), args.unlock_time, args.nettype ); @@ -527,6 +527,7 @@ void monero_send_routine::async__send_funds(Async_SendFunds_Args args) *(parsed_res.unspent_outs), *(parsed_res.per_byte_fee), *(parsed_res.fee_mask), + parsed_res.fork_version, // sec_viewKey, sec_spendKey }); diff --git a/src/monero_send_routine.hpp b/src/monero_send_routine.hpp index 9a51dce..71837d1 100644 --- a/src/monero_send_routine.hpp +++ b/src/monero_send_routine.hpp @@ -202,6 +202,7 @@ namespace monero_send_routine optional per_byte_fee; optional fee_mask; optional> unspent_outs; + uint8_t fork_version; }; struct LightwalletAPI_Res_GetRandomOuts {