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