Python bitcoin.core.CMutableTxIn() Examples

The following are 9 code examples of bitcoin.core.CMutableTxIn(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bitcoin.core , or try the search function .
Example #1
Source File: channel.py    From Lightning with MIT License 6 votes vote down vote up
def select_coins(amount):
    """Get a txin set and change to spend amount."""
    coins = g.bit.listunspent()
    out = []
    for coin in coins:
        if not coin['spendable']:
            continue
        out.append(CMutableTxIn(coin['outpoint']))
        amount -= coin['amount']
        if amount <= 0:
            break
    if amount > 0:
        raise Exception("Not enough money")
    change = CMutableTxOut(
        -amount, g.bit.getrawchangeaddress().to_scriptPubKey())
    return out, change 
Example #2
Source File: utxo.py    From clove with GNU General Public License v3.0 5 votes vote down vote up
def tx_in(self):
        return CMutableTxIn(self.outpoint, scriptSig=script.CScript(self.unsigned_script_sig), nSequence=0) 
Example #3
Source File: transactions.py    From OpenBazaar-Server with MIT License 5 votes vote down vote up
def make_unsigned(cls, outpoints, outputs, tx_fee=TRANSACTION_FEE, testnet=False, out_value=None):
        """
        Build an unsigned transaction.

        Args:
            outpoints: A `list` of `dict` objects which contain a txid, vout, value, and scriptPubkey.
            outputs: If a single address the full value of the inputs (minus the tx fee) will be sent there.
                Otherwise it should be a `list` of `dict` objects containing address and value.
            tx_fee: The Bitcoin network fee to be paid on this transaction.
            testnet: Should this transaction be built for testnet?
            out_value: used if you want to specify a specific output value otherwise the full value
                of the inputs (minus the tx fee) will be used.
        """
        # build the inputs from the outpoints object
        SelectParams("testnet" if testnet else "mainnet")
        txins = []
        in_value = 0
        for outpoint in outpoints:
            in_value += outpoint["value"]
            txin = CMutableTxIn(COutPoint(lx(outpoint["txid"]), outpoint["vout"]))
            txin.scriptSig = CScript(x(outpoint["scriptPubKey"]))
            txins.append(txin)

        # build the outputs
        txouts = []
        if isinstance(outputs, list):
            for output in outputs:
                value = output["value"]
                address = output["address"]
                txouts.append(CMutableTxOut(value, CBitcoinAddress(address).to_scriptPubKey()))
        else:
            value = out_value if out_value is not None else (in_value - tx_fee)
            txouts.append(CMutableTxOut(value, CBitcoinAddress(outputs).to_scriptPubKey()))

        # make the transaction
        tx = CMutableTransaction(txins, txouts)

        return BitcoinTransaction(tx) 
Example #4
Source File: channel.py    From Lightning with MIT License 5 votes vote down vote up
def commitment(self, ours=False):
        """Return an unsigned commitment transaction."""
        first = CMutableTxOut(self.our_balance, self.our_addr.to_scriptPubKey())
        second = CMutableTxOut(self.their_balance, self.their_addr.to_scriptPubKey())
        if not ours:
            first, second = second, first
        return CMutableTransaction([CMutableTxIn(self.anchor_point)],
                                   [first, second]) 
Example #5
Source File: channel.py    From Lightning with MIT License 5 votes vote down vote up
def settlement(self):
        """Generate the settlement transaction."""
        # Put outputs in the order of the inputs, so that both versions are the same
        first = CMutableTxOut(self.our_balance,
                              self.our_addr.to_scriptPubKey())
        second = CMutableTxOut(self.their_balance,
                               self.their_addr.to_scriptPubKey())
        if self.anchor_index == 0:
            pass
        elif self.anchor_index == 1:
            first, second = second, first
        else:
            raise Exception("Unknown index", self.anchor_index)
        return CMutableTransaction([CMutableTxIn(self.anchor_point)],
                                   [first, second]) 
Example #6
Source File: test_jsonrpcproxy.py    From Lightning with MIT License 5 votes vote down vote up
def test_json_roundtrip(self):
        VALUES = [
            42, 0, -42, 2100000000000000, -2100000000000000,
            "basic string", "\u1111Unicode", "\U00010000Wide Unicode",
            "\x00\n\t\r\nEscape codes", "\"'\"Quotes", "",
            None,
            b"\x00\x01\xFFBinary data", b"",
            CBase58Data.from_bytes(b'\x00\x01\xFF', 42),
            P2SHBitcoinAddress.from_bytes(b'\x00\x01\xFF'),
            P2PKHBitcoinAddress.from_bytes(b'\x00\x01\xFF'),
            CMutableTxIn(COutPoint(b'\x00'*16+b'\xFF'*16, 42),
                         CScript(b'\x00\x01\xFF'),
                         42),
            CMutableTxOut(42, CScript(b'\x00\x01\xFF')),
            CMutableTransaction([CMutableTxIn(COutPoint(b'\x00'*32, 42),
                                              CScript(b'\x00\x01\xFF'),
                                              42),
                                 CMutableTxIn(COutPoint(b'\xFF'*32, 42),
                                              CScript(b'\xFF\x01\x00'),
                                              43)],
                                [CMutableTxOut(42, CScript(b'\x00\x01\xFF')),
                                 CMutableTxOut(43, CScript(b'\xFF\x01\x00'))],
                                42, 3),
            [1, b'\x00\x01\xFF', "List Test",],
            {'a':1, 'key':b'\xFF\x01\x00', 1:'Dictionary Test'},
            [{3: [0, 1, 2,],}, [[b'\xFFRecursion Test',],],],
        ]
        for value in VALUES:
            self.assertEqual(from_json(to_json(value)), value) 
Example #7
Source File: test_stack.py    From hashmal with GNU General Public License v3.0 5 votes vote down vote up
def build_spending_tx(script_sig, credit_tx):
    tx = Transaction(version=1, locktime=0)
    txin = CMutableTxIn(CMutableOutPoint(credit_tx.GetHash(), 0), script_sig)
    tx.vin = [txin]
    txout = CMutableTxOut(0, Script())
    tx.vout = [txout]
    return tx 
Example #8
Source File: test_stack.py    From hashmal with GNU General Public License v3.0 5 votes vote down vote up
def build_crediting_tx(script_pubkey):
    tx = Transaction(version=1, locktime=0)
    txin = CMutableTxIn()
    txin.scriptSig = Script.from_human('0x00 0x00')
    tx.vin = [txin]
    txout = CMutableTxOut(0, script_pubkey)
    tx.vout = [txout]
    return tx 
Example #9
Source File: tx_builder.py    From hashmal with GNU General Public License v3.0 5 votes vote down vote up
def create_inputs_tab(self):
        form = QFormLayout()
        self.inputs_tree = InputsTree()
        self.inputs_tree.view.setWhatsThis('The inputs of your transaction are displayed here.')
        self.inputs_editor = InputsEditor(self.handler.gui, self.inputs_tree)
        self.inputs_editor.setEnabled(False)

        def update_enabled_widgets():
            num_inputs = len(self.inputs_tree.get_inputs())
            self.inputs_editor.setEnabled(num_inputs > 0)

        def add_input():
            outpoint = CMutableOutPoint(n=0)
            new_input = CMutableTxIn(prevout=outpoint)
            self.inputs_tree.add_input(new_input)

            update_enabled_widgets()
            if len(self.inputs_tree.get_inputs()) > 0:
                self.inputs_tree.view.selectRow(self.inputs_tree.model.rowCount() - 1)

        update_enabled_widgets()

        add_input_button = QPushButton('New input')
        add_input_button.setToolTip('Add a new input')
        add_input_button.setWhatsThis('Clicking this button will add a new input to your transaction.')
        add_input_button.clicked.connect(add_input)

        form.addRow(self.inputs_tree)
        form.addRow(Separator())

        form.addRow(self.inputs_editor)

        form.addRow(Separator())
        form.addRow(floated_buttons([add_input_button]))

        w = QWidget()
        w.setLayout(form)
        return w