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.
 */
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.
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 .
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