src/wallet/wallet.cpp
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state)
{
    {
        LOCK2(cs_main, cs_wallet);
        LogPrintf("CommitTransaction:\n%s", wtxNew.ToString());
        {
            // Take key pair from key pool so it won't be used again
            reservekey.KeepKey();

            // Add tx to wallet, because if it has change it's also ours,
            // otherwise just for transaction history.
            AddToWallet(wtxNew);

            // Notify that old coins are spent
            for (const CTxIn& txin : wtxNew.vin)
            {
                CWalletTx &coin = mapWallet[txin.prevout.hash];
                coin.BindWallet(this);
                NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED);
            }
        }

        // Track how many getdata requests our transaction gets
        mapRequestCount[wtxNew.GetHash()] = 0;

        // Get the inserted-CWalletTx from mapWallet so that the
        // fInMempool flag is cached properly
        CWalletTx& wtx = mapWallet[wtxNew.GetHash()];

        if (fBroadcastTransactions)
        {
            // Broadcast
            if (wtx.fValidated && !wtx.AcceptToMemoryPool(false, maxTxFee, state)) {
                LogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", state.GetRejectReason());
                // TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
            } else {
                wtx.RelayWalletTransaction(connman);
            }
        }
    }
    return true;
}
/**
 * Call after CreateTransaction unless you want to abort
 */
Call after CreateTransaction unless you want to abort
Call after CreateTransaction unless you want to abort
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state)
{
    {
        LOCK2(cs_main, cs_wallet);
        LogPrintf("CommitTransaction:\n%s", wtxNew.ToString());
        {
            reservekey.KeepKey();
            AddToWallet(wtxNew);
            for (const CTxIn& txin : wtxNew.vin)
            {
                CWalletTx &coin = mapWallet[txin.prevout.hash];
                coin.BindWallet(this);
                NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED);
            }
        }
        mapRequestCount[wtxNew.GetHash()] = 0;
        CWalletTx& wtx = mapWallet[wtxNew.GetHash()];
        if (fBroadcastTransactions)
        {
            if (wtx.fValidated && !wtx.AcceptToMemoryPool(false, maxTxFee, state)) {
                LogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", state.GetRejectReason());
            } else {
                wtx.RelayWalletTransaction(connman);
            }
        }
    }
    return true;
}
bool CWallet :: CommitTransaction ( CWalletTx & wtxNew , CReserveKey & reservekey , CConnman * connman , CValidationState & state ) { { LOCK2 ( cs_main , cs_wallet ) ; LogPrintf ( " \n " , wtxNew . ToString ( ) ) ; { reservekey . KeepKey ( ) ; AddToWallet ( wtxNew ) ; for ( const CTxIn & txin : wtxNew . vin ) { CWalletTx & coin = mapWallet [ txin . prevout . hash ] ; coin . BindWallet ( this ) ; NotifyTransactionChanged ( this , coin . GetHash ( ) , CT_UPDATED ) ; } } mapRequestCount [ wtxNew . GetHash ( ) ] = 0 ; CWalletTx & wtx = mapWallet [ wtxNew . GetHash ( ) ] ; if ( fBroadcastTransactions ) { if ( wtx . fValidated && ! wtx . AcceptToMemoryPool ( false , maxTxFee , state ) ) { LogPrintf ( " \n " , state . GetRejectReason ( ) ) ; } else { wtx . RelayWalletTransaction ( connman ) ; } } } return true ; }
Call after CreateTransaction unless you want to abort
Call after CreateTransaction unless you want to abort
// Take key pair from key pool so it won't be used again // Add tx to wallet, because if it has change it's also ours, // otherwise just for transaction history. // Notify that old coins are spent // Track how many getdata requests our transaction gets // Get the inserted-CWalletTx from mapWallet so that the // fInMempool flag is cached properly // Broadcast // TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.