diff options
author | monero-project <sempre.amaro@gmail.com> | 2014-06-02 10:53:52 -0400 |
---|---|---|
committer | monero-project <sempre.amaro@gmail.com> | 2014-06-02 10:53:52 -0400 |
commit | 24b4f47413bf9e1874ff01866b7dc50cd41c415a (patch) | |
tree | 37e90eb393071d3ca4fabe72513501c7066b3e54 | |
parent | Merge pull request #20 from artifexd/wallet_refresh (diff) | |
parent | Added 'payment_id' optional argument to 'transfer' wallet RPC method (diff) | |
download | monero-24b4f47413bf9e1874ff01866b7dc50cd41c415a.tar.xz |
Merge pull request #21 from Neozaru/master
Added 'payment_id' optional argument to 'transfer' wallet RPC method
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 17 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 14 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 2 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 29 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server_commans_defs.h | 2 |
5 files changed, 48 insertions, 16 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index dc45d9d74..4cab12c22 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -64,19 +64,6 @@ namespace return err; } - bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id) - { - blobdata payment_id_data; - if(!string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_data)) - return false; - - if(sizeof(crypto::hash) != payment_id_data.size()) - return false; - - payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_data.data()); - return true; - } - class message_writer { public: @@ -680,7 +667,7 @@ bool simple_wallet::show_payments(const std::vector<std::string> &args) for(std::string arg : args) { crypto::hash payment_id; - if(parse_payment_id(arg, payment_id)) + if(tools::wallet2::parse_payment_id(arg, payment_id)) { std::list<tools::wallet2::payment_details> payments; m_wallet->get_payments(payment_id, payments); @@ -763,7 +750,7 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_) local_args.pop_back(); crypto::hash payment_id; - bool r = parse_payment_id(payment_id_str, payment_id); + bool r = tools::wallet2::parse_payment_id(payment_id_str, payment_id); if(r) { std::string extra_nonce; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 111b76117..fb1e5575b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -19,6 +19,7 @@ using namespace epee; #include "profile_tools.h" #include "crypto/crypto.h" #include "serialization/binary_utils.h" +#include "cryptonote_protocol/blobdatatype.h" using namespace cryptonote; @@ -465,6 +466,19 @@ void wallet2::wallet_exists(const std::string& file_path, bool& keys_file_exists wallet_file_exists = boost::filesystem::exists(wallet_file, ignore); } //---------------------------------------------------------------------------------------------------- +bool wallet2::parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id) +{ + cryptonote::blobdata payment_id_data; + if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_data)) + return false; + + if(sizeof(crypto::hash) != payment_id_data.size()) + return false; + + payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_data.data()); + return true; +} +//---------------------------------------------------------------------------------------------------- bool wallet2::prepare_file_names(const std::string& file_path) { do_prepare_file_names(file_path, m_keys_file, m_wallet_file); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f90fc4fac..9ca586425 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -151,6 +151,8 @@ namespace tools static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists); + static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id); + private: bool store_keys(const std::string& keys_file_name, const std::string& password); void load_keys(const std::string& keys_file_name, const std::string& password); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 55f81aacc..af195cfcc 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -102,10 +102,37 @@ namespace tools de.amount = it->amount; dsts.push_back(de); } + + std::vector<uint8_t> extra; + if (!req.payment_id.empty()) { + + /* Just to clarify */ + const std::string& payment_id_str = req.payment_id; + + crypto::hash payment_id; + /* Parse payment ID */ + if (!wallet2::parse_payment_id(payment_id_str, payment_id)) { + er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; + er.message = "Payment id has invalid format: \"" + payment_id_str + "\", expected 64-character string"; + return false; + } + + std::string extra_nonce; + cryptonote::set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id); + + /* Append Payment ID data into extra */ + if (!cryptonote::add_extra_nonce_to_tx_extra(extra, extra_nonce)) { + er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; + er.message = "Something went wront with payment_id. Please check its format: \"" + payment_id_str + "\", expected 64-character string"; + return false; + } + + } + try { cryptonote::transaction tx; - m_wallet.transfer(dsts, req.mixin, req.unlock_time, req.fee, std::vector<uint8_t>(), tx); + m_wallet.transfer(dsts, req.mixin, req.unlock_time, req.fee, extra, tx); res.tx_hash = boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(tx)); return true; } diff --git a/src/wallet/wallet_rpc_server_commans_defs.h b/src/wallet/wallet_rpc_server_commans_defs.h index cc005b29c..df05b4e0a 100644 --- a/src/wallet/wallet_rpc_server_commans_defs.h +++ b/src/wallet/wallet_rpc_server_commans_defs.h @@ -70,12 +70,14 @@ namespace wallet_rpc uint64_t fee; uint64_t mixin; uint64_t unlock_time; + std::string payment_id; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(destinations) KV_SERIALIZE(fee) KV_SERIALIZE(mixin) KV_SERIALIZE(unlock_time) + KV_SERIALIZE(payment_id) END_KV_SERIALIZE_MAP() }; |