oxen-core/src/wallet/wallet_rpc_server.h

226 lines
16 KiB
C
Raw Normal View History

// Copyright (c) 2014-2019, The Monero Project
2018-04-10 06:49:20 +02:00
// Copyright (c) 2018, The Loki Project
2014-07-23 15:03:52 +02:00
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
2014-04-02 18:00:17 +02:00
2014-05-03 18:19:43 +02:00
#pragma once
2014-04-02 18:00:17 +02:00
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <string>
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
#include <uWebSockets/App.h>
#include "common/util.h"
#include "common/fs.h"
#include "common/periodic_task.h"
#include "wallet_rpc_server_commands_defs.h"
2014-04-02 18:00:17 +02:00
#include "wallet2.h"
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
#include "rpc/http_server_base.h"
Change logging to easylogging++ This replaces the epee and data_loggers logging systems with a single one, and also adds filename:line and explicit severity levels. Categories may be defined, and logging severity set by category (or set of categories). epee style 0-4 log level maps to a sensible severity configuration. Log files now also rotate when reaching 100 MB. To select which logs to output, use the MONERO_LOGS environment variable, with a comma separated list of categories (globs are supported), with their requested severity level after a colon. If a log matches more than one such setting, the last one in the configuration string applies. A few examples: This one is (mostly) silent, only outputting fatal errors: MONERO_LOGS=*:FATAL This one is very verbose: MONERO_LOGS=*:TRACE This one is totally silent (logwise): MONERO_LOGS="" This one outputs all errors and warnings, except for the "verify" category, which prints just fatal errors (the verify category is used for logs about incoming transactions and blocks, and it is expected that some/many will fail to verify, hence we don't want the spam): MONERO_LOGS=*:WARNING,verify:FATAL Log levels are, in decreasing order of priority: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE Subcategories may be added using prefixes and globs. This example will output net.p2p logs at the TRACE level, but all other net* logs only at INFO: MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE Logs which are intended for the user (which Monero was using a lot through epee, but really isn't a nice way to go things) should use the "global" category. There are a few helper macros for using this category, eg: MGINFO("this shows up by default") or MGINFO_RED("this is red"), to try to keep a similar look and feel for now. Existing epee log macros still exist, and map to the new log levels, but since they're used as a "user facing" UI element as much as a logging system, they often don't map well to log severities (ie, a log level 0 log may be an error, or may be something we want the user to see, such as an important info). In those cases, I tried to use the new macros. In other cases, I left the existing macros in. When modifying logs, it is probably best to switch to the new macros with explicit levels. The --log-level options and set_log commands now also accept category settings, in addition to the epee style log levels.
2017-01-01 17:34:23 +01:00
2021-01-04 04:19:42 +01:00
#undef OXEN_DEFAULT_LOG_CATEGORY
#define OXEN_DEFAULT_LOG_CATEGORY "wallet.rpc"
Change logging to easylogging++ This replaces the epee and data_loggers logging systems with a single one, and also adds filename:line and explicit severity levels. Categories may be defined, and logging severity set by category (or set of categories). epee style 0-4 log level maps to a sensible severity configuration. Log files now also rotate when reaching 100 MB. To select which logs to output, use the MONERO_LOGS environment variable, with a comma separated list of categories (globs are supported), with their requested severity level after a colon. If a log matches more than one such setting, the last one in the configuration string applies. A few examples: This one is (mostly) silent, only outputting fatal errors: MONERO_LOGS=*:FATAL This one is very verbose: MONERO_LOGS=*:TRACE This one is totally silent (logwise): MONERO_LOGS="" This one outputs all errors and warnings, except for the "verify" category, which prints just fatal errors (the verify category is used for logs about incoming transactions and blocks, and it is expected that some/many will fail to verify, hence we don't want the spam): MONERO_LOGS=*:WARNING,verify:FATAL Log levels are, in decreasing order of priority: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE Subcategories may be added using prefixes and globs. This example will output net.p2p logs at the TRACE level, but all other net* logs only at INFO: MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE Logs which are intended for the user (which Monero was using a lot through epee, but really isn't a nice way to go things) should use the "global" category. There are a few helper macros for using this category, eg: MGINFO("this shows up by default") or MGINFO_RED("this is red"), to try to keep a similar look and feel for now. Existing epee log macros still exist, and map to the new log levels, but since they're used as a "user facing" UI element as much as a logging system, they often don't map well to log severities (ie, a log level 0 log may be an error, or may be something we want the user to see, such as an important info). In those cases, I tried to use the new macros. In other cases, I left the existing macros in. When modifying logs, it is probably best to switch to the new macros with explicit levels. The --log-level options and set_log commands now also accept category settings, in addition to the epee style log levels.
2017-01-01 17:34:23 +01:00
2014-04-02 18:00:17 +02:00
namespace tools
{
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
using HttpRequest = uWS::HttpRequest;
using HttpResponse = uWS::HttpResponse<false/*SSL*/>;
2014-04-02 18:00:17 +02:00
/************************************************************************/
/* */
/************************************************************************/
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
class wallet_rpc_server final : public cryptonote::rpc::http_server_base
2014-04-02 18:00:17 +02:00
{
public:
static const char* tr(const char* str);
2014-04-02 18:00:17 +02:00
daemon & daemonize overhaul This commit continues the complete replacement of the spaghetti code mess that was inside daemon/ and daemonize/ which started in #1138, and looked like a entry level Java programmer threw up inside the code base. This greatly simplifies it, removing a whole pile of useless abstraction layers that don't actually abstract anything, and results in considerably simpler code. (Many of the changes here were also carried out in #1138; this commit updates them with the merged result which amends some things from that PR and goes further in some places). In detail: - the `--detach` (and related `--pidfile`) options are gone. (--detach is still handled, but now just prints a fatal error). Detaching a process is an archaic unix mechanism that has no place on a modern system. If you *really* want to do it anyway, `nohup lokid &` will do the job. (The Windows service control code, which is probably seldom used, is kept because it seems potentially useful for Windows users). - Many of the `t_whatever` classes in daemon/* are just deleted (mostly done in #1138); each one was a bunch of junk code that wraps 3-4 lines but forces an extra layer (not even a generic abstraction, just a useless wrapper) for no good reason and made the daemon code painfully hard to understand and work with. - All of the remaining `t_whatever` classes in daemon/* are either renamed to `whatever` (because prefixing every class with `t_` is moronic). - Some stupid related code (e.g. epee's command handler returning an unsuitable "usage" string that has to be string modified into what we want) was replaced with more generic, useful code. - Replaced boost mutexes/cvs with std ones in epee command handler, and deleted some commented out code. - The `--public-node` option handling was terrible: it was being handled in main, but main doesn't know anything about options, so then it forced it through the spaghetti objects *beside* the pack of all options that got passed along. Moved it to a more sane location (core_rpc_server) and parse it out with some sanity. - Changed a bunch of std::bind's to lambdas because, at least for small lambdas (i.e. with only one-or-two pointers for captures) they will generally be more efficient as the values can be stored in std::function's without any memory allocations.
2020-04-02 22:38:52 +02:00
wallet_rpc_server(boost::program_options::variables_map vm);
2014-04-02 18:00:17 +02:00
bool init();
daemon & daemonize overhaul This commit continues the complete replacement of the spaghetti code mess that was inside daemon/ and daemonize/ which started in #1138, and looked like a entry level Java programmer threw up inside the code base. This greatly simplifies it, removing a whole pile of useless abstraction layers that don't actually abstract anything, and results in considerably simpler code. (Many of the changes here were also carried out in #1138; this commit updates them with the merged result which amends some things from that PR and goes further in some places). In detail: - the `--detach` (and related `--pidfile`) options are gone. (--detach is still handled, but now just prints a fatal error). Detaching a process is an archaic unix mechanism that has no place on a modern system. If you *really* want to do it anyway, `nohup lokid &` will do the job. (The Windows service control code, which is probably seldom used, is kept because it seems potentially useful for Windows users). - Many of the `t_whatever` classes in daemon/* are just deleted (mostly done in #1138); each one was a bunch of junk code that wraps 3-4 lines but forces an extra layer (not even a generic abstraction, just a useless wrapper) for no good reason and made the daemon code painfully hard to understand and work with. - All of the remaining `t_whatever` classes in daemon/* are either renamed to `whatever` (because prefixing every class with `t_` is moronic). - Some stupid related code (e.g. epee's command handler returning an unsuitable "usage" string that has to be string modified into what we want) was replaced with more generic, useful code. - Replaced boost mutexes/cvs with std ones in epee command handler, and deleted some commented out code. - The `--public-node` option handling was terrible: it was being handled in main, but main doesn't know anything about options, so then it forced it through the spaghetti objects *beside* the pack of all options that got passed along. Moved it to a more sane location (core_rpc_server) and parse it out with some sanity. - Changed a bunch of std::bind's to lambdas because, at least for small lambdas (i.e. with only one-or-two pointers for captures) they will generally be more efficient as the values can be stored in std::function's without any memory allocations.
2020-04-02 22:38:52 +02:00
bool run(bool /*interactive - ignored (rpc wallet is always non-interactive) */);
void stop(); // Makes run() start cleaning up and shutting down
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
/// Thrown if we get invalid/unparseable JSON data.
struct parse_error : std::runtime_error { using std::runtime_error::runtime_error; };
//json_rpc
wallet_rpc::GET_BALANCE::response invoke(wallet_rpc::GET_BALANCE::request&& req);
wallet_rpc::GET_ADDRESS::response invoke(wallet_rpc::GET_ADDRESS::request&& req);
wallet_rpc::GET_ADDRESS_INDEX::response invoke(wallet_rpc::GET_ADDRESS_INDEX::request&& req);
wallet_rpc::CREATE_ADDRESS::response invoke(wallet_rpc::CREATE_ADDRESS::request&& req);
wallet_rpc::LABEL_ADDRESS::response invoke(wallet_rpc::LABEL_ADDRESS::request&& req);
wallet_rpc::GET_ACCOUNTS::response invoke(wallet_rpc::GET_ACCOUNTS::request&& req);
wallet_rpc::CREATE_ACCOUNT::response invoke(wallet_rpc::CREATE_ACCOUNT::request&& req);
wallet_rpc::LABEL_ACCOUNT::response invoke(wallet_rpc::LABEL_ACCOUNT::request&& req);
wallet_rpc::GET_ACCOUNT_TAGS::response invoke(wallet_rpc::GET_ACCOUNT_TAGS::request&& req);
wallet_rpc::TAG_ACCOUNTS::response invoke(wallet_rpc::TAG_ACCOUNTS::request&& req);
wallet_rpc::UNTAG_ACCOUNTS::response invoke(wallet_rpc::UNTAG_ACCOUNTS::request&& req);
wallet_rpc::SET_ACCOUNT_TAG_DESCRIPTION::response invoke(wallet_rpc::SET_ACCOUNT_TAG_DESCRIPTION::request&& req);
wallet_rpc::GET_HEIGHT::response invoke(wallet_rpc::GET_HEIGHT::request&& req);
wallet_rpc::TRANSFER::response invoke(wallet_rpc::TRANSFER::request&& req);
wallet_rpc::TRANSFER_SPLIT::response invoke(wallet_rpc::TRANSFER_SPLIT::request&& req);
wallet_rpc::SIGN_TRANSFER::response invoke(wallet_rpc::SIGN_TRANSFER::request&& req);
wallet_rpc::DESCRIBE_TRANSFER::response invoke(wallet_rpc::DESCRIBE_TRANSFER::request&& req);
wallet_rpc::SUBMIT_TRANSFER::response invoke(wallet_rpc::SUBMIT_TRANSFER::request&& req);
wallet_rpc::SWEEP_DUST::response invoke(wallet_rpc::SWEEP_DUST::request&& req);
wallet_rpc::SWEEP_ALL::response invoke(wallet_rpc::SWEEP_ALL::request&& req);
wallet_rpc::SWEEP_SINGLE::response invoke(wallet_rpc::SWEEP_SINGLE::request&& req);
wallet_rpc::RELAY_TX::response invoke(wallet_rpc::RELAY_TX::request&& req);
wallet_rpc::MAKE_INTEGRATED_ADDRESS::response invoke(wallet_rpc::MAKE_INTEGRATED_ADDRESS::request&& req);
wallet_rpc::SPLIT_INTEGRATED_ADDRESS::response invoke(wallet_rpc::SPLIT_INTEGRATED_ADDRESS::request&& req);
wallet_rpc::STORE::response invoke(wallet_rpc::STORE::request&& req);
wallet_rpc::GET_PAYMENTS::response invoke(wallet_rpc::GET_PAYMENTS::request&& req);
wallet_rpc::GET_BULK_PAYMENTS::response invoke(wallet_rpc::GET_BULK_PAYMENTS::request&& req);
wallet_rpc::INCOMING_TRANSFERS::response invoke(wallet_rpc::INCOMING_TRANSFERS::request&& req);
wallet_rpc::STOP_WALLET::response invoke(wallet_rpc::STOP_WALLET::request&& req);
wallet_rpc::RESCAN_BLOCKCHAIN::response invoke(wallet_rpc::RESCAN_BLOCKCHAIN::request&& req);
wallet_rpc::SET_TX_NOTES::response invoke(wallet_rpc::SET_TX_NOTES::request&& req);
wallet_rpc::GET_TX_NOTES::response invoke(wallet_rpc::GET_TX_NOTES::request&& req);
wallet_rpc::SET_ATTRIBUTE::response invoke(wallet_rpc::SET_ATTRIBUTE::request&& req);
wallet_rpc::GET_ATTRIBUTE::response invoke(wallet_rpc::GET_ATTRIBUTE::request&& req);
wallet_rpc::GET_TX_KEY::response invoke(wallet_rpc::GET_TX_KEY::request&& req);
wallet_rpc::CHECK_TX_KEY::response invoke(wallet_rpc::CHECK_TX_KEY::request&& req);
wallet_rpc::GET_TX_PROOF::response invoke(wallet_rpc::GET_TX_PROOF::request&& req);
wallet_rpc::CHECK_TX_PROOF::response invoke(wallet_rpc::CHECK_TX_PROOF::request&& req);
wallet_rpc::GET_SPEND_PROOF::response invoke(wallet_rpc::GET_SPEND_PROOF::request&& req);
wallet_rpc::CHECK_SPEND_PROOF::response invoke(wallet_rpc::CHECK_SPEND_PROOF::request&& req);
wallet_rpc::GET_RESERVE_PROOF::response invoke(wallet_rpc::GET_RESERVE_PROOF::request&& req);
wallet_rpc::CHECK_RESERVE_PROOF::response invoke(wallet_rpc::CHECK_RESERVE_PROOF::request&& req);
wallet_rpc::GET_TRANSFERS::response invoke(wallet_rpc::GET_TRANSFERS::request&& req);
wallet_rpc::GET_TRANSFERS_CSV::response invoke(wallet_rpc::GET_TRANSFERS_CSV::request&& req);
wallet_rpc::GET_TRANSFER_BY_TXID::response invoke(wallet_rpc::GET_TRANSFER_BY_TXID::request&& req);
wallet_rpc::SIGN::response invoke(wallet_rpc::SIGN::request&& req);
wallet_rpc::VERIFY::response invoke(wallet_rpc::VERIFY::request&& req);
wallet_rpc::EXPORT_OUTPUTS::response invoke(wallet_rpc::EXPORT_OUTPUTS::request&& req);
wallet_rpc::EXPORT_TRANSFERS::response invoke(wallet_rpc::EXPORT_TRANSFERS::request&& req);
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
wallet_rpc::IMPORT_OUTPUTS::response invoke(wallet_rpc::IMPORT_OUTPUTS::request&& req);
wallet_rpc::EXPORT_KEY_IMAGES::response invoke(wallet_rpc::EXPORT_KEY_IMAGES::request&& req);
wallet_rpc::IMPORT_KEY_IMAGES::response invoke(wallet_rpc::IMPORT_KEY_IMAGES::request&& req);
wallet_rpc::MAKE_URI::response invoke(wallet_rpc::MAKE_URI::request&& req);
wallet_rpc::PARSE_URI::response invoke(wallet_rpc::PARSE_URI::request&& req);
wallet_rpc::GET_ADDRESS_BOOK_ENTRY::response invoke(wallet_rpc::GET_ADDRESS_BOOK_ENTRY::request&& req);
wallet_rpc::ADD_ADDRESS_BOOK_ENTRY::response invoke(wallet_rpc::ADD_ADDRESS_BOOK_ENTRY::request&& req);
wallet_rpc::EDIT_ADDRESS_BOOK_ENTRY::response invoke(wallet_rpc::EDIT_ADDRESS_BOOK_ENTRY::request&& req);
wallet_rpc::DELETE_ADDRESS_BOOK_ENTRY::response invoke(wallet_rpc::DELETE_ADDRESS_BOOK_ENTRY::request&& req);
wallet_rpc::REFRESH::response invoke(wallet_rpc::REFRESH::request&& req);
wallet_rpc::AUTO_REFRESH::response invoke(wallet_rpc::AUTO_REFRESH::request&& req);
wallet_rpc::RESCAN_SPENT::response invoke(wallet_rpc::RESCAN_SPENT::request&& req);
wallet_rpc::START_MINING::response invoke(wallet_rpc::START_MINING::request&& req);
wallet_rpc::STOP_MINING::response invoke(wallet_rpc::STOP_MINING::request&& req);
wallet_rpc::GET_LANGUAGES::response invoke(wallet_rpc::GET_LANGUAGES::request&& req);
wallet_rpc::CREATE_WALLET::response invoke(wallet_rpc::CREATE_WALLET::request&& req);
wallet_rpc::OPEN_WALLET::response invoke(wallet_rpc::OPEN_WALLET::request&& req);
wallet_rpc::CLOSE_WALLET::response invoke(wallet_rpc::CLOSE_WALLET::request&& req);
wallet_rpc::CHANGE_WALLET_PASSWORD::response invoke(wallet_rpc::CHANGE_WALLET_PASSWORD::request&& req);
wallet_rpc::GENERATE_FROM_KEYS::response invoke(wallet_rpc::GENERATE_FROM_KEYS::request&& req);
wallet_rpc::RESTORE_DETERMINISTIC_WALLET::response invoke(wallet_rpc::RESTORE_DETERMINISTIC_WALLET::request&& req);
wallet_rpc::IS_MULTISIG::response invoke(wallet_rpc::IS_MULTISIG::request&& req);
wallet_rpc::PREPARE_MULTISIG::response invoke(wallet_rpc::PREPARE_MULTISIG::request&& req);
wallet_rpc::MAKE_MULTISIG::response invoke(wallet_rpc::MAKE_MULTISIG::request&& req);
wallet_rpc::EXPORT_MULTISIG::response invoke(wallet_rpc::EXPORT_MULTISIG::request&& req);
wallet_rpc::IMPORT_MULTISIG::response invoke(wallet_rpc::IMPORT_MULTISIG::request&& req);
wallet_rpc::FINALIZE_MULTISIG::response invoke(wallet_rpc::FINALIZE_MULTISIG::request&& req);
wallet_rpc::EXCHANGE_MULTISIG_KEYS::response invoke(wallet_rpc::EXCHANGE_MULTISIG_KEYS::request&& req);
wallet_rpc::SIGN_MULTISIG::response invoke(wallet_rpc::SIGN_MULTISIG::request&& req);
wallet_rpc::SUBMIT_MULTISIG::response invoke(wallet_rpc::SUBMIT_MULTISIG::request&& req);
wallet_rpc::VALIDATE_ADDRESS::response invoke(wallet_rpc::VALIDATE_ADDRESS::request&& req);
wallet_rpc::SET_DAEMON::response invoke(wallet_rpc::SET_DAEMON::request&& req);
wallet_rpc::SET_LOG_LEVEL::response invoke(wallet_rpc::SET_LOG_LEVEL::request&& req);
wallet_rpc::SET_LOG_CATEGORIES::response invoke(wallet_rpc::SET_LOG_CATEGORIES::request&& req);
wallet_rpc::GET_VERSION::response invoke(wallet_rpc::GET_VERSION::request&& req);
wallet_rpc::STAKE::response invoke(wallet_rpc::STAKE::request&& req);
wallet_rpc::REGISTER_SERVICE_NODE::response invoke(wallet_rpc::REGISTER_SERVICE_NODE::request&& req);
wallet_rpc::CAN_REQUEST_STAKE_UNLOCK::response invoke(wallet_rpc::CAN_REQUEST_STAKE_UNLOCK::request&& req);
wallet_rpc::REQUEST_STAKE_UNLOCK::response invoke(wallet_rpc::REQUEST_STAKE_UNLOCK::request&& req);
2021-02-12 05:19:30 +01:00
wallet_rpc::ONS_BUY_MAPPING::response invoke(wallet_rpc::ONS_BUY_MAPPING::request&& req);
wallet_rpc::ONS_RENEW_MAPPING::response invoke(wallet_rpc::ONS_RENEW_MAPPING::request&& req);
wallet_rpc::ONS_UPDATE_MAPPING::response invoke(wallet_rpc::ONS_UPDATE_MAPPING::request&& req);
wallet_rpc::ONS_MAKE_UPDATE_SIGNATURE::response invoke(wallet_rpc::ONS_MAKE_UPDATE_SIGNATURE::request&& req);
wallet_rpc::ONS_HASH_NAME::response invoke(wallet_rpc::ONS_HASH_NAME::request&& req);
wallet_rpc::ONS_KNOWN_NAMES::response invoke(wallet_rpc::ONS_KNOWN_NAMES::request&& req);
wallet_rpc::ONS_ADD_KNOWN_NAMES::response invoke(wallet_rpc::ONS_ADD_KNOWN_NAMES::request&& req);
wallet_rpc::ONS_DECRYPT_VALUE::response invoke(wallet_rpc::ONS_DECRYPT_VALUE::request&& req);
wallet_rpc::ONS_ENCRYPT_VALUE::response invoke(wallet_rpc::ONS_ENCRYPT_VALUE::request&& req);
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
wallet_rpc::QUERY_KEY::response invoke(wallet_rpc::QUERY_KEY::request&& req);
2014-04-02 18:00:17 +02:00
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
private:
2014-04-02 18:00:17 +02:00
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
/// Handles a POST request to /json_rpc.
void handle_json_rpc_request(HttpResponse& res, HttpRequest& req);
2019-02-21 00:53:25 +01:00
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
// Checks that a wallet is open; if not, throws an error.
void require_open();
2014-04-02 18:00:17 +02:00
// Safely and cleanly closes the currently open wallet (if one is open)
void close_wallet(bool save_current);
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
template<typename Ts, typename Tu>
void fill_response(std::vector<tools::wallet2::pending_tx> &ptx_vector,
bool get_tx_key, Ts& tx_key, Tu &amount, Tu &fee, std::string &multisig_txset, std::string &unsigned_txset, bool do_not_relay, bool blink,
Ts &tx_hash, bool get_tx_hex, Ts &tx_blob, bool get_tx_metadata, Ts &tx_metadata);
2014-04-02 18:00:17 +02:00
cryptonote::address_parse_info extract_account_addr(cryptonote::network_type nettype, std::string_view addr_or_url);
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
void validate_transfer(const std::list<wallet::transfer_destination>& destinations, const std::string& payment_id, std::vector<cryptonote::tx_destination_entry>& dsts, std::vector<uint8_t>& extra, bool at_least_one_destination);
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
// Parse options and opens the wallet. Returns nullptr if in directory mode (i.e. no wallet
// gets opened). Throws on error.
std::unique_ptr<tools::wallet2> load_wallet();
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
// Sets up the RPC endpoints (called before listening).
void create_rpc_endpoints(uWS::App& http);
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
// Runs the server event loop; does not return until the server is shut down (by a signal or a
// remote STOP command).
void run_loop();
// Starts the long poll thread, if not already active and m_long_poll_disabled is not set.
// m_wallet must already be set.
void start_long_poll_thread();
// Stops the long poll thread and joins it. This must be done before resetting m_wallet.
// After the call `m_long_poll_disabled` will be false (and must be set back to true if you
// want to re-start the thread).
void stop_long_poll_thread();
daemon & daemonize overhaul This commit continues the complete replacement of the spaghetti code mess that was inside daemon/ and daemonize/ which started in #1138, and looked like a entry level Java programmer threw up inside the code base. This greatly simplifies it, removing a whole pile of useless abstraction layers that don't actually abstract anything, and results in considerably simpler code. (Many of the changes here were also carried out in #1138; this commit updates them with the merged result which amends some things from that PR and goes further in some places). In detail: - the `--detach` (and related `--pidfile`) options are gone. (--detach is still handled, but now just prints a fatal error). Detaching a process is an archaic unix mechanism that has no place on a modern system. If you *really* want to do it anyway, `nohup lokid &` will do the job. (The Windows service control code, which is probably seldom used, is kept because it seems potentially useful for Windows users). - Many of the `t_whatever` classes in daemon/* are just deleted (mostly done in #1138); each one was a bunch of junk code that wraps 3-4 lines but forces an extra layer (not even a generic abstraction, just a useless wrapper) for no good reason and made the daemon code painfully hard to understand and work with. - All of the remaining `t_whatever` classes in daemon/* are either renamed to `whatever` (because prefixing every class with `t_` is moronic). - Some stupid related code (e.g. epee's command handler returning an unsuitable "usage" string that has to be string modified into what we want) was replaced with more generic, useful code. - Replaced boost mutexes/cvs with std ones in epee command handler, and deleted some commented out code. - The `--public-node` option handling was terrible: it was being handled in main, but main doesn't know anything about options, so then it forced it through the spaghetti objects *beside* the pack of all options that got passed along. Moved it to a more sane location (core_rpc_server) and parse it out with some sanity. - Changed a bunch of std::bind's to lambdas because, at least for small lambdas (i.e. with only one-or-two pointers for captures) they will generally be more efficient as the values can be stored in std::function's without any memory allocations.
2020-04-02 22:38:52 +02:00
std::unique_ptr<wallet2> m_wallet;
fs::path m_wallet_dir;
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
std::vector<std::tuple<std::string /*ip*/, uint16_t /*port*/, bool /*required*/>> m_bind;
tools::private_file rpc_login_file;
std::atomic<bool> m_stop;
bool m_restricted;
daemon & daemonize overhaul This commit continues the complete replacement of the spaghetti code mess that was inside daemon/ and daemonize/ which started in #1138, and looked like a entry level Java programmer threw up inside the code base. This greatly simplifies it, removing a whole pile of useless abstraction layers that don't actually abstract anything, and results in considerably simpler code. (Many of the changes here were also carried out in #1138; this commit updates them with the merged result which amends some things from that PR and goes further in some places). In detail: - the `--detach` (and related `--pidfile`) options are gone. (--detach is still handled, but now just prints a fatal error). Detaching a process is an archaic unix mechanism that has no place on a modern system. If you *really* want to do it anyway, `nohup lokid &` will do the job. (The Windows service control code, which is probably seldom used, is kept because it seems potentially useful for Windows users). - Many of the `t_whatever` classes in daemon/* are just deleted (mostly done in #1138); each one was a bunch of junk code that wraps 3-4 lines but forces an extra layer (not even a generic abstraction, just a useless wrapper) for no good reason and made the daemon code painfully hard to understand and work with. - All of the remaining `t_whatever` classes in daemon/* are either renamed to `whatever` (because prefixing every class with `t_` is moronic). - Some stupid related code (e.g. epee's command handler returning an unsuitable "usage" string that has to be string modified into what we want) was replaced with more generic, useful code. - Replaced boost mutexes/cvs with std ones in epee command handler, and deleted some commented out code. - The `--public-node` option handling was terrible: it was being handled in main, but main doesn't know anything about options, so then it forced it through the spaghetti objects *beside* the pack of all options that got passed along. Moved it to a more sane location (core_rpc_server) and parse it out with some sanity. - Changed a bunch of std::bind's to lambdas because, at least for small lambdas (i.e. with only one-or-two pointers for captures) they will generally be more efficient as the values can be stored in std::function's without any memory allocations.
2020-04-02 22:38:52 +02:00
boost::program_options::variables_map m_vm;
std::chrono::milliseconds m_auto_refresh_period;
std::chrono::steady_clock::time_point m_last_auto_refresh_time;
std::atomic<bool> m_long_poll_new_changes;
Wallet RPC server modernization - Replaces the wallet RPC classes with ones like the core RPC server (with serialization code moved into a new .cpp file). - Restricted commands are now carried through the RPC serialization types (by inheriting from RESTRICTED instead of RPC_COMMAND) and restrictions are handled in one place rather than being handled in each of the 49 restricted endpoints. This differs a little from how the core http server works (which has a PUBLIC base class) because for the wallet rpc server unrestricted really doesn't mean "public", it means something closer to view-only. - GET_TRANSFERS_CSV is now restricted (it looks like an oversight that it wasn't before since GET_TRANSFERS is restricted) - GET_ADDRESS_BOOK_ENTRY is now restricted. Since restricted mode is meant to provide something like view-only access, it doesn't make much sense that address book entries were available. - Use uWebSockets to provide the wallet RPC server HTTP functionality. This version is quite a bit simpler than the core RPC version since it doesn't support multithreaded (parallel) requests, and so we don't have to worry about queuing jobs. - Converted all the numeric wallet rpc error codes defines to constexprs - Changed how endpoints get called; previous this was called: bool on_some_endpoint(const wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request& req, wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL) This PR changes it similarly to how core_rpc_server's endpoints work: wallet_rpc::SOME_ENDPOINT invoke(wallet_rpc::COMMAND_RPC_SOME_ENDPOINT::request&& req); That is: - the response is now returned - the request is provided by mutable rvalue reference - the error object is gone (just throw instead) - the connection_context is gone (it was not used at all by any wallet rpc endpoint). - Consolidated most of the (identical) exception handling to the RPC method invocation point rather than needing to repeat it in each individual endpoint. This means each endpoint's `invoke` method can now just throw (or not catch) exceptions. Some try/catches are still there because they are converting one type of exception into another, but the generic ones that return a generic error are gone. - Removed all remaining epee http code. - DRYed out some wallet rpc code.
2020-07-29 19:15:40 +02:00
std::atomic<bool> m_long_poll_disabled;
std::thread m_long_poll_thread;
2014-04-02 18:00:17 +02:00
};
}