Skip to content

Commit b799814

Browse files
committed
wallet: Store tx time in COutput
1 parent 4602295 commit b799814

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

src/bench/coin_selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void CoinSelection(benchmark::Bench& bench)
5858
// Create coins
5959
std::vector<COutput> coins;
6060
for (const auto& wtx : wtxs) {
61-
coins.emplace_back(wallet, *wtx, /*iIn=*/ 0, /*depth=*/ 6 * 24, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, /*use_max_sig_in=*/ false);
61+
coins.emplace_back(wallet, *wtx, /*iIn=*/ 0, /*depth=*/ 6 * 24, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx->GetTxTime(), /*use_max_sig_in=*/ false);
6262
}
6363

6464
const CoinEligibilityFilter filter_standard(1, 6, 0);

src/wallet/interfaces.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet,
111111
return result;
112112
}
113113

114+
WalletTxOut MakeWalletTxOut(const CWallet& wallet,
115+
const COutput& output) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
116+
{
117+
WalletTxOut result;
118+
result.txout = output.tx->tx->vout[output.i];
119+
result.time = output.time;
120+
result.depth_in_main_chain = output.depth;
121+
result.is_spent = wallet.IsSpent(output.tx->GetHash(), output.i);
122+
return result;
123+
}
124+
114125
class WalletImpl : public Wallet
115126
{
116127
public:
@@ -420,7 +431,7 @@ class WalletImpl : public Wallet
420431
auto& group = result[entry.first];
421432
for (const auto& coin : entry.second) {
422433
group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
423-
MakeWalletTxOut(*m_wallet, *coin.tx, coin.i, coin.depth));
434+
MakeWalletTxOut(*m_wallet, coin));
424435
}
425436
}
426437
return result;

src/wallet/spend.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void AvailableCoins(const CWallet& wallet, std::vector<COutput>& vCoins, const C
191191
bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false;
192192
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
193193

194-
vCoins.push_back(COutput(wallet, wtx, i, nDepth, spendable, solvable, safeTx, (coinControl && coinControl->fAllowWatchOnly)));
194+
vCoins.emplace_back(wallet, wtx, i, nDepth, spendable, solvable, safeTx, wtx.GetTxTime(), /*use_max_sig_in=*/ (coinControl && coinControl->fAllowWatchOnly));
195195

196196
// Checks the sum amount of all UTXO's.
197197
if (nMinimumSumAmount != MAX_MONEY) {
@@ -268,14 +268,15 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
268268
for (const COutPoint& output : lockedCoins) {
269269
auto it = wallet.mapWallet.find(output.hash);
270270
if (it != wallet.mapWallet.end()) {
271-
int depth = wallet.GetTxDepthInMainChain(it->second);
272-
if (depth >= 0 && output.n < it->second.tx->vout.size() &&
273-
wallet.IsMine(it->second.tx->vout[output.n]) == is_mine_filter
271+
const auto& wtx = it->second;
272+
int depth = wallet.GetTxDepthInMainChain(wtx);
273+
if (depth >= 0 && output.n < wtx.tx->vout.size() &&
274+
wallet.IsMine(wtx.tx->vout[output.n]) == is_mine_filter
274275
) {
275276
CTxDestination address;
276-
if (ExtractDestination(FindNonChangeParentOutput(wallet, *it->second.tx, output.n).scriptPubKey, address)) {
277+
if (ExtractDestination(FindNonChangeParentOutput(wallet, *wtx.tx, output.n).scriptPubKey, address)) {
277278
result[address].emplace_back(
278-
wallet, it->second, output.n, depth, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, /*use_max_sig_in=*/ false);
279+
wallet, wtx, output.n, depth, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), /*use_max_sig_in=*/ false);
279280
}
280281
}
281282
}

src/wallet/spend.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ class COutput
4848
*/
4949
bool safe;
5050

51-
COutput(const CWallet& wallet, const CWalletTx& wtx, int iIn, int depth, bool spendable, bool solvable, bool safe, bool use_max_sig_in)
51+
/** The time of the transaction containing this output as determined by CWalletTx::nTimeSmart */
52+
int64_t time;
53+
54+
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)
5255
: tx(&wtx),
5356
i(iIn),
5457
depth(depth),
5558
input_bytes(-1),
5659
spendable(spendable),
5760
solvable(solvable),
5861
use_max_sig(use_max_sig_in),
59-
safe(safe)
62+
safe(safe),
63+
time(time)
6064
{
6165
// If known and signable by the given wallet, compute input_bytes
6266
// Failure will keep this value -1

src/wallet/test/coinselector_tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
9898
wtx.m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1);
9999
wtx.m_is_cache_empty = false;
100100
}
101-
COutput output(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, /*use_max_sig_in=*/ false);
102-
coins.push_back(output);
101+
coins.emplace_back(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), /*use_max_sig_in=*/ false);
103102
}
104103

105104
/** Check if SelectionResult a is equivalent to SelectionResult b.

0 commit comments

Comments
 (0)