From 3fab389f05539168be3154b1dd3cd447d6d53af4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 22 May 2023 19:58:22 +0200 Subject: [PATCH 01/20] Reset testnet to next formation --- src/currency_core/currency_config.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index b559d696..2ece02f4 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -10,7 +10,7 @@ #ifndef TESTNET #define CURRENCY_FORMATION_VERSION 84 #else -#define CURRENCY_FORMATION_VERSION 88 +#define CURRENCY_FORMATION_VERSION 89 #endif #define CURRENCY_GENESIS_NONCE (CURRENCY_FORMATION_VERSION + 101011010121) //bender's nightmare @@ -238,7 +238,7 @@ #ifndef TESTNET #define WALLET_FILE_SERIALIZATION_VERSION 154 #else -#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+69) +#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+70) #endif #define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31) @@ -257,7 +257,7 @@ #define ZANO_HARDFORK_01_AFTER_HEIGHT 0 #define ZANO_HARDFORK_02_AFTER_HEIGHT 0 #define ZANO_HARDFORK_03_AFTER_HEIGHT 0 -#define ZANO_HARDFORK_04_AFTER_HEIGHT CURRENCY_MAX_BLOCK_NUMBER +#define ZANO_HARDFORK_04_AFTER_HEIGHT 1440 #endif @@ -275,6 +275,11 @@ static_assert(PREMINE_AMOUNT / WALLET_MAX_ALLOWED_OUTPUT_AMOUNT < CURRENCY_MINER #define CURRENCY_RELAY_TXS_MAX_COUNT 5 +#ifndef TESTNET + #define WALLET_ASSETS_WHITELIST_URL "https://zano.org/assets_whitelist.json" +#else + #define WALLET_ASSETS_WHITELIST_URL "https://zano.org/assets_whitelist_testnet.json" +#endif + -#define WALLET_ASSETS_WHITELIST_URL "https://zano.org/assets_whitelist.json" #define WALLET_ASSETS_WHITELIST_VALIDATION_PUBLIC_KEY "" //TODO@#@ \ No newline at end of file From e97d14c7e409c1aff1847148c995e6e863dfe761 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 22 May 2023 23:08:12 +0200 Subject: [PATCH 02/20] Fixed simplewallet ionic_swap functions --- src/simplewallet/simplewallet.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index d23a3ea1..fa6a42ed 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1876,8 +1876,8 @@ bool simple_wallet::generate_ionic_swap_proposal(const std::vector fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; } - view::ionic_swap_proposal_info proposal = AUTO_VAL_INIT(proposal); - bool r = epee::serialization::load_t_from_json_file(proposal, args[0]); + view::ionic_swap_proposal_info proposal_info = AUTO_VAL_INIT(proposal_info); + bool r = epee::serialization::load_t_from_json_file(proposal_info, args[0]); if (!r) { fail_msg_writer() << "Failed to load json file with asset specification: " << args[0]; @@ -1895,8 +1895,8 @@ bool simple_wallet::generate_ionic_swap_proposal(const std::vector return true; } - transaction tx_template = AUTO_VAL_INIT(tx_template); - r = m_wallet->create_ionic_swap_proposal(proposal, destination_addr, tx_template); + tools::wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); + r = m_wallet->create_ionic_swap_proposal(proposal_info, destination_addr, proposal); if (!r) { fail_msg_writer() << "Failed to create ionic_swap proposal"; @@ -1904,7 +1904,7 @@ bool simple_wallet::generate_ionic_swap_proposal(const std::vector } else { - success_msg_writer() << "Generated proposal: " << ENDL << epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx_template)); + success_msg_writer() << "Generated proposal: " << ENDL << epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(proposal)); } return true; } @@ -1916,24 +1916,24 @@ bool simple_wallet::get_ionic_swap_proposal_info(const std::vector fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; } - std::string raw_tx_template; - bool r = epee::string_tools::parse_hexstr_to_binbuff(args[0], raw_tx_template); + std::string raw_proposal; + bool r = epee::string_tools::parse_hexstr_to_binbuff(args[0], raw_proposal); if (!r) { fail_msg_writer() << "Failed to parse proposal hex to raw data"; return true; } - view::ionic_swap_proposal_info proposal = AUTO_VAL_INIT(proposal); - if (!m_wallet->get_ionic_swap_proposal_info(raw_tx_template, proposal)) + view::ionic_swap_proposal_info proposal_info = AUTO_VAL_INIT(proposal_info); + if (!m_wallet->get_ionic_swap_proposal_info(raw_proposal, proposal_info)) { fail_msg_writer() << "Failed to decode proposal info"; return true; } - std::string json_proposal = epee::serialization::store_t_to_json(proposal); + std::string json_proposal_info = epee::serialization::store_t_to_json(proposal_info); - success_msg_writer() << "Proposal details: " << ENDL << json_proposal; + success_msg_writer() << "Proposal details: " << ENDL << json_proposal_info; return true; } @@ -1945,8 +1945,8 @@ bool simple_wallet::accept_ionic_swap_proposal(const std::vector &a fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; } - std::string raw_tx_template; - bool r = epee::string_tools::parse_hexstr_to_binbuff(args[0], raw_tx_template); + std::string raw_proposal; + bool r = epee::string_tools::parse_hexstr_to_binbuff(args[0], raw_proposal); if (!r) { fail_msg_writer() << "Failed to parse proposal hex to raw data"; @@ -1954,7 +1954,7 @@ bool simple_wallet::accept_ionic_swap_proposal(const std::vector &a } currency::transaction result_tx = AUTO_VAL_INIT(result_tx); - if (!m_wallet->accept_ionic_swap_proposal(raw_tx_template, result_tx)) + if (!m_wallet->accept_ionic_swap_proposal(raw_proposal, result_tx)) { fail_msg_writer() << "Failed accept ionic_swap proposal"; return true; From 52f11a77b916025904da8999e2c37665e926bb3b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 22 May 2023 23:24:20 +0200 Subject: [PATCH 03/20] Fixed wrong p2p ports --- src/p2p/net_node.inl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 04c3bd10..22c2e457 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -322,14 +322,14 @@ namespace nodetool ADD_HARDCODED_SEED_NODE("144.76.183.143", P2P_DEFAULT_PORT); #else // TESTNET - //ADD_HARDCODED_SEED_NODE("95.217.43.225", P2P_DEFAULT_PORT); - //ADD_HARDCODED_SEED_NODE("94.130.137.230", P2P_DEFAULT_PORT); - //ADD_HARDCODED_SEED_NODE("95.217.42.247", P2P_DEFAULT_PORT); - //ADD_HARDCODED_SEED_NODE("94.130.160.115", P2P_DEFAULT_PORT); - - // TODO @#@# Here's the only Zarcanum Testnet Pre-Alpha node, update when ready - ADD_HARDCODED_SEED_NODE("95.217.42.247", 22070); - + ADD_HARDCODED_SEED_NODE("95.217.43.225", P2P_DEFAULT_PORT); + ADD_HARDCODED_SEED_NODE("94.130.137.230", P2P_DEFAULT_PORT); + ADD_HARDCODED_SEED_NODE("95.217.42.247", P2P_DEFAULT_PORT); + ADD_HARDCODED_SEED_NODE("94.130.160.115", P2P_DEFAULT_PORT); + ADD_HARDCODED_SEED_NODE("195.201.107.230", P2P_DEFAULT_PORT); + ADD_HARDCODED_SEED_NODE("95.217.46.49", P2P_DEFAULT_PORT); + ADD_HARDCODED_SEED_NODE("159.69.76.144", P2P_DEFAULT_PORT); + ADD_HARDCODED_SEED_NODE("144.76.183.143", P2P_DEFAULT_PORT); #endif bool res = handle_command_line(vm); From 756e6e526fc47ce1e514071828784a307469224c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 23 May 2023 12:39:31 +0200 Subject: [PATCH 04/20] version updated --- src/version.h.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/version.h.in b/src/version.h.in index 50c2fe88..886d5293 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -3,11 +3,11 @@ #define BUILD_COMMIT_ID "@VERSION@" -#define PROJECT_MAJOR_VERSION "1" -#define PROJECT_MINOR_VERSION "5" +#define PROJECT_MAJOR_VERSION "2" +#define PROJECT_MINOR_VERSION "0" #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 144 +#define PROJECT_VERSION_BUILD_NO 200 #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 "]" From a9bbfdcf824dbb25c03c62b4f62edcdde11e310b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 23 May 2023 23:47:42 +0200 Subject: [PATCH 05/20] wallet_rpc_server refactoring for blocking API calls(for browser extension) --- src/wallet/wallet_rpc_server.cpp | 468 ++++++++++++++----------------- src/wallet/wallet_rpc_server.h | 254 ++++++++++------- 2 files changed, 370 insertions(+), 352 deletions(-) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index e9b156cd..a5068051 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -18,7 +18,9 @@ using namespace epee; #include "wallet_helpers.h" #include "wrap_service.h" -#define WALLET_RPC_BEGIN_TRY_ENTRY() try { +#define GET_WALLET() wallet_rpc_locker w(m_pwallet_provider); + +#define WALLET_RPC_BEGIN_TRY_ENTRY() try { GET_WALLET(); #define WALLET_RPC_CATCH_TRY_ENTRY() } \ catch (const tools::error::wallet_error& e) \ { \ @@ -56,17 +58,24 @@ namespace tools command_line::add_arg(desc, arg_deaf_mode); } //------------------------------------------------------------------------------------------------------------------------------ - wallet_rpc_server::wallet_rpc_server(std::shared_ptr wptr) - : m_pwallet(wptr) + wallet_rpc_server::wallet_rpc_server(std::shared_ptr wptr): + m_pwallet_provider(new wallet_provider_simple(wptr)) , m_do_mint(false) , m_deaf(false) , m_last_wallet_store_height(0) {} //------------------------------------------------------------------------------------------------------------------------------ - std::shared_ptr wallet_rpc_server::get_wallet() - { - return std::shared_ptr(m_pwallet); - } + wallet_rpc_server::wallet_rpc_server(std::shared_ptr provider_ptr): + m_pwallet_provider(provider_ptr) + , m_do_mint(false) + , m_deaf(false) + , m_last_wallet_store_height(0) + {} + //------------------------------------------------------------------------------------------------------------------------------ +// std::shared_ptr wallet_rpc_server::get_wallet() +// { +// return std::shared_ptr(m_pwallet); +// } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::run(bool do_mint, bool offline_mode, const currency::account_public_address& miner_address) { @@ -80,11 +89,12 @@ namespace tools { try { + GET_WALLET(); size_t blocks_fetched = 0; bool received_money = false, ok = false; std::atomic stop(false); LOG_PRINT_L2("wallet RPC idle: refreshing..."); - get_wallet()->refresh(blocks_fetched, received_money, ok, stop); + w.get_wallet()->refresh(blocks_fetched, received_money, ok, stop); if (stop) { LOG_PRINT_L1("wallet RPC idle: refresh failed"); @@ -93,24 +103,24 @@ namespace tools bool has_related_alias_in_unconfirmed = false; LOG_PRINT_L2("wallet RPC idle: scanning tx pool..."); - get_wallet()->scan_tx_pool(has_related_alias_in_unconfirmed); + w.get_wallet()->scan_tx_pool(has_related_alias_in_unconfirmed); if (m_do_mint) { LOG_PRINT_L2("wallet RPC idle: trying to do PoS iteration..."); - get_wallet()->try_mint_pos(miner_address); + w.get_wallet()->try_mint_pos(miner_address); } //auto-store wallet in server mode, let's do it every 24-hour - if (get_wallet()->get_top_block_height() < m_last_wallet_store_height) + if (w.get_wallet()->get_top_block_height() < m_last_wallet_store_height) { - LOG_ERROR("Unexpected m_last_wallet_store_height = " << m_last_wallet_store_height << " or " << get_wallet()->get_top_block_height()); + LOG_ERROR("Unexpected m_last_wallet_store_height = " << m_last_wallet_store_height << " or " << w.get_wallet()->get_top_block_height()); } - else if (get_wallet()->get_top_block_height() - m_last_wallet_store_height > CURRENCY_BLOCKS_PER_DAY) + else if (w.get_wallet()->get_top_block_height() - m_last_wallet_store_height > CURRENCY_BLOCKS_PER_DAY) { //store wallet - get_wallet()->store(); - m_last_wallet_store_height = get_wallet()->get_top_block_height(); + w.get_wallet()->store(); + m_last_wallet_store_height = w.get_wallet()->get_top_block_height(); } } catch (error::no_connection_to_daemon&) @@ -136,6 +146,7 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::handle_command_line(const boost::program_options::variables_map& vm) { + GET_WALLET(); m_bind_ip = command_line::get_arg(vm, arg_rpc_bind_ip); m_port = command_line::get_arg(vm, arg_rpc_bind_port); m_deaf = command_line::get_arg(vm, arg_deaf_mode); @@ -146,14 +157,15 @@ namespace tools if (command_line::has_arg(vm, arg_miner_text_info)) { - get_wallet()->set_miner_text_info(command_line::get_arg(vm, arg_miner_text_info)); + w.get_wallet()->set_miner_text_info(command_line::get_arg(vm, arg_miner_text_info)); } return true; } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::init(const boost::program_options::variables_map& vm) { - m_last_wallet_store_height = get_wallet()->get_top_block_height(); + GET_WALLET(); + m_last_wallet_store_height = w.get_wallet()->get_top_block_height(); m_net_server.set_threads_prefix("RPC"); bool r = handle_command_line(vm); CHECK_AND_ASSERT_MES(r, false, "Failed to process command line in core_rpc_server"); @@ -189,125 +201,94 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx) { - try + WALLET_RPC_BEGIN_TRY_ENTRY(); + uint64_t stub_mined = 0; // unused + bool r = w.get_wallet()->balance(res.balances, stub_mined); + CHECK_AND_ASSERT_THROW_MES(r, "m_wallet.balance failed"); + for (auto it = res.balances.begin(); it != res.balances.end(); ++it) { - uint64_t stub_mined = 0; // unused - bool r = get_wallet()->balance(res.balances, stub_mined); - CHECK_AND_ASSERT_THROW_MES(r, "m_wallet.balance failed"); - for (auto it = res.balances.begin(); it != res.balances.end(); ++it) + if (it->asset_info.asset_id == currency::native_coin_asset_id) { - if (it->asset_info.asset_id == currency::native_coin_asset_id) - { - res.balance = it->total; - res.unlocked_balance = it->unlocked; - break; - } + res.balance = it->total; + res.unlocked_balance = it->unlocked; + break; } } - catch (std::exception& e) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = e.what(); - return false; - } + WALLET_RPC_CATCH_TRY_ENTRY(); return true; } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx) { - try - { - res.address = get_wallet()->get_account().get_public_address_str(); - } - catch (std::exception& e) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = e.what(); - return false; - } + WALLET_RPC_BEGIN_TRY_ENTRY(); + res.address = w.get_wallet()->get_account().get_public_address_str(); + WALLET_RPC_CATCH_TRY_ENTRY(); return true; } bool wallet_rpc_server::on_getwallet_info(const wallet_public::COMMAND_RPC_GET_WALLET_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx) { - try - { - res.address = get_wallet()->get_account().get_public_address_str(); - res.is_whatch_only = get_wallet()->is_watch_only(); - res.path = epee::string_encoding::convert_to_ansii(get_wallet()->get_wallet_path()); - res.transfers_count = get_wallet()->get_recent_transfers_total_count(); - res.transfer_entries_count = get_wallet()->get_transfer_entries_count(); - std::map distribution; - get_wallet()->get_utxo_distribution(distribution); - for (const auto& ent : distribution) - res.utxo_distribution.push_back(currency::print_money_brief(ent.first) + ":" + std::to_string(ent.second)); - - res.current_height = get_wallet()->get_top_block_height(); - return true; - } - catch (std::exception& e) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = e.what(); - return false; - } + WALLET_RPC_BEGIN_TRY_ENTRY(); + + res.address = w.get_wallet()->get_account().get_public_address_str(); + res.is_whatch_only = w.get_wallet()->is_watch_only(); + res.path = epee::string_encoding::convert_to_ansii(w.get_wallet()->get_wallet_path()); + res.transfers_count = w.get_wallet()->get_recent_transfers_total_count(); + res.transfer_entries_count = w.get_wallet()->get_transfer_entries_count(); + std::map distribution; + w.get_wallet()->get_utxo_distribution(distribution); + for (const auto& ent : distribution) + res.utxo_distribution.push_back(currency::print_money_brief(ent.first) + ":" + std::to_string(ent.second)); + + res.current_height = w.get_wallet()->get_top_block_height(); + return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } bool wallet_rpc_server::on_getwallet_restore_info(const wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx) { - try - { - res.seed_phrase = get_wallet()->get_account().get_seed_phrase(req.seed_password); - return true; - } - catch (std::exception& e) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = e.what(); - return false; - } + WALLET_RPC_BEGIN_TRY_ENTRY(); + res.seed_phrase = w.get_wallet()->get_account().get_seed_phrase(req.seed_password); + return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } bool wallet_rpc_server::on_get_seed_phrase_info(const wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO::request& req, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx) { - tools::get_seed_phrase_info(req.seed_phrase, req.seed_password, res); - return true; + WALLET_RPC_BEGIN_TRY_ENTRY(); + tools::get_seed_phrase_info(req.seed_phrase, req.seed_password, res); + return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } bool wallet_rpc_server::on_get_recent_txs_and_info(const wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request& req, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx) { - try + WALLET_RPC_BEGIN_TRY_ENTRY(); + if (req.update_provision_info) { - if (req.update_provision_info) - { - res.pi.balance = get_wallet()->balance(res.pi.unlocked_balance); - res.pi.transfer_entries_count = get_wallet()->get_transfer_entries_count(); - res.pi.transfers_count = get_wallet()->get_recent_transfers_total_count(); - res.pi.curent_height = get_wallet()->get_top_block_height(); - } - - if (req.offset == 0 && !req.exclude_unconfirmed) - get_wallet()->get_unconfirmed_transfers(res.transfers, req.exclude_mining_txs); - - bool start_from_end = true; - if (req.order == ORDER_FROM_BEGIN_TO_END) - { - start_from_end = false; - } - get_wallet()->get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers, res.last_item_index, req.exclude_mining_txs, start_from_end); - - return true; + res.pi.balance = w.get_wallet()->balance(res.pi.unlocked_balance); + res.pi.transfer_entries_count = w.get_wallet()->get_transfer_entries_count(); + res.pi.transfers_count = w.get_wallet()->get_recent_transfers_total_count(); + res.pi.curent_height = w.get_wallet()->get_top_block_height(); } - catch (std::exception& e) + + if (req.offset == 0 && !req.exclude_unconfirmed) + w.get_wallet()->get_unconfirmed_transfers(res.transfers, req.exclude_mining_txs); + + bool start_from_end = true; + if (req.order == ORDER_FROM_BEGIN_TO_END) { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = e.what(); - return false; + start_from_end = false; } + w.get_wallet()->get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers, res.last_item_index, req.exclude_mining_txs, start_from_end); + + return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx) { - if (req.fee < get_wallet()->get_core_runtime_config().tx_pool_min_fee) + WALLET_RPC_BEGIN_TRY_ENTRY(); + if (req.fee < w.get_wallet()->get_core_runtime_config().tx_pool_min_fee) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; - er.message = std::string("Given fee is too low: ") + epee::string_tools::num_to_string_fast(req.fee) + ", minimum is: " + epee::string_tools::num_to_string_fast(get_wallet()->get_core_runtime_config().tx_pool_min_fee); + er.message = std::string("Given fee is too low: ") + epee::string_tools::num_to_string_fast(req.fee) + ", minimum is: " + epee::string_tools::num_to_string_fast(w.get_wallet()->get_core_runtime_config().tx_pool_min_fee); return false; } @@ -319,7 +300,7 @@ namespace tools return false; } - construct_tx_param ctp = get_wallet()->get_default_construct_tx_param_inital(); + construct_tx_param ctp = w.get_wallet()->get_default_construct_tx_param_inital(); if (req.service_entries_permanent) { //put it to extra @@ -332,7 +313,7 @@ namespace tools } bool wrap = false; std::vector& dsts = ctp.dsts; - for (auto it = req.destinations.begin(); it != req.destinations.end(); it++) + for (auto it = req.destinations.begin(); it != req.destinations.end(); it++) { currency::tx_destination_entry de; de.addr.resize(1); @@ -362,7 +343,7 @@ namespace tools wrap = true; //encrypt body with a special way } - else if(!get_wallet()->get_transfer_address(it->address, de.addr.back(), embedded_payment_id)) + else if (!w.get_wallet()->get_transfer_address(it->address, de.addr.back(), embedded_payment_id)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + it->address; @@ -381,88 +362,70 @@ namespace tools de.amount = it->amount; dsts.push_back(de); } - try - { - std::vector& attachments = ctp.attachments; - std::vector& extra = ctp.extra; - if (!payment_id.empty() && !currency::set_payment_id_to_tx(attachments, payment_id)) - { - er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; - er.message = std::string("payment id ") + payment_id + " is invalid and can't be set"; - return false; - } - if (!req.comment.empty()) - { - currency::tx_comment comment = AUTO_VAL_INIT(comment); - comment.comment = req.comment; - attachments.push_back(comment); - } + std::vector& attachments = ctp.attachments; + std::vector& extra = ctp.extra; + if (!payment_id.empty() && !currency::set_payment_id_to_tx(attachments, payment_id)) + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; + er.message = std::string("payment id ") + payment_id + " is invalid and can't be set"; + return false; + } - if (req.push_payer && !wrap) - { - currency::create_and_add_tx_payer_to_container_from_address(extra, get_wallet()->get_account().get_keys().account_address, get_wallet()->get_top_block_height(), get_wallet()->get_core_runtime_config()); - } - - if (!req.hide_receiver) - { - for (auto& d : dsts) - { - for (auto& a : d.addr) - currency::create_and_add_tx_receiver_to_container_from_address(extra, a, get_wallet()->get_top_block_height(), get_wallet()->get_core_runtime_config()); - } - } + if (!req.comment.empty()) + { + currency::tx_comment comment = AUTO_VAL_INIT(comment); + comment.comment = req.comment; + attachments.push_back(comment); + } - currency::finalized_tx result = AUTO_VAL_INIT(result); - std::string unsigned_tx_blob_str; - ctp.fee = req.fee; - ctp.fake_outputs_count = req.mixin; - get_wallet()->transfer(ctp, result, true, &unsigned_tx_blob_str); - if (get_wallet()->is_watch_only()) + if (req.push_payer && !wrap) + { + currency::create_and_add_tx_payer_to_container_from_address(extra, w.get_wallet()->get_account().get_keys().account_address, w.get_wallet()->get_top_block_height(), w.get_wallet()->get_core_runtime_config()); + } + + if (!req.hide_receiver) + { + for (auto& d : dsts) { - res.tx_unsigned_hex = epee::string_tools::buff_to_hex_nodelimer(unsigned_tx_blob_str); // watch-only wallets could not sign and relay transactions - // leave res.tx_hash empty, because tx hash will change after signing + for (auto& a : d.addr) + currency::create_and_add_tx_receiver_to_container_from_address(extra, a, w.get_wallet()->get_top_block_height(), w.get_wallet()->get_core_runtime_config()); } - else - { - res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(result.tx)); - res.tx_size = get_object_blobsize(result.tx); - } - return true; } - catch (const tools::error::daemon_busy& e) + + currency::finalized_tx result = AUTO_VAL_INIT(result); + std::string unsigned_tx_blob_str; + ctp.fee = req.fee; + ctp.fake_outputs_count = req.mixin; + w.get_wallet()->transfer(ctp, result, true, &unsigned_tx_blob_str); + if (w.get_wallet()->is_watch_only()) { - er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY; - er.message = e.what(); - return false; + res.tx_unsigned_hex = epee::string_tools::buff_to_hex_nodelimer(unsigned_tx_blob_str); // watch-only wallets could not sign and relay transactions + // leave res.tx_hash empty, because tx hash will change after signing } - catch (const std::exception& e) + else { - er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; - er.message = e.what(); - return false; - } - catch (...) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR"; - return false; + res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(result.tx)); + res.tx_size = get_object_blobsize(result.tx); } return true; + + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_store(const wallet_public::COMMAND_RPC_STORE::request& req, wallet_public::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->store(); + w.get_wallet()->store(); boost::system::error_code ec = AUTO_VAL_INIT(ec); - res.wallet_file_size = get_wallet()->get_wallet_file_size(); + res.wallet_file_size = w.get_wallet()->get_wallet_file_size(); WALLET_RPC_CATCH_TRY_ENTRY(); return true; } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_get_payments(const wallet_public::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string payment_id; if (!currency::parse_payment_id_from_hex_str(req.payment_id, payment_id)) { @@ -473,7 +436,7 @@ namespace tools res.payments.clear(); std::list payment_list; - get_wallet()->get_payments(payment_id, payment_list); + w.get_wallet()->get_payments(payment_id, payment_list); for (auto payment : payment_list) { if (payment.m_unlock_time && !req.allow_locked_transactions) @@ -491,12 +454,13 @@ namespace tools rpc_payment.unlock_time = payment.m_unlock_time; res.payments.push_back(rpc_payment); } - + WALLET_RPC_CATCH_TRY_ENTRY(); return true; } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_get_bulk_payments(const wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); res.payments.clear(); for (auto & payment_id_str : req.payment_ids) @@ -510,7 +474,7 @@ namespace tools } std::list payment_list; - get_wallet()->get_payments(payment_id, payment_list, req.min_block_height); + w.get_wallet()->get_payments(payment_id, payment_list, req.min_block_height); for (auto & payment : payment_list) { @@ -531,12 +495,13 @@ namespace tools res.payments.push_back(std::move(rpc_payment)); } } - + WALLET_RPC_CATCH_TRY_ENTRY(); return true; } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_make_integrated_address(const wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string payment_id; if (!epee::string_tools::parse_hexstr_to_binbuff(req.payment_id, payment_id)) { @@ -558,14 +523,15 @@ namespace tools crypto::generate_random_bytes(payment_id.size(), &payment_id.front()); } - res.integrated_address = currency::get_account_address_and_payment_id_as_str(get_wallet()->get_account().get_public_address(), payment_id); + res.integrated_address = currency::get_account_address_and_payment_id_as_str(w.get_wallet()->get_account().get_public_address(), payment_id); res.payment_id = epee::string_tools::buff_to_hex_nodelimer(payment_id); - return !res.integrated_address.empty(); + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_split_integrated_address(const wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); currency::account_public_address addr; std::string payment_id; if (!currency::get_account_address_and_payment_id_from_str(addr, payment_id, req.integrated_address)) @@ -578,10 +544,12 @@ namespace tools res.standard_address = currency::get_account_address_as_str(addr); res.payment_id = epee::string_tools::buff_to_hex_nodelimer(payment_id); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_sweep_below(const wallet_public::COMMAND_SWEEP_BELOW::request& req, wallet_public::COMMAND_SWEEP_BELOW::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); currency::payment_id_t payment_id; if (!req.payment_id_hex.empty() && !currency::parse_payment_id_from_hex_str(req.payment_id_hex, payment_id)) { @@ -592,7 +560,7 @@ namespace tools currency::account_public_address addr; currency::payment_id_t integrated_payment_id; - if (!get_wallet()->get_transfer_address(req.address, addr, integrated_payment_id)) + if (!w.get_wallet()->get_transfer_address(req.address, addr, integrated_payment_id)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; er.message = std::string("Invalid address: ") + req.address; @@ -611,59 +579,37 @@ namespace tools payment_id = integrated_payment_id; } - if (req.fee < get_wallet()->get_core_runtime_config().tx_pool_min_fee) + if (req.fee < w.get_wallet()->get_core_runtime_config().tx_pool_min_fee) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; - er.message = std::string("Given fee is too low: ") + epee::string_tools::num_to_string_fast(req.fee) + ", minimum is: " + epee::string_tools::num_to_string_fast(get_wallet()->get_core_runtime_config().tx_pool_min_fee); + er.message = std::string("Given fee is too low: ") + epee::string_tools::num_to_string_fast(req.fee) + ", minimum is: " + epee::string_tools::num_to_string_fast(w.get_wallet()->get_core_runtime_config().tx_pool_min_fee); return false; } - try - { - currency::transaction tx = AUTO_VAL_INIT(tx); - size_t outs_total = 0, outs_swept = 0; - uint64_t amount_total = 0, amount_swept = 0; + currency::transaction tx = AUTO_VAL_INIT(tx); + size_t outs_total = 0, outs_swept = 0; + uint64_t amount_total = 0, amount_swept = 0; - std::string unsigned_tx_blob_str; - get_wallet()->sweep_below(req.mixin, addr, req.amount, payment_id, req.fee, outs_total, amount_total, outs_swept, amount_swept, &tx, &unsigned_tx_blob_str); + std::string unsigned_tx_blob_str; + w.get_wallet()->sweep_below(req.mixin, addr, req.amount, payment_id, req.fee, outs_total, amount_total, outs_swept, amount_swept, &tx, &unsigned_tx_blob_str); - res.amount_swept = amount_swept; - res.amount_total = amount_total; - res.outs_swept = outs_swept; - res.outs_total = outs_total; + res.amount_swept = amount_swept; + res.amount_total = amount_total; + res.outs_swept = outs_swept; + res.outs_total = outs_total; - if (get_wallet()->is_watch_only()) - { - res.tx_unsigned_hex = epee::string_tools::buff_to_hex_nodelimer(unsigned_tx_blob_str); // watch-only wallets can't sign and relay transactions - // leave res.tx_hash empty, because tx has will change after signing - } - else - { - res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(tx)); - } - - - } - catch (const tools::error::daemon_busy& e) + if (w.get_wallet()->is_watch_only()) { - er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY; - er.message = e.what(); - return false; + res.tx_unsigned_hex = epee::string_tools::buff_to_hex_nodelimer(unsigned_tx_blob_str); // watch-only wallets can't sign and relay transactions + // leave res.tx_hash empty, because tx has will change after signing } - catch (const std::exception& e) + else { - er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; - er.message = e.what(); - return false; - } - catch (...) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR"; - return false; + res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(tx)); } return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_sign_transfer(const wallet_public::COMMAND_SIGN_TRANSFER::request& req, wallet_public::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx) @@ -678,7 +624,7 @@ namespace tools return false; } std::string tx_signed_blob; - get_wallet()->sign_transfer(tx_unsigned_blob, tx_signed_blob, tx); + w.get_wallet()->sign_transfer(tx_unsigned_blob, tx_signed_blob, tx); res.tx_signed_hex = epee::string_tools::buff_to_hex_nodelimer(tx_signed_blob); res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx)); @@ -688,6 +634,7 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_submit_transfer(const wallet_public::COMMAND_SUBMIT_TRANSFER::request& req, wallet_public::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string tx_signed_blob; if (!string_tools::parse_hexstr_to_binbuff(req.tx_signed_hex, tx_signed_blob)) { @@ -696,9 +643,9 @@ namespace tools return false; } - WALLET_RPC_BEGIN_TRY_ENTRY(); + currency::transaction tx = AUTO_VAL_INIT(tx); - get_wallet()->submit_transfer(tx_signed_blob, tx); + w.get_wallet()->submit_transfer(tx_signed_blob, tx); res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx)); WALLET_RPC_CATCH_TRY_ENTRY(); @@ -707,10 +654,11 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); bool tx_id_specified = req.tx_id != currency::null_hash; // process confirmed txs - get_wallet()->enumerate_transfers_history([&](const wallet_public::wallet_transfer_info& wti) -> bool { + w.get_wallet()->enumerate_transfers_history([&](const wallet_public::wallet_transfer_info& wti) -> bool { if (tx_id_specified) { @@ -746,7 +694,7 @@ namespace tools // process unconfirmed txs if (req.pool) { - get_wallet()->enumerate_unconfirmed_transfers([&](const wallet_public::wallet_transfer_info& wti) -> bool { + w.get_wallet()->enumerate_unconfirmed_transfers([&](const wallet_public::wallet_transfer_info& wti) -> bool { if ((wti.is_income && req.in) || (!wti.is_income && req.out)) res.pool.push_back(wti); return true; // continue @@ -754,11 +702,14 @@ namespace tools } return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } bool wallet_rpc_server::on_get_mining_history(const wallet_public::COMMAND_RPC_GET_MINING_HISTORY::request& req, wallet_public::COMMAND_RPC_GET_MINING_HISTORY::response& res, epee::json_rpc::error& er, connection_context& cntx) { - get_wallet()->get_mining_history(res, req.v); + WALLET_RPC_BEGIN_TRY_ENTRY(); + w.get_wallet()->get_mining_history(res, req.v); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_register_alias(const wallet_public::COMMAND_RPC_REGISTER_ALIAS::request& req, wallet_public::COMMAND_RPC_REGISTER_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx) @@ -780,7 +731,7 @@ namespace tools } currency::transaction tx = AUTO_VAL_INIT(tx); - get_wallet()->request_alias_registration(ai, tx, get_wallet()->get_default_fee(), 0, req.authority_key); + w.get_wallet()->request_alias_registration(ai, tx, w.get_wallet()->get_default_fee(), 0, req.authority_key); res.tx_id = get_transaction_hash(tx); return true; WALLET_RPC_CATCH_TRY_ENTRY(); @@ -791,7 +742,7 @@ namespace tools WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction tx = AUTO_VAL_INIT(tx); currency::transaction template_tx = AUTO_VAL_INIT(template_tx); - get_wallet()->send_escrow_proposal(req, tx, template_tx); + w.get_wallet()->send_escrow_proposal(req, tx, template_tx); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -799,7 +750,7 @@ namespace tools bool wallet_rpc_server::on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->accept_proposal(req.contract_id, req.acceptance_fee); + w.get_wallet()->accept_proposal(req.contract_id, req.acceptance_fee); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -808,7 +759,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); tools::wallet2::escrow_contracts_container ecc; - get_wallet()->get_contracts(ecc); + w.get_wallet()->get_contracts(ecc); res.contracts.resize(ecc.size()); size_t i = 0; for (auto& c : ecc) @@ -824,7 +775,7 @@ namespace tools bool wallet_rpc_server::on_contracts_release(const wallet_public::COMMAND_CONTRACTS_RELEASE::request& req, wallet_public::COMMAND_CONTRACTS_RELEASE::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->finish_contract(req.contract_id, req.release_type); + w.get_wallet()->finish_contract(req.contract_id, req.release_type); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -832,7 +783,7 @@ namespace tools bool wallet_rpc_server::on_contracts_request_cancel(const wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->request_cancel_contract(req.contract_id, req.fee, req.expiration_period); + w.get_wallet()->request_cancel_contract(req.contract_id, req.fee, req.expiration_period); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -840,7 +791,7 @@ namespace tools bool wallet_rpc_server::on_contracts_accept_cancel(const wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->accept_cancel_contract(req.contract_id); + w.get_wallet()->accept_cancel_contract(req.contract_id); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -848,9 +799,9 @@ namespace tools bool wallet_rpc_server::on_marketplace_get_my_offers(const wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::request& req, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->get_actual_offers(res.offers); + w.get_wallet()->get_actual_offers(res.offers); size_t offers_count_before_filtering = res.offers.size(); - bc_services::filter_offers_list(res.offers, req.filter, get_wallet()->get_core_runtime_config().get_core_time()); + bc_services::filter_offers_list(res.offers, req.filter, w.get_wallet()->get_core_runtime_config().get_core_time()); LOG_PRINT("get_my_offers(): " << res.offers.size() << " offers returned (" << offers_count_before_filtering << " was before filter)", LOG_LEVEL_1); return true; WALLET_RPC_CATCH_TRY_ENTRY(); @@ -860,7 +811,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - get_wallet()->push_offer(req.od, res_tx); + w.get_wallet()->push_offer(req.od, res_tx); res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(res_tx)); res.tx_blob_size = currency::get_object_blobsize(res_tx); @@ -873,7 +824,7 @@ namespace tools WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - get_wallet()->update_offer_by_id(req.tx_id, req.no, req.od, res_tx); + w.get_wallet()->update_offer_by_id(req.tx_id, req.no, req.od, res_tx); res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(res_tx)); res.tx_blob_size = currency::get_object_blobsize(res_tx); @@ -885,7 +836,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - get_wallet()->cancel_offer_by_id(req.tx_id, req.no, req.fee, res_tx); + w.get_wallet()->cancel_offer_by_id(req.tx_id, req.no, req.fee, res_tx); res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(res_tx)); res.tx_blob_size = currency::get_object_blobsize(res_tx); @@ -897,7 +848,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction tx = AUTO_VAL_INIT(tx); - get_wallet()->create_htlc_proposal(req.amount, req.counterparty_address, req.lock_blocks_count, tx, req.htlc_hash, res.derived_origin_secret); + w.get_wallet()->create_htlc_proposal(req.amount, req.counterparty_address, req.lock_blocks_count, tx, req.htlc_hash, res.derived_origin_secret); res.result_tx_blob = currency::tx_to_blob(tx); res.result_tx_id = get_transaction_hash(tx); WALLET_RPC_CATCH_TRY_ENTRY(); @@ -907,7 +858,7 @@ namespace tools bool wallet_rpc_server::on_get_list_of_active_htlc(const wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC::request& req, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->get_list_of_active_htlc(res.htlcs, req.income_redeem_only); + w.get_wallet()->get_list_of_active_htlc(res.htlcs, req.income_redeem_only); WALLET_RPC_CATCH_TRY_ENTRY(); return true; } @@ -916,7 +867,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction tx = AUTO_VAL_INIT(tx); - get_wallet()->redeem_htlc(req.tx_id, req.origin_secret, tx); + w.get_wallet()->redeem_htlc(req.tx_id, req.origin_secret, tx); res.result_tx_blob = currency::tx_to_blob(tx); res.result_tx_id = get_transaction_hash(tx); WALLET_RPC_CATCH_TRY_ENTRY(); @@ -926,16 +877,17 @@ namespace tools bool wallet_rpc_server::on_check_htlc_redeemed(const wallet_public::COMMAND_CHECK_HTLC_REDEEMED::request& req, wallet_public::COMMAND_CHECK_HTLC_REDEEMED::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - get_wallet()->check_htlc_redeemed(req.htlc_tx_id, res.origin_secrete, res.redeem_tx_id); + w.get_wallet()->check_htlc_redeemed(req.htlc_tx_id, res.origin_secrete, res.redeem_tx_id); WALLET_RPC_CATCH_TRY_ENTRY(); return true; } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_ionic_swap_generate_proposal(const wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL::request& req, wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); currency::account_public_address destination_addr = AUTO_VAL_INIT(destination_addr); currency::payment_id_t integrated_payment_id; - if (!get_wallet()->get_transfer_address(req.destination_address, destination_addr, integrated_payment_id)) + if (!w.get_wallet()->get_transfer_address(req.destination_address, destination_addr, integrated_payment_id)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; er.message = "WALLET_RPC_ERROR_CODE_WRONG_ADDRESS"; @@ -949,7 +901,7 @@ namespace tools } wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); - bool r = get_wallet()->create_ionic_swap_proposal(req.proposal, destination_addr, proposal); + bool r = w.get_wallet()->create_ionic_swap_proposal(req.proposal, destination_addr, proposal); if (!r) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; @@ -958,10 +910,12 @@ namespace tools } res.hex_raw_proposal = epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(proposal)); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_ionic_swap_get_proposal_info(const wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO::request& req, wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string raw_tx_template; bool r = epee::string_tools::parse_hexstr_to_binbuff(req.hex_raw_proposal, raw_tx_template); if (!r) @@ -971,18 +925,19 @@ namespace tools return false; } - if (!get_wallet()->get_ionic_swap_proposal_info(raw_tx_template, res.proposal)) + if (!w.get_wallet()->get_ionic_swap_proposal_info(raw_tx_template, res.proposal)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; er.message = "WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT - get_ionic_swap_proposal_info"; return false; } return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_ionic_swap_accept_proposal(const wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx) { - + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string raw_tx_template; bool r = epee::string_tools::parse_hexstr_to_binbuff(req.hex_raw_proposal, raw_tx_template); if (!r) @@ -993,7 +948,7 @@ namespace tools } currency::transaction result_tx = AUTO_VAL_INIT(result_tx); - if (!get_wallet()->accept_ionic_swap_proposal(raw_tx_template, result_tx)) + if (!w.get_wallet()->accept_ionic_swap_proposal(raw_tx_template, result_tx)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; er.message = "WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT - failed to accept_ionic_swap_proposal()"; @@ -1002,11 +957,13 @@ namespace tools res.result_tx_id = currency::get_transaction_hash(result_tx); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_mw_get_wallets(const wallet_public::COMMAND_MW_GET_WALLETS::request& req, wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, connection_context& cntx) { - i_wallet2_callback* pcallback = get_wallet()->get_callback(); + WALLET_RPC_BEGIN_TRY_ENTRY(); + i_wallet2_callback* pcallback = w.get_wallet()->get_callback(); if (!pcallback) { er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; @@ -1015,11 +972,13 @@ namespace tools } pcallback->on_mw_get_wallets(res.wallets); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_mw_select_wallet(const wallet_public::COMMAND_MW_SELECT_WALLET::request& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx) { - i_wallet2_callback* pcallback = get_wallet()->get_callback(); + WALLET_RPC_BEGIN_TRY_ENTRY(); + i_wallet2_callback* pcallback = w.get_wallet()->get_callback(); if (!pcallback) { er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; @@ -1028,19 +987,23 @@ namespace tools } pcallback->on_mw_select_wallet(req.wallet_id); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_sign_message(const wallet_public::COMMAND_SIGN_MESSAGE::request& req, wallet_public::COMMAND_SIGN_MESSAGE::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string buff = epee::string_encoding::base64_decode(req.buff); - get_wallet()->sign_buffer(buff, res.sig); + w.get_wallet()->sign_buffer(buff, res.sig); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_validate_signature(const wallet_public::COMMAND_VALIDATE_SIGNATURE::request& req, wallet_public::COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string buff = epee::string_encoding::base64_decode(req.buff); - bool r = get_wallet()->validate_sign(buff, req.sig, req.pkey); + bool r = w.get_wallet()->validate_sign(buff, req.sig, req.pkey); if (!r) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; @@ -1048,28 +1011,33 @@ namespace tools return false; } return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_encrypt_data(const wallet_public::COMMAND_ENCRYPT_DATA::request& req, wallet_public::COMMAND_ENCRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string buff = epee::string_encoding::base64_decode(req.buff); - bool r = get_wallet()->encrypt_buffer(buff, res.res_buff); + bool r = w.get_wallet()->encrypt_buffer(buff, res.res_buff); res.res_buff = epee::string_encoding::base64_encode(res.res_buff); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_decrypt_data(const wallet_public::COMMAND_DECRYPT_DATA::request& req, wallet_public::COMMAND_DECRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx) { + WALLET_RPC_BEGIN_TRY_ENTRY(); std::string buff = epee::string_encoding::base64_decode(req.buff); - bool r = get_wallet()->encrypt_buffer(buff, res.res_buff); + bool r = w.get_wallet()->encrypt_buffer(buff, res.res_buff); res.res_buff = epee::string_encoding::base64_encode(res.res_buff); return true; + WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ - bool wallet_rpc_server::reset_active_wallet(std::shared_ptr w) - { - m_pwallet = w; - return true; - } +// bool wallet_rpc_server::reset_active_wallet(std::shared_ptr w) +// { +// m_pwallet = w; +// return true; +// } //------------------------------------------------------------------------------------------------------------------------------ } // namespace tools diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index b72c93de..653c592b 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -14,15 +14,65 @@ #include "common/command_line.h" namespace tools { + + + + struct i_wallet_provider + { + virtual void lock() {}; + virtual void unlock() {}; + virtual std::shared_ptr get_wallet() = 0; + }; + + struct wallet_rpc_locker + { + wallet_rpc_locker(std::shared_ptr wallet_provider) :m_pwallet_provider(wallet_provider) + { + m_wallet_ptr = get_wallet(); + if (!m_wallet_ptr.get()) + { + throw std::runtime_error("Wallet object closed"); + } + m_pwallet_provider->lock(); + } + + std::shared_ptr get_wallet() { return m_wallet_ptr; } + + ~wallet_rpc_locker() + { + m_pwallet_provider->unlock(); + } + + private: + std::shared_ptr m_wallet_ptr; + std::shared_ptr m_pwallet_provider; + }; + + + struct wallet_provider_simple : public i_wallet_provider + { + wallet_provider_simple(std::shared_ptr wallet_ptr) : m_wallet_ptr(wallet_ptr) + {} + virtual std::shared_ptr get_wallet() + { + return m_wallet_ptr; + } + + private: + std::shared_ptr m_wallet_ptr; + }; + + /************************************************************************/ /* */ /************************************************************************/ - class wallet_rpc_server: public epee::http_server_impl_base + class wallet_rpc_server : public epee::http_server_impl_base { public: typedef epee::net_utils::connection_context_base connection_context; wallet_rpc_server(std::shared_ptr wptr); + wallet_rpc_server(std::shared_ptr provider_ptr); const static command_line::arg_descriptor arg_rpc_bind_port; const static command_line::arg_descriptor arg_rpc_bind_ip; @@ -36,125 +86,125 @@ namespace tools bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context); BEGIN_URI_MAP2() - BEGIN_JSON_RPC_MAP("/json_rpc") - MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_public::COMMAND_RPC_GET_BALANCE) - MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_public::COMMAND_RPC_GET_ADDRESS) - MAP_JON_RPC_WE("get_wallet_info", on_getwallet_info, wallet_public::COMMAND_RPC_GET_WALLET_INFO) - MAP_JON_RPC_WE("get_recent_txs_and_info", on_get_recent_txs_and_info, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO) - MAP_JON_RPC_WE("transfer", on_transfer, wallet_public::COMMAND_RPC_TRANSFER) - MAP_JON_RPC_WE("store", on_store, wallet_public::COMMAND_RPC_STORE) - MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_public::COMMAND_RPC_GET_PAYMENTS) - MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS) - MAP_JON_RPC_WE("make_integrated_address", on_make_integrated_address, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS) - MAP_JON_RPC_WE("split_integrated_address", on_split_integrated_address, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS) - MAP_JON_RPC_WE("sweep_below", on_sweep_below, wallet_public::COMMAND_SWEEP_BELOW) - MAP_JON_RPC_WE("sign_transfer", on_sign_transfer, wallet_public::COMMAND_SIGN_TRANSFER) - MAP_JON_RPC_WE("submit_transfer", on_submit_transfer, wallet_public::COMMAND_SUBMIT_TRANSFER) - MAP_JON_RPC_WE("search_for_transactions", on_search_for_transactions, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS) - MAP_JON_RPC_WE("get_restore_info", on_getwallet_restore_info, wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO) - MAP_JON_RPC_WE("get_seed_phrase_info", on_get_seed_phrase_info, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO) - MAP_JON_RPC_WE("get_mining_history", on_get_mining_history, wallet_public::COMMAND_RPC_GET_MINING_HISTORY) - MAP_JON_RPC_WE("register_alias", on_register_alias, wallet_public::COMMAND_RPC_REGISTER_ALIAS) - //contracts API - MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL) - MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL) - MAP_JON_RPC_WE("contracts_get_all", on_contracts_get_all, wallet_public::COMMAND_CONTRACTS_GET_ALL) - MAP_JON_RPC_WE("contracts_release", on_contracts_release, wallet_public::COMMAND_CONTRACTS_RELEASE) - MAP_JON_RPC_WE("contracts_request_cancel", on_contracts_request_cancel, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL) - MAP_JON_RPC_WE("contracts_accept_cancel", on_contracts_accept_cancel, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL) - //marketplace API - MAP_JON_RPC_WE("marketplace_get_offers_ex", on_marketplace_get_my_offers, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS) - MAP_JON_RPC_WE("marketplace_push_offer", on_marketplace_push_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER) - MAP_JON_RPC_WE("marketplace_push_update_offer", on_marketplace_push_update_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER) - MAP_JON_RPC_WE("marketplace_cancel_offer", on_marketplace_cancel_offer, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER) - //HTLC API - MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL) - MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC) - MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC) - MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED) + BEGIN_JSON_RPC_MAP("/json_rpc") + MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_public::COMMAND_RPC_GET_BALANCE) + MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_public::COMMAND_RPC_GET_ADDRESS) + MAP_JON_RPC_WE("get_wallet_info", on_getwallet_info, wallet_public::COMMAND_RPC_GET_WALLET_INFO) + MAP_JON_RPC_WE("get_recent_txs_and_info", on_get_recent_txs_and_info, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO) + MAP_JON_RPC_WE("transfer", on_transfer, wallet_public::COMMAND_RPC_TRANSFER) + MAP_JON_RPC_WE("store", on_store, wallet_public::COMMAND_RPC_STORE) + MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_public::COMMAND_RPC_GET_PAYMENTS) + MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS) + MAP_JON_RPC_WE("make_integrated_address", on_make_integrated_address, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS) + MAP_JON_RPC_WE("split_integrated_address", on_split_integrated_address, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS) + MAP_JON_RPC_WE("sweep_below", on_sweep_below, wallet_public::COMMAND_SWEEP_BELOW) + MAP_JON_RPC_WE("sign_transfer", on_sign_transfer, wallet_public::COMMAND_SIGN_TRANSFER) + MAP_JON_RPC_WE("submit_transfer", on_submit_transfer, wallet_public::COMMAND_SUBMIT_TRANSFER) + MAP_JON_RPC_WE("search_for_transactions", on_search_for_transactions, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS) + MAP_JON_RPC_WE("get_restore_info", on_getwallet_restore_info, wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO) + MAP_JON_RPC_WE("get_seed_phrase_info", on_get_seed_phrase_info, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO) + MAP_JON_RPC_WE("get_mining_history", on_get_mining_history, wallet_public::COMMAND_RPC_GET_MINING_HISTORY) + MAP_JON_RPC_WE("register_alias", on_register_alias, wallet_public::COMMAND_RPC_REGISTER_ALIAS) + //contracts API + MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL) + MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL) + MAP_JON_RPC_WE("contracts_get_all", on_contracts_get_all, wallet_public::COMMAND_CONTRACTS_GET_ALL) + MAP_JON_RPC_WE("contracts_release", on_contracts_release, wallet_public::COMMAND_CONTRACTS_RELEASE) + MAP_JON_RPC_WE("contracts_request_cancel", on_contracts_request_cancel, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL) + MAP_JON_RPC_WE("contracts_accept_cancel", on_contracts_accept_cancel, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL) + //marketplace API + MAP_JON_RPC_WE("marketplace_get_offers_ex", on_marketplace_get_my_offers, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS) + MAP_JON_RPC_WE("marketplace_push_offer", on_marketplace_push_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER) + MAP_JON_RPC_WE("marketplace_push_update_offer", on_marketplace_push_update_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER) + MAP_JON_RPC_WE("marketplace_cancel_offer", on_marketplace_cancel_offer, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER) + //HTLC API + MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL) + MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC) + MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC) + MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED) - //IONIC_SWAPS API - MAP_JON_RPC_WE("ionic_swap_generate_proposal", on_ionic_swap_generate_proposal, wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL) - MAP_JON_RPC_WE("ionic_swap_get_proposal_info", on_ionic_swap_get_proposal_info, wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO) - MAP_JON_RPC_WE("ionic_swap_accept_proposal", on_ionic_swap_accept_proposal, wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL) + //IONIC_SWAPS API + MAP_JON_RPC_WE("ionic_swap_generate_proposal", on_ionic_swap_generate_proposal, wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL) + MAP_JON_RPC_WE("ionic_swap_get_proposal_info", on_ionic_swap_get_proposal_info, wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO) + MAP_JON_RPC_WE("ionic_swap_accept_proposal", on_ionic_swap_accept_proposal, wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL) - //MULTIWALLET APIs - MAP_JON_RPC_WE("mw_get_wallets", on_mw_get_wallets, wallet_public::COMMAND_MW_GET_WALLETS) - MAP_JON_RPC_WE("mw_select_wallet", on_mw_select_wallet, wallet_public::COMMAND_MW_SELECT_WALLET) + //MULTIWALLET APIs + MAP_JON_RPC_WE("mw_get_wallets", on_mw_get_wallets, wallet_public::COMMAND_MW_GET_WALLETS) + MAP_JON_RPC_WE("mw_select_wallet", on_mw_select_wallet, wallet_public::COMMAND_MW_SELECT_WALLET) - //basic crypto operations - MAP_JON_RPC_WE("sign_message", on_sign_message, wallet_public::COMMAND_SIGN_MESSAGE) - MAP_JON_RPC_WE("validate_signature", on_validate_signature, wallet_public::COMMAND_VALIDATE_SIGNATURE) - MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA) - MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA) - END_JSON_RPC_MAP() + //basic crypto operations + MAP_JON_RPC_WE("sign_message", on_sign_message, wallet_public::COMMAND_SIGN_MESSAGE) + MAP_JON_RPC_WE("validate_signature", on_validate_signature, wallet_public::COMMAND_VALIDATE_SIGNATURE) + MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA) + MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA) + END_JSON_RPC_MAP() END_URI_MAP2() //json_rpc bool on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_getwallet_info(const wallet_public::COMMAND_RPC_GET_WALLET_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_getwallet_restore_info(const wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_get_seed_phrase_info(const wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO::request& req, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_get_recent_txs_and_info(const wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request& req, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_store(const wallet_public::COMMAND_RPC_STORE::request& req, wallet_public::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_get_payments(const wallet_public::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_get_bulk_payments(const wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_make_integrated_address(const wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_split_integrated_address(const wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_sweep_below(const wallet_public::COMMAND_SWEEP_BELOW::request& req, wallet_public::COMMAND_SWEEP_BELOW::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_sign_transfer(const wallet_public::COMMAND_SIGN_TRANSFER::request& req, wallet_public::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_submit_transfer(const wallet_public::COMMAND_SUBMIT_TRANSFER::request& req, wallet_public::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_get_mining_history(const wallet_public::COMMAND_RPC_GET_MINING_HISTORY::request& req, wallet_public::COMMAND_RPC_GET_MINING_HISTORY::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_register_alias(const wallet_public::COMMAND_RPC_REGISTER_ALIAS::request& req, wallet_public::COMMAND_RPC_REGISTER_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx); - - - bool on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_contracts_get_all(const wallet_public::COMMAND_CONTRACTS_GET_ALL::request& req, wallet_public::COMMAND_CONTRACTS_GET_ALL::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_contracts_release(const wallet_public::COMMAND_CONTRACTS_RELEASE::request& req, wallet_public::COMMAND_CONTRACTS_RELEASE::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_contracts_request_cancel(const wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_contracts_accept_cancel(const wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_getwallet_info(const wallet_public::COMMAND_RPC_GET_WALLET_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_getwallet_restore_info(const wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_get_seed_phrase_info(const wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO::request& req, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_get_recent_txs_and_info(const wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request& req, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_store(const wallet_public::COMMAND_RPC_STORE::request& req, wallet_public::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_get_payments(const wallet_public::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_get_bulk_payments(const wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_make_integrated_address(const wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_split_integrated_address(const wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_sweep_below(const wallet_public::COMMAND_SWEEP_BELOW::request& req, wallet_public::COMMAND_SWEEP_BELOW::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_sign_transfer(const wallet_public::COMMAND_SIGN_TRANSFER::request& req, wallet_public::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_submit_transfer(const wallet_public::COMMAND_SUBMIT_TRANSFER::request& req, wallet_public::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_get_mining_history(const wallet_public::COMMAND_RPC_GET_MINING_HISTORY::request& req, wallet_public::COMMAND_RPC_GET_MINING_HISTORY::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_register_alias(const wallet_public::COMMAND_RPC_REGISTER_ALIAS::request& req, wallet_public::COMMAND_RPC_REGISTER_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_marketplace_get_my_offers(const wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::request& req, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_marketplace_push_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_marketplace_push_update_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_marketplace_cancel_offer(const wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_create_htlc_proposal(const wallet_public::COMMAND_CREATE_HTLC_PROPOSAL::request& req, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_get_list_of_active_htlc(const wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC::request& req, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_redeem_htlc(const wallet_public::COMMAND_REDEEM_HTLC::request& req, wallet_public::COMMAND_REDEEM_HTLC::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_check_htlc_redeemed(const wallet_public::COMMAND_CHECK_HTLC_REDEEMED::request& req, wallet_public::COMMAND_CHECK_HTLC_REDEEMED::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_contracts_get_all(const wallet_public::COMMAND_CONTRACTS_GET_ALL::request& req, wallet_public::COMMAND_CONTRACTS_GET_ALL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_contracts_release(const wallet_public::COMMAND_CONTRACTS_RELEASE::request& req, wallet_public::COMMAND_CONTRACTS_RELEASE::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_contracts_request_cancel(const wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_contracts_accept_cancel(const wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_ionic_swap_generate_proposal(const wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL::request& req, wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_ionic_swap_get_proposal_info(const wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO::request& req, wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_ionic_swap_accept_proposal(const wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_marketplace_get_my_offers(const wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::request& req, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_marketplace_push_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_marketplace_push_update_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_marketplace_cancel_offer(const wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_mw_get_wallets(const wallet_public::COMMAND_MW_GET_WALLETS::request& req, wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_mw_select_wallet(const wallet_public::COMMAND_MW_SELECT_WALLET::request& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_create_htlc_proposal(const wallet_public::COMMAND_CREATE_HTLC_PROPOSAL::request& req, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_get_list_of_active_htlc(const wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC::request& req, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_redeem_htlc(const wallet_public::COMMAND_REDEEM_HTLC::request& req, wallet_public::COMMAND_REDEEM_HTLC::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_check_htlc_redeemed(const wallet_public::COMMAND_CHECK_HTLC_REDEEMED::request& req, wallet_public::COMMAND_CHECK_HTLC_REDEEMED::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_sign_message(const wallet_public::COMMAND_SIGN_MESSAGE::request& req, wallet_public::COMMAND_SIGN_MESSAGE::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_validate_signature(const wallet_public::COMMAND_VALIDATE_SIGNATURE::request& req, wallet_public::COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_encrypt_data(const wallet_public::COMMAND_ENCRYPT_DATA::request& req, wallet_public::COMMAND_ENCRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_decrypt_data(const wallet_public::COMMAND_DECRYPT_DATA::request& req, wallet_public::COMMAND_DECRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_ionic_swap_generate_proposal(const wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL::request& req, wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_ionic_swap_get_proposal_info(const wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO::request& req, wallet_public::COMMAND_IONIC_SWAP_GET_PROPOSAL_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_ionic_swap_accept_proposal(const wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_IONIC_SWAP_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); + + bool on_mw_get_wallets(const wallet_public::COMMAND_MW_GET_WALLETS::request& req, wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_mw_select_wallet(const wallet_public::COMMAND_MW_SELECT_WALLET::request& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx); + + bool on_sign_message(const wallet_public::COMMAND_SIGN_MESSAGE::request& req, wallet_public::COMMAND_SIGN_MESSAGE::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_validate_signature(const wallet_public::COMMAND_VALIDATE_SIGNATURE::request& req, wallet_public::COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_encrypt_data(const wallet_public::COMMAND_ENCRYPT_DATA::request& req, wallet_public::COMMAND_ENCRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_decrypt_data(const wallet_public::COMMAND_DECRYPT_DATA::request& req, wallet_public::COMMAND_DECRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); - std::shared_ptr get_wallet(); - - bool reset_active_wallet(std::shared_ptr w); + //std::shared_ptr get_wallet(); - bool handle_command_line(const boost::program_options::variables_map& vm); + //bool reset_active_wallet(std::shared_ptr w); + + bool handle_command_line(const boost::program_options::variables_map& vm); private: - std::weak_ptr m_pwallet; - std::string m_port; - std::string m_bind_ip; - bool m_do_mint; - bool m_deaf; - uint64_t m_last_wallet_store_height; + std::shared_ptr m_pwallet_provider; + std::string m_port; + std::string m_bind_ip; + bool m_do_mint; + bool m_deaf; + uint64_t m_last_wallet_store_height; }; } // namespace tools From 3fec14f95e2ae69bbfe7c436d338a0ba8233d873 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 24 May 2023 23:43:44 +0200 Subject: [PATCH 06/20] Implemented multiple map rpc processing(lets chain RPC processing to different handlers maps in different objects) --- .../include/net/http_server_handlers_map2.h | 27 ++++++++++ contrib/epee/include/sync_locked_object.h | 2 + src/rpc/core_rpc_server.h | 4 ++ src/wallet/wallet_rpc_server.cpp | 5 +- src/wallet/wallet_rpc_server.h | 18 ++++--- src/wallet/wallets_manager.cpp | 49 ++++++++++++++++++- src/wallet/wallets_manager.h | 26 +++++++++- 7 files changed, 118 insertions(+), 13 deletions(-) diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index 6b45950a..5f002c42 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -29,6 +29,7 @@ #include "serialization/keyvalue_serialization.h" #include "storages/portable_storage_template_helper.h" #include "http_base.h" +#include "net/net_utils_base.h" template bool auto_doc_t(const std::string& prefix_name, std::string& generate_reference) @@ -51,6 +52,20 @@ bool auto_doc(const std::string& prefix_name, std::string& generate_reference) return auto_doc_t(prefix_name, generate_reference); } +namespace epee { + namespace net_utils { + namespace http { + struct i_chain_handler + { + virtual bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response_info, + epee::net_utils::connection_context_base& m_conn_context, bool& call_found, std::string& generate_reference) = 0; + }; + } + } +} + + + #define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \ epee::net_utils::http::http_response_info& response, \ @@ -73,6 +88,13 @@ bool auto_doc(const std::string& prefix_name, std::string& generate_reference) call_found = false; \ if(false) return true; //just a stub to have "else if" +#define BEGIN_URI_MAP2_VIRTUAL() virtual bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \ + epee::net_utils::http::http_response_info& response_info, \ + epee::net_utils::connection_context_base& m_conn_context, bool& call_found, std::string& generate_reference) { \ + call_found = false; \ + if(false) return true; //just a stub to have "else if" + + #define MAP_URI2(pattern, callback) else if(std::string::npos != query_info.m_URI.find(pattern)) return callback(query_info, response_info, m_conn_context); #define MAP_URI_AUTO_XML2(s_pattern, callback_f, command_type) //TODO: don't think i ever again will use xml - ambiguous and "overtagged" format @@ -117,6 +139,8 @@ bool auto_doc(const std::string& prefix_name, std::string& generate_reference) LOG_PRINT( "[HTTP/BIN][" << epee::string_tools::get_ip_string_from_int32(m_conn_context.m_remote_ip ) << "][" << query_info.m_URI << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \ } +#define CHAIN_TO_PHANDLER(pi_chain_handler) else if (pi_chain_handler && pi_chain_handler->handle_http_request_map(query_info, response_info, m_conn_context, call_found, generate_reference) && call_found) { return true;} + #define CHAIN_URI_MAP2(callback) else {callback(query_info, response_info, m_conn_context);call_found = true;} #define END_URI_MAP2() return true;} @@ -287,6 +311,7 @@ struct json_command_type_t #define MAP_JON_RPC_WE(method_name, callback_f, command_type) \ else if(auto_doc>("[" method_name "]", generate_reference) && callback_name == method_name) \ { \ + call_found = true; \ PREPARE_OBJECTS_FROM_JSON(command_type) \ epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \ fail_resp.jsonrpc = "2.0"; \ @@ -304,6 +329,7 @@ struct json_command_type_t #define MAP_JON_RPC_WERI(method_name, callback_f, command_type) \ else if(auto_doc>("[" method_name "]", generate_reference) && callback_name == method_name) \ { \ + call_found = true; \ PREPARE_OBJECTS_FROM_JSON(command_type) \ epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \ fail_resp.jsonrpc = "2.0"; \ @@ -321,6 +347,7 @@ struct json_command_type_t #define MAP_JON_RPC(method_name, callback_f, command_type) \ else if(auto_doc>(std::string("[") + method_name + "]", generate_reference) && callback_name == method_name) \ { \ + call_found = true; \ PREPARE_OBJECTS_FROM_JSON(command_type) \ if(!callback_f(req.params, resp.result, m_conn_context)) \ { \ diff --git a/contrib/epee/include/sync_locked_object.h b/contrib/epee/include/sync_locked_object.h index 2980bbb7..aa01e110 100644 --- a/contrib/epee/include/sync_locked_object.h +++ b/contrib/epee/include/sync_locked_object.h @@ -84,6 +84,8 @@ namespace epee template friend class locked_object_proxy; public: + typedef std::shared_ptr> lock_shared_ptr; + std::shared_ptr> lock() { std::shared_ptr> res; diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 4e52d22d..f6cf669c 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -37,6 +37,7 @@ namespace currency static void init_options(boost::program_options::options_description& desc); bool init(const boost::program_options::variables_map& vm); + void set_rpc_chain_handler(epee::net_utils::http::i_chain_handler* prpc_chain_handler) { m_prpc_chain_handler = prpc_chain_handler; } bool on_get_blocks_direct(const COMMAND_RPC_GET_BLOCKS_DIRECT::request& req, COMMAND_RPC_GET_BLOCKS_DIRECT::response& res, connection_context& cntx); @@ -149,7 +150,9 @@ namespace currency MAP_JON_RPC ("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN) // MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX) + CHAIN_TO_PHANDLER(m_prpc_chain_handler) END_JSON_RPC_MAP() + CHAIN_TO_PHANDLER(m_prpc_chain_handler) END_URI_MAP2() private: @@ -170,6 +173,7 @@ namespace currency std::string m_port; std::string m_bind_ip; bool m_ignore_status; + epee::net_utils::http::i_chain_handler* m_prpc_chain_handler = nullptr; }; } diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index a5068051..98a3a5ab 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -59,13 +59,14 @@ namespace tools } //------------------------------------------------------------------------------------------------------------------------------ wallet_rpc_server::wallet_rpc_server(std::shared_ptr wptr): - m_pwallet_provider(new wallet_provider_simple(wptr)) + m_pwallet_provider_sh_ptr(new wallet_provider_simple(wptr)) + , m_pwallet_provider(m_pwallet_provider_sh_ptr.get()) , m_do_mint(false) , m_deaf(false) , m_last_wallet_store_height(0) {} //------------------------------------------------------------------------------------------------------------------------------ - wallet_rpc_server::wallet_rpc_server(std::shared_ptr provider_ptr): + wallet_rpc_server::wallet_rpc_server(i_wallet_provider* provider_ptr): m_pwallet_provider(provider_ptr) , m_do_mint(false) , m_deaf(false) diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 653c592b..f0c4e178 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -26,14 +26,15 @@ namespace tools struct wallet_rpc_locker { - wallet_rpc_locker(std::shared_ptr wallet_provider) :m_pwallet_provider(wallet_provider) + wallet_rpc_locker(i_wallet_provider* wallet_provider) :m_pwallet_provider(wallet_provider) { - m_wallet_ptr = get_wallet(); + m_pwallet_provider->lock(); + + m_wallet_ptr = m_pwallet_provider->get_wallet(); if (!m_wallet_ptr.get()) { throw std::runtime_error("Wallet object closed"); } - m_pwallet_provider->lock(); } std::shared_ptr get_wallet() { return m_wallet_ptr; } @@ -45,7 +46,7 @@ namespace tools private: std::shared_ptr m_wallet_ptr; - std::shared_ptr m_pwallet_provider; + i_wallet_provider* m_pwallet_provider; }; @@ -66,13 +67,13 @@ namespace tools /************************************************************************/ /* */ /************************************************************************/ - class wallet_rpc_server : public epee::http_server_impl_base + class wallet_rpc_server : public epee::http_server_impl_base, public epee::net_utils::http::i_chain_handler { public: typedef epee::net_utils::connection_context_base connection_context; wallet_rpc_server(std::shared_ptr wptr); - wallet_rpc_server(std::shared_ptr provider_ptr); + wallet_rpc_server(i_wallet_provider* provider_ptr); const static command_line::arg_descriptor arg_rpc_bind_port; const static command_line::arg_descriptor arg_rpc_bind_ip; @@ -85,7 +86,7 @@ namespace tools bool run(bool do_mint, bool offline_mode, const currency::account_public_address& miner_address); bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context); - BEGIN_URI_MAP2() + BEGIN_URI_MAP2_VIRTUAL() BEGIN_JSON_RPC_MAP("/json_rpc") MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_public::COMMAND_RPC_GET_BALANCE) MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_public::COMMAND_RPC_GET_ADDRESS) @@ -199,7 +200,8 @@ namespace tools bool handle_command_line(const boost::program_options::variables_map& vm); private: - std::shared_ptr m_pwallet_provider; + std::shared_ptr m_pwallet_provider_sh_ptr; + i_wallet_provider* m_pwallet_provider; std::string m_port; std::string m_bind_ip; bool m_do_mint; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index d8159122..c98ef0a2 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -73,6 +73,7 @@ wallets_manager::wallets_manager():m_pview(&m_view_stub), m_rpc_server(m_ccore, m_p2psrv, m_offers_service), m_rpc_proxy(new tools::core_fast_rpc_proxy(m_rpc_server)), m_offers_service(nullptr), + m_wallet_rpc_server(this), #else m_rpc_proxy(new tools::default_http_core_proxy()), #endif @@ -545,6 +546,11 @@ bool wallets_manager::init_local_daemon() CHECK_AND_ASSERT_AND_SET_GUI(res, "Failed to initialize core rpc server."); LOG_PRINT_GREEN("Core rpc server initialized OK on port: " << m_rpc_server.get_binded_port(), LOG_LEVEL_0); + //chain calls to rpc server + m_prpc_chain_handler = &m_wallet_rpc_server; + m_rpc_server.set_rpc_chain_handler(this); + + LOG_PRINT_L0("Starting core rpc server..."); //dsi.text_state = "Starting core rpc server"; m_pview->update_daemon_status(dsi); @@ -2043,12 +2049,51 @@ bool wallets_manager::on_mw_select_wallet(uint64_t wallet_id) auto it = m_wallets.find(wallet_id); if (it == m_wallets.end()) return false; - auto& wo = it->second; - //m_wallet_rpc_server.reset_active_wallet(wo.w); + + m_rpc_selected_wallet_id = wallet_id; return false; } +bool wallets_manager::on_mw_get_wallets(const tools::wallet_public::COMMAND_MW_GET_WALLETS::request& req, tools::wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, epee::net_utils::connection_context_base& cntx) +{ + this->on_mw_get_wallets(res.wallets); + return true; +} +bool wallets_manager::on_mw_select_wallet(const tools::wallet_public::COMMAND_MW_SELECT_WALLET::request& req, tools::wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, epee::net_utils::connection_context_base& cntx) +{ + this->on_mw_select_wallet(req.wallet_id); + return true; +} + + +void wallets_manager::lock() +{ + { + SHARED_CRITICAL_REGION_LOCAL(m_wallets_lock); + auto it = m_wallets.find(m_rpc_selected_wallet_id); + if (it == m_wallets.end()) + { + throw std::runtime_error("Wallet not selected"); + } + m_current_wallet_locked_object = it->second.w.lock(); + } +} + +void wallets_manager::unlock() +{ + m_current_wallet_locked_object.reset(); +} + +std::shared_ptr wallets_manager::get_wallet() +{ + if (!m_current_wallet_locked_object.get()) + { + throw std::runtime_error("Wallet is not locked for get_wallet() call"); + } + return **m_current_wallet_locked_object; +} + void wallets_manager::wallet_vs_options::worker_func() { LOG_PRINT_GREEN("[WALLET_HANDLER] Wallet handler thread started, addr: " << w->get()->get_account().get_public_address_str(), LOG_LEVEL_0); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index b9542b2a..636e731c 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -47,7 +47,7 @@ struct wallet_lock_time_watching_policy }; -class wallets_manager : public i_backend_wallet_callback +class wallets_manager : public i_backend_wallet_callback, public tools::i_wallet_provider, epee::net_utils::http::i_chain_handler { public: @@ -55,6 +55,7 @@ public: { currency::core_runtime_config core_conf; epee::locked_object, wallet_lock_time_watching_policy> w; + typedef epee::locked_object, wallet_lock_time_watching_policy>::lock_shared_ptr wallet_lock_object; std::shared_ptr rpc_wrapper; //500 bytes of extra data, we can afford it, to have rpc-like invoke map std::atomic do_mining; std::atomic major_stop; @@ -196,8 +197,27 @@ private: virtual void on_mw_get_wallets(std::vector& wallets) override; virtual bool on_mw_select_wallet(uint64_t wallet_id) override; + //----- i_wallet_provider ------ + virtual void lock(); + virtual void unlock(); + virtual std::shared_ptr get_wallet(); //-------- + BEGIN_URI_MAP2_VIRTUAL() + BEGIN_JSON_RPC_MAP("/json_rpc") + //MULTIWALLET APIs + MAP_JON_RPC_WE("mw_get_wallets", on_mw_get_wallets, tools::wallet_public::COMMAND_MW_GET_WALLETS) + MAP_JON_RPC_WE("mw_select_wallet", on_mw_select_wallet, tools::wallet_public::COMMAND_MW_SELECT_WALLET) + CHAIN_TO_PHANDLER(m_prpc_chain_handler) + END_JSON_RPC_MAP() + CHAIN_TO_PHANDLER(m_prpc_chain_handler) + END_URI_MAP2() + + bool on_mw_get_wallets(const tools::wallet_public::COMMAND_MW_GET_WALLETS::request& req, tools::wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, epee::net_utils::connection_context_base& cntx); + bool on_mw_select_wallet(const tools::wallet_public::COMMAND_MW_SELECT_WALLET::request& req, tools::wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, epee::net_utils::connection_context_base& cntx); + + + epee::net_utils::http::i_chain_handler* m_prpc_chain_handler = nullptr; std::thread m_main_worker_thread; std::atomic m_stop_singal_sent; @@ -228,6 +248,10 @@ private: currency::t_currency_protocol_handler m_cprotocol; nodetool::node_server > m_p2psrv; currency::core_rpc_server m_rpc_server; + + tools::wallet_rpc_server m_wallet_rpc_server; + wallet_vs_options::wallet_lock_object m_current_wallet_locked_object; + uint64_t m_rpc_selected_wallet_id = 0; #endif bool m_remote_node_mode; From 84066c7203111617fe742ff8f4310f1c4826cf0d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 25 May 2023 20:05:39 +0200 Subject: [PATCH 07/20] added more proper handling of exception in rpc handlers --- src/simplewallet/simplewallet.cpp | 238 ++++++++++++++++-------------- src/wallet/wallet_rpc_server.cpp | 7 +- src/wallet/wallets_manager.cpp | 2 +- 3 files changed, 134 insertions(+), 113 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index fa6a42ed..7b9db781 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -41,6 +41,86 @@ namespace ph = boost::placeholders; #define EXTENDED_LOGS_FILE "wallet_details.log" +#define SIMPLE_WALLET_BEGIN_TRY_ENTRY() try { +#define SIMPLE_WALLET_CATCH_TRY_ENTRY() } \ + catch (const tools::error::daemon_busy&) \ + { \ + fail_msg_writer() << "daemon is busy. Please try later"; \ + } \ + catch (const tools::error::no_connection_to_daemon&) \ + { \ + fail_msg_writer() << "no connection to daemon. Please, make sure daemon is running."; \ + } \ + catch (const tools::error::wallet_rpc_error& e) \ + { \ + LOG_ERROR("Unknown RPC error: " << e.to_string()); \ + fail_msg_writer() << "RPC error \"" << e.what() << '"'; \ + } \ + catch (const tools::error::get_random_outs_error&) \ + { \ + fail_msg_writer() << "failed to get random outputs to mix"; \ + } \ + catch (const tools::error::not_enough_money& e) \ + { \ + fail_msg_writer() << "not enough money to transfer, available only " << print_money(e.available()) << \ + ", transaction amount " << print_money(e.tx_amount() + e.fee()) << " = " << print_money(e.tx_amount()) << \ + " + " << print_money(e.fee()) << " (fee)"; \ + } \ + catch (const tools::error::not_enough_outs_to_mix& e) \ + { \ + auto writer = fail_msg_writer(); \ + writer << "not enough outputs for specified mixin_count = " << e.mixin_count() << ":"; \ + for (const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& outs_for_amount : e.scanty_outs()) \ + { \ + writer << "\noutput amount = " << print_money(outs_for_amount.amount) << ", fount outputs to mix = " << outs_for_amount.outs.size(); \ + } \ + } \ + catch (const tools::error::tx_not_constructed&) \ + { \ + fail_msg_writer() << "transaction was not constructed"; \ + } \ + catch (const tools::error::tx_rejected& e) \ + { \ + fail_msg_writer() << "transaction " << get_transaction_hash(e.tx()) << " was rejected by daemon with status \"" << e.status() << '"'; \ + } \ + catch (const tools::error::tx_sum_overflow& e) \ + { \ + fail_msg_writer() << e.what(); \ + } \ + catch (const tools::error::tx_too_big& e) \ + { \ + currency::transaction tx = e.tx(); \ + fail_msg_writer() << "transaction " << get_transaction_hash(e.tx()) << " is too big. Transaction size: " << \ + get_object_blobsize(e.tx()) << " bytes, transaction size limit: " << e.tx_size_limit() << " bytes. Try to separate this payment into few smaller transfers."; \ + } \ + catch (const tools::error::zero_destination&) \ + { \ + fail_msg_writer() << "one of destinations is zero"; \ + } \ + catch (const tools::error::transfer_error& e) \ + { \ + LOG_ERROR("unknown transfer error: " << e.to_string()); \ + fail_msg_writer() << "unknown transfer error: " << e.what(); \ + } \ + catch (const tools::error::wallet_internal_error& e) \ + { \ + LOG_ERROR("internal error: " << e.to_string()); \ + fail_msg_writer() << "internal error: " << e.what(); \ + } \ + catch (const std::exception& e) \ + { \ + LOG_ERROR("unexpected error: " << e.what()); \ + fail_msg_writer() << "unexpected error: " << e.what(); \ + } \ + catch (...) \ + { \ + LOG_ERROR("Unknown error"); \ + fail_msg_writer() << "unknown error"; \ + } \ + + + + namespace { const command_line::arg_descriptor arg_wallet_file ("wallet-file", "Use wallet ", ""); @@ -1271,6 +1351,7 @@ bool preprocess_asset_id(std::string& address_arg, crypto::public_key& asset_id) //---------------------------------------------------------------------------------------------------- bool simple_wallet::transfer(const std::vector &args_) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); if (!try_connect_to_daemon()) return true; @@ -1389,97 +1470,21 @@ bool simple_wallet::transfer(const std::vector &args_) return true; } - try - { - currency::transaction tx; - m_wallet->transfer(dsts, fake_outs_count, 0, m_wallet->get_core_runtime_config().tx_default_fee, extra, attachments, tx); + currency::transaction tx; + m_wallet->transfer(dsts, fake_outs_count, 0, m_wallet->get_core_runtime_config().tx_default_fee, extra, attachments, tx); - if (!m_wallet->is_watch_only()) - { - if(wrapped_transaction) - success_msg_writer(true) << "Money successfully sent to wZano custody wallet, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; - else - success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; - } + if (!m_wallet->is_watch_only()) + { + if(wrapped_transaction) + success_msg_writer(true) << "Money successfully sent to wZano custody wallet, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; else - { - success_msg_writer(true) << "Transaction prepared for signing and saved into \"zano_tx_unsigned\" file, use full wallet to sign transfer and then use \"submit_transfer\" on this wallet to broadcast the transaction to the network"; - } + success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; } - catch (const tools::error::daemon_busy&) + else { - fail_msg_writer() << "daemon is busy. Please try later"; - } - catch (const tools::error::no_connection_to_daemon&) - { - fail_msg_writer() << "no connection to daemon. Please, make sure daemon is running."; - } - catch (const tools::error::wallet_rpc_error& e) - { - LOG_ERROR("Unknown RPC error: " << e.to_string()); - fail_msg_writer() << "RPC error \"" << e.what() << '"'; - } - catch (const tools::error::get_random_outs_error&) - { - fail_msg_writer() << "failed to get random outputs to mix"; - } - catch (const tools::error::not_enough_money& e) - { - fail_msg_writer() << "not enough money to transfer, available only " << print_money(e.available()) << - ", transaction amount " << print_money(e.tx_amount() + e.fee()) << " = " << print_money(e.tx_amount()) << - " + " << print_money(e.fee()) << " (fee)"; - } - catch (const tools::error::not_enough_outs_to_mix& e) - { - auto writer = fail_msg_writer(); - writer << "not enough outputs for specified mixin_count = " << e.mixin_count() << ":"; - for (const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& outs_for_amount : e.scanty_outs()) - { - writer << "\noutput amount = " << print_money(outs_for_amount.amount) << ", fount outputs to mix = " << outs_for_amount.outs.size(); - } - } - catch (const tools::error::tx_not_constructed&) - { - fail_msg_writer() << "transaction was not constructed"; - } - catch (const tools::error::tx_rejected& e) - { - fail_msg_writer() << "transaction " << get_transaction_hash(e.tx()) << " was rejected by daemon with status \"" << e.status() << '"'; - } - catch (const tools::error::tx_sum_overflow& e) - { - fail_msg_writer() << e.what(); - } - catch (const tools::error::tx_too_big& e) - { - currency::transaction tx = e.tx(); - fail_msg_writer() << "transaction " << get_transaction_hash(e.tx()) << " is too big. Transaction size: " << - get_object_blobsize(e.tx()) << " bytes, transaction size limit: " << e.tx_size_limit() << " bytes. Try to separate this payment into few smaller transfers."; - } - catch (const tools::error::zero_destination&) - { - fail_msg_writer() << "one of destinations is zero"; - } - catch (const tools::error::transfer_error& e) - { - LOG_ERROR("unknown transfer error: " << e.to_string()); - fail_msg_writer() << "unknown transfer error: " << e.what(); - } - catch (const tools::error::wallet_internal_error& e) - { - LOG_ERROR("internal error: " << e.to_string()); - fail_msg_writer() << "internal error: " << e.what(); - } - catch (const std::exception& e) - { - LOG_ERROR("unexpected error: " << e.what()); - fail_msg_writer() << "unexpected error: " << e.what(); - } - catch (...) - { - LOG_ERROR("Unknown error"); - fail_msg_writer() << "unknown error"; - } + success_msg_writer(true) << "Transaction prepared for signing and saved into \"zano_tx_unsigned\" file, use full wallet to sign transfer and then use \"submit_transfer\" on this wallet to broadcast the transaction to the network"; + } + SIMPLE_WALLET_CATCH_TRY_ENTRY() return true; } @@ -1806,6 +1811,7 @@ bool simple_wallet::tor_disable(const std::vector &args) //---------------------------------------------------------------------------------------------------- bool simple_wallet::deploy_new_asset(const std::vector &args) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); asset_descriptor_base adb = AUTO_VAL_INIT(adb); if (!args.size() || args.size() > 1) { @@ -1826,19 +1832,21 @@ bool simple_wallet::deploy_new_asset(const std::vector &args) crypto::public_key result_asset_id = currency::null_pkey; m_wallet->publish_new_asset(adb, destinations, result_tx, result_asset_id); - success_msg_writer(true) << "New asset deployed: " << ENDL - << "Asset ID: " << result_asset_id << ENDL + success_msg_writer(true) << "New asset deployed: " << ENDL + << "Asset ID: " << result_asset_id << ENDL << "Title: " << adb.full_name << ENDL << "Ticker: " << adb.ticker << ENDL << "Emitted: " << print_fixed_decimal_point(adb.current_supply, adb.decimal_point) << ENDL << "Max emission: " << print_fixed_decimal_point(adb.total_max_supply, adb.decimal_point) << ENDL ; - + + SIMPLE_WALLET_CATCH_TRY_ENTRY(); return true; } //---------------------------------------------------------------------------------------------------- bool simple_wallet::add_custom_asset_id(const std::vector &args) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); if (!args.size() || args.size() > 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; @@ -1865,11 +1873,14 @@ bool simple_wallet::add_custom_asset_id(const std::vector &args) << " supply: " << print_fixed_decimal_point(asset_descriptor.current_supply, asset_descriptor.decimal_point) << ENDL ; } + SIMPLE_WALLET_CATCH_TRY_ENTRY(); return true; + } //---------------------------------------------------------------------------------------------------- bool simple_wallet::generate_ionic_swap_proposal(const std::vector &args) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); if (args.size() != 2) { @@ -1906,11 +1917,15 @@ bool simple_wallet::generate_ionic_swap_proposal(const std::vector { success_msg_writer() << "Generated proposal: " << ENDL << epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(proposal)); } + SIMPLE_WALLET_CATCH_TRY_ENTRY(); return true; + } //---------------------------------------------------------------------------------------------------- bool simple_wallet::get_ionic_swap_proposal_info(const std::vector &args) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); + if (args.size() != 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; @@ -1935,11 +1950,14 @@ bool simple_wallet::get_ionic_swap_proposal_info(const std::vector success_msg_writer() << "Proposal details: " << ENDL << json_proposal_info; + SIMPLE_WALLET_CATCH_TRY_ENTRY(); return true; } //---------------------------------------------------------------------------------------------------- bool simple_wallet::accept_ionic_swap_proposal(const std::vector &args) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); + if (args.size() != 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; @@ -1962,12 +1980,14 @@ bool simple_wallet::accept_ionic_swap_proposal(const std::vector &a success_msg_writer() << "Proposal accepted and executed, tx_id : " << currency::get_transaction_hash(result_tx); + SIMPLE_WALLET_CATCH_TRY_ENTRY(); return true; } //---------------------------------------------------------------------------------------------------- bool simple_wallet::remove_custom_asset_id(const std::vector &args) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); if (!args.size() || args.size() > 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; @@ -1989,11 +2009,14 @@ bool simple_wallet::remove_custom_asset_id(const std::vector &args) { success_msg_writer() << "Asset id " << asset_id << " removed from wallet custom list" << ENDL; } + + SIMPLE_WALLET_CATCH_TRY_ENTRY(); return true; } //---------------------------------------------------------------------------------------------------- bool simple_wallet::sweep_below(const std::vector &args) { + SIMPLE_WALLET_BEGIN_TRY_ENTRY(); bool r = false; if (args.size() < 3 || args.size() > 4) { @@ -2051,30 +2074,23 @@ bool simple_wallet::sweep_below(const std::vector &args) return true; } - try - { - uint64_t fee = m_wallet->get_core_runtime_config().tx_default_fee; - size_t outs_total = 0, outs_swept = 0; - uint64_t amount_total = 0, amount_swept = 0; - currency::transaction result_tx = AUTO_VAL_INIT(result_tx); - std::string filename = "zano_tx_unsigned"; - m_wallet->sweep_below(fake_outs_count, addr, amount, payment_id, fee, outs_total, amount_total, outs_swept, amount_swept, &result_tx, &filename); - success_msg_writer(false) << outs_swept << " outputs (" << print_money_brief(amount_swept) << " coins) of " << outs_total << " total (" << print_money_brief(amount_total) - << ") below the specified limit of " << print_money_brief(amount) << " were successfully swept"; + uint64_t fee = m_wallet->get_core_runtime_config().tx_default_fee; + size_t outs_total = 0, outs_swept = 0; + uint64_t amount_total = 0, amount_swept = 0; + currency::transaction result_tx = AUTO_VAL_INIT(result_tx); + std::string filename = "zano_tx_unsigned"; + m_wallet->sweep_below(fake_outs_count, addr, amount, payment_id, fee, outs_total, amount_total, outs_swept, amount_swept, &result_tx, &filename); - if (m_wallet->is_watch_only()) - success_msg_writer(true) << "Transaction prepared for signing and saved into \"" << filename << "\" file, use full wallet to sign transfer and then use \"submit_transfer\" on this wallet to broadcast the transaction to the network"; - else - success_msg_writer(true) << "tx: " << get_transaction_hash(result_tx) << " size: " << get_object_blobsize(result_tx) << " bytes"; - } - catch (const std::exception& e) - { - LOG_ERROR(e.what()); - fail_msg_writer() << e.what(); - return true; - } + success_msg_writer(false) << outs_swept << " outputs (" << print_money_brief(amount_swept) << " coins) of " << outs_total << " total (" << print_money_brief(amount_total) + << ") below the specified limit of " << print_money_brief(amount) << " were successfully swept"; + if (m_wallet->is_watch_only()) + success_msg_writer(true) << "Transaction prepared for signing and saved into \"" << filename << "\" file, use full wallet to sign transfer and then use \"submit_transfer\" on this wallet to broadcast the transaction to the network"; + else + success_msg_writer(true) << "tx: " << get_transaction_hash(result_tx) << " size: " << get_object_blobsize(result_tx) << " bytes"; + + SIMPLE_WALLET_CATCH_TRY_ENTRY(); return true; } diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 98a3a5ab..38c8146e 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -28,6 +28,12 @@ using namespace epee; er.message = e.error_code(); \ return false; \ } \ + catch (const tools::error::daemon_busy& e) \ + { \ + er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY; \ + er.message = e.what(); \ + return false; \ + } \ catch (const std::exception& e) \ { \ er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \ @@ -41,7 +47,6 @@ using namespace epee; return false; \ } - namespace tools { //----------------------------------------------------------------------------------- diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index c98ef0a2..48ce8eb3 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -2051,7 +2051,7 @@ bool wallets_manager::on_mw_select_wallet(uint64_t wallet_id) return false; m_rpc_selected_wallet_id = wallet_id; - return false; + return true; } From 768309d72ef7b7e96bee0bfcf946595271558817 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 25 May 2023 21:15:42 +0200 Subject: [PATCH 08/20] tx_out_zarcanum serialization fixed + fixed compilation for MSVC 2022 --- src/currency_core/currency_boost_serialization.h | 1 + src/simplewallet/simplewallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_boost_serialization.h b/src/currency_core/currency_boost_serialization.h index 9a09dce1..5d7c40f7 100644 --- a/src/currency_core/currency_boost_serialization.h +++ b/src/currency_core/currency_boost_serialization.h @@ -116,6 +116,7 @@ namespace boost a & x.stealth_address; a & x.concealing_point; a & x.amount_commitment; + a & x.blinded_asset_id; a & x.encrypted_amount; a & x.mix_attr; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 7b9db781..75075d70 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -312,9 +312,9 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("add_custom_asset_id", boost::bind(&simple_wallet::add_custom_asset_id, this, ph::_1), "Approve asset id to be recognized in the wallet and returned in balances"); m_cmd_binder.set_handler("remove_custom_asset_id", boost::bind(&simple_wallet::remove_custom_asset_id, this, ph::_1), "Cancel previously made approval for asset id"); - m_cmd_binder.set_handler("generate_ionic_swap_proposal", boost::bind(&simple_wallet::generate_ionic_swap_proposal, this, _1), "generate_ionic_swap_proposal - Generates ionic_swap proposal with given conditions"); - m_cmd_binder.set_handler("get_ionic_swap_proposal_info", boost::bind(&simple_wallet::get_ionic_swap_proposal_info, this, _1), "get_ionic_swap_proposal_info - Extracts and display information from ionic_swap proposal raw data"); - m_cmd_binder.set_handler("accept_ionic_swap_proposal", boost::bind(&simple_wallet::accept_ionic_swap_proposal, this, _1), "accept_ionic_swap_proposal - Accept ionic_swap proposal and generates exchange transaction"); + m_cmd_binder.set_handler("generate_ionic_swap_proposal", boost::bind(&simple_wallet::generate_ionic_swap_proposal, this, ph::_1), "generate_ionic_swap_proposal - Generates ionic_swap proposal with given conditions"); + m_cmd_binder.set_handler("get_ionic_swap_proposal_info", boost::bind(&simple_wallet::get_ionic_swap_proposal_info, this, ph::_1), "get_ionic_swap_proposal_info - Extracts and display information from ionic_swap proposal raw data"); + m_cmd_binder.set_handler("accept_ionic_swap_proposal", boost::bind(&simple_wallet::accept_ionic_swap_proposal, this, ph::_1), "accept_ionic_swap_proposal - Accept ionic_swap proposal and generates exchange transaction"); } //---------------------------------------------------------------------------------------------------- From b4cdae8bd8148822008687667a4faf5ca86c278d Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 25 May 2023 21:24:28 +0200 Subject: [PATCH 09/20] version bump: 2.0.0.200 -> 2.0.0.201 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 886d5293..8ec01170 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 200 +#define PROJECT_VERSION_BUILD_NO 201 #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 "]" From dbd8c39fe23b2545f4657996bb0f7565d496589a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 26 May 2023 20:23:16 +0200 Subject: [PATCH 10/20] multiple fixes over wallet/core api --- src/rpc/core_rpc_server.cpp | 33 +++++++++++++++++++++++++ src/rpc/core_rpc_server.h | 5 ++-- src/rpc/core_rpc_server_commands_defs.h | 28 +++++++++++++++++++++ src/wallet/wallet_public_structs_defs.h | 32 +++++------------------- src/wallet/wallet_rpc_server.cpp | 28 ++++++--------------- src/wallet/wallet_rpc_server.h | 2 -- src/wallet/wallets_manager.cpp | 1 + 7 files changed, 78 insertions(+), 51 deletions(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 3a7e4b12..456c84a9 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -494,6 +494,39 @@ namespace currency return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_validate_signature(const COMMAND_VALIDATE_SIGNATURE::request& req, COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx) + { + if (!m_p2p.get_connections_count()) + { + res.status = API_RETURN_CODE_DISCONNECTED; + return true; + } + std::string buff = epee::string_encoding::base64_decode(req.buff); + crypto::public_key pkey = req.pkey; + + if(pkey == currency::null_pkey) + { + //need to load pkey from alias + extra_alias_entry_base eaeb = AUTO_VAL_INIT(eaeb); + if (!m_core.get_blockchain_storage().get_alias_info(req.alias, eaeb)) + { + res.status = API_RETURN_CODE_NOT_FOUND; + return true; + } + pkey = eaeb.m_address.spend_public_key; + } + + crypto::hash h = crypto::cn_fast_hash(buff.data(), buff.size()); + bool sig_check_res = crypto::check_signature(h, pkey, req.sig); + if (!sig_check_res) + { + res.status = API_RETURN_CODE_FAIL; + return true; + } + res.status = API_RETURN_CODE_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_pos_mining_details(const COMMAND_RPC_GET_POS_MINING_DETAILS::request& req, COMMAND_RPC_GET_POS_MINING_DETAILS::response& res, connection_context& cntx) { if (!m_p2p.get_connections_count()) diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index f6cf669c..ba08319a 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -89,7 +89,7 @@ namespace currency bool on_get_alt_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_alt_blocks_details(const COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::request& req, COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::response& res, connection_context& cntx); bool on_get_est_height_from_date(const COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& req, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& res, connection_context& cntx); - + bool on_validate_signature(const COMMAND_VALIDATE_SIGNATURE::request& req, COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx); @@ -149,7 +149,8 @@ namespace currency MAP_JON_RPC ("reset_transaction_pool", on_reset_transaction_pool, COMMAND_RPC_RESET_TX_POOL) MAP_JON_RPC ("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN) // - MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX) + MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX) + MAP_JON_RPC_WE("validate_signature", on_validate_signature, COMMAND_VALIDATE_SIGNATURE) CHAIN_TO_PHANDLER(m_prpc_chain_handler) END_JSON_RPC_MAP() CHAIN_TO_PHANDLER(m_prpc_chain_handler) diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 6bc12cde..4926e3c9 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -1584,6 +1584,34 @@ namespace currency }; }; + + struct COMMAND_VALIDATE_SIGNATURE + { + struct request + { + std::string buff; //base64 encoded data + crypto::signature sig = currency::null_sig; + crypto::public_key pkey = currency::null_pkey; + std::string alias; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(buff) + KV_SERIALIZE_POD_AS_HEX_STRING(sig) + KV_SERIALIZE_POD_AS_HEX_STRING(pkey) + KV_SERIALIZE(alias) + END_KV_SERIALIZE_MAP() + }; + + + struct response + { + std::string status; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(status) + END_KV_SERIALIZE_MAP() + }; + }; + struct void_struct { BEGIN_KV_SERIALIZE_MAP() diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 75539c96..5e9cd041 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -1389,7 +1389,9 @@ namespace wallet_public struct response { + std::string status; BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(status) END_KV_SERIALIZE_MAP() }; }; @@ -1400,7 +1402,6 @@ namespace wallet_public { std::string buff; //base64 encoded data - BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(buff) END_KV_SERIALIZE_MAP() @@ -1409,37 +1410,16 @@ namespace wallet_public struct response { - crypto::signature sig; + crypto::signature sig = currency::null_sig; + crypto::public_key pkey = currency::null_pkey; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE_POD_AS_HEX_STRING(sig) - END_KV_SERIALIZE_MAP() - }; - }; - - struct COMMAND_VALIDATE_SIGNATURE - { - struct request - { - std::string buff; //base64 encoded data - crypto::signature sig; - crypto::public_key pkey; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(buff) - KV_SERIALIZE_POD_AS_HEX_STRING(sig) KV_SERIALIZE_POD_AS_HEX_STRING(pkey) END_KV_SERIALIZE_MAP() }; - - - struct response - { - BEGIN_KV_SERIALIZE_MAP() - END_KV_SERIALIZE_MAP() - }; - }; - + }; + struct COMMAND_ENCRYPT_DATA { struct request diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 38c8146e..6ea7b2e4 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -22,18 +22,18 @@ using namespace epee; #define WALLET_RPC_BEGIN_TRY_ENTRY() try { GET_WALLET(); #define WALLET_RPC_CATCH_TRY_ENTRY() } \ - catch (const tools::error::wallet_error& e) \ - { \ - er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \ - er.message = e.error_code(); \ - return false; \ - } \ catch (const tools::error::daemon_busy& e) \ { \ er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY; \ er.message = e.what(); \ return false; \ } \ + catch (const tools::error::wallet_error& e) \ + { \ + er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \ + er.message = e.error_code(); \ + return false; \ + } \ catch (const std::exception& e) \ { \ er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \ @@ -1001,21 +1001,7 @@ namespace tools WALLET_RPC_BEGIN_TRY_ENTRY(); std::string buff = epee::string_encoding::base64_decode(req.buff); w.get_wallet()->sign_buffer(buff, res.sig); - return true; - WALLET_RPC_CATCH_TRY_ENTRY(); - } - //------------------------------------------------------------------------------------------------------------------------------ - bool wallet_rpc_server::on_validate_signature(const wallet_public::COMMAND_VALIDATE_SIGNATURE::request& req, wallet_public::COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx) - { - WALLET_RPC_BEGIN_TRY_ENTRY(); - std::string buff = epee::string_encoding::base64_decode(req.buff); - bool r = w.get_wallet()->validate_sign(buff, req.sig, req.pkey); - if (!r) - { - er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; - er.message = "WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT"; - return false; - } + res.pkey = w.get_wallet()->get_account().get_public_address().spend_public_key; return true; WALLET_RPC_CATCH_TRY_ENTRY(); } diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index f0c4e178..895e81d3 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -135,7 +135,6 @@ namespace tools //basic crypto operations MAP_JON_RPC_WE("sign_message", on_sign_message, wallet_public::COMMAND_SIGN_MESSAGE) - MAP_JON_RPC_WE("validate_signature", on_validate_signature, wallet_public::COMMAND_VALIDATE_SIGNATURE) MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA) MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA) END_JSON_RPC_MAP() @@ -187,7 +186,6 @@ namespace tools bool on_mw_select_wallet(const wallet_public::COMMAND_MW_SELECT_WALLET::request& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_sign_message(const wallet_public::COMMAND_SIGN_MESSAGE::request& req, wallet_public::COMMAND_SIGN_MESSAGE::response& res, epee::json_rpc::error& er, connection_context& cntx); - bool on_validate_signature(const wallet_public::COMMAND_VALIDATE_SIGNATURE::request& req, wallet_public::COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_encrypt_data(const wallet_public::COMMAND_ENCRYPT_DATA::request& req, wallet_public::COMMAND_ENCRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_decrypt_data(const wallet_public::COMMAND_DECRYPT_DATA::request& req, wallet_public::COMMAND_DECRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 48ce8eb3..3b14ebf5 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -2063,6 +2063,7 @@ bool wallets_manager::on_mw_get_wallets(const tools::wallet_public::COMMAND_MW_G bool wallets_manager::on_mw_select_wallet(const tools::wallet_public::COMMAND_MW_SELECT_WALLET::request& req, tools::wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, epee::net_utils::connection_context_base& cntx) { this->on_mw_select_wallet(req.wallet_id); + res.status = API_RETURN_CODE_OK; return true; } From 943e234a3d6a04379e570aa610d9eabf812b211f Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 26 May 2023 22:01:01 +0200 Subject: [PATCH 11/20] simplewallet & wallet: printing balance unlocked + disabling tor by default --- src/currency_core/currency_format_utils.h | 13 ++++- src/simplewallet/simplewallet.cpp | 12 +---- src/wallet/wallet2.cpp | 66 +++++++++++++++++------ src/wallet/wallet2.h | 3 +- 4 files changed, 65 insertions(+), 29 deletions(-) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 195e1cb3..378c9a48 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2023 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Copyright (c) 2012-2013 The Boolberry developers @@ -556,12 +556,23 @@ namespace currency return true; } //--------------------------------------------------------------- + // outputs "1391306.970000000000" template std::string print_fixed_decimal_point(t_number amount, size_t decimal_point) { return epee::string_tools::print_fixed_decimal_point(amount, decimal_point); } //--------------------------------------------------------------- + // outputs "1391306.97 " + template + std::string print_fixed_decimal_point_with_trailing_spaces(t_number amount, size_t decimal_point) + { + std::string s = epee::string_tools::print_fixed_decimal_point(amount, decimal_point); + for(size_t n = s.size() - 1; n != 0 && s[n] == '0'; --n) + s[n] = ' '; + return s; + } + //--------------------------------------------------------------- template std::string print_money(t_number amount) { diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 75075d70..ef987f68 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2019 Zano Project +// Copyright (c) 2014-2023 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying @@ -857,15 +857,7 @@ bool simple_wallet::refresh(const std::vector& args) //---------------------------------------------------------------------------------------------------- bool simple_wallet::show_balance(const std::vector& args/* = std::vector()*/) { - std::list balances; - uint64_t mined = 0; - m_wallet->balance(balances, mined); - std::stringstream ss; - for (const tools::wallet_public::asset_balance_entry& b : balances) - { - ss << std::setw(21) << print_fixed_decimal_point(b.total, b.asset_info.decimal_point) << "\t" << b.asset_info.ticker << "\t" << b.asset_info.asset_id << ENDL; - } - success_msg_writer() << "Balance: " << ENDL << ss.str(); + success_msg_writer() << m_wallet->get_balance_str(); return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9a8b6057..4c4e8a94 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2022 Zano Project +// Copyright (c) 2014-2023 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying @@ -53,22 +53,27 @@ using namespace currency; ENABLE_CHANNEL_BY_DEFAULT("wallet") namespace tools { - wallet2::wallet2() : m_stop(false), - m_wcallback(new i_wallet2_callback()), //stub - m_core_proxy(new default_http_core_proxy()), - m_upper_transaction_size_limit(0), - m_height_of_start_sync(0), - m_last_sync_percent(0), - m_fake_outputs_count(0), - m_do_rise_transfer(false), - m_log_prefix("???"), - m_watch_only(false), - m_last_pow_block_h(0), - m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST), - m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE), - m_current_wallet_file_size(0), - m_use_deffered_global_outputs(false), - m_disable_tor_relay(false) + wallet2::wallet2() + : m_stop(false) + , m_wcallback(new i_wallet2_callback()) //stub + , m_core_proxy(new default_http_core_proxy()) + , m_upper_transaction_size_limit(0) + , m_height_of_start_sync(0) + , m_last_sync_percent(0) + , m_fake_outputs_count(0) + , m_do_rise_transfer(false) + , m_log_prefix("???") + , m_watch_only(false) + , m_last_pow_block_h(0) + , m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST) + , m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE) + , m_current_wallet_file_size(0) + , m_use_deffered_global_outputs(false) +#ifdef DISABLE_TOR + , m_disable_tor_relay(true) +#else + , m_disable_tor_relay(false) +#endif { m_core_runtime_config = currency::get_default_core_runtime_config(); } @@ -3413,6 +3418,33 @@ std::string wallet2::get_transfers_str(bool include_spent /*= true*/, bool inclu return ss.str(); } //---------------------------------------------------------------------------------------------------- +std::string wallet2::get_balance_str() const +{ + // balance unlocked / [balance total] ticker asset id + // 1391306.970000000000 / 1391306.970000000000 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a + // 1391306.97 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a + // 106.971 / 206.4 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a + + static const char* header = " balance unlocked / [balance total] ticker asset id"; + std::stringstream ss; + ss << header << ENDL; + + std::list balances; + uint64_t mined = 0; + balance(balances, mined); + for (const tools::wallet_public::asset_balance_entry& b : balances) + { + ss << " " << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(b.unlocked, b.asset_info.decimal_point); + if (b.total == b.unlocked) + ss << " "; + else + ss << " / " << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(b.total, b.asset_info.decimal_point); + ss << " " << std::setw(8) << std::left << b.asset_info.ticker << " " << b.asset_info.asset_id << ENDL; + } + + return ss.str(); +} +//---------------------------------------------------------------------------------------------------- void wallet2::get_payments(const std::string& payment_id, std::list& payments, uint64_t min_height) const { auto range = m_payments.equal_range(payment_id); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 4406be40..64c657c5 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2022 Zano Project +// Copyright (c) 2014-2023 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying @@ -743,6 +743,7 @@ namespace tools void get_transfers(wallet2::transfer_container& incoming_transfers) const; std::string get_transfers_str(bool include_spent = true, bool include_unspent = true) const; + std::string wallet2::get_balance_str() const; // Returns all payments by given id in unspecified order void get_payments(const std::string& payment_id, std::list& payments, uint64_t min_height = 0) const; From d530c165da944167e42fc5882d10249dc75e9242 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 26 May 2023 22:11:23 +0200 Subject: [PATCH 12/20] wallet: PoS timings added --- src/wallet/wallet2.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 4c4e8a94..34ee2e2b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4129,6 +4129,7 @@ bool wallet2::try_mint_pos() //------------------------------------------------------------------ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address) { + TIME_MEASURE_START_MS(mining_duration_ms); mining_context ctx = AUTO_VAL_INIT(ctx); WLT_LOG_L1("Starting PoS mining iteration"); fill_mining_context(ctx); @@ -4154,8 +4155,9 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address { build_minted_block(ctx, miner_address); } + TIME_MEASURE_FINISH_MS(mining_duration_ms); - WLT_LOG_L0("PoS mining: " << ctx.iterations_processed << " iterations finished, status: " << ctx.status << ", " << ctx.total_items_checked << " entries with total amount: " << print_money_brief(ctx.total_amount_checked)); + WLT_LOG_L0("PoS mining: " << ctx.iterations_processed << " iterations finished (" << std::fixed << std::setprecision(2) << (mining_duration_ms / 1000.0f) << "s), status: " << ctx.status << ", " << ctx.total_items_checked << " entries with total amount: " << print_money_brief(ctx.total_amount_checked)); return true; } From 379f4b3535bfbcab2cee20469df12434f34637f1 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 26 May 2023 22:11:59 +0200 Subject: [PATCH 13/20] version bump: 2.0.0.201 -> 2.0.0.202 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 8ec01170..2cd013a7 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 201 +#define PROJECT_VERSION_BUILD_NO 202 #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 "]" From f245df2d09d43fdab743cac3ee6772f0487035b8 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 26 May 2023 22:20:55 +0200 Subject: [PATCH 14/20] some warnings fixed --- src/currency_core/currency_format_utils.cpp | 4 ++-- src/wallet/wallet2.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 946595db..4504aa14 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1143,7 +1143,7 @@ namespace currency blinded_asset_id = crypto::point_t(de.asset_id) + asset_blinding_mask * crypto::c_point_X; out.blinded_asset_id = (crypto::c_scalar_1div8 * blinded_asset_id).to_public_key(); // T = 1/8 * (H_asset + s * X) - CHECK_AND_ASSERT_MES(!de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id || de.asset_id == currency::native_coin_asset_id, false, "explicit_native_asset_id may be used only with native asset id"); + CHECK_AND_ASSERT_MES(~de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id || de.asset_id == currency::native_coin_asset_id, false, "explicit_native_asset_id may be used only with native asset id"); asset_blinding_mask = de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id ? 0 : crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_ASSET_BLINDING_MASK, h); // f = Hs(domain_sep, d, i) amount_commitment = de.amount * blinded_asset_id + amount_blinding_mask * crypto::c_point_G; out.amount_commitment = (crypto::c_scalar_1div8 * amount_commitment).to_public_key(); // E = 1/8 * e * T + 1/8 * y * G @@ -1163,7 +1163,7 @@ namespace currency crypto::scalar_t amount_mask = crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_AMOUNT_MASK, h); out.encrypted_amount = de.amount ^ amount_mask.m_u64[0]; - CHECK_AND_ASSERT_MES(!de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id || de.asset_id == currency::native_coin_asset_id, false, "explicit_native_asset_id may be used only with native asset id"); + CHECK_AND_ASSERT_MES(~de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id || de.asset_id == currency::native_coin_asset_id, false, "explicit_native_asset_id may be used only with native asset id"); asset_blinding_mask = de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id ? 0 : crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_ASSET_BLINDING_MASK, h); // f = Hs(domain_sep, d, i) blinded_asset_id = crypto::point_t(de.asset_id) + asset_blinding_mask * crypto::c_point_X; out.blinded_asset_id = (crypto::c_scalar_1div8 * blinded_asset_id).to_public_key(); // T = 1/8 * (H_asset + s * X) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 64c657c5..f8a42a49 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -743,7 +743,7 @@ namespace tools void get_transfers(wallet2::transfer_container& incoming_transfers) const; std::string get_transfers_str(bool include_spent = true, bool include_unspent = true) const; - std::string wallet2::get_balance_str() const; + std::string get_balance_str() const; // Returns all payments by given id in unspecified order void get_payments(const std::string& payment_id, std::list& payments, uint64_t min_height = 0) const; From 3e1123fcaa420864c175f04ef80e3aef3eda9def Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 29 May 2023 14:25:24 +0200 Subject: [PATCH 15/20] print_fixed_decimal_point_with_trailing_spaces() minor fix --- src/currency_core/currency_format_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 378c9a48..0d8ebaf5 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -568,7 +568,7 @@ namespace currency std::string print_fixed_decimal_point_with_trailing_spaces(t_number amount, size_t decimal_point) { std::string s = epee::string_tools::print_fixed_decimal_point(amount, decimal_point); - for(size_t n = s.size() - 1; n != 0 && s[n] == '0'; --n) + for(size_t n = s.size() - 1; n != 0 && s[n] == '0' && s[n-1] != '.'; --n) s[n] = ' '; return s; } From 0832fac57ef9dd1eca9826a9668be2265d383319 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 29 May 2023 14:31:48 +0200 Subject: [PATCH 16/20] temporary hard-disabled TOR relay (like it was in master) --- src/wallet/wallet2.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 34ee2e2b..f5ed3ba1 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -31,6 +31,9 @@ using namespace epee; #include "version.h" #include "common/encryption_filter.h" #include "crypto/bitcoin/sha256_helper.h" + +#define DISABLE_TOR + #ifndef DISABLE_TOR #include "common/tor_helper.h" #endif From f685929814b737c8cfc0312cc56a63ed33c09aec Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 29 May 2023 14:45:10 +0200 Subject: [PATCH 17/20] version bump: 2.0.0.202 -> 2.0.0.203 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 2cd013a7..74358ce7 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 202 +#define PROJECT_VERSION_BUILD_NO 203 #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 "]" From a21c0a8c1a730501657f26f3538ace259593c54c Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 29 May 2023 22:28:13 +0200 Subject: [PATCH 18/20] wallet: 1) m_custom_assets clearing on resync cmd, 2) deployed asset is automatically added to custom assets list; 3) publish -> deploy; 4) help improved --- src/simplewallet/simplewallet.cpp | 8 ++++---- src/wallet/wallet2.cpp | 5 ++++- src/wallet/wallet2.h | 2 +- tests/core_tests/ionic_swap_tests.cpp | 4 ++-- tests/core_tests/multiassets_test.cpp | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index ef987f68..74e74b59 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -277,7 +277,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("payments", boost::bind(&simple_wallet::show_payments, this, ph::_1), "payments [ ... ] - Show payments , ... "); m_cmd_binder.set_handler("bc_height", boost::bind(&simple_wallet::show_blockchain_height, this,ph::_1), "Show blockchain height"); m_cmd_binder.set_handler("wallet_bc_height", boost::bind(&simple_wallet::show_wallet_bcheight, this,ph::_1), "Show blockchain height"); - m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this,ph::_1), "transfer [ ... ] [payment_id] - Transfer ,... to ,... , respectively. is the number of transactions yours is indistinguishable from (from 0 to maximum available), is an optional HEX-encoded string"); + m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this,ph::_1), "transfer [asset_id_1:] [ [asset_id_2:] ... [asset_id_N:] ] [payment_id] - Transfer ,... to ,... , respectively. is the number of transactions yours is indistinguishable from (from 0 to maximum available), is an optional HEX-encoded string"); m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this,ph::_1), "set_log - Change current log detalisation level, is a number 0-4"); m_cmd_binder.set_handler("enable_console_logger", boost::bind(&simple_wallet::enable_console_logger, this,ph::_1), "Enables console logging"); m_cmd_binder.set_handler("resync", boost::bind(&simple_wallet::resync_wallet, this,ph::_1), "Causes wallet to reset all transfers and re-synchronize wallet"); @@ -308,7 +308,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("export_history", boost::bind(&simple_wallet::submit_transfer, this,ph::_1), "Export transaction history in CSV file"); m_cmd_binder.set_handler("tor_enable", boost::bind(&simple_wallet::tor_enable, this, ph::_1), "Enable relaying transactions over TOR network(enabled by default)"); m_cmd_binder.set_handler("tor_disable", boost::bind(&simple_wallet::tor_disable, this, ph::_1), "Enable relaying transactions over TOR network(enabled by default)"); - m_cmd_binder.set_handler("deploy_new_asset", boost::bind(&simple_wallet::deploy_new_asset, this, ph::_1), "Deploys new asset in the network, with current wallet as a maintainer"); + m_cmd_binder.set_handler("deploy_new_asset", boost::bind(&simple_wallet::deploy_new_asset, this, ph::_1), "deploy_new_asset - Deploys new asset in the network, with current wallet as a maintainer"); m_cmd_binder.set_handler("add_custom_asset_id", boost::bind(&simple_wallet::add_custom_asset_id, this, ph::_1), "Approve asset id to be recognized in the wallet and returned in balances"); m_cmd_binder.set_handler("remove_custom_asset_id", boost::bind(&simple_wallet::remove_custom_asset_id, this, ph::_1), "Cancel previously made approval for asset id"); @@ -1822,9 +1822,9 @@ bool simple_wallet::deploy_new_asset(const std::vector &args) destinations.push_back(td); currency::transaction result_tx = AUTO_VAL_INIT(result_tx); crypto::public_key result_asset_id = currency::null_pkey; - m_wallet->publish_new_asset(adb, destinations, result_tx, result_asset_id); + m_wallet->deploy_new_asset(adb, destinations, result_tx, result_asset_id); - success_msg_writer(true) << "New asset deployed: " << ENDL + success_msg_writer(true) << "New asset successfully deployed with tx " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL << "Asset ID: " << result_asset_id << ENDL << "Title: " << adb.full_name << ENDL << "Ticker: " << adb.ticker << ENDL diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f5ed3ba1..5d0317da 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2696,6 +2696,7 @@ bool wallet2::reset_all() m_last_sync_percent = 0; m_last_pow_block_h = 0; m_current_wallet_file_size = 0; + m_custom_assets.clear(); return true; } //---------------------------------------------------------------------------------------------------- @@ -4481,7 +4482,7 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); } //---------------------------------------------------------------------------------------------------- -void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id) +void wallet2::deploy_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id) { asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; @@ -4498,6 +4499,8 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf bool r = get_type_in_variant_container(result_tx.extra, ado); CHECK_AND_ASSERT_THROW_MES(r, "Failed find asset info in tx"); calculate_asset_id(ado.descriptor.owner, nullptr, &new_asset_id); + + m_custom_assets[new_asset_id] = ado.descriptor; } //---------------------------------------------------------------------------------------------------- void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f8a42a49..8818c7bc 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -606,7 +606,7 @@ namespace tools void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); bool check_available_sources(std::list& amounts); - void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id); + void deploy_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id); bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size); diff --git a/tests/core_tests/ionic_swap_tests.cpp b/tests/core_tests/ionic_swap_tests.cpp index 013176d2..5bbe8bf6 100644 --- a/tests/core_tests/ionic_swap_tests.cpp +++ b/tests/core_tests/ionic_swap_tests.cpp @@ -97,8 +97,8 @@ bool ionic_swap_basic_test::c1(currency::core& c, size_t ev_index, const std::ve currency::transaction tx = AUTO_VAL_INIT(tx); crypto::public_key asset_id = currency::null_pkey; - miner_wlt->publish_new_asset(adb, destinations, tx, asset_id); - LOG_PRINT_L0("Published new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); + miner_wlt->deploy_new_asset(adb, destinations, tx, asset_id); + LOG_PRINT_L0("Deployed new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); currency::transaction res_tx = AUTO_VAL_INIT(res_tx); miner_wlt->transfer(COIN, alice_wlt->get_account().get_public_address(), res_tx); diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 64b861d0..b0c2f026 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -81,8 +81,8 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v currency::transaction tx = AUTO_VAL_INIT(tx); crypto::public_key asset_id = currency::null_pkey; - miner_wlt->publish_new_asset(adb, destinations, tx, asset_id); - LOG_PRINT_L0("Published new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); + miner_wlt->deploy_new_asset(adb, destinations, tx, asset_id); + LOG_PRINT_L0("Deployed new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); //pass over hardfork r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); From 68901d469ac146614c410b8064283fe13f394cad Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 29 May 2023 22:29:08 +0200 Subject: [PATCH 19/20] version bump: 2.0.0.203 -> 2.0.0.204 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 74358ce7..b0c0eff8 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 203 +#define PROJECT_VERSION_BUILD_NO 204 #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 "]" From 0ddac854a5a819d75d3d316c8ab85ed4a4e0ab34 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 31 Mar 2023 15:00:41 +0200 Subject: [PATCH 20/20] build system: added a href to emails for all platforms --- utils/build_script_linux.sh | 2 +- utils/build_script_linux_appimage.sh | 2 +- utils/build_script_mac_osx.sh | 2 +- utils/build_script_windows.bat | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/build_script_linux.sh b/utils/build_script_linux.sh index fe5adbef..ffc5914a 100755 --- a/utils/build_script_linux.sh +++ b/utils/build_script_linux.sh @@ -137,7 +137,7 @@ fi read checksum <<< $(sha256sum $package_filename | awk '/^/ { print $1 }' ) mail_msg="New ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build for linux-x64:
-https://build.zano.org/builds/$package_filename
+https://build.zano.org/builds/$package_filename
sha256: $checksum" echo "$mail_msg" diff --git a/utils/build_script_linux_appimage.sh b/utils/build_script_linux_appimage.sh index 94cb3cce..f6ee4a70 100755 --- a/utils/build_script_linux_appimage.sh +++ b/utils/build_script_linux_appimage.sh @@ -149,7 +149,7 @@ fi read checksum <<< $(sha256sum $package_filename | awk '/^/ { print $1 }' ) mail_msg="New ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build for linux-x64:
-https://build.zano.org/builds/$package_filename
+https://build.zano.org/builds/$package_filename
sha256: $checksum" echo "$mail_msg" diff --git a/utils/build_script_mac_osx.sh b/utils/build_script_mac_osx.sh index 15acd9e3..580a0914 100755 --- a/utils/build_script_mac_osx.sh +++ b/utils/build_script_mac_osx.sh @@ -160,7 +160,7 @@ fi read checksum <<< $( shasum -a 256 $package_filepath | awk '/^/ { print $1 }' ) mail_msg="New ${build_prefix_label}${testnet_label}build for macOS-x64:
-https://build.zano.org/builds/$package_filename
+https://build.zano.org/builds/$package_filename
sha256: $checksum" echo "$mail_msg" diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index 4bdce4d0..840edc7b 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -192,7 +192,7 @@ IF %ERRORLEVEL% NEQ 0 ( ) call :sha256 %build_zip_path% build_zip_checksum -set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST: https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: https://build.zano.org/builds/%build_zip_filename%
sha256: %build_zip_checksum%
" +set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST: https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: