diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-01-18 20:31:08 -0500 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2022-03-17 11:00:45 -0400 |
commit | b799814bbd53736b79495072f3c9e05989a465e8 (patch) | |
tree | 0d1bb9ae46b8dd858ffbff2d053bca68aeb41f66 /src/wallet | |
parent | 46022953ee2e8113167bafd1fd48a383a578b13c (diff) | |
download | bitcoin-b799814bbd53736b79495072f3c9e05989a465e8.tar.xz |
wallet: Store tx time in COutput
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/interfaces.cpp | 13 | ||||
-rw-r--r-- | src/wallet/spend.cpp | 13 | ||||
-rw-r--r-- | src/wallet/spend.h | 8 | ||||
-rw-r--r-- | src/wallet/test/coinselector_tests.cpp | 3 |
4 files changed, 26 insertions, 11 deletions
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 2bc8e48943..56ca2f0cdb 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -111,6 +111,17 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet, return result; } +WalletTxOut MakeWalletTxOut(const CWallet& wallet, + const COutput& output) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) +{ + WalletTxOut result; + result.txout = output.tx->tx->vout[output.i]; + result.time = output.time; + result.depth_in_main_chain = output.depth; + result.is_spent = wallet.IsSpent(output.tx->GetHash(), output.i); + return result; +} + class WalletImpl : public Wallet { public: @@ -420,7 +431,7 @@ public: auto& group = result[entry.first]; for (const auto& coin : entry.second) { group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i), - MakeWalletTxOut(*m_wallet, *coin.tx, coin.i, coin.depth)); + MakeWalletTxOut(*m_wallet, coin)); } } return result; diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 6f5d0fed86..887a5dae77 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -191,7 +191,7 @@ void AvailableCoins(const CWallet& wallet, std::vector<COutput>& vCoins, const C bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false; bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable)); - vCoins.push_back(COutput(wallet, wtx, i, nDepth, spendable, solvable, safeTx, (coinControl && coinControl->fAllowWatchOnly))); + vCoins.emplace_back(wallet, wtx, i, nDepth, spendable, solvable, safeTx, wtx.GetTxTime(), /*use_max_sig_in=*/ (coinControl && coinControl->fAllowWatchOnly)); // Checks the sum amount of all UTXO's. if (nMinimumSumAmount != MAX_MONEY) { @@ -268,14 +268,15 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet) for (const COutPoint& output : lockedCoins) { auto it = wallet.mapWallet.find(output.hash); if (it != wallet.mapWallet.end()) { - int depth = wallet.GetTxDepthInMainChain(it->second); - if (depth >= 0 && output.n < it->second.tx->vout.size() && - wallet.IsMine(it->second.tx->vout[output.n]) == is_mine_filter + const auto& wtx = it->second; + int depth = wallet.GetTxDepthInMainChain(wtx); + if (depth >= 0 && output.n < wtx.tx->vout.size() && + wallet.IsMine(wtx.tx->vout[output.n]) == is_mine_filter ) { CTxDestination address; - if (ExtractDestination(FindNonChangeParentOutput(wallet, *it->second.tx, output.n).scriptPubKey, address)) { + if (ExtractDestination(FindNonChangeParentOutput(wallet, *wtx.tx, output.n).scriptPubKey, address)) { result[address].emplace_back( - wallet, it->second, output.n, depth, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, /*use_max_sig_in=*/ false); + wallet, wtx, output.n, depth, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), /*use_max_sig_in=*/ false); } } } diff --git a/src/wallet/spend.h b/src/wallet/spend.h index eb0a2ec05d..86735fc998 100644 --- a/src/wallet/spend.h +++ b/src/wallet/spend.h @@ -48,7 +48,10 @@ public: */ bool safe; - COutput(const CWallet& wallet, const CWalletTx& wtx, int iIn, int depth, bool spendable, bool solvable, bool safe, bool use_max_sig_in) + /** The time of the transaction containing this output as determined by CWalletTx::nTimeSmart */ + int64_t time; + + COutput(const CWallet& wallet, const CWalletTx& wtx, int iIn, int depth, bool spendable, bool solvable, bool safe, int64_t time, bool use_max_sig_in) : tx(&wtx), i(iIn), depth(depth), @@ -56,7 +59,8 @@ public: spendable(spendable), solvable(solvable), use_max_sig(use_max_sig_in), - safe(safe) + safe(safe), + time(time) { // If known and signable by the given wallet, compute input_bytes // Failure will keep this value -1 diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index 430e202d4f..bcfcfd186a 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -98,8 +98,7 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount wtx.m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1); wtx.m_is_cache_empty = false; } - COutput output(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, /*use_max_sig_in=*/ false); - coins.push_back(output); + coins.emplace_back(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), /*use_max_sig_in=*/ false); } /** Check if SelectionResult a is equivalent to SelectionResult b. |