@@ -227,16 +227,17 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
227
227
isminetype mine;
228
228
229
229
public:
230
- DescribeAddressVisitor (isminetype mineIn) : mine(mineIn) {}
230
+ CWallet * const pwallet;
231
+
232
+ DescribeAddressVisitor (CWallet *_pwallet) : pwallet(_pwallet) {}
231
233
232
234
UniValue operator ()(const CNoDestination &dest) const { return UniValue (UniValue::VOBJ); }
233
235
234
236
UniValue operator ()(const CKeyID &keyID) const {
235
237
UniValue obj (UniValue::VOBJ);
236
238
CPubKey vchPubKey;
237
239
obj.pushKV (" isscript" , false );
238
- if (bool (mine & ISMINE_ALL)) {
239
- pwalletMain->GetPubKey (keyID, vchPubKey);
240
+ if (pwallet && pwallet->GetPubKey (keyID, vchPubKey)) {
240
241
obj.pushKV (" pubkey" , HexStr (vchPubKey));
241
242
obj.pushKV (" iscompressed" , vchPubKey.IsCompressed ());
242
243
}
@@ -247,19 +248,20 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
247
248
UniValue obj (UniValue::VOBJ);
248
249
obj.pushKV (" isscript" , true );
249
250
CScript subscript;
250
- pwalletMain->GetCScript (scriptID, subscript);
251
- std::vector<CTxDestination> addresses;
252
- txnouttype whichType;
253
- int nRequired;
254
- ExtractDestinations (subscript, whichType, addresses, nRequired);
255
- obj.pushKV (" script" , GetTxnOutputType (whichType));
256
- obj.pushKV (" hex" , HexStr (subscript.begin (), subscript.end ()));
257
- UniValue a (UniValue::VARR);
258
- for (const CTxDestination& addr : addresses)
259
- a.push_back (EncodeDestination (addr));
260
- obj.pushKV (" addresses" , a);
261
- if (whichType == TX_MULTISIG)
262
- obj.pushKV (" sigsrequired" , nRequired);
251
+ if (pwallet && pwallet->GetCScript (scriptID, subscript)) {
252
+ std::vector<CTxDestination> addresses;
253
+ txnouttype whichType;
254
+ int nRequired;
255
+ ExtractDestinations (subscript, whichType, addresses, nRequired);
256
+ obj.pushKV (" script" , GetTxnOutputType (whichType));
257
+ obj.pushKV (" hex" , HexStr (subscript.begin (), subscript.end ()));
258
+ UniValue a (UniValue::VARR);
259
+ for (const CTxDestination& addr : addresses)
260
+ a.push_back (EncodeDestination (addr));
261
+ obj.pushKV (" addresses" , a);
262
+ if (whichType == TX_MULTISIG)
263
+ obj.pushKV (" sigsrequired" , nRequired);
264
+ }
263
265
return obj;
264
266
}
265
267
};
@@ -334,16 +336,16 @@ typedef boost::variant<libzcash::InvalidEncoding, libzcash::SaplingPaymentAddres
334
336
class DescribePaymentAddressVisitor : public boost ::static_visitor<UniValue>
335
337
{
336
338
public:
337
- explicit DescribePaymentAddressVisitor (bool _isStaking) : isStaking(_isStaking) {}
339
+ explicit DescribePaymentAddressVisitor (CWallet *_pwallet, bool _isStaking) : pwallet(_pwallet), isStaking(_isStaking) {}
338
340
UniValue operator ()(const libzcash::InvalidEncoding &zaddr) const { return UniValue (UniValue::VOBJ); }
339
341
340
342
UniValue operator ()(const libzcash::SaplingPaymentAddress &zaddr) const {
341
343
UniValue obj (UniValue::VOBJ);
342
344
obj.pushKV (" diversifier" , HexStr (zaddr.d ));
343
345
obj.pushKV (" diversifiedtransmissionkey" , zaddr.pk_d .GetHex ());
344
346
#ifdef ENABLE_WALLET
345
- if (pwalletMain ) {
346
- obj.pushKV (" ismine" , pwalletMain ->HaveSpendingKeyForPaymentAddress (zaddr));
347
+ if (pwallet ) {
348
+ obj.pushKV (" ismine" , pwallet ->HaveSpendingKeyForPaymentAddress (zaddr));
347
349
}
348
350
#endif
349
351
return obj;
@@ -355,19 +357,20 @@ class DescribePaymentAddressVisitor : public boost::static_visitor<UniValue>
355
357
ret.pushKV (" scriptPubKey" , HexStr (scriptPubKey.begin (), scriptPubKey.end ()));
356
358
357
359
#ifdef ENABLE_WALLET
358
- isminetype mine = pwalletMain ? IsMine (*pwalletMain , dest) : ISMINE_NO;
360
+ isminetype mine = pwallet ? IsMine (*pwallet , dest) : ISMINE_NO;
359
361
ret.pushKV (" ismine" , bool (mine & (ISMINE_SPENDABLE_ALL | ISMINE_COLD)));
360
362
ret.pushKV (" isstaking" , isStaking);
361
363
ret.pushKV (" iswatchonly" , bool (mine & ISMINE_WATCH_ONLY));
362
- UniValue detail = boost::apply_visitor (DescribeAddressVisitor (mine ), dest);
364
+ UniValue detail = boost::apply_visitor (DescribeAddressVisitor (pwallet ), dest);
363
365
ret.pushKVs (detail);
364
- if (pwalletMain && pwalletMain ->HasAddressBook (dest))
365
- ret.pushKV (" label" , pwalletMain ->GetNameForAddressBookEntry (dest));
366
+ if (pwallet && pwallet ->HasAddressBook (dest))
367
+ ret.pushKV (" label" , pwallet ->GetNameForAddressBookEntry (dest));
366
368
#endif
367
369
return ret;
368
370
}
369
371
370
372
private:
373
+ CWallet * const pwallet;
371
374
bool isStaking{false };
372
375
};
373
376
@@ -429,7 +432,7 @@ UniValue validateaddress(const JSONRPCRequest& request)
429
432
ret.pushKV (" isvalid" , isValid);
430
433
if (isValid) {
431
434
ret.pushKV (" address" , strAddress);
432
- UniValue detail = boost::apply_visitor (DescribePaymentAddressVisitor (isStakingAddress), finalAddress);
435
+ UniValue detail = boost::apply_visitor (DescribePaymentAddressVisitor (pwalletMain, isStakingAddress), finalAddress);
433
436
ret.pushKVs (detail);
434
437
}
435
438
@@ -439,7 +442,7 @@ UniValue validateaddress(const JSONRPCRequest& request)
439
442
/* *
440
443
* Used by addmultisigaddress / createmultisig:
441
444
*/
442
- CScript _createmultisig_redeemScript (const UniValue& params)
445
+ CScript _createmultisig_redeemScript (CWallet * const pwallet, const UniValue& params)
443
446
{
444
447
int nRequired = params[0 ].get_int ();
445
448
const UniValue& keys = params[1 ].get_array ();
@@ -461,14 +464,14 @@ CScript _createmultisig_redeemScript(const UniValue& params)
461
464
#ifdef ENABLE_WALLET
462
465
// Case 1: PIVX address and we have full public key:
463
466
CTxDestination dest = DecodeDestination (ks);
464
- if (pwalletMain && IsValidDestination (dest)) {
467
+ if (pwallet && IsValidDestination (dest)) {
465
468
const CKeyID* keyID = boost::get<CKeyID>(&dest);
466
469
if (!keyID) {
467
470
throw std::runtime_error (
468
471
strprintf (" %s does not refer to a key" , ks));
469
472
}
470
473
CPubKey vchPubKey;
471
- if (!pwalletMain ->GetPubKey (*keyID, vchPubKey))
474
+ if (!pwallet ->GetPubKey (*keyID, vchPubKey))
472
475
throw std::runtime_error (
473
476
strprintf (" no full public key for address %s" , ks));
474
477
if (!vchPubKey.IsFullyValid ())
@@ -526,7 +529,7 @@ UniValue createmultisig(const JSONRPCRequest& request)
526
529
HelpExampleRpc (" createmultisig" , " 2, \" [\\\" 16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\" ,\\\" 171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\" ]\" " ));
527
530
528
531
// Construct using pay-to-script-hash:
529
- CScript inner = _createmultisig_redeemScript (request.params );
532
+ CScript inner = _createmultisig_redeemScript (pwalletMain, request.params );
530
533
CScriptID innerID (inner);
531
534
532
535
UniValue result (UniValue::VOBJ);
0 commit comments