aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Michaels <mikezackles@gmail.com>2014-07-22 12:00:25 -0400
committerZachary Michaels <mikezackles@gmail.com>2014-07-22 12:16:15 -0400
commit12596ad566b23c0b88678c01c0d1871167fefc79 (patch)
tree3d70b64f7f529681672facc1a5d766b076ef8bc8
parentMerge pull request #65 from tewinget/daemon_rpc (diff)
downloadmonero-12596ad566b23c0b88678c01c0d1871167fefc79.tar.xz
Add get_bulk_payments rpc call
-rw-r--r--src/wallet/wallet2.cpp9
-rw-r--r--src/wallet/wallet2.h2
-rw-r--r--src/wallet/wallet_rpc_server.cpp48
-rw-r--r--src/wallet/wallet_rpc_server.h2
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h25
5 files changed, 81 insertions, 5 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 5b284c619..a56d3b3c9 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -574,11 +574,14 @@ void wallet2::get_transfers(wallet2::transfer_container& incoming_transfers) con
incoming_transfers = m_transfers;
}
//----------------------------------------------------------------------------------------------------
-void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments) const
+void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height) const
{
auto range = m_payments.equal_range(payment_id);
- std::for_each(range.first, range.second, [&payments](const payment_container::value_type& x) {
- payments.push_back(x.second);
+ std::for_each(range.first, range.second, [&payments, &min_height](const payment_container::value_type& x) {
+ if (min_height < x.second.m_block_height)
+ {
+ payments.push_back(x.second);
+ }
});
}
//----------------------------------------------------------------------------------------------------
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 1f5ae7062..d802271d1 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -143,7 +143,7 @@ namespace tools
std::vector<pending_tx> create_transactions(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, const uint64_t fee, const std::vector<uint8_t> extra);
bool check_connection();
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
- void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments) const;
+ void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
uint64_t get_blockchain_current_height() const { return m_local_bc_height; }
template <class t_archive>
inline void serialize(t_archive &a, const unsigned int ver)
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index ec31d4625..228e43678 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -268,9 +268,10 @@ namespace tools
res.payments.clear();
std::list<wallet2::payment_details> payment_list;
m_wallet.get_payments(payment_id, payment_list);
- for (auto payment : payment_list)
+ for (auto & payment : payment_list)
{
wallet_rpc::payment_details rpc_payment;
+ rpc_payment.payment_id = req.payment_id;
rpc_payment.tx_hash = epee::string_tools::pod_to_hex(payment.m_tx_hash);
rpc_payment.amount = payment.m_amount;
rpc_payment.block_height = payment.m_block_height;
@@ -281,6 +282,51 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_get_bulk_payments(const wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx)
+ {
+ res.payments.clear();
+
+ for (auto & payment_id_str : req.payment_ids)
+ {
+ crypto::hash payment_id;
+ cryptonote::blobdata payment_id_blob;
+
+ // TODO - should the whole thing fail because of one bad id?
+
+ if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_blob))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
+ er.message = "Payment ID has invalid format: " + payment_id_str;
+ return false;
+ }
+
+ if(sizeof(payment_id) != payment_id_blob.size())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
+ er.message = "Payment ID has invalid size: " + payment_id_str;
+ return false;
+ }
+
+ payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_blob.data());
+
+ std::list<wallet2::payment_details> payment_list;
+ m_wallet.get_payments(payment_id, payment_list, req.min_block_height);
+
+ for (auto & payment : payment_list)
+ {
+ wallet_rpc::payment_details rpc_payment;
+ rpc_payment.payment_id = payment_id_str;
+ rpc_payment.tx_hash = epee::string_tools::pod_to_hex(payment.m_tx_hash);
+ rpc_payment.amount = payment.m_amount;
+ rpc_payment.block_height = payment.m_block_height;
+ rpc_payment.unlock_time = payment.m_unlock_time;
+ res.payments.push_back(std::move(rpc_payment));
+ }
+ }
+
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::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, connection_context& cntx)
{
if(req.transfer_type.compare("all") != 0 && req.transfer_type.compare("available") != 0 && req.transfer_type.compare("unavailable") != 0)
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index f9893566a..170f215f7 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -41,6 +41,7 @@ namespace tools
MAP_JON_RPC_WE("transfer_split", on_transfer_split, wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT)
MAP_JON_RPC_WE("store", on_store, wallet_rpc::COMMAND_RPC_STORE)
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS)
+ MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS)
MAP_JON_RPC_WE("incoming_transfers", on_incoming_transfers, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -53,6 +54,7 @@ namespace tools
bool on_transfer_split(const wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::request& req, wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_get_payments(const wallet_rpc::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
+ bool on_get_bulk_payments(const wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
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, connection_context& cntx);
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 33130da06..b8b2f4e5f 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -137,12 +137,14 @@ namespace wallet_rpc
struct payment_details
{
+ std::string payment_id;
std::string tx_hash;
uint64_t amount;
uint64_t block_height;
uint64_t unlock_time;
BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(payment_id)
KV_SERIALIZE(tx_hash)
KV_SERIALIZE(amount)
KV_SERIALIZE(block_height)
@@ -170,6 +172,29 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
};
+
+ struct COMMAND_RPC_GET_BULK_PAYMENTS
+ {
+ struct request
+ {
+ std::vector<std::string> payment_ids;
+ uint64_t min_block_height;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(payment_ids)
+ KV_SERIALIZE(min_block_height)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::list<payment_details> payments;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(payments)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
struct transfer_details
{