mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-04 21:05:11 +00:00
transaction: don't convert p2pk to p2pkh address when displaying
also closes #4742
This commit is contained in:
parent
ab1ec57429
commit
4d43d12abf
7 changed files with 26 additions and 27 deletions
|
@ -681,7 +681,7 @@ class AddressSynchronizer(PrintError):
|
|||
delta += v
|
||||
return delta
|
||||
|
||||
def get_wallet_delta(self, tx):
|
||||
def get_wallet_delta(self, tx: Transaction):
|
||||
""" effect of tx on wallet """
|
||||
is_relevant = False # "related to wallet?"
|
||||
is_mine = False
|
||||
|
@ -708,10 +708,10 @@ class AddressSynchronizer(PrintError):
|
|||
is_partial = True
|
||||
if not is_mine:
|
||||
is_partial = False
|
||||
for addr, value in tx.get_outputs():
|
||||
v_out += value
|
||||
if self.is_mine(addr):
|
||||
v_out_mine += value
|
||||
for o in tx.outputs():
|
||||
v_out += o.value
|
||||
if self.is_mine(o.address):
|
||||
v_out_mine += o.value
|
||||
is_relevant = True
|
||||
if is_pruned:
|
||||
# some inputs are mine:
|
||||
|
|
|
@ -130,7 +130,7 @@ class TxDialog(Factory.Popup):
|
|||
self.amount_str = format_amount(-amount)
|
||||
self.fee_str = format_amount(fee) if fee is not None else _('unknown')
|
||||
self.can_sign = self.wallet.can_sign(self.tx)
|
||||
self.ids.output_list.update(self.tx.outputs())
|
||||
self.ids.output_list.update(self.tx.get_outputs_for_UI())
|
||||
|
||||
def do_rbf(self):
|
||||
from .bump_fee_dialog import BumpFeeDialog
|
||||
|
|
|
@ -319,7 +319,8 @@ class TxDialog(QDialog, MessageBoxMixin):
|
|||
o_text.setFont(QFont(MONOSPACE_FONT))
|
||||
o_text.setReadOnly(True)
|
||||
cursor = o_text.textCursor()
|
||||
for addr, v in self.tx.get_outputs():
|
||||
for o in self.tx.get_outputs_for_UI():
|
||||
addr, v = o.address, o.value
|
||||
cursor.insertText(addr, text_format(addr))
|
||||
if v is not None:
|
||||
cursor.insertText('\t', ext)
|
||||
|
|
|
@ -34,7 +34,6 @@ from electrum.plugin import BasePlugin, hook
|
|||
from electrum.i18n import _
|
||||
|
||||
|
||||
|
||||
class Plugin(BasePlugin):
|
||||
|
||||
button_label = _("Verify GA instant")
|
||||
|
@ -49,9 +48,9 @@ class Plugin(BasePlugin):
|
|||
def get_my_addr(self, d):
|
||||
"""Returns the address for given tx which can be used to request
|
||||
instant confirmation verification from GreenAddress"""
|
||||
for addr, _ in d.tx.get_outputs():
|
||||
if d.wallet.is_mine(addr):
|
||||
return addr
|
||||
for o in d.tx.outputs():
|
||||
if d.wallet.is_mine(o.address):
|
||||
return o.address
|
||||
return None
|
||||
|
||||
@hook
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from electrum import transaction
|
||||
from electrum.transaction import TxOutputForUI
|
||||
from electrum.bitcoin import TYPE_ADDRESS
|
||||
from electrum.keystore import xpubkey_to_address
|
||||
from electrum.util import bh2u, bfh
|
||||
|
@ -86,8 +87,7 @@ class TestTransaction(SequentialTestCase):
|
|||
self.assertEqual(tx.deserialize(), None)
|
||||
|
||||
self.assertEqual(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
|
||||
self.assertEqual(tx.get_outputs(), [('14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs', 1000000)])
|
||||
self.assertEqual(tx.get_output_addresses(), ['14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs'])
|
||||
self.assertEqual(tx.get_outputs_for_UI(), [TxOutputForUI('14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs', 1000000)])
|
||||
|
||||
self.assertTrue(tx.has_address('14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs'))
|
||||
self.assertTrue(tx.has_address('1446oU3z268EeFgfcwJv6X2VBXHfoYxfuD'))
|
||||
|
|
|
@ -68,6 +68,9 @@ TxOutput = NamedTuple("TxOutput", [('type', int), ('address', str), ('value', Un
|
|||
# ^ value is str when the output is set to max: '!'
|
||||
|
||||
|
||||
TxOutputForUI = NamedTuple("TxOutputForUI", [('address', str), ('value', int)])
|
||||
|
||||
|
||||
TxOutputHwInfo = NamedTuple("TxOutputHwInfo", [('address_index', Tuple),
|
||||
('sorted_xpubs', Iterable[str]),
|
||||
('num_sig', Optional[int]),
|
||||
|
@ -671,7 +674,7 @@ class Transaction:
|
|||
else:
|
||||
raise Exception("cannot initialize transaction", raw)
|
||||
self._inputs = None
|
||||
self._outputs = None
|
||||
self._outputs = None # type: List[TxOutput]
|
||||
self.locktime = 0
|
||||
self.version = 1
|
||||
# by default we assume this is a partial txn;
|
||||
|
@ -689,7 +692,7 @@ class Transaction:
|
|||
self.deserialize()
|
||||
return self._inputs
|
||||
|
||||
def outputs(self):
|
||||
def outputs(self) -> List[TxOutput]:
|
||||
if self._outputs is None:
|
||||
self.deserialize()
|
||||
return self._outputs
|
||||
|
@ -1221,26 +1224,21 @@ class Transaction:
|
|||
sig = bh2u(sig) + '01'
|
||||
return sig
|
||||
|
||||
def get_outputs(self):
|
||||
"""convert pubkeys to addresses"""
|
||||
def get_outputs_for_UI(self) -> Sequence[TxOutputForUI]:
|
||||
outputs = []
|
||||
for o in self.outputs():
|
||||
if o.type == TYPE_ADDRESS:
|
||||
addr = o.address
|
||||
elif o.type == TYPE_PUBKEY:
|
||||
# TODO do we really want this conversion? it's not really that address after all
|
||||
addr = bitcoin.public_key_to_p2pkh(bfh(o.address))
|
||||
addr = 'PUBKEY ' + o.address
|
||||
else:
|
||||
addr = 'SCRIPT ' + o.address
|
||||
outputs.append((addr, o.value)) # consider using yield (addr, v)
|
||||
outputs.append(TxOutputForUI(addr, o.value)) # consider using yield
|
||||
return outputs
|
||||
|
||||
def get_output_addresses(self):
|
||||
return [addr for addr, val in self.get_outputs()]
|
||||
|
||||
|
||||
def has_address(self, addr):
|
||||
return (addr in self.get_output_addresses()) or (addr in (tx.get("address") for tx in self.inputs()))
|
||||
def has_address(self, addr: str) -> bool:
|
||||
return (addr in (o.address for o in self.outputs())) \
|
||||
or (addr in (txin.get("address") for txin in self.inputs()))
|
||||
|
||||
def as_dict(self):
|
||||
if self.raw is None:
|
||||
|
|
|
@ -412,7 +412,8 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||
if show_addresses:
|
||||
tx = self.transactions.get(tx_hash)
|
||||
item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs()))
|
||||
item['outputs'] = list(map(lambda x:{'address':x[0], 'value':Satoshis(x[1])}, tx.get_outputs()))
|
||||
item['outputs'] = list(map(lambda x:{'address':x.address, 'value':Satoshis(x.value)},
|
||||
tx.get_outputs_for_UI()))
|
||||
# value may be None if wallet is not fully synchronized
|
||||
if value is None:
|
||||
continue
|
||||
|
|
Loading…
Add table
Reference in a new issue