Browse Source

enable generating lightning request.

currently very simple heuristics: if requested amount < lightningCanReceive
then create a lightning request, else onchain
patch-4
Sander van Grieken 3 years ago
parent
commit
098b384348
  1. 11
      electrum/gui/qml/components/Receive.qml
  2. 2
      electrum/gui/qml/components/RequestDialog.qml
  3. 3
      electrum/gui/qml/qeinvoicelistmodel.py
  4. 11
      electrum/gui/qml/qewallet.py

11
electrum/gui/qml/components/Receive.qml

@ -199,8 +199,15 @@ Pane {
}
function createRequest(ignoreGaplimit = false) {
var a = Config.unitsToSats(amount.text)
Daemon.currentWallet.create_request(a, message.text, expires.currentValue, false, ignoreGaplimit)
var qamt = Config.unitsToSats(amount.text)
console.log('about to create req for ' + qamt.satsInt + ' sats')
if (qamt.satsInt > Daemon.currentWallet.lightningCanReceive) {
console.log('Creating OnChain request')
Daemon.currentWallet.create_request(qamt, message.text, expires.currentValue, false, ignoreGaplimit)
} else {
console.log('Creating Lightning request')
Daemon.currentWallet.create_request(qamt, message.text, expires.currentValue, true)
}
}
Connections {

2
electrum/gui/qml/components/RequestDialog.qml

@ -209,6 +209,8 @@ Dialog {
if (!modelItem.is_lightning) {
_bip21uri = bitcoin.create_bip21_uri(modelItem.address, modelItem.amount, modelItem.message, modelItem.timestamp, modelItem.expiration - modelItem.timestamp)
qr.source = 'image://qrgen/' + _bip21uri
} else {
qr.source = 'image://qrgen/' + modelItem.lightning_invoice
}
}

3
electrum/gui/qml/qeinvoicelistmodel.py

@ -19,7 +19,8 @@ class QEAbstractInvoiceListModel(QAbstractListModel):
# define listmodel rolemap
_ROLE_NAMES=('key', 'is_lightning', 'timestamp', 'date', 'message', 'amount',
'status', 'status_str', 'address', 'expiration', 'type', 'onchain_fallback')
'status', 'status_str', 'address', 'expiration', 'type', 'onchain_fallback',
'lightning_invoice')
_ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES))
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS))

11
electrum/gui/qml/qewallet.py

@ -415,8 +415,8 @@ class QEWallet(QObject):
## TODO: check this flow. Only if alias is defined in config. OpenAlias?
#pass
##self.sign_payment_request(addr)
self._requestModel.add_invoice(self.wallet.get_request(req_key))
return addr
return req_key, addr
@pyqtSlot(QEAmount, 'QString', int)
@pyqtSlot(QEAmount, 'QString', int, bool)
@ -428,9 +428,11 @@ class QEWallet(QObject):
self.requestCreateError.emit('fatal',_("You need to open a Lightning channel first."))
return
# TODO maybe show a warning if amount exceeds lnworker.num_sats_can_receive (as in kivy)
key = self.wallet.lnworker.add_request(amount.satsInt, message, expiration)
# TODO fallback address robustness
addr = self.wallet.get_unused_address()
key = self.wallet.create_request(amount.satsInt, message, expiration, addr, True)
else:
key = self.create_bitcoin_request(amount.satsInt, message, expiration, ignore_gap)
key, addr = self.create_bitcoin_request(amount.satsInt, message, expiration, ignore_gap)
if not key:
return
self.addressModel.init_model()
@ -439,6 +441,7 @@ class QEWallet(QObject):
return
assert key is not None
self._requestModel.add_invoice(self.wallet.get_request(key))
self.requestCreateSuccess.emit()
@pyqtSlot('QString')

Loading…
Cancel
Save