diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index f35823c7..ba12e324 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3908,7 +3908,7 @@ bool blockchain_storage::check_tx_inputs(const transaction& tx, const crypto::ha const std::vector* psig = &sig_stub; TIME_MEASURE_START_PD(tx_check_inputs_loop); - BOOST_FOREACH(const auto& txin, tx.vin) + for(const auto& txin : tx.vin) { if (!m_is_in_checkpoint_zone) { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index ad769fa2..7c75dc10 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1605,7 +1605,7 @@ namespace currency return true; size_t i = 0; - BOOST_FOREACH(const tx_out& o, tx.vout) + for(const tx_out& o : tx.vout) { if (o.target.type() == typeid(txout_to_key)) { diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 28706e83..dc00ae0c 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -880,10 +880,10 @@ namespace currency } //@#@ //temporary double check timestamp - if (time(NULL) - get_actual_timestamp(b) > 5) + if (time(NULL) - static_cast(get_actual_timestamp(b)) > 5) { LOG_PRINT_RED_L0("Found block (" << get_block_hash(b) << ") timestamp (" << get_actual_timestamp(b) - << ") is suspiciously less (" << time(NULL) - get_actual_timestamp(b) << ") then curren time( " << time(NULL) << ")"); + << ") is suspiciously less (" << time(NULL) - static_cast(get_actual_timestamp(b)) << ") than current time ( " << time(NULL) << ")"); //mark node to make it easier to find it via scanner m_core.get_blockchain_storage().get_performnce_data().epic_failure_happend = true; } @@ -937,10 +937,10 @@ namespace currency } //@#@ //temporary double check timestamp - if (time(NULL) - get_actual_timestamp(b) > 5) + if (time(NULL) - static_cast(get_actual_timestamp(b)) > 5) { LOG_PRINT_RED_L0("Found block (" << get_block_hash(b) << ") timestamp (" << get_actual_timestamp(b) - << ") is suspiciously less (" << time(NULL) - get_actual_timestamp(b) << ") then curren time( " << time(NULL) << ")"); + << ") is suspiciously less (" << time(NULL) - static_cast(get_actual_timestamp(b)) << ") than current time ( " << time(NULL) << ")"); //mark node to make it easier to find it via scanner m_core.get_blockchain_storage().get_performnce_data().epic_failure_happend = true; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index c6586407..689e9095 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1195,7 +1195,7 @@ bool simple_wallet::transfer(const std::vector &args_) std::vector attachments; - if (!set_payment_id_to_tx(attachments, payment_id)) + if (!payment_id.empty() && !set_payment_id_to_tx(attachments, payment_id)) { fail_msg_writer() << "provided (or embedded) payment id can't be set: \"" << payment_id << "\""; return true; diff --git a/src/version.h.in b/src/version.h.in index e736fb6f..0767f2e7 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -5,9 +5,9 @@ #define PROJECT_MAJOR_VERSION "1" #define PROJECT_MINOR_VERSION "1" -#define PROJECT_REVISION "4" +#define PROJECT_REVISION "5" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 77 +#define PROJECT_VERSION_BUILD_NO 78 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0a6a8c70..09d2542f 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2909,10 +2909,10 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& m_wcallback->on_pos_block_found(b); //@#@ //double check timestamp - if (time(NULL) - get_actual_timestamp(b) > 5) + if (time(NULL) - static_cast(get_actual_timestamp(b)) > 5) { WLT_LOG_RED("Found block (" << get_block_hash(b) << ") timestamp (" << get_actual_timestamp(b) - << ") is suspiciously less (" << time(NULL) - get_actual_timestamp(b) << ") then curren time( " << time(NULL) << ")", LOG_LEVEL_0); + << ") is suspiciously less (" << time(NULL) - static_cast(get_actual_timestamp(b)) << ") than current time ( " << time(NULL) << ")", LOG_LEVEL_0); } // return true; @@ -4358,11 +4358,38 @@ bool wallet2::store_unsigned_tx_to_file_and_reserve_transfers(const finalize_tx_ return true; } //---------------------------------------------------------------------------------------------------- +void wallet2::check_and_throw_if_self_directed_tx_with_payment_id_requested(const construct_tx_param& ctp) +{ + // If someone sends coins to his own address, all tx outputs will be detected as own outputs. + // It's totally okay unless payment id is used, because it would be impossible to distinguish + // between change outs and transfer outs. Thus, such tx with a payment id can't be correctly + // obtained via RPC by the given payment id. It could be a problem for an exchange or other + // service when a user, identifyied by payment id sends coins to another user on the same + // exchange/service. Coins will be received but RPCs like get_payments won't give the transfer. + // To avoid such issues we prohibit such txs with a soft rule on sender side. + + for (auto& d : ctp.dsts) + { + for (auto& addr : d.addr) + { + if (addr != m_account.get_public_address()) + return; // at least one destination address is not our address -- it's not self-directed tx + } + } + + // it's self-directed tx + payment_id_t pid; + bool has_payment_id = get_payment_id_from_tx(ctp.attachments, pid) && !pid.empty(); + WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(!has_payment_id, "sending funds to yourself with payment id is not allowed"); +} +//---------------------------------------------------------------------------------------------------- void wallet2::transfer(const construct_tx_param& ctp, currency::transaction &tx, bool send_to_network, std::string* p_signed_tx_blob_str) { + check_and_throw_if_self_directed_tx_with_payment_id_requested(ctp); + TIME_MEASURE_START(prepare_transaction_time); finalize_tx_param ftp = AUTO_VAL_INIT(ftp); prepare_transaction(ctp, ftp); @@ -4555,7 +4582,7 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public { finalize_transaction(ftp, tx, tx_key, false, false); } - catch (error::tx_too_big) + catch (error::tx_too_big&) { return rc_too_many_outputs; } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f1e10186..02f0e077 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -864,7 +864,7 @@ private: void check_for_free_space_and_throw_if_it_lacks(const std::wstring& path, uint64_t exact_size_needed_if_known = UINT64_MAX); bool generate_packing_transaction_if_needed(currency::transaction& tx, uint64_t fake_outputs_number); bool store_unsigned_tx_to_file_and_reserve_transfers(const finalize_tx_param& ftp, const std::string& filename, std::string* p_unsigned_tx_blob_str = nullptr); - + void check_and_throw_if_self_directed_tx_with_payment_id_requested(const construct_tx_param& ctp); currency::account_base m_account; bool m_watch_only; diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index 0582d3ab..7a50e2a2 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -1622,7 +1622,7 @@ multisig_and_checkpoints::multisig_and_checkpoints() bool multisig_and_checkpoints::set_cp(currency::core& c, size_t ev_index, const std::vector& events) { currency::checkpoints checkpoints; - checkpoints.add_checkpoint(15, "a8e535abb31cd2c07ebd65dbb8d4160954677a0cebcd3dadf81642297cc557af"); + checkpoints.add_checkpoint(15, "72d63d6500c62d6783108f5a2e2c9f1dc1f0aae57011cf123583eec679a52cf9"); c.set_checkpoints(std::move(checkpoints)); return true;