def export_to_file(self, *, tx: Transaction = None): if tx is None: tx = self.tx if isinstance(tx, PartialTransaction): tx.finalize_psbt() if tx.is_complete(): name = 'signed_%s' % (tx.txid()[0:8]) extension = 'txn' default_filter = TRANSACTION_FILE_EXTENSION_FILTER_ONLY_COMPLETE_TX else: name = self.wallet.basename() + time.strftime('-%Y%m%d-%H%M') extension = 'psbt' default_filter = TRANSACTION_FILE_EXTENSION_FILTER_ONLY_PARTIAL_TX name = f'{name}.{extension}' fileName = self.main_window.getSaveFileName(_("Select where to save your transaction"), name, TRANSACTION_FILE_EXTENSION_FILTER_SEPARATE, default_extension=extension, default_filter=default_filter) if not fileName: return if tx.is_complete(): # network tx hex with open(fileName, "w+") as f: network_tx_hex = tx.serialize_to_network() f.write(network_tx_hex + '\n') else: # if partial: PSBT bytes assert isinstance(tx, PartialTransaction) with open(fileName, "wb+") as f: f.write(tx.serialize_as_bytes()) self.show_message(_("Transaction exported successfully")) self.saved = True
def show_qr(self, *, tx: Transaction = None): if tx is None: tx = self.tx tx = copy.deepcopy(tx) # make copy as we mutate tx if isinstance(tx, PartialTransaction): # this makes QR codes a lot smaller (or just possible in the first place!) tx.convert_all_utxos_to_witness_utxos() text = tx.serialize_as_bytes() text = base_encode(text, base=43) try: self.main_window.show_qrcode(text, 'Transaction', parent=self) except qrcode.exceptions.DataOverflowError: self.show_error(_('Failed to display QR code.') + '\n' + _('Transaction is too large in size.')) except Exception as e: self.show_error(_('Failed to display QR code.') + '\n' + repr(e))
def export_to_file(self, *, tx: Transaction = None): if tx is None: tx = self.tx if isinstance(tx, PartialTransaction): tx.finalize_psbt() txid = tx.txid() suffix = txid[0:8] if txid is not None else time.strftime( '%Y%m%d-%H%M') if tx.is_complete(): extension = 'txn' default_filter = TRANSACTION_FILE_EXTENSION_FILTER_ONLY_COMPLETE_TX else: extension = 'psbt' default_filter = TRANSACTION_FILE_EXTENSION_FILTER_ONLY_PARTIAL_TX name = f'{self.wallet.basename()}-{suffix}.{extension}' fileName = getSaveFileName( parent=self, title=_("Select where to save your transaction"), filename=name, filter=TRANSACTION_FILE_EXTENSION_FILTER_SEPARATE, default_extension=extension, default_filter=default_filter, config=self.config, ) if not fileName: return if tx.is_complete(): # network tx hex with open(fileName, "w+") as f: network_tx_hex = tx.serialize_to_network() f.write(network_tx_hex + '\n') else: # if partial: PSBT bytes assert isinstance(tx, PartialTransaction) with open(fileName, "wb+") as f: f.write(tx.serialize_as_bytes()) self.show_message(_("Transaction exported successfully")) self.saved = True