wallet: Store tx time in COutput

pull/24091/head
Andrew Chow 3 years ago
parent 46022953ee
commit b799814bbd

@ -58,7 +58,7 @@ static void CoinSelection(benchmark::Bench& bench)
// Create coins // Create coins
std::vector<COutput> coins; std::vector<COutput> coins;
for (const auto& wtx : wtxs) { for (const auto& wtx : wtxs) {
coins.emplace_back(wallet, *wtx, /*iIn=*/ 0, /*depth=*/ 6 * 24, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, /*use_max_sig_in=*/ false); coins.emplace_back(wallet, *wtx, /*iIn=*/ 0, /*depth=*/ 6 * 24, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx->GetTxTime(), /*use_max_sig_in=*/ false);
} }
const CoinEligibilityFilter filter_standard(1, 6, 0); const CoinEligibilityFilter filter_standard(1, 6, 0);

@ -111,6 +111,17 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet,
return result; 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 class WalletImpl : public Wallet
{ {
public: public:
@ -420,7 +431,7 @@ public:
auto& group = result[entry.first]; auto& group = result[entry.first];
for (const auto& coin : entry.second) { for (const auto& coin : entry.second) {
group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i), group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
MakeWalletTxOut(*m_wallet, *coin.tx, coin.i, coin.depth)); MakeWalletTxOut(*m_wallet, coin));
} }
} }
return result; return result;

@ -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 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)); 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. // Checks the sum amount of all UTXO's.
if (nMinimumSumAmount != MAX_MONEY) { if (nMinimumSumAmount != MAX_MONEY) {
@ -268,14 +268,15 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
for (const COutPoint& output : lockedCoins) { for (const COutPoint& output : lockedCoins) {
auto it = wallet.mapWallet.find(output.hash); auto it = wallet.mapWallet.find(output.hash);
if (it != wallet.mapWallet.end()) { if (it != wallet.mapWallet.end()) {
int depth = wallet.GetTxDepthInMainChain(it->second); const auto& wtx = it->second;
if (depth >= 0 && output.n < it->second.tx->vout.size() && int depth = wallet.GetTxDepthInMainChain(wtx);
wallet.IsMine(it->second.tx->vout[output.n]) == is_mine_filter if (depth >= 0 && output.n < wtx.tx->vout.size() &&
wallet.IsMine(wtx.tx->vout[output.n]) == is_mine_filter
) { ) {
CTxDestination address; 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( 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);
} }
} }
} }

@ -48,7 +48,10 @@ public:
*/ */
bool safe; 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), : tx(&wtx),
i(iIn), i(iIn),
depth(depth), depth(depth),
@ -56,7 +59,8 @@ public:
spendable(spendable), spendable(spendable),
solvable(solvable), solvable(solvable),
use_max_sig(use_max_sig_in), use_max_sig(use_max_sig_in),
safe(safe) safe(safe),
time(time)
{ {
// If known and signable by the given wallet, compute input_bytes // If known and signable by the given wallet, compute input_bytes
// Failure will keep this value -1 // Failure will keep this value -1

@ -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_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1);
wtx.m_is_cache_empty = false; wtx.m_is_cache_empty = false;
} }
COutput output(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, /*use_max_sig_in=*/ false); coins.emplace_back(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), /*use_max_sig_in=*/ false);
coins.push_back(output);
} }
/** Check if SelectionResult a is equivalent to SelectionResult b. /** Check if SelectionResult a is equivalent to SelectionResult b.

Loading…
Cancel
Save