mirror of
https://github.com/logos-blockchain/logos-blockchain-module.git
synced 2026-04-18 16:43:08 +00:00
feat(wallet): Add known address functionality (#11)
* Update flake * Add known addresses functionality
This commit is contained in:
parent
cbab7696d4
commit
4e5703787e
@ -160,6 +160,7 @@ target_sources(${PLUGIN_TARGET} PRIVATE
|
|||||||
|
|
||||||
set_property(TARGET ${PLUGIN_TARGET} PROPERTY PUBLIC_HEADER
|
set_property(TARGET ${PLUGIN_TARGET} PROPERTY PUBLIC_HEADER
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/i_logos_blockchain_module.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/i_logos_blockchain_module.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/known_addresses.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PLUGIN_TARGET} PRIVATE
|
target_include_directories(${PLUGIN_TARGET} PRIVATE
|
||||||
|
|||||||
6
flake.lock
generated
6
flake.lock
generated
@ -23,11 +23,11 @@
|
|||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1770980612,
|
"lastModified": 1771148003,
|
||||||
"narHash": "sha256-MFSBq7BBC+yI3rv2ZWy7CF2l111zCdjNVvpR0Cc8gbI=",
|
"narHash": "sha256-GhA2aeadEN24IMFYXnmCJxtJOx9ctuA8kTF7EWDqtY4=",
|
||||||
"owner": "logos-blockchain",
|
"owner": "logos-blockchain",
|
||||||
"repo": "logos-blockchain",
|
"repo": "logos-blockchain",
|
||||||
"rev": "5457fa1fa8568157c8165fdeab766efc65eb6e38",
|
"rev": "4c3738609e9fd4847db4f918e473da3c69b3366f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@ -2,14 +2,7 @@
|
|||||||
#define I_LOGOS_BLOCKCHAIN_MODULE_API_H
|
#define I_LOGOS_BLOCKCHAIN_MODULE_API_H
|
||||||
|
|
||||||
#include <core/interface.h>
|
#include <core/interface.h>
|
||||||
|
#include "known_addresses.h"
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
#include <logos_blockchain.h>
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class ILogosBlockchainModule {
|
class ILogosBlockchainModule {
|
||||||
public:
|
public:
|
||||||
@ -27,6 +20,7 @@ public:
|
|||||||
BalanceResult* output_balance
|
BalanceResult* output_balance
|
||||||
) = 0;
|
) = 0;
|
||||||
virtual int wallet_transfer_funds(const TransferFundsArguments* transfer_funds_arguments, Hash* output_hash) = 0;
|
virtual int wallet_transfer_funds(const TransferFundsArguments* transfer_funds_arguments, Hash* output_hash) = 0;
|
||||||
|
virtual int wallet_get_known_addresses(lb::KnownAddresses* output) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ILogosBlockchainModule_iid "org.logos.ilogosblockchainmodule"
|
#define ILogosBlockchainModule_iid "org.logos.ilogosblockchainmodule"
|
||||||
|
|||||||
60
src/known_addresses.h
Normal file
60
src/known_addresses.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include <logos_blockchain.h>
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace lb {
|
||||||
|
|
||||||
|
class KnownAddresses {
|
||||||
|
public:
|
||||||
|
KnownAddresses() : data_(nullptr) {}
|
||||||
|
|
||||||
|
explicit KnownAddresses(::KnownAddresses addresses)
|
||||||
|
: data_(new ::KnownAddresses(addresses), [](::KnownAddresses* ptr) {
|
||||||
|
if (ptr) {
|
||||||
|
free_known_addresses(*ptr);
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
size_t size() const {
|
||||||
|
return data_ ? data_->len : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const {
|
||||||
|
return size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t* at(size_t index) const {
|
||||||
|
if (!data_ || index >= data_->len) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return data_->addresses[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t* operator[](size_t index) const {
|
||||||
|
return at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid() const {
|
||||||
|
return data_ != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator bool() const {
|
||||||
|
return valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<::KnownAddresses> data_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace lb
|
||||||
@ -156,6 +156,22 @@ int LogosBlockchainModule::wallet_transfer_funds(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LogosBlockchainModule::wallet_get_known_addresses(lb::KnownAddresses* output) {
|
||||||
|
if (!node) {
|
||||||
|
qWarning() << "Could not execute the operation: The node is not running.";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto [value, error] = get_known_addresses(node);
|
||||||
|
if (!is_ok(&error)) {
|
||||||
|
qCritical() << "Failed to get known addresses. Error:" << error;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*output = lb::KnownAddresses(value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void LogosBlockchainModule::emitEvent(const QString& eventName, const QVariantList& data) {
|
void LogosBlockchainModule::emitEvent(const QString& eventName, const QVariantList& data) {
|
||||||
if (!logosAPI) {
|
if (!logosAPI) {
|
||||||
qWarning() << "LogosBlockchainModule: LogosAPI not available, cannot emit" << eventName;
|
qWarning() << "LogosBlockchainModule: LogosAPI not available, cannot emit" << eventName;
|
||||||
|
|||||||
@ -22,6 +22,7 @@ public:
|
|||||||
Q_INVOKABLE int stop() override;
|
Q_INVOKABLE int stop() override;
|
||||||
Q_INVOKABLE int wallet_get_balance(const uint8_t*, const HeaderId*, BalanceResult*) override;
|
Q_INVOKABLE int wallet_get_balance(const uint8_t*, const HeaderId*, BalanceResult*) override;
|
||||||
Q_INVOKABLE int wallet_transfer_funds(const TransferFundsArguments*, Hash*) override;
|
Q_INVOKABLE int wallet_transfer_funds(const TransferFundsArguments*, Hash*) override;
|
||||||
|
Q_INVOKABLE int wallet_get_known_addresses(lb::KnownAddresses*) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void eventResponse(const QString& eventName, const QVariantList& data);
|
void eventResponse(const QString& eventName, const QVariantList& data);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user