2026-02-03 18:12:53 +01:00
|
|
|
#include "logos_execution_zone_wallet_module.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
2026-02-04 16:18:56 +01:00
|
|
|
LogosExecutionZoneWalletModule::LogosExecutionZoneWalletModule() = default;
|
2026-02-18 11:21:00 +00:00
|
|
|
|
|
|
|
|
LogosExecutionZoneWalletModule::~LogosExecutionZoneWalletModule() {
|
|
|
|
|
if (walletHandle) {
|
|
|
|
|
wallet_ffi_destroy(walletHandle);
|
|
|
|
|
walletHandle = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-03 18:12:53 +01:00
|
|
|
|
2026-02-04 15:51:02 +01:00
|
|
|
// === Plugin Interface ===
|
2026-02-03 18:12:53 +01:00
|
|
|
|
|
|
|
|
QString LogosExecutionZoneWalletModule::name() const {
|
|
|
|
|
return "liblogos-execution-zone-wallet-module";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString LogosExecutionZoneWalletModule::version() const {
|
|
|
|
|
return "1.0.0";
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 15:51:02 +01:00
|
|
|
// === Logos Core ===
|
|
|
|
|
|
2026-02-04 16:18:56 +01:00
|
|
|
void LogosExecutionZoneWalletModule::initLogos(LogosAPI* logosApiInstance) {
|
|
|
|
|
logosApi = logosApiInstance;
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// === Account Management ===
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::create_account_public(FfiBytes32* out_account_id) {
|
|
|
|
|
return wallet_ffi_create_account_public(walletHandle, out_account_id);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::create_account_private(FfiBytes32* out_account_id) {
|
|
|
|
|
return wallet_ffi_create_account_private(walletHandle, out_account_id);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::list_accounts(FfiAccountList* out_list) {
|
|
|
|
|
return wallet_ffi_list_accounts(walletHandle, out_list);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// === Account Queries ===
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::get_balance(
|
|
|
|
|
const FfiBytes32* account_id,
|
2026-02-04 16:18:56 +01:00
|
|
|
const bool is_public,
|
2026-02-04 15:51:02 +01:00
|
|
|
QByteArray* out_balance_le16
|
|
|
|
|
) {
|
|
|
|
|
uint8_t balance[16] = {0};
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
const WalletFfiError err = wallet_ffi_get_balance(walletHandle, account_id, is_public, &balance);
|
2026-02-04 15:51:02 +01:00
|
|
|
if (err == SUCCESS && out_balance_le16) {
|
|
|
|
|
*out_balance_le16 = QByteArray(reinterpret_cast<const char*>(balance), 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::get_account_public(
|
|
|
|
|
const FfiBytes32* account_id,
|
|
|
|
|
FfiAccount* out_account
|
|
|
|
|
) {
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_get_account_public(walletHandle, account_id, out_account);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 09:20:58 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::get_account_private(
|
|
|
|
|
const FfiBytes32* account_id,
|
|
|
|
|
FfiAccount* out_account
|
|
|
|
|
) {
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_get_account_private(walletHandle, account_id, out_account);
|
2026-02-18 09:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 15:51:02 +01:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key(
|
|
|
|
|
const FfiBytes32* account_id,
|
|
|
|
|
FfiPublicAccountKey* out_public_key
|
|
|
|
|
) {
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_get_public_account_key(walletHandle, account_id, out_public_key);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::get_private_account_keys(
|
|
|
|
|
const FfiBytes32* account_id,
|
|
|
|
|
FfiPrivateAccountKeys* out_keys
|
|
|
|
|
) {
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_get_private_account_keys(walletHandle, account_id, out_keys);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// === Account Encoding ===
|
|
|
|
|
|
|
|
|
|
QString LogosExecutionZoneWalletModule::account_id_to_base58(const FfiBytes32* account_id) {
|
|
|
|
|
char* str = wallet_ffi_account_id_to_base58(account_id);
|
|
|
|
|
if (!str) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString result = QString::fromUtf8(str);
|
|
|
|
|
wallet_ffi_free_string(str);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::account_id_from_base58(
|
|
|
|
|
const QString& base58_str,
|
|
|
|
|
FfiBytes32* out_account_id
|
|
|
|
|
) {
|
2026-02-04 16:18:56 +01:00
|
|
|
const QByteArray utf8 = base58_str.toUtf8();
|
2026-02-04 15:51:02 +01:00
|
|
|
return wallet_ffi_account_id_from_base58(utf8.constData(), out_account_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// === Blockchain Synchronisation ===
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::sync_to_block(const uint64_t block_id) {
|
|
|
|
|
return wallet_ffi_sync_to_block(walletHandle, block_id);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::get_last_synced_block(uint64_t* out_block_id) {
|
|
|
|
|
return wallet_ffi_get_last_synced_block(walletHandle, out_block_id);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::get_current_block_height(uint64_t* out_block_height) {
|
|
|
|
|
return wallet_ffi_get_current_block_height(walletHandle, out_block_height);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// === Operations ===
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::transfer_public(
|
|
|
|
|
const FfiBytes32* from,
|
|
|
|
|
const FfiBytes32* to,
|
|
|
|
|
const QByteArray& amount_le16,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
|
|
|
|
if (amount_le16.size() != 16) {
|
|
|
|
|
qWarning() << "transfer_public: amount_le16 must be 16 bytes";
|
|
|
|
|
return SERIALIZATION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 16:18:56 +01:00
|
|
|
uint8_t amount[16];
|
|
|
|
|
memcpy(amount, amount_le16.constData(), 16);
|
2026-02-04 15:51:02 +01:00
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_transfer_public(walletHandle, from, to, &amount, out_result);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 09:20:58 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded(
|
|
|
|
|
const FfiBytes32* from,
|
|
|
|
|
const FfiPrivateAccountKeys* to_keys,
|
|
|
|
|
const QByteArray& amount_le16,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
|
|
|
|
if (amount_le16.size() != 16) {
|
|
|
|
|
qWarning() << "transfer_shielded: amount_le16 must be 16 bytes";
|
|
|
|
|
return SERIALIZATION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t amount[16];
|
|
|
|
|
memcpy(amount, amount_le16.constData(), 16);
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_transfer_shielded(walletHandle, from, to_keys, &amount, out_result);
|
2026-02-18 09:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::transfer_deshielded(
|
|
|
|
|
const FfiBytes32* from,
|
|
|
|
|
const FfiBytes32* to,
|
|
|
|
|
const QByteArray& amount_le16,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
|
|
|
|
if (amount_le16.size() != 16) {
|
|
|
|
|
qWarning() << "transfer_deshielded: amount_le16 must be 16 bytes";
|
|
|
|
|
return SERIALIZATION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t amount[16];
|
|
|
|
|
memcpy(amount, amount_le16.constData(), 16);
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_transfer_deshielded(walletHandle, from, to, &amount, out_result);
|
2026-02-18 09:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::transfer_private(
|
|
|
|
|
const FfiBytes32* from,
|
|
|
|
|
const FfiPrivateAccountKeys* to_keys,
|
|
|
|
|
const QByteArray& amount_le16,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
|
|
|
|
if (amount_le16.size() != 16) {
|
|
|
|
|
qWarning() << "transfer_private: amount_le16 must be 16 bytes";
|
|
|
|
|
return SERIALIZATION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t amount[16];
|
|
|
|
|
memcpy(amount, amount_le16.constData(), 16);
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_transfer_private(walletHandle, from, to_keys, &amount, out_result);
|
2026-02-18 09:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded_owned(
|
|
|
|
|
const FfiBytes32* from,
|
|
|
|
|
const FfiBytes32* to,
|
|
|
|
|
const QByteArray& amount_le16,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
|
|
|
|
if (amount_le16.size() != 16) {
|
|
|
|
|
qWarning() << "transfer_shielded_owned: amount_le16 must be 16 bytes";
|
|
|
|
|
return SERIALIZATION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t amount[16];
|
|
|
|
|
memcpy(amount, amount_le16.constData(), 16);
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_transfer_shielded_owned(walletHandle, from, to, &amount, out_result);
|
2026-02-18 09:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned(
|
|
|
|
|
const FfiBytes32* from,
|
|
|
|
|
const FfiBytes32* to,
|
|
|
|
|
const QByteArray& amount_le16,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
|
|
|
|
if (amount_le16.size() != 16) {
|
|
|
|
|
qWarning() << "transfer_private_owned: amount_le16 must be 16 bytes";
|
|
|
|
|
return SERIALIZATION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t amount[16];
|
|
|
|
|
memcpy(amount, amount_le16.constData(), 16);
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_transfer_private_owned(walletHandle, from, to, &amount, out_result);
|
2026-02-18 09:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 15:51:02 +01:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::register_public_account(
|
|
|
|
|
const FfiBytes32* account_id,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_register_public_account(walletHandle, account_id, out_result);
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 09:20:58 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::register_private_account(
|
|
|
|
|
const FfiBytes32* account_id,
|
|
|
|
|
FfiTransferResult* out_result
|
|
|
|
|
) {
|
2026-02-18 11:21:00 +00:00
|
|
|
return wallet_ffi_register_private_account(walletHandle, account_id, out_result);
|
2026-02-18 09:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 15:51:02 +01:00
|
|
|
// === Wallet Lifecycle ===
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::create_new(
|
2026-02-04 15:51:02 +01:00
|
|
|
const QString& config_path,
|
|
|
|
|
const QString& storage_path,
|
|
|
|
|
const QString& password
|
|
|
|
|
) {
|
2026-02-18 11:21:00 +00:00
|
|
|
if (walletHandle) {
|
|
|
|
|
qWarning() << "create_new: wallet is already open";
|
|
|
|
|
return INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 16:18:56 +01:00
|
|
|
const QByteArray config_utf8 = config_path.toUtf8();
|
|
|
|
|
const QByteArray storage_utf8 = storage_path.toUtf8();
|
|
|
|
|
const QByteArray password_utf8 = password.toUtf8();
|
2026-02-04 15:51:02 +01:00
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
walletHandle = wallet_ffi_create_new(config_utf8.constData(), storage_utf8.constData(), password_utf8.constData());
|
|
|
|
|
if (!walletHandle) {
|
|
|
|
|
qWarning() << "create_new: wallet_ffi_create_new returned null";
|
|
|
|
|
return INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SUCCESS;
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::open(const QString& config_path, const QString& storage_path) {
|
|
|
|
|
if (walletHandle) {
|
|
|
|
|
qWarning() << "open: wallet is already open";
|
|
|
|
|
return INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 16:18:56 +01:00
|
|
|
const QByteArray config_utf8 = config_path.toUtf8();
|
|
|
|
|
const QByteArray storage_utf8 = storage_path.toUtf8();
|
2026-02-04 15:51:02 +01:00
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
walletHandle = wallet_ffi_open(config_utf8.constData(), storage_utf8.constData());
|
|
|
|
|
if (!walletHandle) {
|
|
|
|
|
qWarning() << "open: wallet_ffi_open returned null";
|
|
|
|
|
return INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SUCCESS;
|
2026-02-04 15:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
WalletFfiError LogosExecutionZoneWalletModule::save() {
|
|
|
|
|
return wallet_ffi_save(walletHandle);
|
2026-02-03 18:12:53 +01:00
|
|
|
}
|
2026-02-04 15:51:02 +01:00
|
|
|
|
|
|
|
|
// === Configuration ===
|
|
|
|
|
|
2026-02-18 11:21:00 +00:00
|
|
|
QString LogosExecutionZoneWalletModule::get_sequencer_addr() {
|
|
|
|
|
char* addr = wallet_ffi_get_sequencer_addr(walletHandle);
|
2026-02-04 15:51:02 +01:00
|
|
|
if (!addr) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString result = QString::fromUtf8(addr);
|
|
|
|
|
wallet_ffi_free_string(addr);
|
|
|
|
|
return result;
|
|
|
|
|
}
|