Skip to content

Commit d045664

Browse files
committed
Add to spends only transcations from me
1 parent 9f3a622 commit d045664

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -800,30 +800,35 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
800800
context.args = &gArgs;
801801
context.chain = m_node.chain.get();
802802
auto wallet = TestLoadWallet(context);
803-
CKey key;
804-
key.MakeNewKey(true);
805-
AddKey(*wallet, key);
803+
AddKey(*wallet, coinbaseKey);
806804

807-
std::string error;
805+
// rescan to ensure coinbase transactions from test fixture are picked up by the wallet
806+
{
807+
WalletRescanReserver reserver(*wallet);
808+
reserver.reserve();
809+
wallet->ScanForWalletTransactions(m_node.chain->getBlockHash(0), 0, /* max height= */ {}, reserver, /* update= */ true);
810+
}
811+
// create one more block to get the first block coinbase to maturity
808812
m_coinbase_txns.push_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
809-
auto block_tx = TestSimpleSpend(*m_coinbase_txns[0], 0, coinbaseKey, GetScriptForRawPubKey(key.GetPubKey()));
810-
CreateAndProcessBlock({block_tx}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
813+
// spend first coinbase tx
814+
auto spend_tx = TestSimpleSpend(*m_coinbase_txns[0], 0, coinbaseKey, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
815+
CreateAndProcessBlock({spend_tx}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
811816

812817
SyncWithValidationInterfaceQueue();
813818

814819
{
815-
auto block_hash = block_tx.GetHash();
820+
auto spend_tx_hash = spend_tx.GetHash();
816821
auto prev_hash = m_coinbase_txns[0]->GetHash();
817822

818823
LOCK(wallet->cs_wallet);
819824
BOOST_CHECK(wallet->HasWalletSpend(prev_hash));
820-
BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 1u);
825+
BOOST_CHECK_EQUAL(wallet->mapWallet.count(spend_tx_hash), 1u);
821826

822-
std::vector<uint256> vHashIn{ block_hash }, vHashOut;
827+
std::vector<uint256> vHashIn{spend_tx_hash}, vHashOut;
823828
BOOST_CHECK_EQUAL(wallet->ZapSelectTx(vHashIn, vHashOut), DBErrors::LOAD_OK);
824829

825830
BOOST_CHECK(!wallet->HasWalletSpend(prev_hash));
826-
BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 0u);
831+
BOOST_CHECK_EQUAL(wallet->mapWallet.count(spend_tx_hash), 0u);
827832
}
828833

829834
TestUnloadWallet(std::move(wallet));

src/wallet/wallet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,9 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
915915
wtx.nOrderPos = IncOrderPosNext(&batch);
916916
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
917917
wtx.nTimeSmart = ComputeTimeSmart(wtx, rescanning_old_block);
918-
AddToSpends(hash, &batch);
918+
if (IsFromMe(*tx.get())) {
919+
AddToSpends(hash);
920+
}
919921
}
920922

921923
if (!fInsertedNew)

0 commit comments

Comments
 (0)