Bitcoin ABC  0.28.12
P2P Digital Currency
command.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_RPC_COMMAND_H
6 #define BITCOIN_RPC_COMMAND_H
7 
8 #include <univalue.h>
9 
10 #include <string>
11 
12 class JSONRPCRequest;
13 
20 class RPCCommand {
21 private:
22  const std::string name;
23 
24  /*
25  * Child classes should define dependencies as private members.
26  * These dependencies must not be changed, or successive calls to the same
27  * command will give unexpected behavior.
28  */
29 
30  // TODO: Parameter definitions (these will be used to generate help
31  // messages as well)
32 
33 public:
34  RPCCommand(const std::string &nameIn) : name(nameIn) {}
35  virtual ~RPCCommand() {}
36 
37  RPCCommand(const RPCCommand &) = delete;
38  RPCCommand &operator=(const RPCCommand &) = delete;
39 
45  virtual UniValue Execute(const JSONRPCRequest &request) const = 0;
46 
47  const std::string &GetName() const { return name; };
48 };
49 
55 public:
56  RPCCommandWithArgsContext(const std::string &nameIn) : RPCCommand(nameIn) {}
57 
58  virtual UniValue Execute(const UniValue &args) const = 0;
59 
60  UniValue Execute(const JSONRPCRequest &request) const final;
61 };
62 
63 #endif // BITCOIN_RPC_COMMAND_H
Base class for all RPC commands.
Definition: command.h:20
const std::string & GetName() const
Definition: command.h:47
RPCCommand(const std::string &nameIn)
Definition: command.h:34
RPCCommand & operator=(const RPCCommand &)=delete
const std::string name
Definition: command.h:22
RPCCommand(const RPCCommand &)=delete
virtual UniValue Execute(const JSONRPCRequest &request) const =0
It is recommended to override Execute(JSONRPCRequest) only if the entire request context is required.
virtual ~RPCCommand()
Definition: command.h:35
By default, use RPCCommandWithArgsContext as the parent class for new RPC command classes that only d...
Definition: command.h:54
RPCCommandWithArgsContext(const std::string &nameIn)
Definition: command.h:56
virtual UniValue Execute(const UniValue &args) const =0