~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to src/rpc/server.h

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2010 Satoshi Nakamoto
 
2
// Copyright (c) 2009-2015 The Bitcoin Core developers
 
3
// Distributed under the MIT software license, see the accompanying
 
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
5
 
 
6
#ifndef BITCOIN_RPCSERVER_H
 
7
#define BITCOIN_RPCSERVER_H
 
8
 
 
9
#include "amount.h"
 
10
#include "rpc/protocol.h"
 
11
#include "uint256.h"
 
12
 
 
13
#include <list>
 
14
#include <map>
 
15
#include <stdint.h>
 
16
#include <string>
 
17
 
 
18
#include <boost/function.hpp>
 
19
 
 
20
#include <univalue.h>
 
21
 
 
22
class CRPCCommand;
 
23
 
 
24
namespace RPCServer
 
25
{
 
26
    void OnStarted(boost::function<void ()> slot);
 
27
    void OnStopped(boost::function<void ()> slot);
 
28
    void OnPreCommand(boost::function<void (const CRPCCommand&)> slot);
 
29
    void OnPostCommand(boost::function<void (const CRPCCommand&)> slot);
 
30
}
 
31
 
 
32
class CBlockIndex;
 
33
class CNetAddr;
 
34
 
 
35
/** Wrapper for UniValue::VType, which includes typeAny:
 
36
 * Used to denote don't care type. Only used by RPCTypeCheckObj */
 
37
struct UniValueType {
 
38
    UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
 
39
    UniValueType() : typeAny(true) {}
 
40
    bool typeAny;
 
41
    UniValue::VType type;
 
42
};
 
43
 
 
44
class JSONRequest
 
45
{
 
46
public:
 
47
    UniValue id;
 
48
    std::string strMethod;
 
49
    UniValue params;
 
50
 
 
51
    JSONRequest() { id = NullUniValue; }
 
52
    void parse(const UniValue& valRequest);
 
53
};
 
54
 
 
55
/** Query whether RPC is running */
 
56
bool IsRPCRunning();
 
57
 
 
58
/**
 
59
 * Set the RPC warmup status.  When this is done, all RPC calls will error out
 
60
 * immediately with RPC_IN_WARMUP.
 
61
 */
 
62
void SetRPCWarmupStatus(const std::string& newStatus);
 
63
/* Mark warmup as done.  RPC calls will be processed from now on.  */
 
64
void SetRPCWarmupFinished();
 
65
 
 
66
/* returns the current warmup state.  */
 
67
bool RPCIsInWarmup(std::string *statusOut);
 
68
 
 
69
/**
 
70
 * Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
 
71
 * the right number of arguments are passed, just that any passed are the correct type.
 
72
 */
 
73
void RPCTypeCheck(const UniValue& params,
 
74
                  const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
 
75
 
 
76
/*
 
77
  Check for expected keys/value types in an Object.
 
78
*/
 
79
void RPCTypeCheckObj(const UniValue& o,
 
80
    const std::map<std::string, UniValueType>& typesExpected,
 
81
    bool fAllowNull = false,
 
82
    bool fStrict = false);
 
83
 
 
84
/** Opaque base class for timers returned by NewTimerFunc.
 
85
 * This provides no methods at the moment, but makes sure that delete
 
86
 * cleans up the whole state.
 
87
 */
 
88
class RPCTimerBase
 
89
{
 
90
public:
 
91
    virtual ~RPCTimerBase() {}
 
92
};
 
93
 
 
94
/**
 
95
 * RPC timer "driver".
 
96
 */
 
97
class RPCTimerInterface
 
98
{
 
99
public:
 
100
    virtual ~RPCTimerInterface() {}
 
101
    /** Implementation name */
 
102
    virtual const char *Name() = 0;
 
103
    /** Factory function for timers.
 
104
     * RPC will call the function to create a timer that will call func in *millis* milliseconds.
 
105
     * @note As the RPC mechanism is backend-neutral, it can use different implementations of timers.
 
106
     * This is needed to cope with the case in which there is no HTTP server, but
 
107
     * only GUI RPC console, and to break the dependency of pcserver on httprpc.
 
108
     */
 
109
    virtual RPCTimerBase* NewTimer(boost::function<void(void)>& func, int64_t millis) = 0;
 
110
};
 
111
 
 
112
/** Set the factory function for timers */
 
113
void RPCSetTimerInterface(RPCTimerInterface *iface);
 
114
/** Set the factory function for timer, but only, if unset */
 
115
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface);
 
116
/** Unset factory function for timers */
 
117
void RPCUnsetTimerInterface(RPCTimerInterface *iface);
 
118
 
 
119
/**
 
120
 * Run func nSeconds from now.
 
121
 * Overrides previous timer <name> (if any).
 
122
 */
 
123
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
 
124
 
 
125
typedef UniValue(*rpcfn_type)(const UniValue& params, bool fHelp);
 
126
 
 
127
class CRPCCommand
 
128
{
 
129
public:
 
130
    std::string category;
 
131
    std::string name;
 
132
    rpcfn_type actor;
 
133
    bool okSafeMode;
 
134
};
 
135
 
 
136
/**
 
137
 * Bitcoin RPC command dispatcher.
 
138
 */
 
139
class CRPCTable
 
140
{
 
141
private:
 
142
    std::map<std::string, const CRPCCommand*> mapCommands;
 
143
public:
 
144
    CRPCTable();
 
145
    const CRPCCommand* operator[](const std::string& name) const;
 
146
    std::string help(const std::string& name) const;
 
147
 
 
148
    /**
 
149
     * Execute a method.
 
150
     * @param method   Method to execute
 
151
     * @param params   UniValue Array of arguments (JSON objects)
 
152
     * @returns Result of the call.
 
153
     * @throws an exception (UniValue) when an error happens.
 
154
     */
 
155
    UniValue execute(const std::string &method, const UniValue &params) const;
 
156
 
 
157
    /**
 
158
    * Returns a list of registered commands
 
159
    * @returns List of registered commands.
 
160
    */
 
161
    std::vector<std::string> listCommands() const;
 
162
 
 
163
 
 
164
    /**
 
165
     * Appends a CRPCCommand to the dispatch table.
 
166
     * Returns false if RPC server is already running (dump concurrency protection).
 
167
     * Commands cannot be overwritten (returns false).
 
168
     */
 
169
    bool appendCommand(const std::string& name, const CRPCCommand* pcmd);
 
170
};
 
171
 
 
172
extern CRPCTable tableRPC;
 
173
 
 
174
/**
 
175
 * Utilities: convert hex-encoded Values
 
176
 * (throws error if not hex).
 
177
 */
 
178
extern uint256 ParseHashV(const UniValue& v, std::string strName);
 
179
extern uint256 ParseHashO(const UniValue& o, std::string strKey);
 
180
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
 
181
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
 
182
 
 
183
extern int64_t nWalletUnlockTime;
 
184
extern CAmount AmountFromValue(const UniValue& value);
 
185
extern UniValue ValueFromAmount(const CAmount& amount);
 
186
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
 
187
extern std::string HelpRequiringPassphrase();
 
188
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
 
189
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
 
190
 
 
191
extern void EnsureWalletIsUnlocked();
 
192
 
 
193
bool StartRPC();
 
194
void InterruptRPC();
 
195
void StopRPC();
 
196
std::string JSONRPCExecBatch(const UniValue& vReq);
 
197
 
 
198
#endif // BITCOIN_RPCSERVER_H