Fix crashes in "protx" RPCs when wallet is disabled (#2509)

This commit is contained in:
Alexander Block 2018-11-29 09:12:41 +01:00 committed by GitHub
parent 35550a3f93
commit fc6d651c43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,6 +34,9 @@ static CKey ParsePrivKey(const std::string &strKeyOrAddress, bool allowAddresses
CBitcoinAddress address; CBitcoinAddress address;
if (allowAddresses && address.SetString(strKeyOrAddress) && address.IsValid()) { if (allowAddresses && address.SetString(strKeyOrAddress) && address.IsValid()) {
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if (!pwalletMain) {
throw std::runtime_error("addresses not supported when wallet is disabled");
}
CKeyID keyId; CKeyID keyId;
CKey key; CKey key;
if (!address.GetKeyID(keyId) || !pwalletMain->GetKey(keyId, key)) if (!address.GetKeyID(keyId) || !pwalletMain->GetKey(keyId, key))
@ -643,6 +646,10 @@ void protx_list_help()
} }
static bool CheckWalletOwnsScript(const CScript& script) { static bool CheckWalletOwnsScript(const CScript& script) {
if (!pwalletMain) {
return false;
}
CTxDestination dest; CTxDestination dest;
if (ExtractDestination(script, dest)) { if (ExtractDestination(script, dest)) {
if ((boost::get<CKeyID>(&dest) && pwalletMain->HaveKey(*boost::get<CKeyID>(&dest))) || (boost::get<CScriptID>(&dest) && pwalletMain->HaveCScript(*boost::get<CScriptID>(&dest)))) { if ((boost::get<CKeyID>(&dest) && pwalletMain->HaveKey(*boost::get<CKeyID>(&dest))) || (boost::get<CScriptID>(&dest) && pwalletMain->HaveCScript(*boost::get<CScriptID>(&dest)))) {
@ -665,9 +672,9 @@ UniValue BuildDMNListEntry(const CDeterministicMNCPtr& dmn, bool detailed)
int confirmations = GetUTXOConfirmations(dmn->collateralOutpoint); int confirmations = GetUTXOConfirmations(dmn->collateralOutpoint);
o.push_back(Pair("confirmations", confirmations)); o.push_back(Pair("confirmations", confirmations));
bool hasOwnerKey = pwalletMain->HaveKey(dmn->pdmnState->keyIDOwner); bool hasOwnerKey = pwalletMain && pwalletMain->HaveKey(dmn->pdmnState->keyIDOwner);
bool hasOperatorKey = false; //pwalletMain->HaveKey(dmn->pdmnState->keyIDOperator); bool hasOperatorKey = false; //pwalletMain && pwalletMain->HaveKey(dmn->pdmnState->keyIDOperator);
bool hasVotingKey = pwalletMain->HaveKey(dmn->pdmnState->keyIDVoting); bool hasVotingKey = pwalletMain && pwalletMain->HaveKey(dmn->pdmnState->keyIDVoting);
bool ownsCollateral = false; bool ownsCollateral = false;
CTransactionRef collateralTx; CTransactionRef collateralTx;
@ -701,9 +708,14 @@ UniValue protx_list(const JSONRPCRequest& request)
UniValue ret(UniValue::VARR); UniValue ret(UniValue::VARR);
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK(cs_main);
if (type == "wallet") { if (type == "wallet") {
if (!pwalletMain) {
throw std::runtime_error("\"protx list wallet\" not supported when wallet is disabled");
}
LOCK(pwalletMain->cs_wallet);
if (request.params.size() > 3) { if (request.params.size() > 3) {
protx_list_help(); protx_list_help();
} }