From eca550f2501f3f2bbe682bdc3cb8b90c90c90275 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 9 Sep 2016 05:32:12 +0000 Subject: RPC/Wallet: Pass CWallet as pointer to helper functions --- src/rpc/misc.cpp | 18 +++++++++++------- src/rpc/rawtransaction.cpp | 4 ++-- src/rpc/server.h | 11 +++++++++-- 3 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src/rpc') diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 140cb4840b..f8e9acb08c 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -112,13 +112,17 @@ UniValue getinfo(const JSONRPCRequest& request) class DescribeAddressVisitor : public boost::static_visitor { public: + CWallet * const pwallet; + + DescribeAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {} + UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); } UniValue operator()(const CKeyID &keyID) const { UniValue obj(UniValue::VOBJ); CPubKey vchPubKey; obj.push_back(Pair("isscript", false)); - if (pwalletMain && pwalletMain->GetPubKey(keyID, vchPubKey)) { + if (pwallet && pwallet->GetPubKey(keyID, vchPubKey)) { obj.push_back(Pair("pubkey", HexStr(vchPubKey))); obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed())); } @@ -129,7 +133,7 @@ public: UniValue obj(UniValue::VOBJ); CScript subscript; obj.push_back(Pair("isscript", true)); - if (pwalletMain && pwalletMain->GetCScript(scriptID, subscript)) { + if (pwallet && pwallet->GetCScript(scriptID, subscript)) { std::vector addresses; txnouttype whichType; int nRequired; @@ -200,7 +204,7 @@ UniValue validateaddress(const JSONRPCRequest& request) isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); ret.push_back(Pair("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true: false)); - UniValue detail = boost::apply_visitor(DescribeAddressVisitor(), dest); + UniValue detail = boost::apply_visitor(DescribeAddressVisitor(pwalletMain), dest); ret.pushKVs(detail); if (pwalletMain && pwalletMain->mapAddressBook.count(dest)) ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name)); @@ -227,7 +231,7 @@ UniValue validateaddress(const JSONRPCRequest& request) /** * Used by addmultisigaddress / createmultisig: */ -CScript _createmultisig_redeemScript(const UniValue& params) +CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& params) { int nRequired = params[0].get_int(); const UniValue& keys = params[1].get_array(); @@ -249,14 +253,14 @@ CScript _createmultisig_redeemScript(const UniValue& params) #ifdef ENABLE_WALLET // Case 1: Bitcoin address and we have full public key: CBitcoinAddress address(ks); - if (pwalletMain && address.IsValid()) + if (pwallet && address.IsValid()) { CKeyID keyID; if (!address.GetKeyID(keyID)) throw runtime_error( strprintf("%s does not refer to a key",ks)); CPubKey vchPubKey; - if (!pwalletMain->GetPubKey(keyID, vchPubKey)) + if (!pwallet->GetPubKey(keyID, vchPubKey)) throw runtime_error( strprintf("no full public key for address %s",ks)); if (!vchPubKey.IsFullyValid()) @@ -320,7 +324,7 @@ UniValue createmultisig(const JSONRPCRequest& request) } // Construct using pay-to-script-hash: - CScript inner = _createmultisig_redeemScript(request.params); + CScript inner = _createmultisig_redeemScript(pwalletMain, request.params); CScriptID innerID(inner); CBitcoinAddress address(innerID); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index bf16f27498..faafe9829b 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -603,7 +603,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request) "The third optional argument (may be null) is an array of base58-encoded private\n" "keys that, if given, will be the only keys used to sign the transaction.\n" #ifdef ENABLE_WALLET - + HelpRequiringPassphrase() + "\n" + + HelpRequiringPassphrase(pwalletMain) + "\n" #endif "\nArguments:\n" @@ -718,7 +718,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request) } #ifdef ENABLE_WALLET else if (pwalletMain) - EnsureWalletIsUnlocked(); + EnsureWalletIsUnlocked(pwalletMain); #endif // Add previous txouts given in the RPC call: diff --git a/src/rpc/server.h b/src/rpc/server.h index 52f82866dc..b32eaaa133 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -194,11 +194,18 @@ extern int64_t nWalletUnlockTime; extern CAmount AmountFromValue(const UniValue& value); extern UniValue ValueFromAmount(const CAmount& amount); extern double GetDifficulty(const CBlockIndex* blockindex = NULL); -extern std::string HelpRequiringPassphrase(); extern std::string HelpExampleCli(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args); -extern void EnsureWalletIsUnlocked(); +// Needed even with !ENABLE_WALLET, to pass (ignored) pointers around +class CWallet; + +#ifdef ENABLE_WALLET +// New code should accessing the wallet should be under the ../wallet/ directory +std::string HelpRequiringPassphrase(CWallet *); +void EnsureWalletIsUnlocked(CWallet *); +bool EnsureWalletIsAvailable(CWallet *, bool avoidException); +#endif bool StartRPC(); void InterruptRPC(); -- cgit v1.2.3