Browse Source

kivy: fix paying onchain invoices

when pasting a new invoice and paying it
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/gui/kivy/uix/screens.py", line 358, in _do_send_onchain
    tx = self.app.wallet.make_unsigned_transaction(coins, outputs, None)
  File "/home/user/wspace/electrum/electrum/wallet.py", line 849, in make_unsigned_transaction
    if o.type == TYPE_ADDRESS:
AttributeError: 'tuple' object has no attribute 'type'

when loading back a saved invoice
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/gui/kivy/uix/screens.py", line 358, in _do_send_onchain
    tx = self.app.wallet.make_unsigned_transaction(coins, outputs, None)
  File "/home/user/wspace/electrum/electrum/wallet.py", line 849, in make_unsigned_transaction
    if o.type == TYPE_ADDRESS:
AttributeError: 'list' object has no attribute 'type'
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 5 years ago
parent
commit
c7346c1eb8
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 7
      electrum/gui/kivy/uix/dialogs/invoice_dialog.py
  2. 12
      electrum/gui/kivy/uix/screens.py
  3. 2
      electrum/paymentrequest.py
  4. 6
      electrum/wallet.py

7
electrum/gui/kivy/uix/dialogs/invoice_dialog.py

@ -1,3 +1,5 @@
from typing import TYPE_CHECKING
from kivy.factory import Factory from kivy.factory import Factory
from kivy.lang import Builder from kivy.lang import Builder
from kivy.core.clipboard import Clipboard from kivy.core.clipboard import Clipboard
@ -7,6 +9,9 @@ from kivy.clock import Clock
from electrum.gui.kivy.i18n import _ from electrum.gui.kivy.i18n import _
from electrum.util import pr_tooltips from electrum.util import pr_tooltips
if TYPE_CHECKING:
from electrum.gui.kivy.main_window import ElectrumWindow
Builder.load_string(''' Builder.load_string('''
<InvoiceDialog@Popup> <InvoiceDialog@Popup>
@ -58,7 +63,7 @@ class InvoiceDialog(Factory.Popup):
def __init__(self, title, data, key): def __init__(self, title, data, key):
Factory.Popup.__init__(self) Factory.Popup.__init__(self)
self.app = App.get_running_app() self.app = App.get_running_app() # type: ElectrumWindow
self.title = title self.title = title
self.data = data self.data = data
self.key = key self.key = key

12
electrum/gui/kivy/uix/screens.py

@ -4,6 +4,7 @@ from decimal import Decimal
import re import re
import threading import threading
import traceback, sys import traceback, sys
from typing import TYPE_CHECKING, List
from kivy.app import App from kivy.app import App
from kivy.cache import Cache from kivy.cache import Cache
@ -39,6 +40,9 @@ from .dialogs.lightning_open_channel import LightningOpenChannelDialog
from electrum.gui.kivy.i18n import _ from electrum.gui.kivy.i18n import _
if TYPE_CHECKING:
from electrum.gui.kivy.main_window import ElectrumWindow
class HistoryRecycleView(RecycleView): class HistoryRecycleView(RecycleView):
pass pass
@ -54,7 +58,7 @@ class CScreen(Factory.Screen):
action_view = ObjectProperty(None) action_view = ObjectProperty(None)
loaded = False loaded = False
kvname = None kvname = None
app = App.get_running_app() app = App.get_running_app() # type: ElectrumWindow
def _change_action_view(self): def _change_action_view(self):
app = App.get_running_app() app = App.get_running_app()
@ -310,7 +314,7 @@ class SendScreen(CScreen):
if not bitcoin.is_address(address): if not bitcoin.is_address(address):
self.app.show_error(_('Invalid Bitcoin Address') + ':\n' + address) self.app.show_error(_('Invalid Bitcoin Address') + ':\n' + address)
return return
outputs = [(TYPE_ADDRESS, address, amount)] outputs = [TxOutput(TYPE_ADDRESS, address, amount)]
return self.app.wallet.create_invoice(outputs, message, self.payment_request, self.parsed_URI) return self.app.wallet.create_invoice(outputs, message, self.payment_request, self.parsed_URI)
def do_save(self): def do_save(self):
@ -336,8 +340,8 @@ class SendScreen(CScreen):
return return
elif invoice['type'] == PR_TYPE_ONCHAIN: elif invoice['type'] == PR_TYPE_ONCHAIN:
message = invoice['message'] message = invoice['message']
outputs = invoice['outputs'] outputs = invoice['outputs'] # type: List[TxOutput]
amount = sum(map(lambda x:x[2], outputs)) amount = sum(map(lambda x: x.value, outputs))
do_pay = lambda rbf: self._do_send_onchain(amount, message, outputs, rbf) do_pay = lambda rbf: self._do_send_onchain(amount, message, outputs, rbf)
if self.app.electrum_config.get('use_rbf'): if self.app.electrum_config.get('use_rbf'):
d = Question(_('Should this transaction be replaceable?'), do_pay) d = Question(_('Should this transaction be replaceable?'), do_pay)

2
electrum/paymentrequest.py

@ -248,7 +248,7 @@ class PaymentRequest:
return self.details.expires return self.details.expires
def get_amount(self): def get_amount(self):
return sum(map(lambda x:x[2], self.outputs)) return sum(map(lambda x:x.value, self.outputs))
def get_address(self): def get_address(self):
o = self.outputs[0] o = self.outputs[0]

6
electrum/wallet.py

@ -228,6 +228,12 @@ class Abstract_Wallet(AddressSynchronizer):
self.receive_requests = storage.get('payment_requests', {}) self.receive_requests = storage.get('payment_requests', {})
self.invoices = storage.get('invoices', {}) self.invoices = storage.get('invoices', {})
# convert invoices
for invoice_key, invoice in self.invoices.items():
if invoice['type'] == PR_TYPE_ONCHAIN:
outputs = [TxOutput(*output) for output in invoice.get('outputs')]
invoice['outputs'] = outputs
self.calc_unused_change_addresses() self.calc_unused_change_addresses()
# save wallet type the first time # save wallet type the first time

Loading…
Cancel
Save