wallet: read wallet txs and note data by reference in more RPCs
z_listreceivedbyaddress copied a whole CWalletTx per returned note to call GetTxTime(). z_viewtransaction copied the previous tx of each own spend, CWalletTx::DecryptSaplingNote copied the output and the note data (witness list included) to read one field, and zsTxSpendsToJSON copied the note data. All of them now bind const references to the same elements. The lookups that throw or assert still do, and output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -153,7 +153,7 @@ void zsTxSpendsToJSON(const CWalletTx& wtx, UniValue& spends, CAmount& totalSpen
|
|||||||
if (pwalletMain->IsSaplingNullifierFromMe(spendDesc.nullifier)) {
|
if (pwalletMain->IsSaplingNullifierFromMe(spendDesc.nullifier)) {
|
||||||
const CWalletTx* parent = pwalletMain->GetWalletTx(pwalletMain->mapSaplingNullifiersToNotes[spendDesc.nullifier].hash);
|
const CWalletTx* parent = pwalletMain->GetWalletTx(pwalletMain->mapSaplingNullifiersToNotes[spendDesc.nullifier].hash);
|
||||||
const OutputDescription& output = parent->vShieldedOutput[op.n];
|
const OutputDescription& output = parent->vShieldedOutput[op.n];
|
||||||
auto nd = pwalletMain->mapWallet[pwalletMain->mapSaplingNullifiersToNotes[spendDesc.nullifier].hash].mapSaplingNoteData[op];
|
const SaplingNoteData& nd = pwalletMain->mapWallet[pwalletMain->mapSaplingNullifiersToNotes[spendDesc.nullifier].hash].mapSaplingNoteData[op];
|
||||||
auto pt = libzcash::SaplingNotePlaintext::decrypt(output.encCiphertext,nd.ivk,output.ephemeralKey,output.cm);
|
auto pt = libzcash::SaplingNotePlaintext::decrypt(output.encCiphertext,nd.ivk,output.ephemeralKey,output.cm);
|
||||||
|
|
||||||
if (pt) {
|
if (pt) {
|
||||||
|
|||||||
@@ -4696,7 +4696,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp, const CPubK
|
|||||||
}
|
}
|
||||||
obj.push_back(Pair("outindex", (int)entry.op.n));
|
obj.push_back(Pair("outindex", (int)entry.op.n));
|
||||||
obj.push_back(Pair("rawconfirmations", entry.confirmations));
|
obj.push_back(Pair("rawconfirmations", entry.confirmations));
|
||||||
auto wtx = pwalletMain->mapWallet.at(entry.op.hash); //.ToString());
|
const CWalletTx& wtx = pwalletMain->mapWallet.at(entry.op.hash); //.ToString());
|
||||||
obj.push_back(Pair("time", wtx.GetTxTime()));
|
obj.push_back(Pair("time", wtx.GetTxTime()));
|
||||||
|
|
||||||
obj.push_back(Pair("confirmations", dpowconfs));
|
obj.push_back(Pair("confirmations", dpowconfs));
|
||||||
@@ -4949,7 +4949,7 @@ UniValue z_viewtransaction(const UniValue& params, bool fHelp, const CPubKey& my
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto op = res->second;
|
auto op = res->second;
|
||||||
auto wtxPrev = pwalletMain->mapWallet.at(op.hash);
|
const CWalletTx& wtxPrev = pwalletMain->mapWallet.at(op.hash);
|
||||||
auto decrypted = wtxPrev.DecryptSaplingNote(op).get();
|
auto decrypted = wtxPrev.DecryptSaplingNote(op).get();
|
||||||
auto notePt = decrypted.first;
|
auto notePt = decrypted.first;
|
||||||
auto pa = decrypted.second;
|
auto pa = decrypted.second;
|
||||||
|
|||||||
@@ -2935,12 +2935,13 @@ boost::optional<std::pair<
|
|||||||
SaplingPaymentAddress>> CWalletTx::DecryptSaplingNote(SaplingOutPoint op) const
|
SaplingPaymentAddress>> CWalletTx::DecryptSaplingNote(SaplingOutPoint op) const
|
||||||
{
|
{
|
||||||
// Check whether we can decrypt this SaplingOutPoint
|
// Check whether we can decrypt this SaplingOutPoint
|
||||||
if (this->mapSaplingNoteData.count(op) == 0) {
|
mapSaplingNoteData_t::const_iterator ndIt = this->mapSaplingNoteData.find(op);
|
||||||
|
if (ndIt == this->mapSaplingNoteData.end()) {
|
||||||
return boost::none;
|
return boost::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto output = this->vShieldedOutput[op.n];
|
const OutputDescription& output = this->vShieldedOutput[op.n];
|
||||||
auto nd = this->mapSaplingNoteData.at(op);
|
const SaplingNoteData& nd = ndIt->second;
|
||||||
|
|
||||||
auto maybe_pt = SaplingNotePlaintext::decrypt(
|
auto maybe_pt = SaplingNotePlaintext::decrypt(
|
||||||
output.encCiphertext,
|
output.encCiphertext,
|
||||||
|
|||||||
Reference in New Issue
Block a user