bitcoin/BRWallet.c
// true if tx cannot be immediately spent (i.e. if it or an input tx can be replaced-by-fee)
true if tx cannot be immediately spent
true if tx cannot be immediately spent
int BRWalletTransactionIsPending(BRWallet *wallet, const BRTransaction *tx)
{
    BRTransaction *t;
    time_t now = time(NULL);
    uint32_t blockHeight;
    int r = 0;
    assert(wallet != NULL);
    assert(tx != NULL && BRTransactionIsSigned(tx));
    pthread_mutex_lock(&wallet->lock);
    blockHeight = wallet->blockHeight;
    pthread_mutex_unlock(&wallet->lock);
    if (tx && tx->blockHeight == TX_UNCONFIRMED) { 
        if (BRTransactionVSize(tx) > TX_MAX_SIZE) r = 1; 
        for (size_t i = 0; ! r && i < tx->inCount; i++) {
            if (tx->inputs[i].sequence < UINT32_MAX - 1) r = 1; 
            if (tx->inputs[i].sequence < UINT32_MAX && tx->lockTime < TX_MAX_LOCK_HEIGHT &&
                tx->lockTime > blockHeight + 1) r = 1; 
            if (tx->inputs[i].sequence < UINT32_MAX && tx->lockTime > now) r = 1; 
        }
        for (size_t i = 0; ! r && i < tx->outCount; i++) { 
            if (tx->outputs[i].amount < TX_MIN_OUTPUT_AMOUNT) r = 1;
        }
        for (size_t i = 0; ! r && i < tx->inCount; i++) { 
            t = BRWalletTransactionForHash(wallet, tx->inputs[i].txHash);
            if (t && BRWalletTransactionIsPending(wallet, t)) r = 1;
        }
    }
    return r;
}
int BRWalletTransactionIsPending ( BRWallet * wallet , const BRTransaction * tx ) { BRTransaction * t ; time_t now = time ( NULL ) ; uint32_t blockHeight ; int r = 0 ; assert ( wallet != NULL ) ; assert ( tx != NULL && BRTransactionIsSigned ( tx ) ) ; pthread_mutex_lock ( & wallet -> lock ) ; blockHeight = wallet -> blockHeight ; pthread_mutex_unlock ( & wallet -> lock ) ; if ( tx && tx -> blockHeight == TX_UNCONFIRMED ) { if ( BRTransactionVSize ( tx ) > TX_MAX_SIZE ) r = 1 ; for ( size_t i = 0 ; ! r && i < tx -> inCount ; i ++ ) { if ( tx -> inputs [ i ] . sequence < UINT32_MAX - 1 ) r = 1 ; if ( tx -> inputs [ i ] . sequence < UINT32_MAX && tx -> lockTime < TX_MAX_LOCK_HEIGHT && tx -> lockTime > blockHeight + 1 ) r = 1 ; if ( tx -> inputs [ i ] . sequence < UINT32_MAX && tx -> lockTime > now ) r = 1 ; } for ( size_t i = 0 ; ! r && i < tx -> outCount ; i ++ ) { if ( tx -> outputs [ i ] . amount < TX_MIN_OUTPUT_AMOUNT ) r = 1 ; } for ( size_t i = 0 ; ! r && i < tx -> inCount ; i ++ ) { t = BRWalletTransactionForHash ( wallet , tx -> inputs [ i ] . txHash ) ; if ( t && BRWalletTransactionIsPending ( wallet , t ) ) r = 1 ; } } return r ; }
true if tx cannot be immediately spent (i.e.
true if tx cannot be immediately spent ( i . e .
// only unconfirmed transactions can be postdated // check transaction size is under TX_MAX_SIZE // check for replace-by-fee // future lockTime // future lockTime // check that no outputs are dust // check if any inputs are known to be pending