def _on_direct_split(self) -> None: assert self._direct_splitting_enabled, "direct splitting not enabled" assert not self._faucet_splitting, "already faucet splitting" self._direct_splitting = True self._direct_button.setText(_("Splitting") +"...") self._direct_button.setEnabled(False) unused_key = self._account.get_fresh_keys(CHANGE_SUBPATH, 1)[0] script = self._account.get_script_for_id(unused_key.keyinstance_id) coins = self._account.get_utxos(exclude_frozen=True, mature=True) outputs = [ XTxOutput(all, script) ] outputs.extend(self._account.create_extra_outputs(coins, outputs, force=True)) try: tx = self._account.make_unsigned_transaction(coins, outputs, self._main_window.config) except NotEnoughFunds: self._cleanup_tx_final() self._main_window.show_message(_("Insufficient funds")) return if self._account.type() == AccountType.MULTISIG: self._cleanup_tx_final() tx.context.description = f"{TX_DESC_PREFIX} (multisig)" self._main_window.show_transaction(self._account, tx) return amount = tx.output_value() fee = tx.get_fee() fields = [ (_("Amount to be sent"), QLabel(app_state.format_amount_and_units(amount))), (_("Mining fee"), QLabel(app_state.format_amount_and_units(fee))), ] msg = "\n".join([ "", _("Enter your password to proceed"), ]) password = self._main_window.password_dialog(msg, fields=fields) def sign_done(success: bool) -> None: if success: if not tx.is_complete(): dialog = self._main_window.show_transaction(self._account, tx) dialog.exec() else: extra_text = _("Your split coins") tx.context.description = f"{TX_DESC_PREFIX}: {extra_text}" self._main_window.broadcast_transaction(self._account, tx, success_text=_("Your coins have now been split.")) self._cleanup_tx_final() self._main_window.sign_tx_with_password(tx, sign_done, password)
def _sign_tx_and_broadcast_if_complete(self, amount: int, tx: Transaction, tx_desc: str) -> None: # confirmation dialog fee = tx.get_fee() msg = [] if fee < round(tx.estimated_size() * 0.5): msg.append( _('Warning') + ': ' + _('The fee is less than 500 sats/kb. It may take a very long time to confirm.' )) msg.append("") msg.append(_("Enter your password to proceed")) password = self._main_window.password_dialog( '\n'.join(msg), fields=[ (_("Amount to send"), QLabel(app_state.format_amount_and_units(amount))), (_("Mining fee"), QLabel(app_state.format_amount_and_units(fee))), ]) if not password: return def sign_done(success: bool) -> None: if success: if not tx.is_complete(): self._main_window.show_transaction( self._account, tx, pr=self._payment_request) self.clear() return self._main_window.broadcast_transaction( self._account, tx, tx_desc) tx_context: Optional[TransactionContext] = None if self._payment_request is not None: tx_context = TransactionContext( invoice_id=self._payment_request.get_id()) self._main_window.sign_tx_with_password(tx, sign_done, password, tx_context=tx_context)
def _ask_send_split_transaction(self) -> None: coins = self._account.get_utxos(exclude_frozen=True, mature=True) # Verify that our dust receiving address is in the available UTXOs, if it isn't, the # process has failed in some unexpected way. for coin in coins: if coin.script_pubkey == self.receiving_script_template.to_script(): break else: self._main_window.show_error(_("Error accessing dust coins for correct splitting.")) self._cleanup_tx_final() return unused_key = self._account.get_fresh_keys(RECEIVING_SUBPATH, 1)[0] script = self._account.get_script_for_id(unused_key.keyinstance_id) outputs = [ TxOutput(all, script) ] tx = self._account.make_unsigned_transaction(coins, outputs, self._main_window.config) amount = tx.output_value() fee = tx.get_fee() msg = [ _("Amount to be sent") + ": " + app_state.format_amount_and_units(amount), _("Mining fee") + ": " + app_state.format_amount_and_units(fee), ] msg.append("") msg.append(_("Enter your password to proceed")) password = self._main_window.password_dialog('\n'.join(msg)) def sign_done(success) -> None: if success: if not tx.is_complete(): dialog = self._main_window.show_transaction(self._account, tx) dialog.exec() else: extra_text = _("Your split coins") self._main_window.broadcast_transaction(self._account, tx, f"{TX_DESC_PREFIX}: {extra_text}", success_text=_("Your coins have now been split.")) self._cleanup_tx_final() self._main_window.sign_tx_with_password(tx, sign_done, password)