bitcoin/BRWallet.c
// maximum amount that can be sent from the wallet to a single address after fees
// use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
maximum amount that can be sent from the wallet to a single address after fees
use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
maximum amount that can be sent from the wallet to a single address after fees use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
uint64_t BRWalletMaxOutputAmountWithFeePerKb(BRWallet *wallet, uint64_t feePerKb)
{
    BRTransaction *tx;
    BRUTXO *o;
    uint64_t fee, amount = 0;
    size_t i, txSize, cpfpSize = 0, inCount = 0;
    assert(wallet != NULL);
    pthread_mutex_lock(&wallet->lock);
    feePerKb = UINT64_MAX == feePerKb ? wallet->feePerKb : feePerKb;
    for (i = array_count(wallet->utxos); i > 0; i--) {
        o = &wallet->utxos[i - 1];
        tx = BRSetGet(wallet->allTx, &o->hash);
        if (! tx || o->n >= tx->outCount) continue;
        inCount++;
        amount += tx->outputs[o->n].amount;
    }
    txSize = 8 + BRVarIntSize(inCount) + TX_INPUT_SIZE*inCount + BRVarIntSize(2) + TX_OUTPUT_SIZE*2;
    fee = _txFee(feePerKb, txSize + cpfpSize);
    pthread_mutex_unlock(&wallet->lock);
    return (amount > fee) ? amount - fee : 0;
}
uint64_t BRWalletMaxOutputAmountWithFeePerKb ( BRWallet * wallet , uint64_t feePerKb ) { BRTransaction * tx ; BRUTXO * o ; uint64_t fee , amount = 0 ; size_t i , txSize , cpfpSize = 0 , inCount = 0 ; assert ( wallet != NULL ) ; pthread_mutex_lock ( & wallet -> lock ) ; feePerKb = UINT64_MAX == feePerKb ? wallet -> feePerKb : feePerKb ; for ( i = array_count ( wallet -> utxos ) ; i > 0 ; i -- ) { o = & wallet -> utxos [ i - 1 ] ; tx = BRSetGet ( wallet -> allTx , & o -> hash ) ; if ( ! tx || o -> n >= tx -> outCount ) continue ; inCount ++ ; amount += tx -> outputs [ o -> n ] . amount ; } txSize = 8 + BRVarIntSize ( inCount ) + TX_INPUT_SIZE * inCount + BRVarIntSize ( 2 ) + TX_OUTPUT_SIZE * 2 ; fee = _txFee ( feePerKb , txSize + cpfpSize ) ; pthread_mutex_unlock ( & wallet -> lock ) ; return ( amount > fee ) ? amount - fee : 0 ; }
maximum amount that can be sent from the wallet to a single address after fees
use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
maximum amount that can be sent from the wallet to a single address after fees use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
//        // size of unconfirmed, non-change inputs for child-pays-for-parent fee //        // don't include parent tx with more than 10 inputs or 10 outputs //        if (tx->blockHeight == TX_UNCONFIRMED && tx->inCount <= 10 && tx->outCount <= 10 && //            ! _BRWalletTxIsSend(wallet, tx)) cpfpSize += BRTransactionVSize(tx);