1
0
Fork 0
forked from lthn/blockchain

wallet_rpc_server refactoring for blocking API calls(for browser extension)

This commit is contained in:
cryptozoidberg 2023-05-23 23:47:42 +02:00
parent 756e6e526f
commit a9bbfdcf82
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
2 changed files with 370 additions and 352 deletions

View file

@ -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<wallet2> wptr)
: m_pwallet(wptr)
wallet_rpc_server::wallet_rpc_server(std::shared_ptr<wallet2> 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<wallet2> wallet_rpc_server::get_wallet()
{
return std::shared_ptr<wallet2>(m_pwallet);
}
wallet_rpc_server::wallet_rpc_server(std::shared_ptr<i_wallet_provider> provider_ptr):
m_pwallet_provider(provider_ptr)
, m_do_mint(false)
, m_deaf(false)
, m_last_wallet_store_height(0)
{}
//------------------------------------------------------------------------------------------------------------------------------
// std::shared_ptr<wallet2> wallet_rpc_server::get_wallet()
// {
// return std::shared_ptr<wallet2>(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<bool> 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<uint64_t, uint64_t> 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<uint64_t, uint64_t> 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<currency::tx_destination_entry>& 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<currency::attachment_v>& attachments = ctp.attachments;
std::vector<currency::extra_v>& 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<currency::attachment_v>& attachments = ctp.attachments;
std::vector<currency::extra_v>& 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<wallet2::payment_details> 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<wallet2::payment_details> 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<wallet2> w)
{
m_pwallet = w;
return true;
}
// bool wallet_rpc_server::reset_active_wallet(std::shared_ptr<wallet2> w)
// {
// m_pwallet = w;
// return true;
// }
//------------------------------------------------------------------------------------------------------------------------------
} // namespace tools

View file

@ -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<wallet2> get_wallet() = 0;
};
struct wallet_rpc_locker
{
wallet_rpc_locker(std::shared_ptr<i_wallet_provider> 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<wallet2> get_wallet() { return m_wallet_ptr; }
~wallet_rpc_locker()
{
m_pwallet_provider->unlock();
}
private:
std::shared_ptr<wallet2> m_wallet_ptr;
std::shared_ptr<i_wallet_provider> m_pwallet_provider;
};
struct wallet_provider_simple : public i_wallet_provider
{
wallet_provider_simple(std::shared_ptr<wallet2> wallet_ptr) : m_wallet_ptr(wallet_ptr)
{}
virtual std::shared_ptr<wallet2> get_wallet()
{
return m_wallet_ptr;
}
private:
std::shared_ptr<wallet2> m_wallet_ptr;
};
/************************************************************************/
/* */
/************************************************************************/
class wallet_rpc_server: public epee::http_server_impl_base<wallet_rpc_server>
class wallet_rpc_server : public epee::http_server_impl_base<wallet_rpc_server>
{
public:
typedef epee::net_utils::connection_context_base connection_context;
wallet_rpc_server(std::shared_ptr<wallet2> wptr);
wallet_rpc_server(std::shared_ptr<i_wallet_provider> provider_ptr);
const static command_line::arg_descriptor<std::string> arg_rpc_bind_port;
const static command_line::arg_descriptor<std::string> 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<wallet2> get_wallet();
bool reset_active_wallet(std::shared_ptr<wallet2> w);
//std::shared_ptr<wallet2> get_wallet();
bool handle_command_line(const boost::program_options::variables_map& vm);
//bool reset_active_wallet(std::shared_ptr<wallet2> w);
bool handle_command_line(const boost::program_options::variables_map& vm);
private:
std::weak_ptr<wallet2> 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<i_wallet_provider> 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