diff options
author | monero-project <sempre.amaro@gmail.com> | 2014-06-04 10:16:28 -0400 |
---|---|---|
committer | monero-project <sempre.amaro@gmail.com> | 2014-06-04 10:16:28 -0400 |
commit | 4492317603b73ed0d1a447b7916d228bd62358fd (patch) | |
tree | 2c7ed1b006d05e690a5644b8024c14eaeaf3a59c /src/wallet/wallet_rpc_server.cpp | |
parent | Merge pull request #22 from Neozaru/master (diff) | |
parent | fixed conflict (diff) | |
download | monero-4492317603b73ed0d1a447b7916d228bd62358fd.tar.xz |
Merge pull request #23 from paybee/master
Added incoming_transfers RPC API method
Diffstat (limited to 'src/wallet/wallet_rpc_server.cpp')
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index af195cfcc..a0816946b 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -208,4 +208,55 @@ namespace tools 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) + { + er.code = WALLET_RPC_ERROR_CODE_TRANSFER_TYPE; + er.message = "Transfer type must be one of: all, available, or unavailable"; + return false; + } + + bool filter = false; + bool available = false; + if (req.transfer_type.compare("available") == 0) + { + filter = true; + available = true; + } + else if (req.transfer_type.compare("unavailable") == 0) + { + filter = true; + available = false; + } + + wallet2::transfer_container transfers; + m_wallet.get_transfers(transfers); + + bool transfers_found = false; + for (const auto& td : transfers) + { + if (!filter || available != td.m_spent) + { + if (!transfers_found) + { + transfers_found = true; + } + wallet_rpc::transfer_details rpc_transfers; + rpc_transfers.amount = td.amount(); + rpc_transfers.spent = td.m_spent; + rpc_transfers.global_index = td.m_global_output_index; + rpc_transfers.tx_hash = boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(td.m_tx)); + res.transfers.push_back(rpc_transfers); + } + } + + if (!transfers_found) + { + return false; + } + + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ } |