aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/test/wallet_tests.cpp
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2016-12-19 11:25:15 -0500
committerRussell Yanofsky <russ@yanofsky.org>2020-05-01 05:59:09 -0500
commit2b9cba206594bfbcefcef0c88a0bf793819643bd (patch)
treeb2a2f7ffb44094dd43e234f87cf6da579d315c89 /src/wallet/test/wallet_tests.cpp
parent608359b071dac82a9cf33a6c9e01f87abfcb90eb (diff)
Remove CWalletTx merging logic from AddToWallet
Instead of AddToWallet taking a temporary CWalletTx object and then potentially merging it with a pre-existing CWalletTx, have it take a callback so callers can update the pre-existing CWalletTx directly. This makes AddToWallet simpler because now it is only has to be concerned with saving CWalletTx objects and not merging them. This makes AddToWallet calls clearer because they can now make direct updates to CWalletTx entries without having to make temporary objects and then worry about how they will be merged. This is a pure refactoring, no behavior is changing.
Diffstat (limited to 'src/wallet/test/wallet_tests.cpp')
-rw-r--r--src/wallet/test/wallet_tests.cpp17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index c049f2f15f..f6273bcecd 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -331,6 +331,7 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
static int64_t AddTx(CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64_t blockTime)
{
CMutableTransaction tx;
+ CWalletTx::Confirmation confirm;
tx.nLockTime = lockTime;
SetMockTime(mockTime);
CBlockIndex* block = nullptr;
@@ -341,23 +342,15 @@ static int64_t AddTx(CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64
block = inserted.first->second;
block->nTime = blockTime;
block->phashBlock = &hash;
+ confirm = {CWalletTx::Status::CONFIRMED, block->nHeight, hash, 0};
}
- CWalletTx wtx(&wallet, MakeTransactionRef(tx));
- LOCK(wallet.cs_wallet);
// If transaction is already in map, to avoid inconsistencies, unconfirmation
// is needed before confirm again with different block.
- std::map<uint256, CWalletTx>::iterator it = wallet.mapWallet.find(wtx.GetHash());
- if (it != wallet.mapWallet.end()) {
+ return wallet.AddToWallet(MakeTransactionRef(tx), confirm, [&](CWalletTx& wtx, bool /* new_tx */) {
wtx.setUnconfirmed();
- wallet.AddToWallet(wtx);
- }
- if (block) {
- CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, block->nHeight, block->GetBlockHash(), 0);
- wtx.m_confirm = confirm;
- }
- wallet.AddToWallet(wtx);
- return wallet.mapWallet.at(wtx.GetHash()).nTimeSmart;
+ return true;
+ })->nTimeSmart;
}
// Simple test to verify assignment of CWalletTx::nSmartTime value. Could be