Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/node.cpp
// Copyright (c) 2018 The Bitcoin Core developers | // Copyright (c) 2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <interfaces/node.h> | #include <interfaces/node.h> | ||||
#include <addrdb.h> | #include <addrdb.h> | ||||
#include <amount.h> | |||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <init.h> | #include <init.h> | ||||
#include <interfaces/handler.h> | #include <interfaces/handler.h> | ||||
#include <interfaces/wallet.h> | #include <interfaces/wallet.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <net_processing.h> | #include <net_processing.h> | ||||
#include <netaddress.h> | #include <netaddress.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <primitives/block.h> | #include <primitives/block.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
#if defined(HAVE_CONFIG_H) | #if defined(HAVE_CONFIG_H) | ||||
#include <config/bitcoin-config.h> | #include <config/bitcoin-config.h> | ||||
#endif | #endif | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
#include <wallet/wallet.h> | |||||
#define CHECK_WALLET(x) x | #define CHECK_WALLET(x) x | ||||
#else | #else | ||||
#define CHECK_WALLET(x) \ | #define CHECK_WALLET(x) \ | ||||
throw std::logic_error("Wallet function called in non-wallet build.") | throw std::logic_error("Wallet function called in non-wallet build.") | ||||
#endif | #endif | ||||
#include <boost/thread/thread.hpp> | #include <boost/thread/thread.hpp> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <atomic> | #include <atomic> | ||||
class CWallet; | |||||
class HTTPRPCRequestProcessor; | class HTTPRPCRequestProcessor; | ||||
namespace interfaces { | namespace interfaces { | ||||
namespace { | namespace { | ||||
class NodeImpl : public Node { | class NodeImpl : public Node { | ||||
void parseParameters(int argc, const char *const argv[]) override { | void parseParameters(int argc, const char *const argv[]) override { | ||||
gArgs.ParseParameters(argc, argv); | gArgs.ParseParameters(argc, argv); | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | class NodeImpl : public Node { | ||||
void setNetworkActive(bool active) override { | void setNetworkActive(bool active) override { | ||||
if (g_connman) { | if (g_connman) { | ||||
g_connman->SetNetworkActive(active); | g_connman->SetNetworkActive(active); | ||||
} | } | ||||
} | } | ||||
bool getNetworkActive() override { | bool getNetworkActive() override { | ||||
return g_connman && g_connman->GetNetworkActive(); | return g_connman && g_connman->GetNetworkActive(); | ||||
} | } | ||||
Amount getMaxTxFee() override { return ::maxTxFee; } | |||||
UniValue executeRpc(Config &config, const std::string &command, | UniValue executeRpc(Config &config, const std::string &command, | ||||
const UniValue ¶ms, | const UniValue ¶ms, | ||||
const std::string &uri) override { | const std::string &uri) override { | ||||
JSONRPCRequest req; | JSONRPCRequest req; | ||||
req.params = params; | req.params = params; | ||||
req.strMethod = command; | req.strMethod = command; | ||||
req.URI = uri; | req.URI = uri; | ||||
return ::tableRPC.execute(config, req); | return ::tableRPC.execute(config, req); | ||||
} | } | ||||
std::vector<std::string> listRpcCommands() override { | std::vector<std::string> listRpcCommands() override { | ||||
return ::tableRPC.listCommands(); | return ::tableRPC.listCommands(); | ||||
} | } | ||||
void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface) override { | void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface) override { | ||||
RPCSetTimerInterfaceIfUnset(iface); | RPCSetTimerInterfaceIfUnset(iface); | ||||
} | } | ||||
void rpcUnsetTimerInterface(RPCTimerInterface *iface) override { | void rpcUnsetTimerInterface(RPCTimerInterface *iface) override { | ||||
RPCUnsetTimerInterface(iface); | RPCUnsetTimerInterface(iface); | ||||
} | } | ||||
std::vector<std::unique_ptr<Wallet>> getWallets() override { | |||||
#ifdef ENABLE_WALLET | |||||
std::vector<std::unique_ptr<Wallet>> wallets; | |||||
for (CWalletRef wallet : ::vpwallets) { | |||||
wallets.emplace_back(MakeWallet(*wallet)); | |||||
} | |||||
return wallets; | |||||
#else | |||||
throw std::logic_error( | |||||
"Node::getWallets() called in non-wallet build."); | |||||
#endif | |||||
} | |||||
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override { | std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override { | ||||
return MakeHandler(::uiInterface.InitMessage.connect(fn)); | return MakeHandler(::uiInterface.InitMessage.connect(fn)); | ||||
} | } | ||||
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override { | std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override { | ||||
return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn)); | return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn)); | ||||
} | } | ||||
std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override { | std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override { | ||||
return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn)); | return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn)); | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |