Browse Source

initial working channel open flow

patch-4
Sander van Grieken 3 years ago
parent
commit
dc69391204
  1. 29
      electrum/gui/qml/components/OpenChannel.qml
  2. 73
      electrum/gui/qml/qechannelopener.py

29
electrum/gui/qml/components/OpenChannel.qml

@ -136,6 +136,16 @@ Pane {
} }
} }
Component {
id: confirmOpenChannelDialog
ConfirmTxDialog {
title: qsTr('Confirm Open Channel')
amountLabelText: qsTr('Channel capacity')
sendButtonText: qsTr('Open Channel')
finalizer: channelopener.finalizer
}
}
ChannelOpener { ChannelOpener {
id: channelopener id: channelopener
@ -147,12 +157,29 @@ Pane {
} }
} }
onConflictingBackup: { onConflictingBackup: {
var dialog = app.messageDialog.createObject(root, { 'text': message }) var dialog = app.messageDialog.createObject(root, { 'text': message, 'yesno': true })
dialog.open() dialog.open()
dialog.yesClicked.connect(function() { dialog.yesClicked.connect(function() {
channelopener.open_channel(true) channelopener.open_channel(true)
}) })
} }
onFinalizerChanged: {
var dialog = confirmOpenChannelDialog.createObject(root, {
'satoshis': channelopener.amount
})
dialog.open()
}
onChannelOpenError: {
var dialog = app.messageDialog.createObject(root, { 'text': message })
dialog.open()
}
onChannelOpenSuccess: {
var message = 'success!'
if (!has_backup)
message = message = ' (but no backup. TODO: show QR)'
var dialog = app.messageDialog.createObject(root, { 'text': message })
dialog.open()
}
} }
} }

73
electrum/gui/qml/qechannelopener.py

@ -1,13 +1,14 @@
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from electrum.i18n import _
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.util import format_time from electrum.lnutil import extract_nodeid, ConnStringFormatError, LNPeerAddr, ln_dummy_address
from electrum.lnutil import extract_nodeid, ConnStringFormatError, LNPeerAddr
from electrum.lnworker import hardcoded_trampoline_nodes from electrum.lnworker import hardcoded_trampoline_nodes
from electrum.gui import messages from electrum.gui import messages
from .qewallet import QEWallet from .qewallet import QEWallet
from .qetypes import QEAmount from .qetypes import QEAmount
from .qetxfinalizer import QETxFinalizer
class QEChannelOpener(QObject): class QEChannelOpener(QObject):
def __init__(self, parent=None): def __init__(self, parent=None):
@ -23,6 +24,8 @@ class QEChannelOpener(QObject):
validationError = pyqtSignal([str,str], arguments=['code','message']) validationError = pyqtSignal([str,str], arguments=['code','message'])
conflictingBackup = pyqtSignal([str], arguments=['message']) conflictingBackup = pyqtSignal([str], arguments=['message'])
channelOpenError = pyqtSignal([str], arguments=['message'])
channelOpenSuccess = pyqtSignal([bool], arguments=['has_backup'])
dataChanged = pyqtSignal() # generic notify signal dataChanged = pyqtSignal() # generic notify signal
@ -67,10 +70,10 @@ class QEChannelOpener(QObject):
def valid(self): def valid(self):
return self._valid return self._valid
openTxChanged = pyqtSignal() finalizerChanged = pyqtSignal()
@pyqtProperty(bool, notify=openTxChanged) @pyqtProperty(QETxFinalizer, notify=finalizerChanged)
def openTx(self): def finalizer(self):
return self._opentx return self._finalizer
@pyqtProperty(list, notify=dataChanged) @pyqtProperty(list, notify=dataChanged)
def trampolineNodeNames(self): def trampolineNodeNames(self):
@ -118,45 +121,45 @@ class QEChannelOpener(QObject):
self._logger.debug('Connect String: %s' % str(self._peer)) self._logger.debug('Connect String: %s' % str(self._peer))
amount = '!' if self._amount.isMax else self._amount.satsInt
lnworker = self._wallet.wallet.lnworker lnworker = self._wallet.wallet.lnworker
if lnworker.has_conflicting_backup_with(self._peer.pubkey) and not confirm_backup_conflict: if lnworker.has_conflicting_backup_with(self._peer.pubkey) and not confirm_backup_conflict:
self.conflictingBackup.emit(messages.MGS_CONFLICTING_BACKUP_INSTANCE) self.conflictingBackup.emit(messages.MGS_CONFLICTING_BACKUP_INSTANCE)
return return
amount = '!' if self._amount.isMax else self._amount.satsInt
coins = self._wallet.wallet.get_spendable_coins(None, nonlocal_only=True) coins = self._wallet.wallet.get_spendable_coins(None, nonlocal_only=True)
#node_id, rest = extract_nodeid(conn_str)
make_tx = lambda rbf: lnworker.mktx_for_open_channel( mktx = lambda: lnworker.mktx_for_open_channel(
coins=coins, coins=coins,
funding_sat=amount, funding_sat=amount,
node_id=self._peer.pubkey, node_id=self._peer.pubkey,
fee_est=None) fee_est=None)
#on_pay = lambda tx: self.app.protected('Create a new channel?', self.do_open_channel, (tx, conn_str))
#d = ConfirmTxDialog( acpt = lambda tx: self.do_open_channel(tx, str(self._peer), None)
#self.app,
#amount = amount, self._finalizer = QETxFinalizer(self, make_tx=mktx, accept=acpt)
#make_tx=make_tx, self._finalizer.wallet = self._wallet
#on_pay=on_pay, self.finalizerChanged.emit()
#show_final=False)
#d.open() def do_open_channel(self, funding_tx, conn_str, password):
# read funding_sat from tx; converts '!' to int value
#def do_open_channel(self, funding_tx, conn_str, password): funding_sat = funding_tx.output_value_for_address(ln_dummy_address())
## read funding_sat from tx; converts '!' to int value lnworker = self._wallet.wallet.lnworker
#funding_sat = funding_tx.output_value_for_address(ln_dummy_address()) try:
#lnworker = self.app.wallet.lnworker chan, funding_tx = lnworker.open_channel(
#try: connect_str=conn_str,
#chan, funding_tx = lnworker.open_channel( funding_tx=funding_tx,
#connect_str=conn_str, funding_sat=funding_sat,
#funding_tx=funding_tx, push_amt_sat=0,
#funding_sat=funding_sat, password=password)
#push_amt_sat=0, except Exception as e:
#password=password) self._logger.exception("Problem opening channel")
#except Exception as e: self.channelOpenError.emit(_('Problem opening channel: ') + '\n' + repr(e))
#self.app.logger.exception("Problem opening channel") return
#self.app.show_error(_('Problem opening channel: ') + '\n' + repr(e))
#return self.channelOpenSuccess.emit(chan.has_onchain_backup())
## TODO: it would be nice to show this before broadcasting
# TODO: it would be nice to show this before broadcasting
#if chan.has_onchain_backup(): #if chan.has_onchain_backup():
#self.maybe_show_funding_tx(chan, funding_tx) #self.maybe_show_funding_tx(chan, funding_tx)
#else: #else:

Loading…
Cancel
Save