transaction: impl tx.to_qr_data(): move logic from GUI to tx class
This commit is contained in:
@@ -271,16 +271,9 @@ class TxDialog(Factory.Popup):
|
||||
self.app.broadcast(self.tx)
|
||||
|
||||
def show_qr(self):
|
||||
from electrum.bitcoin import base_encode, bfh
|
||||
original_raw_tx = str(self.tx)
|
||||
tx = copy.deepcopy(self.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)
|
||||
self.app.qr_dialog(_("Raw Transaction"), text, text_for_clipboard=original_raw_tx)
|
||||
qr_data = self.tx.to_qr_data()
|
||||
self.app.qr_dialog(_("Raw Transaction"), qr_data, text_for_clipboard=original_raw_tx)
|
||||
|
||||
def remove_local_tx(self):
|
||||
txid = self.tx.txid()
|
||||
|
||||
@@ -288,14 +288,9 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
|
||||
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)
|
||||
qr_data = tx.to_qr_data()
|
||||
try:
|
||||
self.main_window.show_qrcode(text, 'Transaction', parent=self)
|
||||
self.main_window.show_qrcode(qr_data, 'Transaction', parent=self)
|
||||
except qrcode.exceptions.DataOverflowError:
|
||||
self.show_error(_('Failed to display QR code.') + '\n' +
|
||||
_('Transaction is too large in size.'))
|
||||
|
||||
@@ -38,6 +38,7 @@ from collections import defaultdict
|
||||
from enum import IntEnum
|
||||
import itertools
|
||||
import binascii
|
||||
import copy
|
||||
|
||||
from . import ecc, bitcoin, constants, segwit_addr, bip32
|
||||
from .bip32 import BIP32Node
|
||||
@@ -46,7 +47,8 @@ from .bitcoin import (TYPE_ADDRESS, TYPE_SCRIPT, hash_160,
|
||||
hash160_to_p2sh, hash160_to_p2pkh, hash_to_segwit_addr,
|
||||
var_int, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC, COIN,
|
||||
int_to_hex, push_script, b58_address_to_hash160,
|
||||
opcodes, add_number_to_script, base_decode, is_segwit_script_type)
|
||||
opcodes, add_number_to_script, base_decode, is_segwit_script_type,
|
||||
base_encode)
|
||||
from .crypto import sha256d
|
||||
from .logging import get_logger
|
||||
|
||||
@@ -832,6 +834,15 @@ class Transaction:
|
||||
else:
|
||||
return nVersion + txins + txouts + nLocktime
|
||||
|
||||
def to_qr_data(self) -> str:
|
||||
"""Returns tx as data to be put into a QR code. No side-effects."""
|
||||
tx = copy.deepcopy(self) # 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()
|
||||
tx_bytes = tx.serialize_as_bytes()
|
||||
return base_encode(tx_bytes, base=43)
|
||||
|
||||
def txid(self) -> Optional[str]:
|
||||
if self._cached_txid is None:
|
||||
self.deserialize()
|
||||
|
||||
Reference in New Issue
Block a user