enable generating lightning request.
currently very simple heuristics: if requested amount < lightningCanReceive then create a lightning request, else onchain
This commit is contained in:
@@ -199,8 +199,15 @@ Pane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createRequest(ignoreGaplimit = false) {
|
function createRequest(ignoreGaplimit = false) {
|
||||||
var a = Config.unitsToSats(amount.text)
|
var qamt = Config.unitsToSats(amount.text)
|
||||||
Daemon.currentWallet.create_request(a, message.text, expires.currentValue, false, ignoreGaplimit)
|
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 {
|
Connections {
|
||||||
|
|||||||
@@ -209,6 +209,8 @@ Dialog {
|
|||||||
if (!modelItem.is_lightning) {
|
if (!modelItem.is_lightning) {
|
||||||
_bip21uri = bitcoin.create_bip21_uri(modelItem.address, modelItem.amount, modelItem.message, modelItem.timestamp, modelItem.expiration - modelItem.timestamp)
|
_bip21uri = bitcoin.create_bip21_uri(modelItem.address, modelItem.amount, modelItem.message, modelItem.timestamp, modelItem.expiration - modelItem.timestamp)
|
||||||
qr.source = 'image://qrgen/' + _bip21uri
|
qr.source = 'image://qrgen/' + _bip21uri
|
||||||
|
} else {
|
||||||
|
qr.source = 'image://qrgen/' + modelItem.lightning_invoice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ class QEAbstractInvoiceListModel(QAbstractListModel):
|
|||||||
|
|
||||||
# define listmodel rolemap
|
# define listmodel rolemap
|
||||||
_ROLE_NAMES=('key', 'is_lightning', 'timestamp', 'date', 'message', 'amount',
|
_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_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES))
|
||||||
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
|
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
|
||||||
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS))
|
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS))
|
||||||
|
|||||||
@@ -415,8 +415,8 @@ class QEWallet(QObject):
|
|||||||
## TODO: check this flow. Only if alias is defined in config. OpenAlias?
|
## TODO: check this flow. Only if alias is defined in config. OpenAlias?
|
||||||
#pass
|
#pass
|
||||||
##self.sign_payment_request(addr)
|
##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)
|
||||||
@pyqtSlot(QEAmount, 'QString', int, bool)
|
@pyqtSlot(QEAmount, 'QString', int, bool)
|
||||||
@@ -428,9 +428,11 @@ class QEWallet(QObject):
|
|||||||
self.requestCreateError.emit('fatal',_("You need to open a Lightning channel first."))
|
self.requestCreateError.emit('fatal',_("You need to open a Lightning channel first."))
|
||||||
return
|
return
|
||||||
# TODO maybe show a warning if amount exceeds lnworker.num_sats_can_receive (as in kivy)
|
# 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:
|
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:
|
if not key:
|
||||||
return
|
return
|
||||||
self.addressModel.init_model()
|
self.addressModel.init_model()
|
||||||
@@ -439,6 +441,7 @@ class QEWallet(QObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
assert key is not None
|
assert key is not None
|
||||||
|
self._requestModel.add_invoice(self.wallet.get_request(key))
|
||||||
self.requestCreateSuccess.emit()
|
self.requestCreateSuccess.emit()
|
||||||
|
|
||||||
@pyqtSlot('QString')
|
@pyqtSlot('QString')
|
||||||
|
|||||||
Reference in New Issue
Block a user