14
14
#include " util.h"
15
15
#include " utilstrencodings.h"
16
16
#ifdef ENABLE_WALLET
17
+ #include " wallet/rpcwallet.h"
17
18
#include " wallet/wallet.h"
18
19
#include " wallet/walletdb.h"
19
20
#endif
@@ -70,7 +71,9 @@ UniValue getinfo(const JSONRPCRequest& request)
70
71
);
71
72
72
73
#ifdef ENABLE_WALLET
73
- LOCK2 (cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL );
74
+ CWallet * const pwallet = GetWalletForJSONRPCRequest (request);
75
+
76
+ LOCK2 (cs_main, pwallet ? &pwallet->cs_wallet : NULL );
74
77
#else
75
78
LOCK (cs_main);
76
79
#endif
@@ -82,9 +85,9 @@ UniValue getinfo(const JSONRPCRequest& request)
82
85
obj.push_back (Pair (" version" , CLIENT_VERSION));
83
86
obj.push_back (Pair (" protocolversion" , PROTOCOL_VERSION));
84
87
#ifdef ENABLE_WALLET
85
- if (pwalletMain ) {
86
- obj.push_back (Pair (" walletversion" , pwalletMain ->GetVersion ()));
87
- obj.push_back (Pair (" balance" , ValueFromAmount (pwalletMain ->GetBalance ())));
88
+ if (pwallet ) {
89
+ obj.push_back (Pair (" walletversion" , pwallet ->GetVersion ()));
90
+ obj.push_back (Pair (" balance" , ValueFromAmount (pwallet ->GetBalance ())));
88
91
}
89
92
#endif
90
93
obj.push_back (Pair (" blocks" , (int )chainActive.Height ()));
@@ -95,12 +98,13 @@ UniValue getinfo(const JSONRPCRequest& request)
95
98
obj.push_back (Pair (" difficulty" , (double )GetDifficulty ()));
96
99
obj.push_back (Pair (" testnet" , Params ().NetworkIDString () == CBaseChainParams::TESTNET));
97
100
#ifdef ENABLE_WALLET
98
- if (pwalletMain) {
99
- obj.push_back (Pair (" keypoololdest" , pwalletMain->GetOldestKeyPoolTime ()));
100
- obj.push_back (Pair (" keypoolsize" , (int )pwalletMain->GetKeyPoolSize ()));
101
+ if (pwallet) {
102
+ obj.push_back (Pair (" keypoololdest" , pwallet->GetOldestKeyPoolTime ()));
103
+ obj.push_back (Pair (" keypoolsize" , (int )pwallet->GetKeyPoolSize ()));
104
+ }
105
+ if (pwallet && pwallet->IsCrypted ()) {
106
+ obj.push_back (Pair (" unlocked_until" , pwallet->nRelockTime ));
101
107
}
102
- if (pwalletMain && pwalletMain->IsCrypted ())
103
- obj.push_back (Pair (" unlocked_until" , nWalletUnlockTime));
104
108
obj.push_back (Pair (" paytxfee" , ValueFromAmount (payTxFee.GetFeePerK ())));
105
109
#endif
106
110
obj.push_back (Pair (" relayfee" , ValueFromAmount (::minRelayTxFee.GetFeePerK ())));
@@ -112,13 +116,17 @@ UniValue getinfo(const JSONRPCRequest& request)
112
116
class DescribeAddressVisitor : public boost ::static_visitor<UniValue>
113
117
{
114
118
public:
119
+ CWallet * const pwallet;
120
+
121
+ DescribeAddressVisitor (CWallet *_pwallet) : pwallet(_pwallet) {}
122
+
115
123
UniValue operator ()(const CNoDestination &dest) const { return UniValue (UniValue::VOBJ); }
116
124
117
125
UniValue operator ()(const CKeyID &keyID) const {
118
126
UniValue obj (UniValue::VOBJ);
119
127
CPubKey vchPubKey;
120
128
obj.push_back (Pair (" isscript" , false ));
121
- if (pwalletMain && pwalletMain ->GetPubKey (keyID, vchPubKey)) {
129
+ if (pwallet && pwallet ->GetPubKey (keyID, vchPubKey)) {
122
130
obj.push_back (Pair (" pubkey" , HexStr (vchPubKey)));
123
131
obj.push_back (Pair (" iscompressed" , vchPubKey.IsCompressed ()));
124
132
}
@@ -129,7 +137,7 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
129
137
UniValue obj (UniValue::VOBJ);
130
138
CScript subscript;
131
139
obj.push_back (Pair (" isscript" , true ));
132
- if (pwalletMain && pwalletMain ->GetCScript (scriptID, subscript)) {
140
+ if (pwallet && pwallet ->GetCScript (scriptID, subscript)) {
133
141
std::vector<CTxDestination> addresses;
134
142
txnouttype whichType;
135
143
int nRequired;
@@ -177,7 +185,9 @@ UniValue validateaddress(const JSONRPCRequest& request)
177
185
);
178
186
179
187
#ifdef ENABLE_WALLET
180
- LOCK2 (cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL );
188
+ CWallet * const pwallet = GetWalletForJSONRPCRequest (request);
189
+
190
+ LOCK2 (cs_main, pwallet ? &pwallet->cs_wallet : NULL );
181
191
#else
182
192
LOCK (cs_main);
183
193
#endif
@@ -197,16 +207,17 @@ UniValue validateaddress(const JSONRPCRequest& request)
197
207
ret.push_back (Pair (" scriptPubKey" , HexStr (scriptPubKey.begin (), scriptPubKey.end ())));
198
208
199
209
#ifdef ENABLE_WALLET
200
- isminetype mine = pwalletMain ? IsMine (*pwalletMain , dest) : ISMINE_NO;
210
+ isminetype mine = pwallet ? IsMine (*pwallet , dest) : ISMINE_NO;
201
211
ret.push_back (Pair (" ismine" , (mine & ISMINE_SPENDABLE) ? true : false ));
202
212
ret.push_back (Pair (" iswatchonly" , (mine & ISMINE_WATCH_ONLY) ? true : false ));
203
- UniValue detail = boost::apply_visitor (DescribeAddressVisitor (), dest);
213
+ UniValue detail = boost::apply_visitor (DescribeAddressVisitor (pwallet ), dest);
204
214
ret.pushKVs (detail);
205
- if (pwalletMain && pwalletMain->mapAddressBook .count (dest))
206
- ret.push_back (Pair (" account" , pwalletMain->mapAddressBook [dest].name ));
215
+ if (pwallet && pwallet->mapAddressBook .count (dest)) {
216
+ ret.push_back (Pair (" account" , pwallet->mapAddressBook [dest].name ));
217
+ }
207
218
CKeyID keyID;
208
- if (pwalletMain ) {
209
- const auto & meta = pwalletMain ->mapKeyMetadata ;
219
+ if (pwallet ) {
220
+ const auto & meta = pwallet ->mapKeyMetadata ;
210
221
auto it = address.GetKeyID (keyID) ? meta.find (keyID) : meta.end ();
211
222
if (it == meta.end ()) {
212
223
it = meta.find (CScriptID (scriptPubKey));
@@ -224,10 +235,13 @@ UniValue validateaddress(const JSONRPCRequest& request)
224
235
return ret;
225
236
}
226
237
238
+ // Needed even with !ENABLE_WALLET, to pass (ignored) pointers around
239
+ class CWallet ;
240
+
227
241
/* *
228
242
* Used by addmultisigaddress / createmultisig:
229
243
*/
230
- CScript _createmultisig_redeemScript (const UniValue& params)
244
+ CScript _createmultisig_redeemScript (CWallet * const pwallet, const UniValue& params)
231
245
{
232
246
int nRequired = params[0 ].get_int ();
233
247
const UniValue& keys = params[1 ].get_array ();
@@ -249,16 +263,16 @@ CScript _createmultisig_redeemScript(const UniValue& params)
249
263
#ifdef ENABLE_WALLET
250
264
// Case 1: Bitcoin address and we have full public key:
251
265
CBitcoinAddress address (ks);
252
- if (pwalletMain && address.IsValid ())
253
- {
266
+ if (pwallet && address.IsValid ()) {
254
267
CKeyID keyID;
255
268
if (!address.GetKeyID (keyID))
256
269
throw runtime_error (
257
270
strprintf (" %s does not refer to a key" ,ks));
258
271
CPubKey vchPubKey;
259
- if (!pwalletMain ->GetPubKey (keyID, vchPubKey))
272
+ if (!pwallet ->GetPubKey (keyID, vchPubKey)) {
260
273
throw runtime_error (
261
274
strprintf (" no full public key for address %s" ,ks));
275
+ }
262
276
if (!vchPubKey.IsFullyValid ())
263
277
throw runtime_error (" Invalid public key: " +ks);
264
278
pubkeys[i] = vchPubKey;
@@ -290,6 +304,12 @@ CScript _createmultisig_redeemScript(const UniValue& params)
290
304
291
305
UniValue createmultisig (const JSONRPCRequest& request)
292
306
{
307
+ #ifdef ENABLE_WALLET
308
+ CWallet * const pwallet = GetWalletForJSONRPCRequest (request);
309
+ #else
310
+ CWallet * const pwallet = NULL ;
311
+ #endif
312
+
293
313
if (request.fHelp || request.params .size () < 2 || request.params .size () > 2 )
294
314
{
295
315
string msg = " createmultisig nrequired [\" key\" ,...]\n "
@@ -320,7 +340,7 @@ UniValue createmultisig(const JSONRPCRequest& request)
320
340
}
321
341
322
342
// Construct using pay-to-script-hash:
323
- CScript inner = _createmultisig_redeemScript (request.params );
343
+ CScript inner = _createmultisig_redeemScript (pwallet, request.params );
324
344
CScriptID innerID (inner);
325
345
CBitcoinAddress address (innerID);
326
346
0 commit comments