def set_tx(self, tx): """Reset the model to reflect tx.""" self.beginResetModel() self.vout = [] for o in tx.vout: self.vout.append(CMutableTxOut.from_txout(o)) self.endResetModel()
def set_tx(self, tx): """Reset the model to reflect tx.""" self.beginResetModel() self.vout = [] for o in tx.vout: self.vout.append(CMutableTxOut.from_txout(o)) self.endResetModel()
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 add_output(self, tx_out=None, output_index=None): """Add an output at output_index, or append one if output_index is None.""" if tx_out is None: tx_out = CMutableTxOut() elif tx_out.__class__ == CTxOut: tx_out = CMutableTxOut.from_txout(tx_out) if output_index is None: output_index = len(self.vout) self.beginInsertRows(QModelIndex(), output_index, output_index) self.vout.insert(output_index, tx_out) self.endInsertRows()
def add_output(self, tx_out=None, output_index=None): """Add an output at output_index, or append one if output_index is None.""" if tx_out is None: tx_out = CMutableTxOut() elif tx_out.__class__ == CTxOut: tx_out = CMutableTxOut.from_txout(tx_out) if output_index is None: output_index = len(self.vout) self.beginInsertRows(QModelIndex(), output_index, output_index) self.vout.insert(output_index, tx_out) self.endInsertRows()
def from_tx(cls, tx): if not issubclass(tx.__class__, Transaction): return super(Transaction, cls).from_tx(tx) else: kwfields = {} for attr, _, _, default in transaction_fields: if attr in ['vin', 'vout']: continue if hasattr(tx, attr): kwfields[attr] = getattr(tx, attr) vin = [CMutableTxIn.from_txin(txin) for txin in tx.vin] vout = [CMutableTxOut.from_txout(txout) for txout in tx.vout] kwfields['vin'] = vin kwfields['vout'] = vout return cls(kwfields=kwfields)
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!")