Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
12class JSONRPCRequest;
13
21private:
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
33public:
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
55public:
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
RPCCommand(const std::string &nameIn)
Definition command.h:34
const std::string & GetName() const
Definition command.h:47
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
RPCCommand & operator=(const RPCCommand &)=delete
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
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85