Add wallet method for finding spendable notes in a CTransaction

This commit is contained in:
Jack Grigg
2016-08-24 15:50:45 +12:00
parent 5db5e42ec3
commit 02e674555e
8 changed files with 264 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
#include "coincontrol.h"
#include "consensus/consensus.h"
#include "consensus/validation.h"
#include "init.h"
#include "main.h"
#include "net.h"
#include "script/script.h"
@@ -17,6 +18,7 @@
#include "timedata.h"
#include "util.h"
#include "utilmoneystr.h"
#include "zcash/Note.hpp"
#include <assert.h>
@@ -57,6 +59,11 @@ struct CompareValueOnly
}
};
std::string JSOutPoint::ToString() const
{
return strprintf("JSOutPoint(%s, %d, %d)", hash.ToString().substr(0,10), js, n);
}
std::string COutput::ToString() const
{
return strprintf("COutput(%s, %d, %d) [%s]", tx->GetTxid().ToString(), i, nDepth, FormatMoney(tx->vout[i].nValue));
@@ -843,6 +850,42 @@ void CWallet::EraseFromWallet(const uint256 &hash)
}
mapNoteData_t CWallet::FindMyNotes(const CTransaction& tx) const
{
uint256 hash = tx.GetTxid();
mapNoteData_t noteData;
std::set<NoteDecryptorMap::value_type> decryptors;
GetNoteDecryptors(decryptors);
libzcash::SpendingKey key;
for (size_t i = 0; i < tx.vjoinsplit.size(); i++) {
auto hSig = tx.vjoinsplit[i].h_sig(*pzcashParams, tx.joinSplitPubKey);
for (uint8_t j = 0; j < tx.vjoinsplit[i].ciphertexts.size(); j++) {
for (const NoteDecryptorMap::value_type& item : decryptors) {
try {
auto note_pt = libzcash::NotePlaintext::decrypt(
item.second,
tx.vjoinsplit[i].ciphertexts[j],
tx.vjoinsplit[i].ephemeralKey,
hSig,
(unsigned char) j);
auto address = item.first;
// Decryptors are only cached when SpendingKeys are added
assert(GetSpendingKey(address, key));
auto note = note_pt.note(address);
JSOutPoint jsoutpt {hash, i, j};
CNoteData nd {address, note.nullifier(key)};
noteData.insert(std::make_pair(jsoutpt, nd));
break;
} catch (const std::exception &) {
// Couldn't decrypt with this spending key
}
}
}
}
return noteData;
}
isminetype CWallet::IsMine(const CTxIn &txin) const
{
{