diff --git a/src/wallet/rpchushwallet.cpp b/src/wallet/rpchushwallet.cpp index 85574b7c7..74f0c6702 100644 --- a/src/wallet/rpchushwallet.cpp +++ b/src/wallet/rpchushwallet.cpp @@ -148,12 +148,16 @@ void zsTxSpendsToJSON(const CWalletTx& wtx, UniValue& spends, CAmount& totalSpen const SpendDescription& spendDesc = wtx.vShieldedSpend[i]; UniValue obj(UniValue::VOBJ); - SaplingOutPoint op = pwalletMain->mapSaplingNullifiersToNotes[spendDesc.nullifier]; + std::map::const_iterator nfIt = pwalletMain->mapSaplingNullifiersToNotes.find(spendDesc.nullifier); - if (pwalletMain->IsSaplingNullifierFromMe(spendDesc.nullifier)) { - const CWalletTx* parent = pwalletMain->GetWalletTx(pwalletMain->mapSaplingNullifiersToNotes[spendDesc.nullifier].hash); + // Same test as IsSaplingNullifierFromMe(), but find() so a read-only RPC never inserts into wallet maps. + if (nfIt != pwalletMain->mapSaplingNullifiersToNotes.end() && pwalletMain->mapWallet.count(nfIt->second.hash)) { + const SaplingOutPoint op = nfIt->second; + const CWalletTx* parent = pwalletMain->GetWalletTx(op.hash); + mapSaplingNoteData_t::const_iterator ndIt = parent->mapSaplingNoteData.find(op); + if (ndIt == parent->mapSaplingNoteData.end()) continue; // stale entry: old code inserted an empty note that never decrypts const OutputDescription& output = parent->vShieldedOutput[op.n]; - const SaplingNoteData& nd = pwalletMain->mapWallet[pwalletMain->mapSaplingNullifiersToNotes[spendDesc.nullifier].hash].mapSaplingNoteData[op]; + const SaplingNoteData& nd = ndIt->second; auto pt = libzcash::SaplingNotePlaintext::decrypt(output.encCiphertext,nd.ivk,output.ephemeralKey,output.cm); if (pt) {