Skip to content

Commit

Permalink
Added 'transfer' to the list of extended RPC methods in simplewallet …
Browse files Browse the repository at this point in the history
…requiring an explicit flag to enable these methods. Updated existing methods to throw an error informing the user that their request has been restricted when attempting to access extended methods without authorisation.
  • Loading branch information
nnamon committed Feb 1, 2018
1 parent df303ba commit db53d46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Wallet/WalletRpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ void wallet_rpc_server::processRequest(const CryptoNote::HttpRequest& request, C

static std::unordered_map<std::string, JsonMemberMethod> s_methods = {
{ "getbalance", makeMemberMethod(&wallet_rpc_server::on_getbalance) },
{ "transfer", makeMemberMethod(&wallet_rpc_server::on_transfer) },
{ "store", makeMemberMethod(&wallet_rpc_server::on_store) },
{ "get_payments", makeMemberMethod(&wallet_rpc_server::on_get_payments) },
{ "get_transfers", makeMemberMethod(&wallet_rpc_server::on_get_transfers) },
{ "get_height", makeMemberMethod(&wallet_rpc_server::on_get_height) },
// below are the restricted methods, use --enable-extended-rpc
{ "transfer", makeMemberMethod(&wallet_rpc_server::on_transfer) },
{ "reset", makeMemberMethod(&wallet_rpc_server::on_reset) },
{ "stop_wallet", makeMemberMethod(&wallet_rpc_server::on_stop_wallet) },
{ "get_address", makeMemberMethod(&wallet_rpc_server::on_get_address) },
Expand Down Expand Up @@ -142,6 +142,11 @@ bool wallet_rpc_server::on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE:
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res) {

if(!m_allow_extended_rpc) {
throw JsonRpc::JsonRpcError(WALLET_RPC_ERROR_METHOD_RESTRICTED, "Unable to invoke extended RPC method without explicit --allow-extended-rpc flag.");
}

std::vector<CryptoNote::WalletLegacyTransfer> transfers;
for (auto it = req.destinations.begin(); it != req.destinations.end(); it++) {
CryptoNote::WalletLegacyTransfer transfer;
Expand Down Expand Up @@ -311,6 +316,9 @@ bool wallet_rpc_server::on_stop_wallet(const wallet_rpc::COMMAND_RPC_STOP::reque

wallet_rpc_server::send_stop_signal();
}
else {
throw JsonRpc::JsonRpcError(WALLET_RPC_ERROR_METHOD_RESTRICTED, "Unable to invoke extended RPC method without explicit --allow-extended-rpc flag.");
}
return true;

}
Expand All @@ -320,6 +328,9 @@ bool wallet_rpc_server::on_get_address(const wallet_rpc::COMMAND_RPC_GET_ADDRESS
if(m_allow_extended_rpc) {
res.address = m_wallet.getAddress();
}
else {
throw JsonRpc::JsonRpcError(WALLET_RPC_ERROR_METHOD_RESTRICTED, "Unable to invoke extended RPC method without explicit --allow-extended-rpc flag.");
}
return true;

}
Expand All @@ -332,6 +343,9 @@ bool wallet_rpc_server::on_view_keys(const wallet_rpc::COMMAND_RPC_VIEW_KEYS::re
res.view_key = Common::podToHex(keys.viewSecretKey);
res.spend_key = Common::podToHex(keys.spendSecretKey);
}
else {
throw JsonRpc::JsonRpcError(WALLET_RPC_ERROR_METHOD_RESTRICTED, "Unable to invoke extended RPC method without explicit --allow-extended-rpc flag.");
}
return true;

}
Expand Down
1 change: 1 addition & 0 deletions src/Wallet/WalletRpcServerErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
#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_METHOD_RESTRICTED -6

0 comments on commit db53d46

Please sign in to comment.