def add_io(self, vbox): vbox.addWidget(QLabel(_("Inputs") + ' (%d)'%len(self.tx.inputs()))) ext = QTextCharFormat() rec = QTextCharFormat() rec.setBackground(QBrush(ColorScheme.GREEN.as_color(background=True))) rec.setToolTip(_("Wallet receive address")) chg = QTextCharFormat() chg.setBackground(QBrush(ColorScheme.YELLOW.as_color(background=True))) chg.setToolTip(_("Wallet change address")) twofactor = QTextCharFormat() twofactor.setBackground(QBrush(ColorScheme.BLUE.as_color(background=True))) twofactor.setToolTip(_("TrustedCoin (2FA) fee for the next batch of transactions")) def text_format(addr): if self.wallet.is_mine(addr): return chg if self.wallet.is_change(addr) else rec elif self.wallet.is_billing_address(addr): return twofactor return ext def format_amount(amt): return self.main_window.format_amount(amt, whitespaces=True) i_text = QTextEditWithDefaultSize() i_text.setFont(QFont(MONOSPACE_FONT)) i_text.setReadOnly(True) cursor = i_text.textCursor() for x in self.tx.inputs(): if x['type'] == 'coinbase': cursor.insertText('coinbase') else: prevout_hash = x.get('prevout_hash') prevout_n = x.get('prevout_n') cursor.insertText(prevout_hash + ":%-4d " % prevout_n, ext) addr = self.wallet.get_txin_address(x) if addr is None: addr = '' cursor.insertText(addr, text_format(addr)) if x.get('value'): cursor.insertText(format_amount(x['value']), ext) cursor.insertBlock() vbox.addWidget(i_text) vbox.addWidget(QLabel(_("Outputs") + ' (%d)'%len(self.tx.outputs()))) o_text = QTextEditWithDefaultSize() o_text.setFont(QFont(MONOSPACE_FONT)) o_text.setReadOnly(True) cursor = o_text.textCursor() for o in self.tx.get_outputs_for_UI(): addr, v, name_op = o.address, o.value, o.name_op cursor.insertText(addr, text_format(addr)) if v is not None: cursor.insertText('\t', ext) cursor.insertText(format_amount(v), ext) if name_op is not None: cursor.insertText('\n', ext) cursor.insertText(format_name_op(name_op), ext) cursor.insertBlock() vbox.addWidget(o_text)
def update_io(self): inputs_header_text = _("Inputs") + ' (%d)' % len(self.tx.inputs()) if not self.finalized: selected_coins = self.main_window.get_manually_selected_coins() if selected_coins is not None: inputs_header_text += f" - " + _( "Coin selection active ({} UTXOs selected)").format( len(selected_coins)) self.inputs_header.setText(inputs_header_text) ext = QTextCharFormat() rec = QTextCharFormat() rec.setBackground(QBrush(ColorScheme.GREEN.as_color(background=True))) rec.setToolTip(_("Wallet receive address")) chg = QTextCharFormat() chg.setBackground(QBrush(ColorScheme.YELLOW.as_color(background=True))) chg.setToolTip(_("Wallet change address")) twofactor = QTextCharFormat() twofactor.setBackground( QBrush(ColorScheme.BLUE.as_color(background=True))) twofactor.setToolTip( _("TrustedCoin (2FA) fee for the next batch of transactions")) def text_format(addr): if self.wallet.is_mine(addr): return chg if self.wallet.is_change(addr) else rec elif self.wallet.is_billing_address(addr): return twofactor return ext def format_amount(amt): return self.main_window.format_amount(amt, whitespaces=True) i_text = self.inputs_textedit i_text.clear() i_text.setFont(QFont(MONOSPACE_FONT)) i_text.setReadOnly(True) cursor = i_text.textCursor() for txin in self.tx.inputs(): if txin.is_coinbase_input(): cursor.insertText('coinbase') else: prevout_hash = txin.prevout.txid.hex() prevout_n = txin.prevout.out_idx cursor.insertText(prevout_hash + ":%-4d " % prevout_n, ext) addr = self.wallet.get_txin_address(txin) if addr is None: addr = '' cursor.insertText(addr, text_format(addr)) if isinstance(txin, PartialTxInput ) and txin.value_sats_display() is not None: cursor.insertText(format_amount(txin.value_sats_display()), ext) cursor.insertBlock() self.outputs_header.setText( _("Outputs") + ' (%d)' % len(self.tx.outputs())) o_text = self.outputs_textedit o_text.clear() o_text.setFont(QFont(MONOSPACE_FONT)) o_text.setReadOnly(True) cursor = o_text.textCursor() for o in self.tx.outputs(): addr, v, name_op = o.get_ui_address_str( ), o.value_display, o.name_op cursor.insertText(addr, text_format(addr)) if v is not None: cursor.insertText('\t', ext) cursor.insertText(format_amount(v), ext) if name_op is not None: cursor.insertText('\n', ext) cursor.insertText(format_name_op(name_op), ext) cursor.insertBlock()