Add transactions to wallet if we spend notes in them
This commit is contained in:
parent
38a6e7a74d
commit
1551db870a
|
@ -291,6 +291,34 @@ TEST(wallet_tests, navigate_from_nullifier_to_note) {
|
|||
EXPECT_EQ(1, wallet.mapNullifiersToNotes[nullifier].n);
|
||||
}
|
||||
|
||||
TEST(wallet_tests, spent_note_is_from_me) {
|
||||
CWallet wallet;
|
||||
|
||||
auto sk = libzcash::SpendingKey::random();
|
||||
wallet.AddSpendingKey(sk);
|
||||
|
||||
auto wtx = GetValidReceive(sk, 10, true);
|
||||
auto note = GetNote(sk, wtx, 0, 1);
|
||||
auto nullifier = note.nullifier(sk);
|
||||
auto wtx2 = GetValidSpend(sk, note, 5);
|
||||
|
||||
EXPECT_FALSE(wallet.IsFromMe(wtx));
|
||||
EXPECT_FALSE(wallet.IsFromMe(wtx2));
|
||||
|
||||
mapNoteData_t noteData;
|
||||
JSOutPoint jsoutpt {wtx.GetTxid(), 0, 1};
|
||||
CNoteData nd {sk.address(), nullifier};
|
||||
noteData[jsoutpt] = nd;
|
||||
|
||||
wtx.SetNoteData(noteData);
|
||||
EXPECT_FALSE(wallet.IsFromMe(wtx));
|
||||
EXPECT_FALSE(wallet.IsFromMe(wtx2));
|
||||
|
||||
wallet.AddToWallet(wtx, true, NULL);
|
||||
EXPECT_FALSE(wallet.IsFromMe(wtx));
|
||||
EXPECT_TRUE(wallet.IsFromMe(wtx2));
|
||||
}
|
||||
|
||||
TEST(wallet_tests, cached_witnesses_empty_chain) {
|
||||
TestWallet wallet;
|
||||
|
||||
|
|
|
@ -1060,6 +1060,18 @@ mapNoteData_t CWallet::FindMyNotes(const CTransaction& tx) const
|
|||
return noteData;
|
||||
}
|
||||
|
||||
bool CWallet::IsFromMe(const uint256& nullifier) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
if (mapNullifiersToNotes.count(nullifier) &&
|
||||
mapWallet.count(mapNullifiersToNotes.at(nullifier).hash)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CWallet::GetNoteWitnesses(std::vector<JSOutPoint> notes,
|
||||
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
|
||||
uint256 &final_anchor)
|
||||
|
@ -1171,7 +1183,17 @@ bool CWallet::IsMine(const CTransaction& tx) const
|
|||
|
||||
bool CWallet::IsFromMe(const CTransaction& tx) const
|
||||
{
|
||||
return (GetDebit(tx, ISMINE_ALL) > 0);
|
||||
if (GetDebit(tx, ISMINE_ALL) > 0) {
|
||||
return true;
|
||||
}
|
||||
for (const JSDescription& jsdesc : tx.vjoinsplit) {
|
||||
for (const uint256& nullifier : jsdesc.nullifiers) {
|
||||
if (IsFromMe(nullifier)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CAmount CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) const
|
||||
|
|
|
@ -795,6 +795,7 @@ public:
|
|||
std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const;
|
||||
|
||||
mapNoteData_t FindMyNotes(const CTransaction& tx) const;
|
||||
bool IsFromMe(const uint256& nullifier) const;
|
||||
void GetNoteWitnesses(
|
||||
std::vector<JSOutPoint> notes,
|
||||
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
|
||||
|
|
Loading…
Reference in New Issue