Skip to content

Commit

Permalink
onion_message: add callback for unsolicited onionmsg_tlv.message payl…
Browse files Browse the repository at this point in the history
…oads and display received text message on Qt client console
  • Loading branch information
accumulator committed Jun 6, 2024
1 parent 3fd4cd9 commit 9c4bec1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions electrum/gui/qt/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from electrum import util
from electrum.i18n import _

from .util import MONOSPACE_FONT, font_height
from .util import MONOSPACE_FONT, font_height, QtEventListener, qt_event_listener

# sys.ps1 and sys.ps2 are only declared if an interpreter is in interactive mode.
sys.ps1 = '>>> '
Expand Down Expand Up @@ -47,9 +47,10 @@ def on_resize(self, w):
self.setFixedWidth(w - padding)


class Console(QtWidgets.QPlainTextEdit):
class Console(QtWidgets.QPlainTextEdit, QtEventListener):
def __init__(self, parent=None):
QtWidgets.QPlainTextEdit.__init__(self, parent)
QtEventListener.__init__(self)

self.history = []
self.namespace = {}
Expand All @@ -72,6 +73,16 @@ def __init__(self, parent=None):
)
self.messageOverlay = OverlayLabel(warning_text, self)

self.register_callbacks()
self.destroyed.connect(lambda: self.on_destroy())

def on_destroy(self):
self.unregister_callbacks()

@qt_event_listener
def on_event_onion_message_textmessage(self, text):
self.showMessage(f'ONION_MESSAGE text message received: {text}')

def resizeEvent(self, e):
super().resizeEvent(e)
vertical_scrollbar_width = self.verticalScrollBar().width() * self.verticalScrollBar().isVisible()
Expand Down
4 changes: 3 additions & 1 deletion electrum/onion_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from electrum.lnonion import (get_shared_secrets_along_route2, get_bolt04_onion_key, OnionPacket, process_onion_packet,
OnionHopsDataSingle, new_onion_packet2)
from electrum.lnutil import get_ecdh
from electrum.util import OldTaskGroup, now
from electrum.util import OldTaskGroup, now, trigger_callback

if TYPE_CHECKING:
from electrum.lnworker import LNWallet
Expand Down Expand Up @@ -222,6 +222,8 @@ def on_onion_message_received_unsolicited(self, recipient_data, payload):

self.logger.info(f'onion message with text received: {text}')

trigger_callback('onion_message_textmessage', text)

def on_onion_message(self, payload):
blinding = payload.get('blinding')
if not blinding:
Expand Down

0 comments on commit 9c4bec1

Please sign in to comment.