mirror of
https://github.com/logos-blockchain/logos-blockchain-ui.git
synced 2026-04-20 10:13:12 +00:00
feat: add api calls
This commit is contained in:
parent
dc260dc9eb
commit
dd50913373
38
flake.lock
generated
38
flake.lock
generated
@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1769737823,
|
||||
"narHash": "sha256-DrBaNpZ+sJ4stXm+0nBX7zqZT9t9P22zbk6m5YhQxS4=",
|
||||
"lastModified": 1770419512,
|
||||
"narHash": "sha256-o8Vcdz6B6bkiGUYkZqFwH3Pv1JwZyXht3dMtS7RchIo=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "b2f45c3830aa96b7456a4c4bc327d04d7a43e1ba",
|
||||
"rev": "2510f2cbc3ccd237f700bb213756a8f35c32d8d7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -23,11 +23,11 @@
|
||||
"rust-overlay": "rust-overlay"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1770888466,
|
||||
"narHash": "sha256-7IJz+UIwa8QPg81cvqunpnpO87VUdWt0TcPz7HGBnYE=",
|
||||
"lastModified": 1771256037,
|
||||
"narHash": "sha256-8/sdrRyHYd01pYQwnjL2QWN8zACSUkMd/JPmhAFaaoc=",
|
||||
"owner": "logos-blockchain",
|
||||
"repo": "logos-blockchain",
|
||||
"rev": "3ef7a137b91c4a5a7708405815354ff58e0e179c",
|
||||
"rev": "fe11562ea895b2d39af9d9c97c561cd14cbcedbe",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -41,11 +41,11 @@
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1769780029,
|
||||
"narHash": "sha256-B2CYcJWuJIXAJaWgBcY4k0FTxo62mI8Hd9RqBECfq4o=",
|
||||
"lastModified": 1770979891,
|
||||
"narHash": "sha256-cvkVnE7btuFLzv70ORAZve9K1Huiplq0iECgXSXb0ZY=",
|
||||
"owner": "logos-blockchain",
|
||||
"repo": "logos-blockchain-circuits",
|
||||
"rev": "480b9bc4fddb4643f528d607f046f27610439a78",
|
||||
"rev": "ec7d298e5a3a0507bb8570df86cdf78dc452d024",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -67,17 +67,17 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1770934619,
|
||||
"narHash": "sha256-DyksgOrea/gktElcOZmMDUcYW45JPpkDA5BnPkwVmmc=",
|
||||
"lastModified": 1771367673,
|
||||
"narHash": "sha256-te82eiZeM1XNp8qg+BcdPMp0Rful0nIpJCcvPT3gP/A=",
|
||||
"owner": "logos-blockchain",
|
||||
"repo": "logos-blockchain-module",
|
||||
"rev": "578308270ecfe7463a94ac50cae0584451c135ef",
|
||||
"rev": "0cae35a33bc5d5148096d5aaacb653c2b99da2c4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "logos-blockchain",
|
||||
"repo": "logos-blockchain-module",
|
||||
"rev": "578308270ecfe7463a94ac50cae0584451c135ef",
|
||||
"rev": "0cae35a33bc5d5148096d5aaacb653c2b99da2c4",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
@ -1164,11 +1164,11 @@
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1769461804,
|
||||
"narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=",
|
||||
"lastModified": 1770841267,
|
||||
"narHash": "sha256-9xejG0KoqsoKEGp2kVbXRlEYtFFcDTHjidiuX8hGO44=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d",
|
||||
"rev": "ec7c70d12ce2fc37cb92aff673dcdca89d187bae",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -1392,11 +1392,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1769742225,
|
||||
"narHash": "sha256-roSD/OJ3x9nF+Dxr+/bLClX3U8FP9EkCQIFpzxKjSUM=",
|
||||
"lastModified": 1770952264,
|
||||
"narHash": "sha256-CjymNrJZWBtpavyuTkfPVPaZkwzIzGaf0E/3WgcwM14=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "bcdd8d37594f0e201639f55889c01c827baf5c75",
|
||||
"rev": "ec6a3d5cdf14bb5a1dd03652bd3f6351004d2188",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
nixpkgs.follows = "logos-liblogos/nixpkgs";
|
||||
logos-cpp-sdk.url = "github:logos-co/logos-cpp-sdk";
|
||||
logos-liblogos.url = "github:logos-co/logos-liblogos";
|
||||
logos-blockchain-module.url = "github:logos-blockchain/logos-blockchain-module/578308270ecfe7463a94ac50cae0584451c135ef";
|
||||
logos-blockchain-module.url = "github:logos-blockchain/logos-blockchain-module/0cae35a33bc5d5148096d5aaacb653c2b99da2c4";
|
||||
logos-capability-module.url = "github:logos-co/logos-capability-module";
|
||||
logos-design-system.url = "github:logos-co/logos-design-system";
|
||||
logos-design-system.inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
"author": "Logos Blockchain Team",
|
||||
"type": "ui",
|
||||
"main": "blockchain_ui",
|
||||
"icon": ":/icons/blockchain.png",
|
||||
"dependencies": ["liblogos_blockchain_module"],
|
||||
"category": "blockchain",
|
||||
"build": {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include "BlockchainBackend.h"
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
|
||||
BlockchainBackend::BlockchainBackend(LogosAPI* logosAPI, QObject* parent)
|
||||
@ -66,11 +68,7 @@ QString BlockchainBackend::getBalance(const QString& addressHex)
|
||||
if (!m_blockchainModule) {
|
||||
return QStringLiteral("Error: Module not initialized.");
|
||||
}
|
||||
// The generated proxy converts C pointer params (uint8_t*, BalanceResult*) to QVariant,
|
||||
// which cannot carry raw C pointers. The module needs to expose a QString-based
|
||||
// wrapper (e.g. getWalletBalanceQ) for this to work through the proxy.
|
||||
Q_UNUSED(addressHex)
|
||||
return QStringLiteral("Not yet available: module needs Qt-friendly wallet API.");
|
||||
return m_blockchainModule->wallet_get_balance(addressHex);
|
||||
}
|
||||
|
||||
QString BlockchainBackend::transferFunds(const QString& fromKeyHex, const QString& toKeyHex, const QString& amountStr)
|
||||
@ -78,12 +76,9 @@ QString BlockchainBackend::transferFunds(const QString& fromKeyHex, const QStrin
|
||||
if (!m_blockchainModule) {
|
||||
return QStringLiteral("Error: Module not initialized.");
|
||||
}
|
||||
// Same limitation: TransferFundsArguments and Hash are C types that cannot
|
||||
// pass through the QVariant-based generated proxy.
|
||||
Q_UNUSED(fromKeyHex)
|
||||
Q_UNUSED(toKeyHex)
|
||||
Q_UNUSED(amountStr)
|
||||
return QStringLiteral("Not yet available: module needs Qt-friendly wallet API.");
|
||||
QStringList senderAddresses;
|
||||
senderAddresses << fromKeyHex;
|
||||
return m_blockchainModule->wallet_transfer_funds(fromKeyHex, senderAddresses, toKeyHex, amountStr, "");
|
||||
}
|
||||
|
||||
void BlockchainBackend::startBlockchain()
|
||||
@ -99,6 +94,7 @@ void BlockchainBackend::startBlockchain()
|
||||
|
||||
if (result == 0 || result == 1) {
|
||||
setStatus(Running);
|
||||
QTimer::singleShot(500, this, [this]() { refreshKnownAddresses(); });
|
||||
} else if (result == 2) {
|
||||
setStatus(ErrorConfigMissing);
|
||||
} else if (result == 3) {
|
||||
@ -108,6 +104,17 @@ void BlockchainBackend::startBlockchain()
|
||||
}
|
||||
}
|
||||
|
||||
void BlockchainBackend::refreshKnownAddresses()
|
||||
{
|
||||
if (!m_blockchainModule) return;
|
||||
QStringList list = m_blockchainModule->wallet_get_known_addresses();
|
||||
qDebug() << "BlockchainBackend: received from blockchain lib: type=QStringList, count=" << list.size();
|
||||
if (m_knownAddresses != list) {
|
||||
m_knownAddresses = std::move(list);
|
||||
emit knownAddressesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void BlockchainBackend::stopBlockchain()
|
||||
{
|
||||
if (m_status != Running && m_status != Starting) {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <utility>
|
||||
#include "logos_api.h"
|
||||
#include "logos_api_client.h"
|
||||
@ -33,6 +34,7 @@ public:
|
||||
Q_PROPERTY(BlockchainStatus status READ status NOTIFY statusChanged)
|
||||
Q_PROPERTY(QString configPath READ configPath WRITE setConfigPath NOTIFY configPathChanged)
|
||||
Q_PROPERTY(LogModel* logModel READ logModel CONSTANT)
|
||||
Q_PROPERTY(QStringList knownAddresses READ knownAddresses NOTIFY knownAddressesChanged)
|
||||
|
||||
explicit BlockchainBackend(LogosAPI* logosAPI = nullptr, QObject* parent = nullptr);
|
||||
~BlockchainBackend();
|
||||
@ -40,13 +42,18 @@ public:
|
||||
BlockchainStatus status() const { return m_status; }
|
||||
QString configPath() const { return m_configPath; }
|
||||
LogModel* logModel() const { return m_logModel; }
|
||||
QStringList knownAddresses() const { return m_knownAddresses; }
|
||||
|
||||
void setConfigPath(const QString& path);
|
||||
Q_INVOKABLE void clearLogs();
|
||||
Q_INVOKABLE QString getBalance(const QString& addressHex);
|
||||
Q_INVOKABLE QString transferFunds(const QString& fromKeyHex, const QString& toKeyHex, const QString& amountStr);
|
||||
Q_INVOKABLE QString transferFunds(
|
||||
const QString& fromKeyHex,
|
||||
const QString& toKeyHex,
|
||||
const QString& amountStr);
|
||||
Q_INVOKABLE void startBlockchain();
|
||||
Q_INVOKABLE void stopBlockchain();
|
||||
Q_INVOKABLE void refreshKnownAddresses();
|
||||
|
||||
public slots:
|
||||
void onNewBlock(const QVariantList& data);
|
||||
@ -54,6 +61,7 @@ public slots:
|
||||
signals:
|
||||
void statusChanged();
|
||||
void configPathChanged();
|
||||
void knownAddressesChanged();
|
||||
|
||||
private:
|
||||
void setStatus(BlockchainStatus newStatus);
|
||||
@ -61,6 +69,7 @@ private:
|
||||
BlockchainStatus m_status;
|
||||
QString m_configPath;
|
||||
LogModel* m_logModel;
|
||||
QStringList m_knownAddresses;
|
||||
|
||||
LogosModules* m_logos;
|
||||
BlockchainModuleProxy* m_blockchainModule;
|
||||
|
||||
@ -5,5 +5,6 @@
|
||||
<file>qml/views/StatusConfigView.qml</file>
|
||||
<file>qml/views/LogsView.qml</file>
|
||||
<file>qml/views/WalletView.qml</file>
|
||||
<file>icons/blockchain.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
src/icons/blockchain.png
Normal file
BIN
src/icons/blockchain.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 495 B |
@ -78,6 +78,7 @@ Rectangle {
|
||||
WalletView {
|
||||
id: walletView
|
||||
Layout.preferredWidth: parent.width / 2
|
||||
knownAddresses: backend.knownAddresses
|
||||
|
||||
onGetBalanceRequested: function(addressHex) {
|
||||
walletView.setBalanceResult(backend.getBalance(addressHex))
|
||||
|
||||
@ -8,6 +8,9 @@ import Logos.Controls
|
||||
ColumnLayout {
|
||||
id: root
|
||||
|
||||
// list of known wallet addresses for Get balance dropdown
|
||||
property var knownAddresses: []
|
||||
|
||||
// --- Public API ---
|
||||
signal getBalanceRequested(string addressHex)
|
||||
signal transferRequested(string fromKeyHex, string toKeyHex, string amount)
|
||||
@ -25,7 +28,8 @@ ColumnLayout {
|
||||
// Get balance card
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: balanceCol.implicitHeight
|
||||
implicitHeight: balanceCol.implicitHeight + 2 * Theme.spacing.large
|
||||
Layout.preferredHeight: implicitHeight
|
||||
color: Theme.palette.backgroundTertiary
|
||||
radius: Theme.spacing.radiusLarge
|
||||
border.color: Theme.palette.border
|
||||
@ -33,7 +37,9 @@ ColumnLayout {
|
||||
|
||||
ColumnLayout {
|
||||
id: balanceCol
|
||||
anchors.fill: parent
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.margins: Theme.spacing.large
|
||||
spacing: Theme.spacing.large
|
||||
|
||||
@ -43,23 +49,48 @@ ColumnLayout {
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
CustomTextFeild {
|
||||
id: balanceAddressField
|
||||
placeholderText: qsTr("Wallet address (64 hex chars)")
|
||||
}
|
||||
|
||||
LogosButton {
|
||||
text: qsTr("Get balance")
|
||||
Layout.alignment: Qt.AlignRight
|
||||
onClicked: root.getBalanceRequested(balanceAddressField.text)
|
||||
}
|
||||
|
||||
LogosText {
|
||||
id: balanceResultText
|
||||
// Dropdown of known addresses, or type a custom address
|
||||
ComboBox {
|
||||
id: balanceAddressCombo
|
||||
Layout.fillWidth: true
|
||||
editable: true
|
||||
model: knownAddresses
|
||||
font.pixelSize: Theme.typography.secondaryText
|
||||
color: Theme.palette.textSecondary
|
||||
wrapMode: Text.WordWrap
|
||||
onActivated: function(index) {
|
||||
if (index >= 0 && index < knownAddresses.length)
|
||||
currentText = knownAddresses[index]
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: balanceButton.implicitHeight
|
||||
spacing: Theme.spacing.large
|
||||
|
||||
LogosButton {
|
||||
id: balanceButton
|
||||
text: qsTr("Get balance")
|
||||
onClicked: root.getBalanceRequested(balanceAddressCombo.currentText.trim())
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: balanceResultText.height + 2 * Theme.spacing.large
|
||||
color: Theme.palette.backgroundSecondary
|
||||
radius: Theme.spacing.radiusXlarge
|
||||
border.color: Theme.palette.border
|
||||
border.width: 1
|
||||
LogosText {
|
||||
id: balanceResultText
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.margins: Theme.spacing.large
|
||||
font.pixelSize: Theme.typography.secondaryText
|
||||
color: Theme.palette.textSecondary
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,6 +119,7 @@ ColumnLayout {
|
||||
}
|
||||
|
||||
CustomTextFeild {
|
||||
id: transferFromField
|
||||
placeholderText: qsTr("From key (64 hex chars)")
|
||||
}
|
||||
|
||||
@ -97,6 +129,7 @@ ColumnLayout {
|
||||
}
|
||||
|
||||
CustomTextFeild {
|
||||
id: transferAmountField
|
||||
placeholderText: qsTr("Amount")
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user