Skip to content

Commit

Permalink
[BUG] fix a few places improperly checking boost::get<CKeyID>
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Dec 20, 2020
1 parent 95ed10a commit 12240dc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/qt/pivx/settings/settingsbittoolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void SettingsBitToolWidget::onEncryptKeyButtonENCClicked()
return;
}

CKeyID keyID = *boost::get<CKeyID>(&dest);
const CKeyID* keyID = boost::get<CKeyID>(&dest);
if (!keyID) {
//ui->addressIn_ENC->setValid(false);
ui->statusLabel_ENC->setStyleSheet("QLabel { color: red; }");
Expand All @@ -166,7 +166,7 @@ void SettingsBitToolWidget::onEncryptKeyButtonENCClicked()
}

CKey key;
if (!pwalletMain->GetKey(keyID, key)) {
if (!pwalletMain->GetKey(*keyID, key)) {
ui->statusLabel_ENC->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_ENC->setText(tr("Private key for the entered address is not available."));
return;
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
CTxDestination dest = DecodeDestination(strAddress);
if (!IsValidDestination(dest))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PIVX address");
CKeyID keyID = *boost::get<CKeyID>(&dest);
const CKeyID* keyID = boost::get<CKeyID>(&dest);
if (!keyID)
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
CKey vchSecret;
if (!pwalletMain->GetKey(keyID, vchSecret))
if (!pwalletMain->GetKey(*keyID, vchSecret))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
return EncodeSecret(vchSecret);
}
Expand Down Expand Up @@ -610,11 +610,11 @@ UniValue bip38encrypt(const JSONRPCRequest& request)
CTxDestination address = DecodeDestination(strAddress);
if (!IsValidDestination(address))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PIVX address");
CKeyID keyID = *boost::get<CKeyID>(&address);
const CKeyID* keyID = boost::get<CKeyID>(&address);
if (!keyID)
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
CKey vchSecret;
if (!pwalletMain->GetKey(keyID, vchSecret))
if (!pwalletMain->GetKey(*keyID, vchSecret))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");

uint256 privKey = vchSecret.GetPrivKey_256();
Expand Down Expand Up @@ -944,4 +944,4 @@ UniValue exportsaplingkey(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private key for this shielded addr");
}
return KeyIO::EncodeSpendingKey(libzcash::SpendingKey(sk.get()));
}
}
18 changes: 7 additions & 11 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ UniValue delegatoradd(const JSONRPCRequest& request)

const std::string strLabel = (request.params.size() > 1 ? request.params[1].get_str() : "");

CKeyID keyID = boost::get<CKeyID>(DecodeDestination(request.params[0].get_str()));
const CKeyID* keyID = boost::get<CKeyID>(&dest);
if (!keyID)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to get KeyID from PIVX address");

return pwalletMain->SetAddressBook(keyID, strLabel, AddressBook::AddressBookPurpose::DELEGATOR);
return pwalletMain->SetAddressBook(*keyID, strLabel, AddressBook::AddressBookPurpose::DELEGATOR);
}

UniValue delegatorremove(const JSONRPCRequest& request)
Expand All @@ -709,11 +709,11 @@ UniValue delegatorremove(const JSONRPCRequest& request)
if (!IsValidDestination(dest) || isStakingAddress)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PIVX address");

CKeyID keyID = *boost::get<CKeyID>(&dest);
const CKeyID* keyID = boost::get<CKeyID>(&dest);
if (!keyID)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to get KeyID from PIVX address");

if (!pwalletMain->HasAddressBook(keyID))
if (!pwalletMain->HasAddressBook(*keyID))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to get PIVX address from addressBook");

std::string label = "";
Expand All @@ -722,7 +722,7 @@ UniValue delegatorremove(const JSONRPCRequest& request)
label = optAdd->name;
}

return pwalletMain->SetAddressBook(keyID, label, AddressBook::AddressBookPurpose::DELEGABLE);
return pwalletMain->SetAddressBook(*keyID, label, AddressBook::AddressBookPurpose::DELEGABLE);
}

UniValue ListaddressesForPurpose(const std::string strPurpose)
Expand Down Expand Up @@ -1103,8 +1103,6 @@ UniValue CreateColdStakeDelegation(const UniValue& params, CWalletTx& wtxNew, CR
if (!IsValidDestination(dest) || isStaking)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PIVX spending address");
ownerKey = *boost::get<CKeyID>(&dest);
if (!ownerKey)
throw JSONRPCError(RPC_WALLET_ERROR, "Unable to get spend pubkey hash from owneraddress");
// Check that the owner address belongs to this wallet, or fForceExternalAddr is true
bool fForceExternalAddr = params.size() > 3 && !params[3].isNull() ? params[3].get_bool() : false;
if (!fForceExternalAddr && !pwalletMain->HaveKey(ownerKey)) {
Expand All @@ -1119,8 +1117,6 @@ UniValue CreateColdStakeDelegation(const UniValue& params, CWalletTx& wtxNew, CR
// Get new owner address from keypool
CTxDestination ownerAddr = GetNewAddressFromLabel("delegated", NullUniValue);
ownerKey = *boost::get<CKeyID>(&ownerAddr);
if (!ownerKey)
throw JSONRPCError(RPC_WALLET_ERROR, "Unable to get spend pubkey hash from owneraddress");
ownerAddressStr = EncodeDestination(ownerAddr);
}

Expand Down Expand Up @@ -1838,12 +1834,12 @@ UniValue signmessage(const JSONRPCRequest& request)
if (!IsValidDestination(dest))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");

CKeyID keyID = *boost::get<CKeyID>(&dest);
const CKeyID* keyID = boost::get<CKeyID>(&dest);
if (!keyID)
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");

CKey key;
if (!pwalletMain->GetKey(keyID, key))
if (!pwalletMain->GetKey(*keyID, key))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");

CHashWriter ss(SER_GETHASH, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ bool CWallet::GetVinAndKeysFromOutput(COutput out, CTxIn& txinRet, CPubKey& pubK
CTxDestination address1;
ExtractDestination(pubScript, address1, fColdStake);

CKeyID* keyID = boost::get<CKeyID>(&address1);
const CKeyID* keyID = boost::get<CKeyID>(&address1);
if (!keyID) {
LogPrintf("CWallet::GetVinAndKeysFromOutput -- Address does not refer to a key\n");
return false;
Expand Down

0 comments on commit 12240dc

Please sign in to comment.