From 9c83633120aa2f76881da2bf1fc73193f5fff42a Mon Sep 17 00:00:00 2001 From: Some Random Crypto Guy Date: Mon, 8 Jul 2024 21:12:06 +0100 Subject: [PATCH] fixed RPC functionality for TRANSFER functionality; bumped version --- README.md | 8 ++-- src/version.cpp.in | 2 +- src/wallet/wallet2.cpp | 4 +- src/wallet/wallet_rpc_server.cpp | 50 +++++++++++++------- src/wallet/wallet_rpc_server.h | 2 +- src/wallet/wallet_rpc_server_commands_defs.h | 4 ++ 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0dc99ed11..e574ff521 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Salvium Zero v0.4.0 +# Salvium Zero v0.4.1 Copyright (c) 2023-2024, Salvium Portions Copyright (c) 2014-2023, The Monero Project @@ -251,7 +251,7 @@ Tested on a Raspberry Pi Zero with a clean install of minimal Raspbian Stretch ( ```bash git clone https://github.com/salvium/salvium cd salvium - git checkout v0.4.0 + git checkout v0.4.1 ``` * Build: @@ -370,10 +370,10 @@ application. cd salvium ``` -* If you would like a specific [version/tag](https://github.com/salvium/salvium/tags), do a git checkout for that version. eg. 'v0.4.0'. If you don't care about the version and just want binaries from master, skip this step: +* If you would like a specific [version/tag](https://github.com/salvium/salvium/tags), do a git checkout for that version. eg. 'v0.4.1'. If you don't care about the version and just want binaries from master, skip this step: ```bash - git checkout v0.4.0 + git checkout v0.4.1 ``` * If you are on a 64-bit system, run: diff --git a/src/version.cpp.in b/src/version.cpp.in index 5e572465f..07dc12dc1 100644 --- a/src/version.cpp.in +++ b/src/version.cpp.in @@ -1,5 +1,5 @@ #define DEF_SALVIUM_VERSION_TAG "@VERSIONTAG@" -#define DEF_SALVIUM_VERSION "0.4.0" +#define DEF_SALVIUM_VERSION "0.4.1" #define DEF_MONERO_VERSION_TAG "release" #define DEF_MONERO_VERSION "0.18.3.3" #define DEF_MONERO_RELEASE_NAME "Zero" diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f17e3ca6b..bb13ae1e6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2720,7 +2720,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote crypto::public_key P_change = crypto::null_pkey; size_t change_idx = o; THROW_WALLET_EXCEPTION_IF(!cryptonote::get_output_public_key(tx.vout[change_idx], P_change), error::wallet_internal_error, "Failed to get output public key"); - m_subaddresses[P_change] = {0,0}; + m_subaddresses[P_change] = tx_scan_info[o].received->index;//{0,0}; m_salvium_txs.insert({P_change, m_transfers.size()-1}); } } @@ -3001,7 +3001,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote // only for regular transfers if (!miner_tx) { for (auto& asset: total_received_1) { - if (asset.second != total_received_2[asset.first]) { + if (asset.second != total_received_2[asset.first] + (asset.first == source_asset ? sub_change : 0)) { //if (source_asset == dest_asset && !miner_tx) { //if (total_received_1 != total_received_2) //{ diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 5d7309fc1..2839a7d44 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -897,7 +897,7 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ - bool wallet_rpc_server::validate_transfer(const std::list& destinations, const std::string& payment_id, std::vector& dsts, std::vector& extra, bool at_least_one_destination, epee::json_rpc::error& er) + bool wallet_rpc_server::validate_transfer(const std::list& destinations, const std::string& source_asset, const std::string& dest_asset, const cryptonote::transaction_type& type, const std::string& payment_id, std::vector& dsts, std::vector& extra, bool at_least_one_destination, epee::json_rpc::error& er) { crypto::hash8 integrated_payment_id = crypto::null_hash8; std::string extra_nonce; @@ -932,6 +932,7 @@ namespace tools de.is_subaddress = info.is_subaddress; de.amount = it->amount; de.is_integrated = info.has_payment_id; + de.asset_type = it->asset_type; dsts.push_back(de); if (info.has_payment_id) @@ -1107,8 +1108,11 @@ namespace tools CHECK_MULTISIG_ENABLED(); + // Cast the TX type into the correct var + const cryptonote::transaction_type type = static_cast(req.tx_type); + // validate the transfer requested and populate dsts & extra - if (!validate_transfer(req.destinations, req.payment_id, dsts, extra, true, er)) + if (!validate_transfer(req.destinations, req.source_asset, req.dest_asset, type, req.payment_id, dsts, extra, true, er)) { return false; } @@ -1117,7 +1121,7 @@ namespace tools { uint64_t mixin = m_wallet->adjust_mixin(req.ring_size ? req.ring_size - 1 : 0); uint32_t priority = m_wallet->adjust_priority(req.priority); - std::vector ptx_vector = m_wallet->create_transactions_2(dsts, req.source_asset, req.dest_asset, static_cast(req.tx_type), mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, req.subtract_fee_from_outputs); + std::vector ptx_vector = m_wallet->create_transactions_2(dsts, req.source_asset, req.dest_asset, type, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, req.subtract_fee_from_outputs); if (ptx_vector.empty()) { @@ -1161,8 +1165,11 @@ namespace tools CHECK_MULTISIG_ENABLED(); - // validate the transfer requested and populate dsts & extra; RPC_TRANSFER::request and RPC_TRANSFER_SPLIT::request are identical types. - if (!validate_transfer(req.destinations, req.payment_id, dsts, extra, true, er)) + // Cast the TX type into the correct var + const cryptonote::transaction_type type = static_cast(req.tx_type); + + // validate the transfer requested and populate dsts & extra + if (!validate_transfer(req.destinations, req.source_asset, req.dest_asset, type, req.payment_id, dsts, extra, true, er)) { return false; } @@ -1172,7 +1179,7 @@ namespace tools uint64_t mixin = m_wallet->adjust_mixin(req.ring_size ? req.ring_size - 1 : 0); uint32_t priority = m_wallet->adjust_priority(req.priority); LOG_PRINT_L2("on_transfer_split calling create_transactions_2"); - std::vector ptx_vector = m_wallet->create_transactions_2(dsts, req.source_asset, req.dest_asset, static_cast(req.tx_type), mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices); + std::vector ptx_vector = m_wallet->create_transactions_2(dsts, req.source_asset, req.dest_asset, type, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices); LOG_PRINT_L2("on_transfer_split called create_transactions_2"); if (ptx_vector.empty()) @@ -1597,13 +1604,17 @@ namespace tools CHECK_MULTISIG_ENABLED(); - // validate the transfer requested and populate dsts & extra - std::list destination; - destination.push_back(wallet_rpc::transfer_destination()); - destination.back().amount = 0; - destination.back().address = req.address; std::string asset_type = req.asset_type.empty() ? "SAL" : req.asset_type; - if (!validate_transfer(destination, req.payment_id, dsts, extra, true, er)) + + // validate the transfer requested and populate dsts & extra + std::list destinations; + destinations.push_back(wallet_rpc::transfer_destination()); + destinations.back().amount = 0; + destinations.back().address = req.address; + destinations.back().asset_type = asset_type; + + // validate the transfer requested and populate dsts & extra + if (!validate_transfer(destinations, asset_type, asset_type, cryptonote::transaction_type::TRANSFER, req.payment_id, dsts, extra, true, er)) { return false; } @@ -1665,12 +1676,17 @@ namespace tools CHECK_MULTISIG_ENABLED(); + std::string asset_type = req.asset_type.empty() ? "SAL" : req.asset_type; + // validate the transfer requested and populate dsts & extra - std::list destination; - destination.push_back(wallet_rpc::transfer_destination()); - destination.back().amount = 0; - destination.back().address = req.address; - if (!validate_transfer(destination, req.payment_id, dsts, extra, true, er)) + std::list destinations; + destinations.push_back(wallet_rpc::transfer_destination()); + destinations.back().amount = 0; + destinations.back().address = req.address; + destinations.back().asset_type = asset_type; + + // validate the transfer requested and populate dsts & extra + if (!validate_transfer(destinations, asset_type, asset_type, cryptonote::transaction_type::TRANSFER, req.payment_id, dsts, extra, true, er)) { return false; } diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 3308d1751..40bb543e2 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -268,7 +268,7 @@ namespace tools bool get_tx_key, Ts& tx_key, Tu &amount, Ta &amounts_by_dest, Tu &fee, Tu &weight, std::string &multisig_txset, std::string &unsigned_txset, bool do_not_relay, Ts &tx_hash, bool get_tx_hex, Ts &tx_blob, bool get_tx_metadata, Ts &tx_metadata, Tk &spent_key_images, epee::json_rpc::error &er); - bool validate_transfer(const std::list& destinations, const std::string& payment_id, std::vector& dsts, std::vector& extra, bool at_least_one_destination, epee::json_rpc::error& er); + bool validate_transfer(const std::list& destinations, const std::string& source_asset, const std::string& dest_asset, const cryptonote::transaction_type& type, const std::string& payment_id, std::vector& dsts, std::vector& extra, bool at_least_one_destination, epee::json_rpc::error& er); void check_background_mining(); diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index ee1bcfa7c..310a832e3 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -465,9 +465,11 @@ namespace wallet_rpc { uint64_t amount; std::string address; + std::string asset_type; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amount) KV_SERIALIZE(address) + KV_SERIALIZE(asset_type) END_KV_SERIALIZE_MAP() }; @@ -921,6 +923,7 @@ namespace wallet_rpc bool do_not_relay; bool get_tx_hex; bool get_tx_metadata; + std::string asset_type; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(address) @@ -934,6 +937,7 @@ namespace wallet_rpc KV_SERIALIZE_OPT(do_not_relay, false) KV_SERIALIZE_OPT(get_tx_hex, false) KV_SERIALIZE_OPT(get_tx_metadata, false) + KV_SERIALIZE(asset_type) END_KV_SERIALIZE_MAP() }; typedef epee::misc_utils::struct_init request;