def bump_feerate(bitcoind, tx, feerate_add, prevouts_amount=None): """Bump the feerate of a CTransaction. :param bitcoind: The bitcoind RPC connection, to access the wallet. :param tx: The CTransaction which is to be bumped. :param feerate_add: How much to increase the feerate, in sat/vbyte. :param prevouts_amount: The sum of the value of all the consumed outputs. :return: (CTransaction) The modified transaction. """ # Work on a copy vin = [CMutableTxIn.from_txin(txin) for txin in tx.vin] vout = [CMutableTxOut.from_txout(txout) for txout in tx.vout] # FIXME: Add this to python-bitcoinlib wit = CTxWitness([ CTxInWitness.from_txinwitness(txinwit) for txinwit in tx.wit.vtxinwit ]) mut_tx = CMutableTransaction(vin, vout, witness=wit, nLockTime=tx.nLockTime, nVersion=tx.nVersion) fees = fees_to_add(bitcoind, mut_tx, feerate_add, prevouts_amount) if bitcoind.getbalance() * COIN > fees: return add_input(bitcoind, mut_tx, fees) raise Exception("Could not bump fees, no suitable utxo available!")
def bump_feerate(bitcoind, tx, feerate_add, prevouts_amount=None): """Bump the feerate of a CTransaction. :param bitcoind: The bitcoind RPC connection, to access the wallet. :param tx: The CTransaction which is to be bumped. :param feerate_add: How much to increase the feerate, in sat/vbyte. :param prevouts_amount: The sum of the value of all the consumed outputs. :return: (CTransaction) The modified transaction. """ # Work on a copy vin = [CMutableTxIn.from_txin(txin) for txin in tx.vin] vout = [CMutableTxOut.from_txout(txout) for txout in tx.vout] wit = CTxWitness([CTxInWitness.from_txinwitness(txinwit) for txinwit in tx.wit.vtxinwit]) mut_tx = CMutableTransaction(vin, vout, witness=wit, nLockTime=tx.nLockTime, nVersion=tx.nVersion) fees = fees_to_add(bitcoind, mut_tx, feerate_add, prevouts_amount) # No smart coin selection here, this is a demo for coin in bitcoind.listunspent(): if coin["amount"] * Decimal(COIN) > fees and coin["spendable"]: return add_input_output(bitcoind, mut_tx, coin, fees) raise Exception("Could not bump fees, no suitable utxo!")