def insert_utxo(self, idx, utxo: PartialTxInput): address = utxo.address height = utxo.block_height name = utxo.prevout.to_str() name_short = utxo.prevout.txid.hex( )[:16] + '...' + ":%d" % utxo.prevout.out_idx self.utxo_dict[name] = utxo label = self.wallet.get_label(utxo.prevout.txid.hex()) amount = self.parent.format_amount(utxo.value_sats(), whitespaces=True) labels = [name_short, address, label, amount, '%d' % height] utxo_item = [QStandardItem(x) for x in labels] self.set_editability(utxo_item) utxo_item[self.Columns.ADDRESS].setFont(QFont(MONOSPACE_FONT)) utxo_item[self.Columns.AMOUNT].setFont(QFont(MONOSPACE_FONT)) utxo_item[self.Columns.OUTPOINT].setFont(QFont(MONOSPACE_FONT)) utxo_item[self.Columns.ADDRESS].setData(name, Qt.UserRole) SELECTED_TO_SPEND_TOOLTIP = _('Coin selected to be spent') if name in (self._spend_set or set()): for col in utxo_item: col.setBackground(ColorScheme.GREEN.as_color(True)) if col != self.Columns.OUTPOINT: col.setToolTip(SELECTED_TO_SPEND_TOOLTIP) if self.wallet.is_frozen_address(address): utxo_item[self.Columns.ADDRESS].setBackground( ColorScheme.BLUE.as_color(True)) utxo_item[self.Columns.ADDRESS].setToolTip(_('Address is frozen')) if self.wallet.is_frozen_coin(utxo): utxo_item[self.Columns.OUTPOINT].setBackground( ColorScheme.BLUE.as_color(True)) utxo_item[self.Columns.OUTPOINT].setToolTip( f"{name}\n{_('Coin is frozen')}") else: tooltip = ("\n" + SELECTED_TO_SPEND_TOOLTIP) if name in (self._spend_set or set()) else "" utxo_item[self.Columns.OUTPOINT].setToolTip(name + tooltip) self.model().insertRow(idx, utxo_item)
wif = 'cQNjiPwYKMBr2oB3bWzf3rgBsu198xb8Nxxe51k6D3zVTA98L25N' txid = x('6d500966f9e494b38a04545f0cea35fc7b3944e341a64b804fed71cdee11d434') vout = 1 sats = 9999 script_type = 'p2sh' binzero = 2**32 sequence = binzero - 3 address = 'tb1qv9hg20f0g08d460l67ph6p4ukwt7m0ttqzj7mk' sats_less_fees = sats - 200 locktime = 1602565200 # Build the Transaction Input _, privkey, compressed = deserialize_privkey(wif) pubkey = ECPrivkey(privkey).get_public_key_hex(compressed=compressed) prevout = TxOutpoint(txid=txid, out_idx=vout) txin = PartialTxInput(prevout=prevout) txin.nsequence = sequence txin.script_type = script_type expiry = b2x(lx(b2x(locktime))) redeem_script = compile([ expiry, 'OP_CHECKLOCKTIMEVERIFY', 'OP_DROP', pubkey, 'OP_CHECKSIG']) txin.redeem_script = x(redeem_script) # Build the Transaction Output txout = PartialTxOutput.from_address_and_value(address, sats_less_fees) # Build and sign the transaction tx = P2SHPartialTransaction.from_io([txin], [txout], locktime=locktime) tx.version = 1 sig = tx.sign_txin(0, privkey) txin.script_sig = x(compile([sig , redeem_script]))
sats = 10_000 sequence = 0 # in retrospect "-3" in two's complement may be better address = 'tb1q5rn69avl3ganw3cmhz5ldcxpash2kusq7sncfl' sats_less_fees = sats - 500 locktime = 1602572140 # Build the Transaction Input _, privkey, compressed = deserialize_privkey(wif) pubkey = ECPrivkey(privkey).get_public_key_hex(compressed=compressed) expiry = b2x(lx(b2x(locktime))) witness_script = compile( [expiry, 'OP_CHECKLOCKTIMEVERIFY', 'OP_DROP', pubkey, 'OP_CHECKSIG']) script_hash = b2x(sha256(x(witness_script))) hodl_address = bech32_encode(script_hash) prevout = TxOutpoint(txid=txid, out_idx=vout) txin = PartialTxInput(prevout=prevout) txin._trusted_value_sats = sats txin.nsequence = sequence txin.script_sig = x(compile([])) # empty script (important!) txin.witness_script = x(witness_script) # Build the Transaction Output txout = PartialTxOutput.from_address_and_value(address, sats_less_fees) # Build and sign the transaction tx = PartialTransaction.from_io([txin], [txout], locktime=locktime) tx.version = 1 txin_index = 0 sig = tx.sign_txin(txin_index, privkey) # Prepend number of elements in script per the spec.