diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-04-20 18:19:42 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-04-26 19:07:33 +0100 |
commit | 7baed9bd8986d33d5892536f081eac284015372f (patch) | |
tree | c80fd726d87a76371796f10e39d891b37ceb0132 /src/wallet | |
parent | wallet: add GMT timestamps to transfers/payments (diff) | |
download | monero-7baed9bd8986d33d5892536f081eac284015372f.tar.xz |
wallet: allow attaching notes to txids
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet2.cpp | 13 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 9 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 63 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.h | 4 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server_commands_defs.h | 41 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server_error_codes.h | 1 |
6 files changed, 130 insertions, 1 deletions
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<crypto::hash, std::string>::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<size_t> select_available_unmixable_outputs(bool trusted_daemon); std::vector<size_t> 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<crypto::key_image, size_t> m_key_images; cryptonote::account_public_address m_account_public_address; + std::unordered_map<crypto::hash, std::string> 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<bool> 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<crypto::hash> txids; + std::list<std::string>::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<const crypto::hash*>(txid_blob.data()); + txids.push_back(txid); + } + + std::list<crypto::hash>::const_iterator il = txids.begin(); + std::list<std::string>::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<crypto::hash> txids; + std::list<std::string>::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<const crypto::hash*>(txid_blob.data()); + txids.push_back(txid); + } + + std::list<crypto::hash>::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<std::string> txids; + std::list<std::string> 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<std::string> txids; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(txids) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::list<std::string> 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 |