src/wallet/wallet.cpp
/**
 * Add a transaction to the wallet, or update it.
 * pblock is optional, but should be provided if the transaction is known to be in a block.
 * If fUpdate is true, existing transactions will be updated.
 *
 * If pblock is null, this transaction has either recently entered the mempool from the
 * network, is re-entering the mempool after a block was disconnected, or is exiting the
 * mempool because it conflicts with another transaction. In all these cases, if there is
 * an existing wallet transaction, the wallet transaction's Merkle branch data is _not_
 * updated; instead, the transaction being in the mempool or conflicted is determined on
 * the fly in CMerkleTx::GetDepthInMainChain().
 */
Add a transaction to the wallet, or update it.
pblock is optional, but should be provided if the transaction is known to be in a block.
If fUpdate is true, existing transactions will be updated.

If pblock is null, this transaction has either recently entered the mempool from the
network, is re-entering the mempool after a block was disconnected, or is exiting the
mempool because it conflicts with another transaction. In all these cases, if there is
an existing wallet transaction, the wallet transaction's Merkle branch data is _not_
updated; instead, the transaction being in the mempool or conflicted is determined on
the fly in CMerkleTx::GetDepthInMainChain().
Add a transaction to the wallet or update it . pblock is optional but should be provided if the transaction is known to be in a block . If fUpdate is true existing transactions will be updated . If pblock is null this transaction has either recently entered the mempool from the network is re - entering the mempool after a block was disconnected or is exiting the mempool because it conflicts with another transaction . In all these cases if there is an existing wallet transaction the wallet transaction ' s Merkle branch data is _not_ updated ; instead the transaction being in the mempool or conflicted is determined on the fly in CMerkleTx :: GetDepthInMainChain () .
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate)
{
    {
        AssertLockHeld(cs_wallet);
        bool fExisted = mapWallet.count(tx.GetHash()) != 0;
        if (fExisted && !fUpdate) return false;
        auto sproutNoteData = FindMySproutNotes(tx);
        auto saplingNoteDataAndAddressesToAdd = FindMySaplingNotes(tx);
        auto saplingNoteData = saplingNoteDataAndAddressesToAdd.first;
        auto addressesToAdd = saplingNoteDataAndAddressesToAdd.second;
        for (const auto &addressToAdd : addressesToAdd) {
            if (!AddSaplingIncomingViewingKey(addressToAdd.second, addressToAdd.first)) {
                return false;
            }
        }
        if (fExisted || IsMine(tx) || IsFromMe(tx) || sproutNoteData.size() > 0 || saplingNoteData.size() > 0)
        {
            CWalletTx wtx(this,tx);
            if (sproutNoteData.size() > 0) {
                wtx.SetSproutNoteData(sproutNoteData);
            }
            if (saplingNoteData.size() > 0) {
                wtx.SetSaplingNoteData(saplingNoteData);
            }
            if (pblock)
                wtx.SetMerkleBranch(*pblock);
            CWalletDB walletdb(strWalletFile, "r+", false);
            return AddToWallet(wtx, false, &walletdb);
        }
    }
    return false;
}
bool CWallet :: AddToWalletIfInvolvingMe ( const CTransaction & tx , const CBlock * pblock , bool fUpdate ) { { AssertLockHeld ( cs_wallet ) ; bool fExisted = mapWallet . count ( tx . GetHash ( ) ) != 0 ; if ( fExisted && ! fUpdate ) return false ; auto sproutNoteData = FindMySproutNotes ( tx ) ; auto saplingNoteDataAndAddressesToAdd = FindMySaplingNotes ( tx ) ; auto saplingNoteData = saplingNoteDataAndAddressesToAdd . first ; auto addressesToAdd = saplingNoteDataAndAddressesToAdd . second ; for ( const auto & addressToAdd : addressesToAdd ) { if ( ! AddSaplingIncomingViewingKey ( addressToAdd . second , addressToAdd . first ) ) { return false ; } } if ( fExisted || IsMine ( tx ) || IsFromMe ( tx ) || sproutNoteData . size ( ) > 0 || saplingNoteData . size ( ) > 0 ) { CWalletTx wtx ( this , tx ) ; if ( sproutNoteData . size ( ) > 0 ) { wtx . SetSproutNoteData ( sproutNoteData ) ; } if ( saplingNoteData . size ( ) > 0 ) { wtx . SetSaplingNoteData ( saplingNoteData ) ; } if ( pblock ) wtx . SetMerkleBranch ( * pblock ) ; CWalletDB walletdb ( strWalletFile , " " , false ) ; return AddToWallet ( wtx , false , & walletdb ) ; } } return false ; }
Add a transaction to the wallet, or update it.
Add a transaction to the wallet or update it .
// Get merkle branch if transaction was found in a block // Do not flush the wallet here for performance reasons // this is safe, as in case of a crash, we rescan the necessary blocks on startup through our SetBestChain-mechanism