bitcoin/BRWallet.c
// fee that will be added for a transaction of the given amount
// use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
fee that will be added for a transaction of the given amount
use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
fee that will be added for a transaction of the given amount use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
uint64_t BRWalletFeeForTxAmountWithFeePerKb(BRWallet *wallet, uint64_t feePerKb, uint64_t amount)
{
    static const uint8_t dummyScript[] = { OP_DUP, OP_HASH160, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                           0, 0, 0, 0, 0, 0, 0, 0, 0, OP_EQUALVERIFY, OP_CHECKSIG };
    BRTxOutput o = BR_TX_OUTPUT_NONE;
    BRTransaction *tx;
    uint64_t fee = 0, maxAmount = 0;
    assert(wallet != NULL);
    assert(amount > 0);
    maxAmount = BRWalletMaxOutputAmountWithFeePerKb(wallet, feePerKb);
    o.amount = (amount < maxAmount) ? amount : maxAmount;
    BRTxOutputSetScript(&o, dummyScript, sizeof(dummyScript)); 
    tx = BRWalletCreateTxForOutputsWithFeePerKb(wallet, feePerKb, &o, 1);
    BRTxOutputSetScript(&o, NULL, 0);
    if (tx) {
        fee = BRWalletFeeForTx(wallet, tx);
        BRTransactionFree(tx);
    }
    return fee;
}
uint64_t BRWalletFeeForTxAmountWithFeePerKb ( BRWallet * wallet , uint64_t feePerKb , uint64_t amount ) { static const uint8_t dummyScript [ ] = { OP_DUP , OP_HASH160 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , OP_EQUALVERIFY , OP_CHECKSIG } ; BRTxOutput o = BR_TX_OUTPUT_NONE ; BRTransaction * tx ; uint64_t fee = 0 , maxAmount = 0 ; assert ( wallet != NULL ) ; assert ( amount > 0 ) ; maxAmount = BRWalletMaxOutputAmountWithFeePerKb ( wallet , feePerKb ) ; o . amount = ( amount < maxAmount ) ? amount : maxAmount ; BRTxOutputSetScript ( & o , dummyScript , sizeof ( dummyScript ) ) ; tx = BRWalletCreateTxForOutputsWithFeePerKb ( wallet , feePerKb , & o , 1 ) ; BRTxOutputSetScript ( & o , NULL , 0 ) ; if ( tx ) { fee = BRWalletFeeForTx ( wallet , tx ) ; BRTransactionFree ( tx ) ; } return fee ; }
fee that will be added for a transaction of the given amount
use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
fee that will be added for a transaction of the given amount use feePerKb UINT64_MAX to indicate that the wallet feePerKb should be used
// unspendable dummy scriptPubKey