diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 7d6e2096..ec4b5b5d 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -695,6 +695,17 @@ void simple_wallet::on_tor_status_change(const std::string& state) message_writer(epee::log_space::console_color_yellow, true, std::string("[TOR]: ")) << human_message; } //---------------------------------------------------------------------------------------------------- +void simple_wallet::on_mw_get_wallets(std::vector& wallets) +{ + wallets.resize(1); + tools::get_wallet_info(*m_wallet, wallets[0].wi); +} +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::on_mw_select_wallet(uint64_t wallet_id) +{ + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::refresh(const std::vector& args) { if (m_offline_mode) diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 7ac24682..2daee3de 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -111,6 +111,8 @@ namespace currency virtual void on_message(i_wallet2_callback::message_severity severity, const std::string& m) override; virtual void on_tor_status_change(const std::string& state) override; + virtual void on_mw_get_wallets(std::vector& wallets) override; + virtual bool on_mw_select_wallet(uint64_t wallet_id) override; //---------------------------------------------------------- friend class refresh_progress_reporter_t; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 920a35b0..5fdd93f4 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -129,7 +129,7 @@ namespace tools //mw api virtual void on_mw_get_wallets(std::vector& wallets) {} - virtual void on_mw_select_wallet(uint64_t wallet_id) {} + virtual bool on_mw_select_wallet(uint64_t wallet_id) {} }; struct tx_dust_policy diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index d9822b23..f9f5db77 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -57,7 +57,7 @@ namespace tools } //------------------------------------------------------------------------------------------------------------------------------ wallet_rpc_server::wallet_rpc_server(wallet2& w) - : m_wallet(w) + : m_pwallet(&w) , m_do_mint(false) , m_deaf(false) , m_last_wallet_store_height(0) @@ -79,7 +79,7 @@ namespace tools bool received_money = false, ok = false; std::atomic stop(false); LOG_PRINT_L2("wallet RPC idle: refreshing..."); - m_wallet.refresh(blocks_fetched, received_money, ok, stop); + m_pwallet->refresh(blocks_fetched, received_money, ok, stop); if (stop) { LOG_PRINT_L1("wallet RPC idle: refresh failed"); @@ -88,24 +88,24 @@ namespace tools bool has_related_alias_in_unconfirmed = false; LOG_PRINT_L2("wallet RPC idle: scanning tx pool..."); - m_wallet.scan_tx_pool(has_related_alias_in_unconfirmed); + m_pwallet->scan_tx_pool(has_related_alias_in_unconfirmed); if (m_do_mint) { LOG_PRINT_L2("wallet RPC idle: trying to do PoS iteration..."); - m_wallet.try_mint_pos(miner_address); + m_pwallet->try_mint_pos(miner_address); } //auto-store wallet in server mode, let's do it every 24-hour - if (m_wallet.get_top_block_height() < m_last_wallet_store_height) + if (m_pwallet->get_top_block_height() < m_last_wallet_store_height) { - LOG_ERROR("Unexpected m_last_wallet_store_height = " << m_last_wallet_store_height << " or " << m_wallet.get_top_block_height()); + LOG_ERROR("Unexpected m_last_wallet_store_height = " << m_last_wallet_store_height << " or " << m_pwallet->get_top_block_height()); } - else if (m_wallet.get_top_block_height() - m_last_wallet_store_height > CURRENCY_BLOCKS_PER_DAY) + else if (m_pwallet->get_top_block_height() - m_last_wallet_store_height > CURRENCY_BLOCKS_PER_DAY) { //store wallet - m_wallet.store(); - m_last_wallet_store_height = m_wallet.get_top_block_height(); + m_pwallet->store(); + m_last_wallet_store_height = m_pwallet->get_top_block_height(); } } catch (error::no_connection_to_daemon&) @@ -141,14 +141,14 @@ namespace tools if (command_line::has_arg(vm, arg_miner_text_info)) { - m_wallet.set_miner_text_info(command_line::get_arg(vm, arg_miner_text_info)); + m_pwallet->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 = m_wallet.get_top_block_height(); + m_last_wallet_store_height = m_pwallet->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"); @@ -186,10 +186,10 @@ namespace tools { try { - // res.balance = m_wallet.balance(); - // res.unlocked_balance = m_wallet.unlocked_balance(); + // res.balance = m_pwallet->balance(); + // res.unlocked_balance = m_pwallet->unlocked_balance(); uint64_t mined = 0; - m_wallet.balance(res.balances, mined); + m_pwallet->balance(res.balances, mined); for (auto it = res.balances.begin(); it != res.balances.end(); it++) { if (it->asset_info.asset_id == currency::null_hash) @@ -212,7 +212,7 @@ namespace tools { try { - res.address = m_wallet.get_account().get_public_address_str(); + res.address = m_pwallet->get_account().get_public_address_str(); } catch (std::exception& e) { @@ -226,17 +226,17 @@ namespace tools { try { - res.address = m_wallet.get_account().get_public_address_str(); - res.is_whatch_only = m_wallet.is_watch_only(); - res.path = epee::string_encoding::convert_to_ansii(m_wallet.get_wallet_path()); - res.transfers_count = m_wallet.get_recent_transfers_total_count(); - res.transfer_entries_count = m_wallet.get_transfer_entries_count(); + res.address = m_pwallet->get_account().get_public_address_str(); + res.is_whatch_only = m_pwallet->is_watch_only(); + res.path = epee::string_encoding::convert_to_ansii(m_pwallet->get_wallet_path()); + res.transfers_count = m_pwallet->get_recent_transfers_total_count(); + res.transfer_entries_count = m_pwallet->get_transfer_entries_count(); std::map distribution; - m_wallet.get_utxo_distribution(distribution); + m_pwallet->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 = m_wallet.get_top_block_height(); + res.current_height = m_pwallet->get_top_block_height(); return true; } catch (std::exception& e) @@ -250,7 +250,7 @@ namespace tools { try { - res.seed_phrase = m_wallet.get_account().get_seed_phrase(req.seed_password); + res.seed_phrase = m_pwallet->get_account().get_seed_phrase(req.seed_password); return true; } catch (std::exception& e) @@ -271,21 +271,21 @@ namespace tools { if (req.update_provision_info) { - res.pi.balance = m_wallet.balance(res.pi.unlocked_balance); - res.pi.transfer_entries_count = m_wallet.get_transfer_entries_count(); - res.pi.transfers_count = m_wallet.get_recent_transfers_total_count(); - res.pi.curent_height = m_wallet.get_top_block_height(); + res.pi.balance = m_pwallet->balance(res.pi.unlocked_balance); + res.pi.transfer_entries_count = m_pwallet->get_transfer_entries_count(); + res.pi.transfers_count = m_pwallet->get_recent_transfers_total_count(); + res.pi.curent_height = m_pwallet->get_top_block_height(); } if (req.offset == 0 && !req.exclude_unconfirmed) - m_wallet.get_unconfirmed_transfers(res.transfers, req.exclude_mining_txs); + m_pwallet->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; } - m_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); + m_pwallet->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; } @@ -299,10 +299,10 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ 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 < m_wallet.get_core_runtime_config().tx_pool_min_fee) + if (req.fee < m_pwallet->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(m_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(m_pwallet->get_core_runtime_config().tx_pool_min_fee); return false; } @@ -314,7 +314,7 @@ namespace tools return false; } - construct_tx_param ctp = m_wallet.get_default_construct_tx_param_inital(); + construct_tx_param ctp = m_pwallet->get_default_construct_tx_param_inital(); if (req.service_entries_permanent) { //put it to extra @@ -357,7 +357,7 @@ namespace tools wrap = true; //encrypt body with a special way } - else if(!m_wallet.get_transfer_address(it->address, de.addr.back(), embedded_payment_id)) + else if(!m_pwallet->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; @@ -396,7 +396,7 @@ namespace tools if (req.push_payer && !wrap) { - currency::create_and_add_tx_payer_to_container_from_address(extra, m_wallet.get_account().get_keys().account_address, m_wallet.get_top_block_height(), m_wallet.get_core_runtime_config()); + currency::create_and_add_tx_payer_to_container_from_address(extra, m_pwallet->get_account().get_keys().account_address, m_pwallet->get_top_block_height(), m_pwallet->get_core_runtime_config()); } if (!req.hide_receiver) @@ -404,7 +404,7 @@ namespace tools for (auto& d : dsts) { for (auto& a : d.addr) - currency::create_and_add_tx_receiver_to_container_from_address(extra, a, m_wallet.get_top_block_height(), m_wallet.get_core_runtime_config()); + currency::create_and_add_tx_receiver_to_container_from_address(extra, a, m_pwallet->get_top_block_height(), m_pwallet->get_core_runtime_config()); } } @@ -412,8 +412,8 @@ namespace tools std::string unsigned_tx_blob_str; ctp.fee = req.fee; ctp.fake_outputs_count = req.mixin; - m_wallet.transfer(ctp, result, true, &unsigned_tx_blob_str); - if (m_wallet.is_watch_only()) + m_pwallet->transfer(ctp, result, true, &unsigned_tx_blob_str); + if (m_pwallet->is_watch_only()) { 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 @@ -449,9 +449,9 @@ namespace tools 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(); - m_wallet.store(); + m_pwallet->store(); boost::system::error_code ec = AUTO_VAL_INIT(ec); - res.wallet_file_size = m_wallet.get_wallet_file_size(); + res.wallet_file_size = m_pwallet->get_wallet_file_size(); WALLET_RPC_CATCH_TRY_ENTRY(); return true; } @@ -468,7 +468,7 @@ namespace tools res.payments.clear(); std::list payment_list; - m_wallet.get_payments(payment_id, payment_list); + m_pwallet->get_payments(payment_id, payment_list); for (auto payment : payment_list) { if (payment.m_unlock_time && !req.allow_locked_transactions) @@ -505,7 +505,7 @@ namespace tools } std::list payment_list; - m_wallet.get_payments(payment_id, payment_list, req.min_block_height); + m_pwallet->get_payments(payment_id, payment_list, req.min_block_height); for (auto & payment : payment_list) { @@ -553,7 +553,7 @@ namespace tools crypto::generate_random_bytes(payment_id.size(), &payment_id.front()); } - res.integrated_address = currency::get_account_address_and_payment_id_as_str(m_wallet.get_account().get_public_address(), payment_id); + res.integrated_address = currency::get_account_address_and_payment_id_as_str(m_pwallet->get_account().get_public_address(), payment_id); res.payment_id = epee::string_tools::buff_to_hex_nodelimer(payment_id); return !res.integrated_address.empty(); @@ -587,7 +587,7 @@ namespace tools currency::account_public_address addr; currency::payment_id_t integrated_payment_id; - if (!m_wallet.get_transfer_address(req.address, addr, integrated_payment_id)) + if (!m_pwallet->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; @@ -606,10 +606,10 @@ namespace tools payment_id = integrated_payment_id; } - if (req.fee < m_wallet.get_core_runtime_config().tx_pool_min_fee) + if (req.fee < m_pwallet->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(m_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(m_pwallet->get_core_runtime_config().tx_pool_min_fee); return false; } @@ -620,14 +620,14 @@ namespace tools uint64_t amount_total = 0, amount_swept = 0; std::string unsigned_tx_blob_str; - m_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); + m_pwallet->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; - if (m_wallet.is_watch_only()) + if (m_pwallet->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 @@ -673,7 +673,7 @@ namespace tools return false; } std::string tx_signed_blob; - m_wallet.sign_transfer(tx_unsigned_blob, tx_signed_blob, tx); + m_pwallet->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)); @@ -693,7 +693,7 @@ namespace tools WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction tx = AUTO_VAL_INIT(tx); - m_wallet.submit_transfer(tx_signed_blob, tx); + m_pwallet->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(); @@ -705,7 +705,7 @@ namespace tools bool tx_id_specified = req.tx_id != currency::null_hash; // process confirmed txs - m_wallet.enumerate_transfers_history([&](const wallet_public::wallet_transfer_info& wti) -> bool { + m_pwallet->enumerate_transfers_history([&](const wallet_public::wallet_transfer_info& wti) -> bool { if (tx_id_specified) { @@ -741,7 +741,7 @@ namespace tools // process unconfirmed txs if (req.pool) { - m_wallet.enumerate_unconfirmed_transfers([&](const wallet_public::wallet_transfer_info& wti) -> bool { + m_pwallet->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 @@ -752,7 +752,7 @@ namespace tools } 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) { - m_wallet.get_mining_history(res, req.v); + m_pwallet->get_mining_history(res, req.v); return true; } //------------------------------------------------------------------------------------------------------------------------------ @@ -775,7 +775,7 @@ namespace tools } currency::transaction tx = AUTO_VAL_INIT(tx); - m_wallet.request_alias_registration(ai, tx, m_wallet.get_default_fee(), 0, req.authority_key); + m_pwallet->request_alias_registration(ai, tx, m_pwallet->get_default_fee(), 0, req.authority_key); res.tx_id = get_transaction_hash(tx); return true; WALLET_RPC_CATCH_TRY_ENTRY(); @@ -786,7 +786,7 @@ namespace tools WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction tx = AUTO_VAL_INIT(tx); currency::transaction template_tx = AUTO_VAL_INIT(template_tx); - m_wallet.send_escrow_proposal(req, tx, template_tx); + m_pwallet->send_escrow_proposal(req, tx, template_tx); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -794,7 +794,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(); - m_wallet.accept_proposal(req.contract_id, req.acceptance_fee); + m_pwallet->accept_proposal(req.contract_id, req.acceptance_fee); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -803,7 +803,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); tools::wallet2::escrow_contracts_container ecc; - m_wallet.get_contracts(ecc); + m_pwallet->get_contracts(ecc); res.contracts.resize(ecc.size()); size_t i = 0; for (auto& c : ecc) @@ -819,7 +819,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(); - m_wallet.finish_contract(req.contract_id, req.release_type); + m_pwallet->finish_contract(req.contract_id, req.release_type); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -827,7 +827,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(); - m_wallet.request_cancel_contract(req.contract_id, req.fee, req.expiration_period); + m_pwallet->request_cancel_contract(req.contract_id, req.fee, req.expiration_period); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -835,7 +835,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(); - m_wallet.accept_cancel_contract(req.contract_id); + m_pwallet->accept_cancel_contract(req.contract_id); return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -843,9 +843,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(); - m_wallet.get_actual_offers(res.offers); + m_pwallet->get_actual_offers(res.offers); size_t offers_count_before_filtering = res.offers.size(); - bc_services::filter_offers_list(res.offers, req.filter, m_wallet.get_core_runtime_config().get_core_time()); + bc_services::filter_offers_list(res.offers, req.filter, m_pwallet->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(); @@ -855,7 +855,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - m_wallet.push_offer(req.od, res_tx); + m_pwallet->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); @@ -868,7 +868,7 @@ namespace tools WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - m_wallet.update_offer_by_id(req.tx_id, req.no, req.od, res_tx); + m_pwallet->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); @@ -880,7 +880,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - m_wallet.cancel_offer_by_id(req.tx_id, req.no, req.fee, res_tx); + m_pwallet->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); @@ -892,7 +892,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction tx = AUTO_VAL_INIT(tx); - m_wallet.create_htlc_proposal(req.amount, req.counterparty_address, req.lock_blocks_count, tx, req.htlc_hash, res.derived_origin_secret); + m_pwallet->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(); @@ -902,7 +902,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(); - m_wallet.get_list_of_active_htlc(res.htlcs, req.income_redeem_only); + m_pwallet->get_list_of_active_htlc(res.htlcs, req.income_redeem_only); WALLET_RPC_CATCH_TRY_ENTRY(); return true; } @@ -911,7 +911,7 @@ namespace tools { WALLET_RPC_BEGIN_TRY_ENTRY(); currency::transaction tx = AUTO_VAL_INIT(tx); - m_wallet.redeem_htlc(req.tx_id, req.origin_secret, tx); + m_pwallet->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(); @@ -921,7 +921,7 @@ 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(); - m_wallet.check_htlc_redeemed(req.htlc_tx_id, res.origin_secrete, res.redeem_tx_id); + m_pwallet->check_htlc_redeemed(req.htlc_tx_id, res.origin_secrete, res.redeem_tx_id); WALLET_RPC_CATCH_TRY_ENTRY(); return true; } @@ -930,7 +930,7 @@ namespace tools { currency::account_public_address destination_addr = AUTO_VAL_INIT(destination_addr); currency::payment_id_t integrated_payment_id; - if (!m_wallet.get_transfer_address(req.destination_address, destination_addr, integrated_payment_id)) + if (!m_pwallet->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"; @@ -944,7 +944,7 @@ namespace tools } currency::transaction tx_template = AUTO_VAL_INIT(tx_template); - bool r = m_wallet.create_ionic_swap_proposal(req.proposal, destination_addr, tx_template); + bool r = m_pwallet->create_ionic_swap_proposal(req.proposal, destination_addr, tx_template); if (!r) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; @@ -966,7 +966,7 @@ namespace tools return false; } - if (!m_wallet.get_ionic_swap_proposal_info(raw_tx_template, res.proposal)) + if (!m_pwallet->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"; @@ -988,7 +988,7 @@ namespace tools } currency::transaction result_tx = AUTO_VAL_INIT(result_tx); - if (!m_wallet.accept_ionic_swap_proposal(raw_tx_template, result_tx)) + if (!m_pwallet->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()"; @@ -1001,7 +1001,7 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_mw_get_wallets(const wallet_public::COMMAND_MW_GET_WALLETS& req, wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, connection_context& cntx) { - i_wallet2_callback* pcallback = m_wallet.get_callback(); + i_wallet2_callback* pcallback = m_pwallet->get_callback(); if (!pcallback) { er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; @@ -1014,7 +1014,7 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_mw_select_wallet(const wallet_public::COMMAND_MW_SELECT_WALLET& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx) { - i_wallet2_callback* pcallback = m_wallet.get_callback(); + i_wallet2_callback* pcallback = m_pwallet->get_callback(); if (!pcallback) { er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; @@ -1025,4 +1025,10 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::reset_active_wallet(wallet2& 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 8c9c8a9d..223e7497 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -129,12 +129,14 @@ namespace tools bool on_mw_get_wallets(const wallet_public::COMMAND_MW_GET_WALLETS& 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& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx); - + + + bool reset_active_wallet(wallet2& w); bool handle_command_line(const boost::program_options::variables_map& vm); private: - wallet2& m_wallet; + wallet2* m_pwallet; 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 21a7f8d0..de0e07f8 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -2002,6 +2002,30 @@ void wallets_manager::on_tor_status_change(size_t wallet_id, const std::string& m_pview->update_tor_status(tsu); } +void wallets_manager::on_mw_get_wallets(std::vector& wallets) +{ + std::list opened_wallets; + this->get_opened_wallets(opened_wallets); + wallets.resize(opened_wallets.size()); + size_t i = 0; + for (const auto& item : opened_wallets) + { + wallets[i].wi = item.wi; + wallets[i].wallet_id = item.wallet_id; + i++; + } +} +bool wallets_manager::on_mw_select_wallet(uint64_t wallet_id) +{ + SHARED_CRITICAL_REGION_LOCAL(m_wallets_lock); + 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); +} + + 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 d17cb437..ba73f431 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -193,6 +193,10 @@ private: virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti); virtual void on_tor_status_change(size_t wallet_id, const std::string& state); + virtual void on_mw_get_wallets(std::vector& wallets) override; + virtual bool on_mw_select_wallet(uint64_t wallet_id) override; + + //-------- std::thread m_main_worker_thread; @@ -224,6 +228,7 @@ 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; //optional initialization #endif bool m_remote_node_mode;