From b0850a9beacb3d6d89003ac38d46e859c45124c6 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 19 Apr 2016 21:20:27 +0100 Subject: wallet: add a new sweep_all command and RPC command This sends all outputs in a wallet to a given address, alleviating the difficulty people have had trying to send all monero but being left with some small amount left. --- src/wallet/wallet_rpc_server.cpp | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/wallet/wallet_rpc_server.cpp') diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 6897c3d45..b01ac2f1e 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -382,6 +382,65 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_sweep_all(const wallet_rpc::COMMAND_RPC_SWEEP_ALL::request& req, wallet_rpc::COMMAND_RPC_SWEEP_ALL::response& res, epee::json_rpc::error& er) + { + std::vector dsts; + std::vector extra; + + if (m_wallet.restricted()) + { + er.code = WALLET_RPC_ERROR_CODE_DENIED; + er.message = "Command unavailable in restricted mode."; + return false; + } + + // validate the transfer requested and populate dsts & extra + std::list destination; + destination.push_back(wallet_rpc::transfer_destination()); + destination.back().amount = 0; + destination.back().address = req.address; + if (!validate_transfer(destination, req.payment_id, dsts, extra, er)) + { + return false; + } + + try + { + std::vector ptx_vector = m_wallet.create_transactions_all(dsts[0].addr, req.mixin, req.unlock_time, req.fee, extra, req.trusted_daemon); + + m_wallet.commit_tx(ptx_vector); + + // populate response with tx hashes + for (auto & ptx : ptx_vector) + { + res.tx_hash_list.push_back(boost::lexical_cast(cryptonote::get_transaction_hash(ptx.tx))); + if (req.get_tx_keys) + res.tx_key_list.push_back(boost::lexical_cast(ptx.tx_key)); + } + + return true; + } + catch (const tools::error::daemon_busy& e) + { + er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY; + er.message = e.what(); + return false; + } + catch (const std::exception& e) + { + er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; + 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; + } + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er) { try -- cgit v1.2.3 From 7baed9bd8986d33d5892536f081eac284015372f Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 20 Apr 2016 18:19:42 +0100 Subject: wallet: allow attaching notes to txids --- src/simplewallet/simplewallet.cpp | 64 ++++++++++++++++++++++++++-- src/simplewallet/simplewallet.h | 2 + src/wallet/wallet2.cpp | 13 ++++++ src/wallet/wallet2.h | 9 +++- src/wallet/wallet_rpc_server.cpp | 63 +++++++++++++++++++++++++++ src/wallet/wallet_rpc_server.h | 4 ++ src/wallet/wallet_rpc_server_commands_defs.h | 41 ++++++++++++++++++ src/wallet/wallet_rpc_server_error_codes.h | 1 + 8 files changed, 193 insertions(+), 4 deletions(-) (limited to 'src/wallet/wallet_rpc_server.cpp') diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8323b9fc1..021e79edb 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -576,6 +576,8 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("check_tx_key", boost::bind(&simple_wallet::check_tx_key, this, _1), tr("Check amount going to
in ")); m_cmd_binder.set_handler("show_transfers", boost::bind(&simple_wallet::show_transfers, this, _1), tr("show_transfers [in|out] [ []] - Show incoming/outgoing transfers within an optional height range")); m_cmd_binder.set_handler("rescan_bc", boost::bind(&simple_wallet::rescan_blockchain, this, _1), tr("Rescan blockchain from scratch")); + m_cmd_binder.set_handler("set_tx_note", boost::bind(&simple_wallet::set_tx_note, this, _1), tr("Set an arbitrary string note for a txid")); + m_cmd_binder.set_handler("get_tx_note", boost::bind(&simple_wallet::get_tx_note, this, _1), tr("Get a string note for a txid")); m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), tr("Show this help")); } //---------------------------------------------------------------------------------------------------- @@ -3026,7 +3028,8 @@ bool simple_wallet::show_transfers(const std::vector &args_) std::string payment_id = string_tools::pod_to_hex(i->first); if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) payment_id = payment_id.substr(0,16); - output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%16.16s %20.20s %s %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % "-").str()))); + std::string note = m_wallet->get_tx_note(pd.m_tx_hash); + output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%16.16s %20.20s %s %s %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % "-" % note).str()))); } } @@ -3046,7 +3049,8 @@ bool simple_wallet::show_transfers(const std::vector &args_) std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id); if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) payment_id = payment_id.substr(0,16); - output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%16.16s %20.20s %s %s %14.14s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests).str()))); + std::string note = m_wallet->get_tx_note(i->first); + output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%16.16s %20.20s %s %s %14.14s %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests % note).str()))); } } @@ -3069,9 +3073,10 @@ bool simple_wallet::show_transfers(const std::vector &args_) std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id); if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) payment_id = payment_id.substr(0,16); + std::string note = m_wallet->get_tx_note(i->first); bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; if ((failed && is_failed) || (!is_failed && pending)) { - message_writer() << (boost::format("%8.8s %6.6s %16.16s %20.20s %s %s %14.14s") % (is_failed ? tr("failed") : tr("pending")) % tr("out") % get_human_readable_timestamp(pd.m_timestamp) % print_money(amount - pd.m_change) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee)).str(); + message_writer() << (boost::format("%8.8s %6.6s %16.16s %20.20s %s %s %14.14s %s") % (is_failed ? tr("failed") : tr("pending")) % tr("out") % get_human_readable_timestamp(pd.m_timestamp) % print_money(amount - pd.m_change) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % note).str(); } } } @@ -3179,6 +3184,59 @@ bool simple_wallet::print_integrated_address(const std::vector &arg return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::set_tx_note(const std::vector &args) +{ + if (args.size() == 0) + { + fail_msg_writer() << tr("usage: set_tx_note [txid] free text note"); + return true; + } + + cryptonote::blobdata txid_data; + if(!epee::string_tools::parse_hexstr_to_binbuff(args.front(), txid_data)) + { + fail_msg_writer() << tr("failed to parse txid"); + return false; + } + crypto::hash txid = *reinterpret_cast(txid_data.data()); + + std::string note = ""; + for (size_t n = 1; n < args.size(); ++n) + { + if (n > 1) + note += " "; + note += args[n]; + } + m_wallet->set_tx_note(txid, note); + + return true; +} +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::get_tx_note(const std::vector &args) +{ + if (args.size() != 1) + { + fail_msg_writer() << tr("usage: get_tx_note [txid]"); + return true; + } + + cryptonote::blobdata txid_data; + if(!epee::string_tools::parse_hexstr_to_binbuff(args.front(), txid_data)) + { + fail_msg_writer() << tr("failed to parse txid"); + return false; + } + crypto::hash txid = *reinterpret_cast(txid_data.data()); + + std::string note = m_wallet->get_tx_note(txid); + if (note.empty()) + success_msg_writer() << "no note found"; + else + success_msg_writer() << "note found: " << note; + + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::process_command(const std::vector &args) { return m_cmd_binder.process_command_vec(args); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index c9b25259c..0c69f0440 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -139,6 +139,8 @@ namespace cryptonote bool show_transfers(const std::vector &args); bool rescan_blockchain(const std::vector &args); bool refresh_main(uint64_t start_height, bool reset = false); + bool set_tx_note(const std::vector &args); + bool get_tx_note(const std::vector &args); uint64_t get_daemon_blockchain_height(std::string& err); bool try_connect_to_daemon(); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 2faf955f5..53ce23490 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3071,6 +3071,19 @@ std::string wallet2::get_keys_file() const return m_keys_file; } +void wallet2::set_tx_note(const crypto::hash &txid, const std::string ¬e) +{ + m_tx_notes[txid] = note; +} + +std::string wallet2::get_tx_note(const crypto::hash &txid) const +{ + std::unordered_map::const_iterator i = m_tx_notes.find(txid); + if (i == m_tx_notes.end()) + return std::string(); + return i->second; +} + //---------------------------------------------------------------------------------------------------- void wallet2::generate_genesis(cryptonote::block& b) { if (m_testnet) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 160a96a12..846a86ef8 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -329,6 +329,9 @@ namespace tools if(ver < 11) return; a & m_refresh_from_block_height; + if(ver < 12) + return; + a & m_tx_notes; } /*! @@ -375,6 +378,9 @@ namespace tools std::vector select_available_unmixable_outputs(bool trusted_daemon); std::vector select_available_mixable_outputs(bool trusted_daemon); + void set_tx_note(const crypto::hash &txid, const std::string ¬e); + std::string get_tx_note(const crypto::hash &txid) const; + private: /*! * \brief Stores wallet information to wallet file. @@ -432,6 +438,7 @@ namespace tools payment_container m_payments; std::unordered_map m_key_images; cryptonote::account_public_address m_account_public_address; + std::unordered_map m_tx_notes; uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value std::atomic m_run; @@ -452,7 +459,7 @@ namespace tools uint64_t m_refresh_from_block_height; }; } -BOOST_CLASS_VERSION(tools::wallet2, 11) +BOOST_CLASS_VERSION(tools::wallet2, 12) BOOST_CLASS_VERSION(tools::wallet2::payment_details, 1) BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 3) BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 2) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index b01ac2f1e..f7b79e3bc 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -770,5 +770,68 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_set_tx_notes(const wallet_rpc::COMMAND_RPC_SET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_SET_TX_NOTES::response& res, epee::json_rpc::error& er) + { + if (req.txids.size() != req.notes.size()) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = "Different amount of txids and notes"; + return false; + } + + std::list txids; + std::list::const_iterator i = req.txids.begin(); + while (i != req.txids.end()) + { + cryptonote::blobdata txid_blob; + if(!epee::string_tools::parse_hexstr_to_binbuff(*i++, txid_blob)) + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_TXID; + er.message = "TX ID has invalid format"; + return false; + } + + crypto::hash txid = *reinterpret_cast(txid_blob.data()); + txids.push_back(txid); + } + + std::list::const_iterator il = txids.begin(); + std::list::const_iterator in = req.notes.begin(); + while (il != txids.end()) + { + m_wallet.set_tx_note(*il++, *in++); + } + + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_get_tx_notes(const wallet_rpc::COMMAND_RPC_GET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_GET_TX_NOTES::response& res, epee::json_rpc::error& er) + { + res.notes.clear(); + + std::list txids; + std::list::const_iterator i = req.txids.begin(); + while (i != req.txids.end()) + { + cryptonote::blobdata txid_blob; + if(!epee::string_tools::parse_hexstr_to_binbuff(*i++, txid_blob)) + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_TXID; + er.message = "TX ID has invalid format"; + return false; + } + + crypto::hash txid = *reinterpret_cast(txid_blob.data()); + txids.push_back(txid); + } + + std::list::const_iterator il = txids.begin(); + while (il != txids.end()) + { + res.notes.push_back(m_wallet.get_tx_note(*il++)); + } + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ } diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index b41590de5..22fe6cd06 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -77,6 +77,8 @@ namespace tools MAP_JON_RPC_WE("split_integrated_address", on_split_integrated_address, wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS) MAP_JON_RPC_WE("stop_wallet", on_stop_wallet, wallet_rpc::COMMAND_RPC_STOP_WALLET) MAP_JON_RPC_WE("rescan_blockchain", on_rescan_blockchain, wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN) + MAP_JON_RPC_WE("set_tx_notes", on_set_tx_notes, wallet_rpc::COMMAND_RPC_SET_TX_NOTES) + MAP_JON_RPC_WE("get_tx_notes", on_get_tx_notes, wallet_rpc::COMMAND_RPC_GET_TX_NOTES) END_JSON_RPC_MAP() END_URI_MAP2() @@ -97,6 +99,8 @@ namespace tools bool on_incoming_transfers(const wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::response& res, epee::json_rpc::error& er); bool on_stop_wallet(const wallet_rpc::COMMAND_RPC_STOP_WALLET::request& req, wallet_rpc::COMMAND_RPC_STOP_WALLET::response& res, epee::json_rpc::error& er); bool on_rescan_blockchain(const wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN::request& req, wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN::response& res, epee::json_rpc::error& er); + bool on_set_tx_notes(const wallet_rpc::COMMAND_RPC_SET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_SET_TX_NOTES::response& res, epee::json_rpc::error& er); + bool on_get_tx_notes(const wallet_rpc::COMMAND_RPC_GET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_GET_TX_NOTES::response& res, epee::json_rpc::error& er); bool handle_command_line(const boost::program_options::variables_map& vm); diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index 73ab66f9b..ebcc67923 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -447,6 +447,47 @@ namespace wallet_rpc }; }; + struct COMMAND_RPC_SET_TX_NOTES + { + struct request + { + std::list txids; + std::list notes; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(txids) + KV_SERIALIZE(notes) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + BEGIN_KV_SERIALIZE_MAP() + END_KV_SERIALIZE_MAP() + }; + }; + + struct COMMAND_RPC_GET_TX_NOTES + { + struct request + { + std::list txids; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(txids) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::list notes; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(notes) + END_KV_SERIALIZE_MAP() + }; + }; + } } diff --git a/src/wallet/wallet_rpc_server_error_codes.h b/src/wallet/wallet_rpc_server_error_codes.h index 063421d80..968836671 100644 --- a/src/wallet/wallet_rpc_server_error_codes.h +++ b/src/wallet/wallet_rpc_server_error_codes.h @@ -38,3 +38,4 @@ #define WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID -5 #define WALLET_RPC_ERROR_CODE_TRANSFER_TYPE -6 #define WALLET_RPC_ERROR_CODE_DENIED -7 +#define WALLET_RPC_ERROR_CODE_WRONG_TXID -8 -- cgit v1.2.3 From 48ab3f93ff26769ee5b686562d768c547ff6478d Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 26 Apr 2016 22:39:08 +0100 Subject: wallet: add get_transfers rpc call Allows getting in, out, pending, and failed transfers, similarly to the show_transfers command. --- src/wallet/wallet_rpc_server.cpp | 89 ++++++++++++++++++++++++++++ src/wallet/wallet_rpc_server.h | 2 + src/wallet/wallet_rpc_server_commands_defs.h | 60 +++++++++++++++++++ 3 files changed, 151 insertions(+) (limited to 'src/wallet/wallet_rpc_server.cpp') diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index f7b79e3bc..5b678fa38 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -833,5 +833,94 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_get_transfers(const wallet_rpc::COMMAND_RPC_GET_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_GET_TRANSFERS::response& res, epee::json_rpc::error& er) + { + if (m_wallet.restricted()) + { + er.code = WALLET_RPC_ERROR_CODE_DENIED; + er.message = "Command unavailable in restricted mode."; + return false; + } + + if (req.in) + { + std::list> payments; + m_wallet.get_payments(payments, req.min_height, req.max_height); + for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { + res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry()); + wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back(); + const tools::wallet2::payment_details &pd = i->second; + + entry.txid = string_tools::pod_to_hex(pd.m_tx_hash); + entry.payment_id = string_tools::pod_to_hex(i->first); + if (entry.payment_id.substr(16).find_first_not_of('0') == std::string::npos) + entry.payment_id = entry.payment_id.substr(0,16); + entry.height = pd.m_block_height; + entry.timestamp = pd.m_timestamp; + entry.amount = pd.m_amount; + entry.fee = 0; // TODO + entry.note = m_wallet.get_tx_note(pd.m_tx_hash); + } + } + + if (req.out) + { + std::list> payments; + m_wallet.get_payments_out(payments, req.min_height, req.max_height); + for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { + res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry()); + wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back(); + const tools::wallet2::confirmed_transfer_details &pd = i->second; + + entry.txid = string_tools::pod_to_hex(i->first); + entry.payment_id = string_tools::pod_to_hex(i->second.m_payment_id); + if (entry.payment_id.substr(16).find_first_not_of('0') == std::string::npos) + entry.payment_id = entry.payment_id.substr(0,16); + entry.height = pd.m_block_height; + entry.timestamp = pd.m_timestamp; + entry.fee = pd.m_amount_in - pd.m_amount_out; + uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known + entry.amount = pd.m_amount_in - change - entry.fee; + entry.note = m_wallet.get_tx_note(i->first); + + for (const auto &d: pd.m_dests) { + entry.destinations.push_back(wallet_rpc::transfer_destination()); + wallet_rpc::transfer_destination &td = entry.destinations.back(); + td.amount = d.amount; + td.address = get_account_address_as_str(m_wallet.testnet(), d.addr); + } + } + } + + if (req.pending || req.failed) { + std::list> upayments; + m_wallet.get_unconfirmed_payments_out(upayments); + for (std::list>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) { + const tools::wallet2::unconfirmed_transfer_details &pd = i->second; + bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; + if (!((req.failed && is_failed) || (!is_failed && req.pending))) + continue; + std::list &entries = is_failed ? res.failed : res.pending; + entries.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry()); + wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = entries.back(); + + entry.txid = string_tools::pod_to_hex(i->first); + entry.payment_id = string_tools::pod_to_hex(i->second.m_payment_id); + entry.payment_id = string_tools::pod_to_hex(i->second.m_payment_id); + if (entry.payment_id.substr(16).find_first_not_of('0') == std::string::npos) + entry.payment_id = entry.payment_id.substr(0,16); + entry.height = 0; + entry.timestamp = pd.m_timestamp; + uint64_t amount = 0; + cryptonote::get_inputs_money_amount(pd.m_tx, amount); + entry.fee = amount - get_outs_money_amount(pd.m_tx); + entry.amount = amount - pd.m_change - entry.fee; + entry.note = m_wallet.get_tx_note(i->first); + } + } + + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ } diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 22fe6cd06..8c90aecfe 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -79,6 +79,7 @@ namespace tools MAP_JON_RPC_WE("rescan_blockchain", on_rescan_blockchain, wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN) MAP_JON_RPC_WE("set_tx_notes", on_set_tx_notes, wallet_rpc::COMMAND_RPC_SET_TX_NOTES) MAP_JON_RPC_WE("get_tx_notes", on_get_tx_notes, wallet_rpc::COMMAND_RPC_GET_TX_NOTES) + MAP_JON_RPC_WE("get_transfers", on_get_transfers, wallet_rpc::COMMAND_RPC_GET_TRANSFERS) END_JSON_RPC_MAP() END_URI_MAP2() @@ -101,6 +102,7 @@ namespace tools bool on_rescan_blockchain(const wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN::request& req, wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN::response& res, epee::json_rpc::error& er); bool on_set_tx_notes(const wallet_rpc::COMMAND_RPC_SET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_SET_TX_NOTES::response& res, epee::json_rpc::error& er); bool on_get_tx_notes(const wallet_rpc::COMMAND_RPC_GET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_GET_TX_NOTES::response& res, epee::json_rpc::error& er); + bool on_get_transfers(const wallet_rpc::COMMAND_RPC_GET_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_GET_TRANSFERS::response& res, epee::json_rpc::error& er); bool handle_command_line(const boost::program_options::variables_map& vm); diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index ebcc67923..9fe85dfc1 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -488,6 +488,66 @@ namespace wallet_rpc }; }; + struct COMMAND_RPC_GET_TRANSFERS + { + struct request + { + bool in; + bool out; + bool pending; + bool failed; + uint64_t min_height; + uint64_t max_height; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(in); + KV_SERIALIZE(out); + KV_SERIALIZE(pending); + KV_SERIALIZE(failed); + KV_SERIALIZE(min_height); + KV_SERIALIZE(max_height); + END_KV_SERIALIZE_MAP() + }; + + struct entry + { + std::string txid; + std::string payment_id; + uint64_t height; + uint64_t timestamp; + uint64_t amount; + uint64_t fee; + std::string note; + std::list destinations; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(txid); + KV_SERIALIZE(payment_id); + KV_SERIALIZE(height); + KV_SERIALIZE(timestamp); + KV_SERIALIZE(amount); + KV_SERIALIZE(fee); + KV_SERIALIZE(note); + KV_SERIALIZE(destinations); + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::list in; + std::list out; + std::list pending; + std::list failed; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(in); + KV_SERIALIZE(out); + KV_SERIALIZE(pending); + KV_SERIALIZE(failed); + END_KV_SERIALIZE_MAP() + }; + }; + } } -- cgit v1.2.3 From 09dddf281a55e918d1d5afa3a184779570538d7e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 27 Apr 2016 23:43:39 +0100 Subject: wallet: add a filter_by_height field to get_transfers It allows a simple get_transfers (with default 0 min_height and max_height) to return all transactions, instead of the unexpected set of txes in block 0, which is probably none at all. --- src/wallet/wallet_rpc_server.cpp | 11 +++++++++-- src/wallet/wallet_rpc_server_commands_defs.h | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/wallet/wallet_rpc_server.cpp') diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 5b678fa38..a082f731b 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -842,10 +842,17 @@ namespace tools return false; } + uint64_t min_height = 0, max_height = (uint64_t)-1; + if (req.filter_by_height) + { + min_height = req.min_height; + max_height = req.max_height; + } + if (req.in) { std::list> payments; - m_wallet.get_payments(payments, req.min_height, req.max_height); + m_wallet.get_payments(payments, min_height, max_height); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry()); wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back(); @@ -866,7 +873,7 @@ namespace tools if (req.out) { std::list> payments; - m_wallet.get_payments_out(payments, req.min_height, req.max_height); + m_wallet.get_payments_out(payments, min_height, max_height); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry()); wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back(); diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index 9fe85dfc1..f8c04c007 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -496,6 +496,8 @@ namespace wallet_rpc bool out; bool pending; bool failed; + + bool filter_by_height; uint64_t min_height; uint64_t max_height; @@ -504,6 +506,7 @@ namespace wallet_rpc KV_SERIALIZE(out); KV_SERIALIZE(pending); KV_SERIALIZE(failed); + KV_SERIALIZE(filter_by_height); KV_SERIALIZE(min_height); KV_SERIALIZE(max_height); END_KV_SERIALIZE_MAP() -- cgit v1.2.3