diff options
author | paybee <dev@payb.ee> | 2014-05-27 12:52:11 +0200 |
---|---|---|
committer | paybee <dev@payb.ee> | 2014-05-27 12:52:11 +0200 |
commit | feacdded6b48fcfe18bc3218b05b27e94db2fc92 (patch) | |
tree | 1a39df95f2319a085f66dede3f00f7451f98a598 /src/wallet | |
parent | simplewallet exits when COMMAND is given as a command-line argument (diff) | |
download | monero-feacdded6b48fcfe18bc3218b05b27e94db2fc92.tar.xz |
Added incoming_transfers RPC API method
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 64 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.h | 10 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server_commans_defs.h | 36 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server_error_codes.h | 2 |
4 files changed, 108 insertions, 4 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; + } + //------------------------------------------------------------------------------------------------------------------------------ } diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index db49df574..69cc9530a 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -35,10 +35,11 @@ namespace tools BEGIN_URI_MAP2() BEGIN_JSON_RPC_MAP("/json_rpc") - MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE) - MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER) - 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("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE) + MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER) + 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("incoming_transfers", on_incoming_transfers, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS) END_JSON_RPC_MAP() END_URI_MAP2() @@ -47,6 +48,7 @@ namespace tools bool on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::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_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_commans_defs.h b/src/wallet/wallet_rpc_server_commans_defs.h index b99d92ca2..7bdb49b2c 100644 --- a/src/wallet/wallet_rpc_server_commans_defs.h +++ b/src/wallet/wallet_rpc_server_commans_defs.h @@ -121,6 +121,42 @@ namespace wallet_rpc END_KV_SERIALIZE_MAP() }; }; + + struct transfer_details + { + uint64_t amount; + bool spent; + uint64_t global_index; + std::string tx_hash; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(amount) + KV_SERIALIZE(spent) + KV_SERIALIZE(global_index) + KV_SERIALIZE(tx_hash) + END_KV_SERIALIZE_MAP() + }; + + struct COMMAND_RPC_INCOMING_TRANSFERS + { + struct request + { + std::string transfer_type; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(transfer_type) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::list<transfer_details> transfers; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(transfers) + 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 7fa536dac..fb3c1c1a9 100644 --- a/src/wallet/wallet_rpc_server_error_codes.h +++ b/src/wallet/wallet_rpc_server_error_codes.h @@ -10,3 +10,5 @@ #define WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY -3 #define WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR -4 #define WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID -5 +#define WALLET_RPC_ERROR_CODE_TRANSFER_TYPE -6 +#define WALLET_RPC_ERROR_CODE_NO_TRANSFERS -7 |