From c47fc8ddeac320c8ee49d29e16dd10192750310d Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 22 Jun 2026 12:46:41 +0200 Subject: [PATCH] Add info box with peer id --- src/BlockchainBackend.cpp | 11 ++++++ src/BlockchainBackend.h | 1 + src/BlockchainBackend.rep | 1 + src/qml/BlockchainView.qml | 34 ++++++++++++++++++- src/qml/views/NodeInfoView.qml | 62 ++++++++++++++++++++++++++++++++++ src/qml/views/qmldir | 1 + 6 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/qml/views/NodeInfoView.qml diff --git a/src/BlockchainBackend.cpp b/src/BlockchainBackend.cpp index 31c2d96..2ca7a91 100644 --- a/src/BlockchainBackend.cpp +++ b/src/BlockchainBackend.cpp @@ -219,6 +219,17 @@ QVariantMap BlockchainBackend::getCryptarchiaInfo() BLOCKCHAIN_MODULE_NAME, QStringLiteral("get_cryptarchia_info")))); } +QVariantMap BlockchainBackend::getPeerId() +{ + if (!m_blockchainClient) + return result::toVariantMap(result::err(QStringLiteral("Module not initialized."))); + + // Derived from the node key in the user config; available without the node + // running. + return result::toVariantMap(result::toLogosResult(m_blockchainClient->invokeRemoteMethod( + BLOCKCHAIN_MODULE_NAME, QStringLiteral("get_peer_id"), userConfig()))); +} + void BlockchainBackend::startBlockchain() { if (!m_blockchainClient) { diff --git a/src/BlockchainBackend.h b/src/BlockchainBackend.h index 52d8472..5a52fe1 100644 --- a/src/BlockchainBackend.h +++ b/src/BlockchainBackend.h @@ -46,6 +46,7 @@ public slots: QVariantMap transferFunds(QString fromKeyHex, QString toKeyHex, QString amountStr) override; QVariantMap claimLeaderRewards() override; QVariantMap getCryptarchiaInfo() override; + QVariantMap getPeerId() override; QVariantMap generateConfig(QString outputPath, QStringList initialPeers, int netPort, int blendPort, QString httpAddr, QString externalAddress, bool noPublicIpCheck, int deploymentMode, diff --git a/src/BlockchainBackend.rep b/src/BlockchainBackend.rep index 983e2a1..4b280bc 100644 --- a/src/BlockchainBackend.rep +++ b/src/BlockchainBackend.rep @@ -16,6 +16,7 @@ class BlockchainBackend SLOT(QVariantMap transferFunds(QString fromKeyHex, QString toKeyHex, QString amountStr)) SLOT(QVariantMap claimLeaderRewards()) SLOT(QVariantMap getCryptarchiaInfo()) + SLOT(QVariantMap getPeerId()) SLOT(QVariantMap generateConfig(QString outputPath, QStringList initialPeers, int netPort, int blendPort, QString httpAddr, QString externalAddress, bool noPublicIpCheck, int deploymentMode, QString deploymentConfigPath, QString statePath)) SLOT(QVariantMap getNotes(QString walletAddressHex, QString optionalTipHex)) SLOT(QVariantMap channelDepositWithNotes(QString channelIdHex, QStringList inputNoteIdHexes, QString metadataBase58, QString changePublicKeyHex, QStringList fundingPublicKeyHexes, QString maxTxFee, QString optionalTipHex)) diff --git a/src/qml/BlockchainView.qml b/src/qml/BlockchainView.qml index 0cf7213..151e069 100644 --- a/src/qml/BlockchainView.qml +++ b/src/qml/BlockchainView.qml @@ -25,8 +25,10 @@ Rectangle { Connections { target: logos function onViewModuleReadyChanged(moduleName, isReady) { - if (moduleName === "blockchain_ui") + if (moduleName === "blockchain_ui") { root.ready = isReady && root.backend !== null + if (root.ready) root.refreshPeerId() + } } } @@ -34,6 +36,7 @@ Rectangle { // Cover the case where the replica is already Valid by the time // we attach the Connections handler. root.ready = root.backend !== null && logos.isViewModuleReady("blockchain_ui") + if (root.ready) root.refreshPeerId() } // Graceful shutdown: if the window is closed while the node is running, @@ -93,6 +96,29 @@ Rectangle { visible: false } + // Self libp2p peer id, derived from the selected user config (no running + // node required). Refreshed when ready and whenever the config changes. + property string peerId: "" + + function refreshPeerId() { + if (!root.backend || !root.backend.userConfig) { + root.peerId = "" + return + } + logos.watch( + root.backend.getPeerId(), + function(result) { root.peerId = result.success ? result.value : "" }, + function(error) { root.peerId = "" } + ) + } + + Connections { + target: root.backend + enabled: root.backend !== null + ignoreUnknownSignals: true + function onUserConfigChanged() { root.refreshPeerId() } + } + // Live Cryptarchia consensus state, polled while the node runs. property string cryptarchiaInfoJson: "" property string cryptarchiaInfoError: "" @@ -306,6 +332,12 @@ Rectangle { onChangeConfigRequested: _d.currentPage = 0 } + NodeInfoView { + Layout.fillWidth: true + peerId: root.peerId + onCopyToClipboard: (text) => root.copyText(text) + } + CryptarchiaInfoView { Layout.fillWidth: true visible: opPage.nodeRunning diff --git a/src/qml/views/NodeInfoView.qml b/src/qml/views/NodeInfoView.qml new file mode 100644 index 0000000..4ddfbaa --- /dev/null +++ b/src/qml/views/NodeInfoView.qml @@ -0,0 +1,62 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +import Logos.Theme +import Logos.Controls + +import "../controls" + +// "Node info" card — node identity that doesn't depend on the consensus +// runtime. Currently the self libp2p peer id (derived from the user config). +Rectangle { + id: root + + property string peerId: "" + + signal copyToClipboard(string text) + + implicitHeight: contentCol.implicitHeight + 2 * Theme.spacing.large + color: Theme.palette.backgroundTertiary + radius: Theme.spacing.radiusLarge + border.color: Theme.palette.border + border.width: 1 + + ColumnLayout { + id: contentCol + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.margins: Theme.spacing.large + spacing: Theme.spacing.small + + LogosText { + text: qsTr("Node info") + font.pixelSize: Theme.typography.secondaryText + font.bold: true + } + + RowLayout { + Layout.fillWidth: true + spacing: Theme.spacing.small + LogosText { + text: qsTr("Peer ID") + Layout.preferredWidth: 70 + color: Theme.palette.textSecondary + font.pixelSize: Theme.typography.secondaryText + } + LogosText { + Layout.fillWidth: true + text: root.peerId || qsTr("—") + elide: Text.ElideMiddle + font.pixelSize: Theme.typography.secondaryText + } + LogosCopyButton { + Layout.preferredHeight: 24 + Layout.preferredWidth: 24 + visible: root.peerId.length > 0 + onCopyText: root.copyToClipboard(root.peerId) + } + } + } +} diff --git a/src/qml/views/qmldir b/src/qml/views/qmldir index 1324617..3696ca1 100644 --- a/src/qml/views/qmldir +++ b/src/qml/views/qmldir @@ -2,6 +2,7 @@ module views StatusConfigView 1.0 StatusConfigView.qml BlocksView 1.0 BlocksView.qml CryptarchiaInfoView 1.0 CryptarchiaInfoView.qml +NodeInfoView 1.0 NodeInfoView.qml AccountsView 1.0 AccountsView.qml TransferView 1.0 TransferView.qml LeaderRewardsView 1.0 LeaderRewardsView.qml