Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/command.h
- This file was added.
// Copyright (c) 2018 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | |||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
#ifndef BITCOIN_RPC_COMMAND_H | |||||
#define BITCOIN_RPC_COMMAND_H | |||||
#include <string> | |||||
#include <univalue.h> | |||||
/** | |||||
* Base class for all RPC commands. | |||||
*/ | |||||
class RPCCommand { | |||||
private: | |||||
// TODO: Parameter definitions (these will be used to generate help | |||||
// messages as well) | |||||
public: | |||||
virtual UniValue Execute(const UniValue &args) const = 0; | |||||
virtual std::string GetName() const = 0; | |||||
/** | |||||
* Child classes of RPCCommand must implement a factory function to pass | |||||
* to RPCServer::RegisterCommand(). Dependency injection can be done via | |||||
* std::bind(). Example: | |||||
* rpcServer.RegisterCommand( | |||||
* MyRPCCommand::commandName, | |||||
* std::bind(&MyRPCCommand::CreateFromJSONRequest, | |||||
* _1, <dependencies...>)); | |||||
*/ | |||||
deadalnix: Why would I register that ugly thing when I can register the command ? | |||||
jasonbcoxAuthorUnsubmitted Done Inline ActionsIt's necessary for dependency injection. jasonbcox: It's necessary for dependency injection. | |||||
}; | |||||
#endif // BITCOIN_RPC_COMMAND_H |
Why would I register that ugly thing when I can register the command ?