Bitcoin Core 28.99.0
P2P Digital Currency
transaction.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#include <interfaces/chain.h>
8
10
11namespace wallet {
13{
14 CMutableTransaction tx1 {*this->tx};
15 CMutableTransaction tx2 {*_tx.tx};
16 for (auto& txin : tx1.vin) txin.scriptSig = CScript();
17 for (auto& txin : tx2.vin) txin.scriptSig = CScript();
18 return CTransaction(tx1) == CTransaction(tx2);
19}
20
22{
23 return state<TxStateInMempool>();
24}
25
26int64_t CWalletTx::GetTxTime() const
27{
28 int64_t n = nTimeSmart;
29 return n ? n : nTimeReceived;
30}
31
33{
34 bool active;
35 auto lookup_block = [&](const uint256& hash, int& height, TxState& state) {
36 // If tx block (or conflicting block) was reorged out of chain
37 // while the wallet was shutdown, change tx status to UNCONFIRMED
38 // and reset block height, hash, and index. ABANDONED tx don't have
39 // associated blocks and don't need to be updated. The case where a
40 // transaction was reorged out while online and then reconfirmed
41 // while offline is covered by the rescan logic.
42 if (!chain.findBlock(hash, FoundBlock().inActiveChain(active).height(height)) || !active) {
44 }
45 };
46 if (auto* conf = state<TxStateConfirmed>()) {
47 lookup_block(conf->confirmed_block_hash, conf->confirmed_block_height, m_state);
48 } else if (auto* conf = state<TxStateBlockConflicted>()) {
49 lookup_block(conf->conflicting_block_hash, conf->conflicting_block_height, m_state);
50 }
51}
52
54{
55 *this = _tx;
56}
57} // namespace wallet
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:415
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:296
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:129
virtual bool findBlock(const uint256 &hash, const FoundBlock &block={})=0
Return whether node has the block and optionally return block metadata or contents.
Helper for findBlock to selectively return pieces of block data.
Definition: chain.h:48
256-bit opaque blob.
Definition: uint256.h:190
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:177
const T * state() const
Definition: transaction.h:338
bool IsEquivalentTo(const CWalletTx &tx) const
True if only scriptSigs are different.
Definition: transaction.cpp:12
void updateState(interfaces::Chain &chain)
Update transaction state when attaching to a chain, filling in heights of conflicted and confirmed bl...
Definition: transaction.cpp:32
void CopyFrom(const CWalletTx &)
Definition: transaction.cpp:53
unsigned int nTimeReceived
time received by this node
Definition: transaction.h:207
CTransactionRef tx
Definition: transaction.h:258
bool InMempool() const
Definition: transaction.cpp:21
int64_t GetTxTime() const
Definition: transaction.cpp:26
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet.
Definition: transaction.h:217
std::variant< TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized > TxState
All possible CWalletTx states.
Definition: transaction.h:78
A mutable version of CTransaction.
Definition: transaction.h:378
State of transaction not confirmed or conflicting with a known block and not in the mempool.
Definition: transaction.h:58