aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet_rpc_server.cpp
diff options
context:
space:
mode:
authorpaybee <dev@payb.ee>2014-05-27 12:52:11 +0200
committerpaybee <dev@payb.ee>2014-05-27 12:52:11 +0200
commitfeacdded6b48fcfe18bc3218b05b27e94db2fc92 (patch)
tree1a39df95f2319a085f66dede3f00f7451f98a598 /src/wallet/wallet_rpc_server.cpp
parentsimplewallet exits when COMMAND is given as a command-line argument (diff)
downloadmonero-feacdded6b48fcfe18bc3218b05b27e94db2fc92.tar.xz
Added incoming_transfers RPC API method
Diffstat (limited to 'src/wallet/wallet_rpc_server.cpp')
-rw-r--r--src/wallet/wallet_rpc_server.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index f1766c3b4..7dc73d8bf 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -166,4 +166,68 @@ 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; provided: "
+ 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)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_NO_TRANSFERS;
+ if (!filter)
+ {
+ er.message = "No incoming transfers";
+ }
+ else if (available)
+ {
+ er.message = "No incoming available transfers";
+ }
+ else
+ {
+ er.message = "No incoming unavailable transfers";
+ }
+ return false;
+ }
+
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
}