From 02723b59221198ce12c9eeb2d0f2665efbab9bbb Mon Sep 17 00:00:00 2001 From: danielSanchezQ <3danimanimal@gmail.com> Date: Wed, 18 Feb 2026 11:00:53 +0000 Subject: [PATCH 1/6] Remove unnecessary free methods --- src/i_logos_execution_zone_wallet_module.h | 8 ------- src/logos_execution_zone_wallet_module.cpp | 26 ---------------------- src/logos_execution_zone_wallet_module.h | 8 ------- 3 files changed, 42 deletions(-) diff --git a/src/i_logos_execution_zone_wallet_module.h b/src/i_logos_execution_zone_wallet_module.h index f03749d..8b13b3a 100644 --- a/src/i_logos_execution_zone_wallet_module.h +++ b/src/i_logos_execution_zone_wallet_module.h @@ -25,7 +25,6 @@ public: virtual WalletFfiError create_account_public(WalletHandle* handle, FfiBytes32* out_account_id) = 0; virtual WalletFfiError create_account_private(WalletHandle* handle, FfiBytes32* out_account_id) = 0; virtual WalletFfiError list_accounts(WalletHandle* handle, FfiAccountList* out_list) = 0; - virtual void free_account_list(FfiAccountList* list) = 0; // Account Queries virtual WalletFfiError get_balance( @@ -44,7 +43,6 @@ public: const FfiBytes32* account_id, FfiAccount* out_account ) = 0; - virtual void free_account_data(FfiAccount* account) = 0; virtual WalletFfiError get_public_account_key( WalletHandle* handle, const FfiBytes32* account_id, @@ -55,7 +53,6 @@ public: const FfiBytes32* account_id, FfiPrivateAccountKeys* out_keys ) = 0; - virtual void free_private_account_keys(FfiPrivateAccountKeys* keys) = 0; // Account Encoding virtual QString account_id_to_base58(const FfiBytes32* account_id) = 0; @@ -119,7 +116,6 @@ public: const FfiBytes32* account_id, FfiTransferResult* out_result ) = 0; - virtual void free_transfer_result(FfiTransferResult* result) = 0; // Wallet Lifecycle virtual WalletHandle* create_new( @@ -128,14 +124,10 @@ public: const QString& password ) = 0; virtual WalletHandle* open(const QString& config_path, const QString& storage_path) = 0; - virtual void destroy_wallet(WalletHandle* handle) = 0; virtual WalletFfiError save(WalletHandle* handle) = 0; // Configuration & Metadata virtual QString get_sequencer_addr(WalletHandle* handle) = 0; - - // Memory Management - virtual void free_string(char* ptr) = 0; }; #define ILogosExecutionZoneWalletModule_iid "org.logos.ilogosexecutionzonewalletmodule" diff --git a/src/logos_execution_zone_wallet_module.cpp b/src/logos_execution_zone_wallet_module.cpp index b93ed9c..bcc1e5e 100644 --- a/src/logos_execution_zone_wallet_module.cpp +++ b/src/logos_execution_zone_wallet_module.cpp @@ -38,10 +38,6 @@ WalletFfiError LogosExecutionZoneWalletModule::list_accounts(WalletHandle* handl return wallet_ffi_list_accounts(handle, out_list); } -void LogosExecutionZoneWalletModule::free_account_list(FfiAccountList* list) { - wallet_ffi_free_account_list(list); -} - // === Account Queries === WalletFfiError LogosExecutionZoneWalletModule::get_balance( @@ -76,10 +72,6 @@ WalletFfiError LogosExecutionZoneWalletModule::get_account_private( return wallet_ffi_get_account_private(handle, account_id, out_account); } -void LogosExecutionZoneWalletModule::free_account_data(FfiAccount* account) { - wallet_ffi_free_account_data(account); -} - WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key( WalletHandle* handle, const FfiBytes32* account_id, @@ -96,10 +88,6 @@ WalletFfiError LogosExecutionZoneWalletModule::get_private_account_keys( return wallet_ffi_get_private_account_keys(handle, account_id, out_keys); } -void LogosExecutionZoneWalletModule::free_private_account_keys(FfiPrivateAccountKeys* keys) { - wallet_ffi_free_private_account_keys(keys); -} - // === Account Encoding === QString LogosExecutionZoneWalletModule::account_id_to_base58(const FfiBytes32* account_id) { @@ -264,10 +252,6 @@ WalletFfiError LogosExecutionZoneWalletModule::register_private_account( return wallet_ffi_register_private_account(handle, account_id, out_result); } -void LogosExecutionZoneWalletModule::free_transfer_result(FfiTransferResult* result) { - wallet_ffi_free_transfer_result(result); -} - // === Wallet Lifecycle === WalletHandle* LogosExecutionZoneWalletModule::create_new( @@ -289,10 +273,6 @@ WalletHandle* LogosExecutionZoneWalletModule::open(const QString& config_path, c return wallet_ffi_open(config_utf8.constData(), storage_utf8.constData()); } -void LogosExecutionZoneWalletModule::destroy_wallet(WalletHandle* handle) { - wallet_ffi_destroy(handle); -} - WalletFfiError LogosExecutionZoneWalletModule::save(WalletHandle* handle) { return wallet_ffi_save(handle); } @@ -309,9 +289,3 @@ QString LogosExecutionZoneWalletModule::get_sequencer_addr(WalletHandle* handle) wallet_ffi_free_string(addr); return result; } - -// === Memory Management === - -void LogosExecutionZoneWalletModule::free_string(char* ptr) { - wallet_ffi_free_string(ptr); -} diff --git a/src/logos_execution_zone_wallet_module.h b/src/logos_execution_zone_wallet_module.h index e50080d..a769bbd 100644 --- a/src/logos_execution_zone_wallet_module.h +++ b/src/logos_execution_zone_wallet_module.h @@ -33,7 +33,6 @@ public: Q_INVOKABLE WalletFfiError create_account_public(WalletHandle* handle, FfiBytes32* out_account_id) override; Q_INVOKABLE WalletFfiError create_account_private(WalletHandle* handle, FfiBytes32* out_account_id) override; Q_INVOKABLE WalletFfiError list_accounts(WalletHandle* handle, FfiAccountList* out_list) override; - Q_INVOKABLE void free_account_list(FfiAccountList* list) override; // Account Queries Q_INVOKABLE WalletFfiError get_balance( @@ -46,7 +45,6 @@ public: get_account_public(WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account) override; Q_INVOKABLE WalletFfiError get_account_private(WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account) override; - Q_INVOKABLE void free_account_data(FfiAccount* account) override; Q_INVOKABLE WalletFfiError get_public_account_key( WalletHandle* handle, const FfiBytes32* account_id, @@ -57,7 +55,6 @@ public: const FfiBytes32* account_id, FfiPrivateAccountKeys* out_keys ) override; - Q_INVOKABLE void free_private_account_keys(FfiPrivateAccountKeys* keys) override; // Account Encoding Q_INVOKABLE QString account_id_to_base58(const FfiBytes32* account_id) override; @@ -115,7 +112,6 @@ public: register_public_account(WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result) override; Q_INVOKABLE WalletFfiError register_private_account(WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result) override; - Q_INVOKABLE void free_transfer_result(FfiTransferResult* result) override; // Wallet Lifecycle Q_INVOKABLE WalletHandle* create_new( @@ -124,15 +120,11 @@ public: const QString& password ) override; Q_INVOKABLE WalletHandle* open(const QString& config_path, const QString& storage_path) override; - Q_INVOKABLE void destroy_wallet(WalletHandle* handle) override; Q_INVOKABLE WalletFfiError save(WalletHandle* handle) override; // Configuration Q_INVOKABLE QString get_sequencer_addr(WalletHandle* handle) override; - // Memory Management - Q_INVOKABLE void free_string(char* ptr) override; - signals: void eventResponse(const QString& eventName, const QVariantList& data); }; From 0b4cd38c89667f4a07376b566e4b3eee4d098025 Mon Sep 17 00:00:00 2001 From: danielSanchezQ <3danimanimal@gmail.com> Date: Wed, 18 Feb 2026 11:21:00 +0000 Subject: [PATCH 2/6] Encapsulate wallet initialization --- src/i_logos_execution_zone_wallet_module.h | 33 ++---- src/logos_execution_zone_wallet_module.cpp | 115 +++++++++++---------- src/logos_execution_zone_wallet_module.h | 38 +++---- 3 files changed, 87 insertions(+), 99 deletions(-) diff --git a/src/i_logos_execution_zone_wallet_module.h b/src/i_logos_execution_zone_wallet_module.h index 8b13b3a..8edc0b6 100644 --- a/src/i_logos_execution_zone_wallet_module.h +++ b/src/i_logos_execution_zone_wallet_module.h @@ -22,34 +22,29 @@ public: // === Logos Execution Zone Wallet === // Account Management - virtual WalletFfiError create_account_public(WalletHandle* handle, FfiBytes32* out_account_id) = 0; - virtual WalletFfiError create_account_private(WalletHandle* handle, FfiBytes32* out_account_id) = 0; - virtual WalletFfiError list_accounts(WalletHandle* handle, FfiAccountList* out_list) = 0; + virtual WalletFfiError create_account_public(FfiBytes32* out_account_id) = 0; + virtual WalletFfiError create_account_private(FfiBytes32* out_account_id) = 0; + virtual WalletFfiError list_accounts(FfiAccountList* out_list) = 0; // Account Queries virtual WalletFfiError get_balance( - WalletHandle* handle, const FfiBytes32* account_id, bool is_public, QByteArray* out_balance_le16 ) = 0; virtual WalletFfiError get_account_public( - WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account ) = 0; virtual WalletFfiError get_account_private( - WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account ) = 0; virtual WalletFfiError get_public_account_key( - WalletHandle* handle, const FfiBytes32* account_id, FfiPublicAccountKey* out_public_key ) = 0; virtual WalletFfiError get_private_account_keys( - WalletHandle* handle, const FfiBytes32* account_id, FfiPrivateAccountKeys* out_keys ) = 0; @@ -59,75 +54,67 @@ public: virtual WalletFfiError account_id_from_base58(const QString& base58_str, FfiBytes32* out_account_id) = 0; // Blockchain Synchronisation - virtual WalletFfiError sync_to_block(WalletHandle* handle, uint64_t block_id) = 0; - virtual WalletFfiError get_last_synced_block(WalletHandle* handle, uint64_t* out_block_id) = 0; - virtual WalletFfiError get_current_block_height(WalletHandle* handle, uint64_t* out_block_height) = 0; + virtual WalletFfiError sync_to_block(uint64_t block_id) = 0; + virtual WalletFfiError get_last_synced_block(uint64_t* out_block_id) = 0; + virtual WalletFfiError get_current_block_height(uint64_t* out_block_height) = 0; // Operations virtual WalletFfiError transfer_public( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_shielded( - WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys, const QByteArray& amount_le16, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_deshielded( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_private( - WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys, const QByteArray& amount_le16, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_shielded_owned( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_private_owned( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) = 0; virtual WalletFfiError register_public_account( - WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result ) = 0; virtual WalletFfiError register_private_account( - WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result ) = 0; // Wallet Lifecycle - virtual WalletHandle* create_new( + virtual WalletFfiError create_new( const QString& config_path, const QString& storage_path, const QString& password ) = 0; - virtual WalletHandle* open(const QString& config_path, const QString& storage_path) = 0; - virtual WalletFfiError save(WalletHandle* handle) = 0; + virtual WalletFfiError open(const QString& config_path, const QString& storage_path) = 0; + virtual WalletFfiError save() = 0; // Configuration & Metadata - virtual QString get_sequencer_addr(WalletHandle* handle) = 0; + virtual QString get_sequencer_addr() = 0; }; #define ILogosExecutionZoneWalletModule_iid "org.logos.ilogosexecutionzonewalletmodule" diff --git a/src/logos_execution_zone_wallet_module.cpp b/src/logos_execution_zone_wallet_module.cpp index bcc1e5e..8e182e1 100644 --- a/src/logos_execution_zone_wallet_module.cpp +++ b/src/logos_execution_zone_wallet_module.cpp @@ -3,7 +3,13 @@ #include LogosExecutionZoneWalletModule::LogosExecutionZoneWalletModule() = default; -LogosExecutionZoneWalletModule::~LogosExecutionZoneWalletModule() = default; + +LogosExecutionZoneWalletModule::~LogosExecutionZoneWalletModule() { + if (walletHandle) { + wallet_ffi_destroy(walletHandle); + walletHandle = nullptr; + } +} // === Plugin Interface === @@ -23,32 +29,28 @@ void LogosExecutionZoneWalletModule::initLogos(LogosAPI* logosApiInstance) { // === Account Management === -WalletFfiError LogosExecutionZoneWalletModule::create_account_public(WalletHandle* handle, FfiBytes32* out_account_id) { - return wallet_ffi_create_account_public(handle, out_account_id); +WalletFfiError LogosExecutionZoneWalletModule::create_account_public(FfiBytes32* out_account_id) { + return wallet_ffi_create_account_public(walletHandle, out_account_id); } -WalletFfiError LogosExecutionZoneWalletModule::create_account_private( - WalletHandle* handle, - FfiBytes32* out_account_id -) { - return wallet_ffi_create_account_private(handle, out_account_id); +WalletFfiError LogosExecutionZoneWalletModule::create_account_private(FfiBytes32* out_account_id) { + return wallet_ffi_create_account_private(walletHandle, out_account_id); } -WalletFfiError LogosExecutionZoneWalletModule::list_accounts(WalletHandle* handle, FfiAccountList* out_list) { - return wallet_ffi_list_accounts(handle, out_list); +WalletFfiError LogosExecutionZoneWalletModule::list_accounts(FfiAccountList* out_list) { + return wallet_ffi_list_accounts(walletHandle, out_list); } // === Account Queries === WalletFfiError LogosExecutionZoneWalletModule::get_balance( - WalletHandle* handle, const FfiBytes32* account_id, const bool is_public, QByteArray* out_balance_le16 ) { uint8_t balance[16] = {0}; - const WalletFfiError err = wallet_ffi_get_balance(handle, account_id, is_public, &balance); + const WalletFfiError err = wallet_ffi_get_balance(walletHandle, account_id, is_public, &balance); if (err == SUCCESS && out_balance_le16) { *out_balance_le16 = QByteArray(reinterpret_cast(balance), 16); } @@ -57,35 +59,31 @@ WalletFfiError LogosExecutionZoneWalletModule::get_balance( } WalletFfiError LogosExecutionZoneWalletModule::get_account_public( - WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account ) { - return wallet_ffi_get_account_public(handle, account_id, out_account); + return wallet_ffi_get_account_public(walletHandle, account_id, out_account); } WalletFfiError LogosExecutionZoneWalletModule::get_account_private( - WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account ) { - return wallet_ffi_get_account_private(handle, account_id, out_account); + return wallet_ffi_get_account_private(walletHandle, account_id, out_account); } WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key( - WalletHandle* handle, const FfiBytes32* account_id, FfiPublicAccountKey* out_public_key ) { - return wallet_ffi_get_public_account_key(handle, account_id, out_public_key); + return wallet_ffi_get_public_account_key(walletHandle, account_id, out_public_key); } WalletFfiError LogosExecutionZoneWalletModule::get_private_account_keys( - WalletHandle* handle, const FfiBytes32* account_id, FfiPrivateAccountKeys* out_keys ) { - return wallet_ffi_get_private_account_keys(handle, account_id, out_keys); + return wallet_ffi_get_private_account_keys(walletHandle, account_id, out_keys); } // === Account Encoding === @@ -111,25 +109,21 @@ WalletFfiError LogosExecutionZoneWalletModule::account_id_from_base58( // === Blockchain Synchronisation === -WalletFfiError LogosExecutionZoneWalletModule::sync_to_block(WalletHandle* handle, const uint64_t block_id) { - return wallet_ffi_sync_to_block(handle, block_id); +WalletFfiError LogosExecutionZoneWalletModule::sync_to_block(const uint64_t block_id) { + return wallet_ffi_sync_to_block(walletHandle, block_id); } -WalletFfiError LogosExecutionZoneWalletModule::get_last_synced_block(WalletHandle* handle, uint64_t* out_block_id) { - return wallet_ffi_get_last_synced_block(handle, out_block_id); +WalletFfiError LogosExecutionZoneWalletModule::get_last_synced_block(uint64_t* out_block_id) { + return wallet_ffi_get_last_synced_block(walletHandle, out_block_id); } -WalletFfiError LogosExecutionZoneWalletModule::get_current_block_height( - WalletHandle* handle, - uint64_t* out_block_height -) { - return wallet_ffi_get_current_block_height(handle, out_block_height); +WalletFfiError LogosExecutionZoneWalletModule::get_current_block_height(uint64_t* out_block_height) { + return wallet_ffi_get_current_block_height(walletHandle, out_block_height); } // === Operations === WalletFfiError LogosExecutionZoneWalletModule::transfer_public( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, @@ -143,11 +137,10 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_public( uint8_t amount[16]; memcpy(amount, amount_le16.constData(), 16); - return wallet_ffi_transfer_public(handle, from, to, &amount, out_result); + return wallet_ffi_transfer_public(walletHandle, from, to, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded( - WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys, const QByteArray& amount_le16, @@ -161,11 +154,10 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded( uint8_t amount[16]; memcpy(amount, amount_le16.constData(), 16); - return wallet_ffi_transfer_shielded(handle, from, to_keys, &amount, out_result); + return wallet_ffi_transfer_shielded(walletHandle, from, to_keys, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_deshielded( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, @@ -179,11 +171,10 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_deshielded( uint8_t amount[16]; memcpy(amount, amount_le16.constData(), 16); - return wallet_ffi_transfer_deshielded(handle, from, to, &amount, out_result); + return wallet_ffi_transfer_deshielded(walletHandle, from, to, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_private( - WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys, const QByteArray& amount_le16, @@ -197,11 +188,10 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private( uint8_t amount[16]; memcpy(amount, amount_le16.constData(), 16); - return wallet_ffi_transfer_private(handle, from, to_keys, &amount, out_result); + return wallet_ffi_transfer_private(walletHandle, from, to_keys, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded_owned( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, @@ -215,11 +205,10 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded_owned( uint8_t amount[16]; memcpy(amount, amount_le16.constData(), 16); - return wallet_ffi_transfer_shielded_owned(handle, from, to, &amount, out_result); + return wallet_ffi_transfer_shielded_owned(walletHandle, from, to, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, @@ -233,54 +222,74 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned( uint8_t amount[16]; memcpy(amount, amount_le16.constData(), 16); - return wallet_ffi_transfer_private_owned(handle, from, to, &amount, out_result); + return wallet_ffi_transfer_private_owned(walletHandle, from, to, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::register_public_account( - WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result ) { - return wallet_ffi_register_public_account(handle, account_id, out_result); + return wallet_ffi_register_public_account(walletHandle, account_id, out_result); } WalletFfiError LogosExecutionZoneWalletModule::register_private_account( - WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result ) { - return wallet_ffi_register_private_account(handle, account_id, out_result); + return wallet_ffi_register_private_account(walletHandle, account_id, out_result); } // === Wallet Lifecycle === -WalletHandle* LogosExecutionZoneWalletModule::create_new( +WalletFfiError LogosExecutionZoneWalletModule::create_new( const QString& config_path, const QString& storage_path, const QString& password ) { + if (walletHandle) { + qWarning() << "create_new: wallet is already open"; + return INTERNAL_ERROR; + } + const QByteArray config_utf8 = config_path.toUtf8(); const QByteArray storage_utf8 = storage_path.toUtf8(); const QByteArray password_utf8 = password.toUtf8(); - return wallet_ffi_create_new(config_utf8.constData(), storage_utf8.constData(), password_utf8.constData()); + 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; } -WalletHandle* LogosExecutionZoneWalletModule::open(const QString& config_path, const QString& storage_path) { +WalletFfiError LogosExecutionZoneWalletModule::open(const QString& config_path, const QString& storage_path) { + if (walletHandle) { + qWarning() << "open: wallet is already open"; + return INTERNAL_ERROR; + } + const QByteArray config_utf8 = config_path.toUtf8(); const QByteArray storage_utf8 = storage_path.toUtf8(); - return wallet_ffi_open(config_utf8.constData(), storage_utf8.constData()); + walletHandle = wallet_ffi_open(config_utf8.constData(), storage_utf8.constData()); + if (!walletHandle) { + qWarning() << "open: wallet_ffi_open returned null"; + return INTERNAL_ERROR; + } + + return SUCCESS; } -WalletFfiError LogosExecutionZoneWalletModule::save(WalletHandle* handle) { - return wallet_ffi_save(handle); +WalletFfiError LogosExecutionZoneWalletModule::save() { + return wallet_ffi_save(walletHandle); } // === Configuration === -QString LogosExecutionZoneWalletModule::get_sequencer_addr(WalletHandle* handle) { - char* addr = wallet_ffi_get_sequencer_addr(handle); +QString LogosExecutionZoneWalletModule::get_sequencer_addr() { + char* addr = wallet_ffi_get_sequencer_addr(walletHandle); if (!addr) { return {}; } diff --git a/src/logos_execution_zone_wallet_module.h b/src/logos_execution_zone_wallet_module.h index a769bbd..7092f9d 100644 --- a/src/logos_execution_zone_wallet_module.h +++ b/src/logos_execution_zone_wallet_module.h @@ -14,6 +14,7 @@ class LogosExecutionZoneWalletModule : public QObject, public PluginInterface, p private: LogosAPI* logosApi = nullptr; + WalletHandle* walletHandle = nullptr; public: LogosExecutionZoneWalletModule(); @@ -30,28 +31,25 @@ public: // === Logos Execution Zone Wallet === // Account Management - Q_INVOKABLE WalletFfiError create_account_public(WalletHandle* handle, FfiBytes32* out_account_id) override; - Q_INVOKABLE WalletFfiError create_account_private(WalletHandle* handle, FfiBytes32* out_account_id) override; - Q_INVOKABLE WalletFfiError list_accounts(WalletHandle* handle, FfiAccountList* out_list) override; + Q_INVOKABLE WalletFfiError create_account_public(FfiBytes32* out_account_id) override; + Q_INVOKABLE WalletFfiError create_account_private(FfiBytes32* out_account_id) override; + Q_INVOKABLE WalletFfiError list_accounts(FfiAccountList* out_list) override; // Account Queries Q_INVOKABLE WalletFfiError get_balance( - WalletHandle* handle, const FfiBytes32* account_id, bool is_public, QByteArray* out_balance_le16 ) override; Q_INVOKABLE WalletFfiError - get_account_public(WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account) override; + get_account_public(const FfiBytes32* account_id, FfiAccount* out_account) override; Q_INVOKABLE WalletFfiError - get_account_private(WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account) override; + get_account_private(const FfiBytes32* account_id, FfiAccount* out_account) override; Q_INVOKABLE WalletFfiError get_public_account_key( - WalletHandle* handle, const FfiBytes32* account_id, FfiPublicAccountKey* out_public_key ) override; Q_INVOKABLE WalletFfiError get_private_account_keys( - WalletHandle* handle, const FfiBytes32* account_id, FfiPrivateAccountKeys* out_keys ) override; @@ -61,69 +59,63 @@ public: Q_INVOKABLE WalletFfiError account_id_from_base58(const QString& base58_str, FfiBytes32* out_account_id) override; // Blockchain Synchronisation - Q_INVOKABLE WalletFfiError sync_to_block(WalletHandle* handle, uint64_t block_id) override; - Q_INVOKABLE WalletFfiError get_last_synced_block(WalletHandle* handle, uint64_t* out_block_id) override; - Q_INVOKABLE WalletFfiError get_current_block_height(WalletHandle* handle, uint64_t* out_block_height) override; + Q_INVOKABLE WalletFfiError sync_to_block(uint64_t block_id) override; + Q_INVOKABLE WalletFfiError get_last_synced_block(uint64_t* out_block_id) override; + Q_INVOKABLE WalletFfiError get_current_block_height(uint64_t* out_block_height) override; // Operations Q_INVOKABLE WalletFfiError transfer_public( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_shielded( - WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys, const QByteArray& amount_le16, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_deshielded( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_private( - WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys, const QByteArray& amount_le16, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_shielded_owned( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_private_owned( - WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to, const QByteArray& amount_le16, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError - register_public_account(WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result) override; + register_public_account(const FfiBytes32* account_id, FfiTransferResult* out_result) override; Q_INVOKABLE WalletFfiError - register_private_account(WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result) override; + register_private_account(const FfiBytes32* account_id, FfiTransferResult* out_result) override; // Wallet Lifecycle - Q_INVOKABLE WalletHandle* create_new( + Q_INVOKABLE WalletFfiError create_new( const QString& config_path, const QString& storage_path, const QString& password ) override; - Q_INVOKABLE WalletHandle* open(const QString& config_path, const QString& storage_path) override; - Q_INVOKABLE WalletFfiError save(WalletHandle* handle) override; + Q_INVOKABLE WalletFfiError open(const QString& config_path, const QString& storage_path) override; + Q_INVOKABLE WalletFfiError save() override; // Configuration - Q_INVOKABLE QString get_sequencer_addr(WalletHandle* handle) override; + Q_INVOKABLE QString get_sequencer_addr() override; signals: void eventResponse(const QString& eventName, const QVariantList& data); From 99c861db4b51f35f3fc415bce38028185cd8fc3e Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Wed, 18 Feb 2026 21:23:16 +0100 Subject: [PATCH 3/6] Update bytes-like parameters to hex strings. --- src/i_logos_execution_zone_wallet_module.h | 58 ++--- src/logos_execution_zone_wallet_module.cpp | 262 +++++++++++++++------ src/logos_execution_zone_wallet_module.h | 58 ++--- 3 files changed, 251 insertions(+), 127 deletions(-) diff --git a/src/i_logos_execution_zone_wallet_module.h b/src/i_logos_execution_zone_wallet_module.h index 8edc0b6..97960c7 100644 --- a/src/i_logos_execution_zone_wallet_module.h +++ b/src/i_logos_execution_zone_wallet_module.h @@ -22,36 +22,36 @@ public: // === Logos Execution Zone Wallet === // Account Management - virtual WalletFfiError create_account_public(FfiBytes32* out_account_id) = 0; - virtual WalletFfiError create_account_private(FfiBytes32* out_account_id) = 0; + virtual WalletFfiError create_account_public(QString& out_account_id_hex) = 0; + virtual WalletFfiError create_account_private(QString& out_account_id_hex) = 0; virtual WalletFfiError list_accounts(FfiAccountList* out_list) = 0; // Account Queries virtual WalletFfiError get_balance( - const FfiBytes32* account_id, + const QString& account_id_hex, bool is_public, - QByteArray* out_balance_le16 + QString& out_balance_le16_hex ) = 0; virtual WalletFfiError get_account_public( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiAccount* out_account ) = 0; virtual WalletFfiError get_account_private( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiAccount* out_account ) = 0; virtual WalletFfiError get_public_account_key( - const FfiBytes32* account_id, - FfiPublicAccountKey* out_public_key + const QString& account_id_hex, + QString& out_public_key_hex ) = 0; virtual WalletFfiError get_private_account_keys( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiPrivateAccountKeys* out_keys ) = 0; // Account Encoding - virtual QString account_id_to_base58(const FfiBytes32* account_id) = 0; - virtual WalletFfiError account_id_from_base58(const QString& base58_str, FfiBytes32* out_account_id) = 0; + virtual QString account_id_to_base58(const QString& account_id_hex) = 0; + virtual WalletFfiError account_id_from_base58(const QString& base58_str, QString& out_account_id_hex) = 0; // Blockchain Synchronisation virtual WalletFfiError sync_to_block(uint64_t block_id) = 0; @@ -60,47 +60,47 @@ public: // Operations virtual WalletFfiError transfer_public( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_shielded( - const FfiBytes32* from, + const QString& from_hex, const FfiPrivateAccountKeys* to_keys, - const QByteArray& amount_le16, + const QString& amount_le16_hex, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_deshielded( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_private( - const FfiBytes32* from, + const QString& from_hex, const FfiPrivateAccountKeys* to_keys, - const QByteArray& amount_le16, + const QString& amount_le16_hex, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_shielded_owned( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) = 0; virtual WalletFfiError transfer_private_owned( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) = 0; virtual WalletFfiError register_public_account( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiTransferResult* out_result ) = 0; virtual WalletFfiError register_private_account( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiTransferResult* out_result ) = 0; diff --git a/src/logos_execution_zone_wallet_module.cpp b/src/logos_execution_zone_wallet_module.cpp index 8e182e1..9994f8f 100644 --- a/src/logos_execution_zone_wallet_module.cpp +++ b/src/logos_execution_zone_wallet_module.cpp @@ -1,6 +1,42 @@ #include "logos_execution_zone_wallet_module.h" #include +#include +#include + +static QString bytesToHex(const uint8_t* data, const size_t length) { + const QByteArray bytearray(reinterpret_cast(data), static_cast(length)); + return QString::fromLatin1(bytearray.toHex()); +} + +static bool hexToBytes(const QString& hex, QByteArray& output_bytes, int expectedLength = -1) { + QString trimmed_hex = hex.trimmed(); + if (trimmed_hex.startsWith("0x", Qt::CaseInsensitive)) trimmed_hex = trimmed_hex.mid(2); + if (trimmed_hex.size() % 2 != 0) return false; + const QByteArray decoded = QByteArray::fromHex(trimmed_hex.toLatin1()); + if (expectedLength != -1 && decoded.size() != expectedLength) return false; + output_bytes = decoded; + return true; +} + +static bool hexToU128(const QString& hex, uint8_t (*output)[16]) { + QByteArray buffer; + if (!hexToBytes(hex, buffer, 16)) return false; + memcpy(output, buffer.constData(), 16); + return true; +} + +static QString bytes32ToHex(const FfiBytes32& bytes) { + return bytesToHex(bytes.data, 32); +} + +static bool hexToBytes32(const QString& hex, FfiBytes32* output_bytes) { + if (output_bytes == nullptr) return false; + QByteArray buffer; + if (!hexToBytes(hex, buffer, 32)) return false; + memcpy(output_bytes->data, buffer.constData(), 32); + return true; +} LogosExecutionZoneWalletModule::LogosExecutionZoneWalletModule() = default; @@ -29,12 +65,22 @@ void LogosExecutionZoneWalletModule::initLogos(LogosAPI* logosApiInstance) { // === Account Management === -WalletFfiError LogosExecutionZoneWalletModule::create_account_public(FfiBytes32* out_account_id) { - return wallet_ffi_create_account_public(walletHandle, out_account_id); +WalletFfiError LogosExecutionZoneWalletModule::create_account_public(QString& out_account_id_hex) { + FfiBytes32 id{}; + const WalletFfiError error = wallet_ffi_create_account_public(walletHandle, &id); + if (error == SUCCESS) { + out_account_id_hex = bytes32ToHex(id); + } + return error; } -WalletFfiError LogosExecutionZoneWalletModule::create_account_private(FfiBytes32* out_account_id) { - return wallet_ffi_create_account_private(walletHandle, out_account_id); +WalletFfiError LogosExecutionZoneWalletModule::create_account_private(QString& out_account_id_hex) { + FfiBytes32 id{}; + const WalletFfiError error = wallet_ffi_create_account_private(walletHandle, &id); + if (error == SUCCESS) { + out_account_id_hex = bytes32ToHex(id); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::list_accounts(FfiAccountList* out_list) { @@ -44,52 +90,81 @@ WalletFfiError LogosExecutionZoneWalletModule::list_accounts(FfiAccountList* out // === Account Queries === WalletFfiError LogosExecutionZoneWalletModule::get_balance( - const FfiBytes32* account_id, + const QString& account_id_hex, const bool is_public, - QByteArray* out_balance_le16 + QString& out_balance_le16_hex ) { - uint8_t balance[16] = {0}; - - const WalletFfiError err = wallet_ffi_get_balance(walletHandle, account_id, is_public, &balance); - if (err == SUCCESS && out_balance_le16) { - *out_balance_le16 = QByteArray(reinterpret_cast(balance), 16); + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return INVALID_ACCOUNT_ID; } - return err; + uint8_t balance[16] = {0}; + const WalletFfiError error = wallet_ffi_get_balance(walletHandle, &id, is_public, &balance); + if (error == SUCCESS) { + out_balance_le16_hex = bytesToHex(balance, 16); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::get_account_public( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiAccount* out_account ) { - return wallet_ffi_get_account_public(walletHandle, account_id, out_account); + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return INVALID_ACCOUNT_ID; + } + return wallet_ffi_get_account_public(walletHandle, &id, out_account); } WalletFfiError LogosExecutionZoneWalletModule::get_account_private( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiAccount* out_account ) { - return wallet_ffi_get_account_private(walletHandle, account_id, out_account); + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return INVALID_ACCOUNT_ID; + } + return wallet_ffi_get_account_private(walletHandle, &id, out_account); } WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key( - const FfiBytes32* account_id, - FfiPublicAccountKey* out_public_key + const QString& account_id_hex, + QString& out_public_key_hex ) { - return wallet_ffi_get_public_account_key(walletHandle, account_id, out_public_key); + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return INVALID_ACCOUNT_ID; + } + FfiPublicAccountKey key{}; + const WalletFfiError error = wallet_ffi_get_public_account_key(walletHandle, &id, &key); + if (error == SUCCESS) { + out_public_key_hex = bytes32ToHex(key.public_key); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::get_private_account_keys( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiPrivateAccountKeys* out_keys ) { - return wallet_ffi_get_private_account_keys(walletHandle, account_id, out_keys); + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return INVALID_ACCOUNT_ID; + } + return wallet_ffi_get_private_account_keys(walletHandle, &id, out_keys); } // === Account Encoding === -QString LogosExecutionZoneWalletModule::account_id_to_base58(const FfiBytes32* account_id) { - char* str = wallet_ffi_account_id_to_base58(account_id); +QString LogosExecutionZoneWalletModule::account_id_to_base58(const QString& account_id_hex) { + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return {}; + } + + char* str = wallet_ffi_account_id_to_base58(&id); if (!str) { return {}; } @@ -101,10 +176,15 @@ QString LogosExecutionZoneWalletModule::account_id_to_base58(const FfiBytes32* a WalletFfiError LogosExecutionZoneWalletModule::account_id_from_base58( const QString& base58_str, - FfiBytes32* out_account_id + QString& out_account_id_hex ) { + FfiBytes32 id{}; const QByteArray utf8 = base58_str.toUtf8(); - return wallet_ffi_account_id_from_base58(utf8.constData(), out_account_id); + const WalletFfiError error = wallet_ffi_account_id_from_base58(utf8.constData(), &id); + if (error == SUCCESS) { + out_account_id_hex = bytes32ToHex(id); + } + return error; } // === Blockchain Synchronisation === @@ -124,119 +204,163 @@ WalletFfiError LogosExecutionZoneWalletModule::get_current_block_height(uint64_t // === Operations === WalletFfiError LogosExecutionZoneWalletModule::transfer_public( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) { - if (amount_le16.size() != 16) { - qWarning() << "transfer_public: amount_le16 must be 16 bytes"; + FfiBytes32 fromId{}, toId{}; + if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { + return INVALID_ACCOUNT_ID; + } + + QByteArray amount_byte_array; + if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + qWarning() << "transfer_public: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_le16.constData(), 16); + memcpy(amount, amount_byte_array.constData(), 16); - return wallet_ffi_transfer_public(walletHandle, from, to, &amount, out_result); + return wallet_ffi_transfer_public(walletHandle, &fromId, &toId, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded( - const FfiBytes32* from, + const QString& from_hex, const FfiPrivateAccountKeys* to_keys, - const QByteArray& amount_le16, + const QString& amount_le16_hex, FfiTransferResult* out_result ) { - if (amount_le16.size() != 16) { - qWarning() << "transfer_shielded: amount_le16 must be 16 bytes"; + FfiBytes32 fromId{}; + if (!hexToBytes32(from_hex, &fromId)) { + return INVALID_ACCOUNT_ID; + } + + QByteArray amount_byte_array; + if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + qWarning() << "transfer_shielded: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_le16.constData(), 16); + memcpy(amount, amount_byte_array.constData(), 16); - return wallet_ffi_transfer_shielded(walletHandle, from, to_keys, &amount, out_result); + return wallet_ffi_transfer_shielded(walletHandle, &fromId, to_keys, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_deshielded( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) { - if (amount_le16.size() != 16) { - qWarning() << "transfer_deshielded: amount_le16 must be 16 bytes"; + FfiBytes32 fromId{}, toId{}; + if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { + return INVALID_ACCOUNT_ID; + } + + QByteArray amount_byte_array; + if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + qWarning() << "transfer_deshielded: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_le16.constData(), 16); + memcpy(amount, amount_byte_array.constData(), 16); - return wallet_ffi_transfer_deshielded(walletHandle, from, to, &amount, out_result); + return wallet_ffi_transfer_deshielded(walletHandle, &fromId, &toId, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_private( - const FfiBytes32* from, + const QString& from_hex, const FfiPrivateAccountKeys* to_keys, - const QByteArray& amount_le16, + const QString& amount_le16_hex, FfiTransferResult* out_result ) { - if (amount_le16.size() != 16) { - qWarning() << "transfer_private: amount_le16 must be 16 bytes"; + FfiBytes32 fromId{}; + if (!hexToBytes32(from_hex, &fromId)) { + return INVALID_ACCOUNT_ID; + } + + QByteArray amount_byte_array; + if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + qWarning() << "transfer_private: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_le16.constData(), 16); + memcpy(amount, amount_byte_array.constData(), 16); - return wallet_ffi_transfer_private(walletHandle, from, to_keys, &amount, out_result); + return wallet_ffi_transfer_private(walletHandle, &fromId, to_keys, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded_owned( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) { - if (amount_le16.size() != 16) { - qWarning() << "transfer_shielded_owned: amount_le16 must be 16 bytes"; + FfiBytes32 fromId{}, toId{}; + if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { + return INVALID_ACCOUNT_ID; + } + + QByteArray amount_byte_array; + if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + qWarning() << "transfer_shielded_owned: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_le16.constData(), 16); + memcpy(amount, amount_byte_array.constData(), 16); - return wallet_ffi_transfer_shielded_owned(walletHandle, from, to, &amount, out_result); + return wallet_ffi_transfer_shielded_owned(walletHandle, &fromId, &toId, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) { - if (amount_le16.size() != 16) { - qWarning() << "transfer_private_owned: amount_le16 must be 16 bytes"; + FfiBytes32 fromId{}, toId{}; + if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { + return INVALID_ACCOUNT_ID; + } + + QByteArray amount_byte_array; + if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + qWarning() << "transfer_private_owned: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_le16.constData(), 16); + memcpy(amount, amount_byte_array.constData(), 16); - return wallet_ffi_transfer_private_owned(walletHandle, from, to, &amount, out_result); + return wallet_ffi_transfer_private_owned(walletHandle, &fromId, &toId, &amount, out_result); } WalletFfiError LogosExecutionZoneWalletModule::register_public_account( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiTransferResult* out_result ) { - return wallet_ffi_register_public_account(walletHandle, account_id, out_result); + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return INVALID_ACCOUNT_ID; + } + return wallet_ffi_register_public_account(walletHandle, &id, out_result); } WalletFfiError LogosExecutionZoneWalletModule::register_private_account( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiTransferResult* out_result ) { - return wallet_ffi_register_private_account(walletHandle, account_id, out_result); + FfiBytes32 id{}; + if (!hexToBytes32(account_id_hex, &id)) { + return INVALID_ACCOUNT_ID; + } + return wallet_ffi_register_private_account(walletHandle, &id, out_result); } // === Wallet Lifecycle === diff --git a/src/logos_execution_zone_wallet_module.h b/src/logos_execution_zone_wallet_module.h index 7092f9d..ab3e431 100644 --- a/src/logos_execution_zone_wallet_module.h +++ b/src/logos_execution_zone_wallet_module.h @@ -31,32 +31,32 @@ public: // === Logos Execution Zone Wallet === // Account Management - Q_INVOKABLE WalletFfiError create_account_public(FfiBytes32* out_account_id) override; - Q_INVOKABLE WalletFfiError create_account_private(FfiBytes32* out_account_id) override; + Q_INVOKABLE WalletFfiError create_account_public(QString& out_account_id_hex) override; + Q_INVOKABLE WalletFfiError create_account_private(QString& out_account_id_hex) override; Q_INVOKABLE WalletFfiError list_accounts(FfiAccountList* out_list) override; // Account Queries Q_INVOKABLE WalletFfiError get_balance( - const FfiBytes32* account_id, + const QString& account_id_hex, bool is_public, - QByteArray* out_balance_le16 + QString& out_balance_le16_hex ) override; Q_INVOKABLE WalletFfiError - get_account_public(const FfiBytes32* account_id, FfiAccount* out_account) override; + get_account_public(const QString& account_id_hex, FfiAccount* out_account) override; Q_INVOKABLE WalletFfiError - get_account_private(const FfiBytes32* account_id, FfiAccount* out_account) override; + get_account_private(const QString& account_id_hex, FfiAccount* out_account) override; Q_INVOKABLE WalletFfiError get_public_account_key( - const FfiBytes32* account_id, - FfiPublicAccountKey* out_public_key + const QString& account_id_hex, + QString& out_public_key_hex ) override; Q_INVOKABLE WalletFfiError get_private_account_keys( - const FfiBytes32* account_id, + const QString& account_id_hex, FfiPrivateAccountKeys* out_keys ) override; // Account Encoding - Q_INVOKABLE QString account_id_to_base58(const FfiBytes32* account_id) override; - Q_INVOKABLE WalletFfiError account_id_from_base58(const QString& base58_str, FfiBytes32* out_account_id) override; + Q_INVOKABLE QString account_id_to_base58(const QString& account_id_hex) override; + Q_INVOKABLE WalletFfiError account_id_from_base58(const QString& base58_str, QString& out_account_id_hex) override; // Blockchain Synchronisation Q_INVOKABLE WalletFfiError sync_to_block(uint64_t block_id) override; @@ -65,45 +65,45 @@ public: // Operations Q_INVOKABLE WalletFfiError transfer_public( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_shielded( - const FfiBytes32* from, + const QString& from_hex, const FfiPrivateAccountKeys* to_keys, - const QByteArray& amount_le16, + const QString& amount_le16_hex, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_deshielded( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_private( - const FfiBytes32* from, + const QString& from_hex, const FfiPrivateAccountKeys* to_keys, - const QByteArray& amount_le16, + const QString& amount_le16_hex, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_shielded_owned( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError transfer_private_owned( - const FfiBytes32* from, - const FfiBytes32* to, - const QByteArray& amount_le16, + const QString& from_hex, + const QString& to_hex, + const QString& amount_le16_hex, FfiTransferResult* out_result ) override; Q_INVOKABLE WalletFfiError - register_public_account(const FfiBytes32* account_id, FfiTransferResult* out_result) override; + register_public_account(const QString& account_id_hex, FfiTransferResult* out_result) override; Q_INVOKABLE WalletFfiError - register_private_account(const FfiBytes32* account_id, FfiTransferResult* out_result) override; + register_private_account(const QString& account_id_hex, FfiTransferResult* out_result) override; // Wallet Lifecycle Q_INVOKABLE WalletFfiError create_new( From 4609ae0bb1b631a5ca26d6758c240641b8f50836 Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Wed, 18 Feb 2026 22:10:38 +0100 Subject: [PATCH 4/6] Update complex types to json types. --- src/i_logos_execution_zone_wallet_module.h | 28 +-- src/logos_execution_zone_wallet_module.cpp | 258 ++++++++++++++++----- src/logos_execution_zone_wallet_module.h | 28 +-- 3 files changed, 232 insertions(+), 82 deletions(-) diff --git a/src/i_logos_execution_zone_wallet_module.h b/src/i_logos_execution_zone_wallet_module.h index 97960c7..590ac60 100644 --- a/src/i_logos_execution_zone_wallet_module.h +++ b/src/i_logos_execution_zone_wallet_module.h @@ -24,7 +24,7 @@ public: // Account Management virtual WalletFfiError create_account_public(QString& out_account_id_hex) = 0; virtual WalletFfiError create_account_private(QString& out_account_id_hex) = 0; - virtual WalletFfiError list_accounts(FfiAccountList* out_list) = 0; + virtual WalletFfiError list_accounts(QJsonArray& out_list) = 0; // Account Queries virtual WalletFfiError get_balance( @@ -34,11 +34,11 @@ public: ) = 0; virtual WalletFfiError get_account_public( const QString& account_id_hex, - FfiAccount* out_account + QString& out_account_json ) = 0; virtual WalletFfiError get_account_private( const QString& account_id_hex, - FfiAccount* out_account + QString& out_account_json ) = 0; virtual WalletFfiError get_public_account_key( const QString& account_id_hex, @@ -46,7 +46,7 @@ public: ) = 0; virtual WalletFfiError get_private_account_keys( const QString& account_id_hex, - FfiPrivateAccountKeys* out_keys + QString& out_keys_json ) = 0; // Account Encoding @@ -63,45 +63,45 @@ public: const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; virtual WalletFfiError transfer_shielded( const QString& from_hex, - const FfiPrivateAccountKeys* to_keys, + const QString& to_keys_json, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; virtual WalletFfiError transfer_deshielded( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; virtual WalletFfiError transfer_private( const QString& from_hex, - const FfiPrivateAccountKeys* to_keys, + const QString& to_keys_json, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; virtual WalletFfiError transfer_shielded_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; virtual WalletFfiError transfer_private_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; virtual WalletFfiError register_public_account( const QString& account_id_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; virtual WalletFfiError register_private_account( const QString& account_id_hex, - FfiTransferResult* out_result + QString& out_result_json ) = 0; // Wallet Lifecycle diff --git a/src/logos_execution_zone_wallet_module.cpp b/src/logos_execution_zone_wallet_module.cpp index 9994f8f..58075ce 100644 --- a/src/logos_execution_zone_wallet_module.cpp +++ b/src/logos_execution_zone_wallet_module.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include #include static QString bytesToHex(const uint8_t* data, const size_t length) { @@ -9,6 +11,19 @@ static QString bytesToHex(const uint8_t* data, const size_t length) { return QString::fromLatin1(bytearray.toHex()); } +namespace JsonKeys { + static constexpr auto TxHash = "tx_hash"; + static constexpr auto Success = "success"; + static constexpr auto ProgramOwner = "program_owner"; + static constexpr auto Balance = "balance"; + static constexpr auto Nonce = "nonce"; + static constexpr auto Data = "data"; + static constexpr auto NullifierPublicKey = "nullifier_public_key"; + static constexpr auto ViewingPublicKey = "viewing_public_key"; + static constexpr auto AccountId = "account_id"; + static constexpr auto IsPublic = "is_public"; +} + static bool hexToBytes(const QString& hex, QByteArray& output_bytes, int expectedLength = -1) { QString trimmed_hex = hex.trimmed(); if (trimmed_hex.startsWith("0x", Qt::CaseInsensitive)) trimmed_hex = trimmed_hex.mid(2); @@ -38,6 +53,69 @@ static bool hexToBytes32(const QString& hex, FfiBytes32* output_bytes) { return true; } +static QString ffiTransferResultToJson(const FfiTransferResult& result) { + QVariantMap map; + map[JsonKeys::TxHash] = result.tx_hash ? QString::fromUtf8(result.tx_hash) : QString(); + map[JsonKeys::Success] = result.success; + return QJsonDocument(QJsonObject::fromVariantMap(map)).toJson(QJsonDocument::Compact); +} + +static QString ffiAccountToJson(const FfiAccount& account) { + QVariantMap map; + map[JsonKeys::ProgramOwner] = bytesToHex(reinterpret_cast(account.program_owner.data), 32); + map[JsonKeys::Balance] = bytesToHex(account.balance.data, 16); + map[JsonKeys::Nonce] = bytesToHex(account.nonce.data, 16); + if (account.data && account.data_len > 0) { + map[JsonKeys::Data] = bytesToHex(account.data, account.data_len); + } else { + map[JsonKeys::Data] = QString(); + } + return QJsonDocument(QJsonObject::fromVariantMap(map)).toJson(QJsonDocument::Compact); +} + +static QJsonObject ffiAccountListEntryToJson(const FfiAccountListEntry& entry) { + QVariantMap map; + map[JsonKeys::AccountId] = bytes32ToHex(entry.account_id); + map[JsonKeys::IsPublic] = entry.is_public; + return QJsonObject::fromVariantMap(map); +} + +static QString ffiPrivateAccountKeysToJson(const FfiPrivateAccountKeys& keys) { + QVariantMap map; + map[JsonKeys::NullifierPublicKey] = bytes32ToHex(keys.nullifier_public_key); + if (keys.viewing_public_key && keys.viewing_public_key_len > 0) { + map[JsonKeys::ViewingPublicKey] = bytesToHex(keys.viewing_public_key, keys.viewing_public_key_len); + } else { + map[JsonKeys::ViewingPublicKey] = QString(); + } + return QJsonDocument(QJsonObject::fromVariantMap(map)).toJson(QJsonDocument::Compact); +} + +static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKeys* out_keys) { + QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); + if (!doc.isObject()) return false; + const QVariantMap map = doc.object().toVariantMap(); + + if (map.contains(JsonKeys::NullifierPublicKey)) { + if (!hexToBytes32(map[JsonKeys::NullifierPublicKey].toString(), &out_keys->nullifier_public_key)) return false; + } + + if (map.contains(JsonKeys::ViewingPublicKey)) { + QByteArray buffer; + if (!hexToBytes(map[JsonKeys::ViewingPublicKey].toString(), buffer)) return false; + + uint8_t* data = static_cast(malloc(buffer.size())); + memcpy(data, buffer.constData(), buffer.size()); + out_keys->viewing_public_key = data; + out_keys->viewing_public_key_len = buffer.size(); + } else { + out_keys->viewing_public_key = nullptr; + out_keys->viewing_public_key_len = 0; + } + + return true; +} + LogosExecutionZoneWalletModule::LogosExecutionZoneWalletModule() = default; LogosExecutionZoneWalletModule::~LogosExecutionZoneWalletModule() { @@ -83,8 +161,16 @@ WalletFfiError LogosExecutionZoneWalletModule::create_account_private(QString& o return error; } -WalletFfiError LogosExecutionZoneWalletModule::list_accounts(FfiAccountList* out_list) { - return wallet_ffi_list_accounts(walletHandle, out_list); +WalletFfiError LogosExecutionZoneWalletModule::list_accounts(QJsonArray& out_list) { + FfiAccountList list{}; + const WalletFfiError error = wallet_ffi_list_accounts(walletHandle, &list); + if (error == SUCCESS) { + for (uintptr_t i = 0; i < list.count; ++i) { + out_list.append(ffiAccountListEntryToJson(list.entries[i])); + } + wallet_ffi_free_account_list(&list); + } + return error; } // === Account Queries === @@ -109,24 +195,36 @@ WalletFfiError LogosExecutionZoneWalletModule::get_balance( WalletFfiError LogosExecutionZoneWalletModule::get_account_public( const QString& account_id_hex, - FfiAccount* out_account + QString& out_account_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { return INVALID_ACCOUNT_ID; } - return wallet_ffi_get_account_public(walletHandle, &id, out_account); + FfiAccount account{}; + const WalletFfiError error = wallet_ffi_get_account_public(walletHandle, &id, &account); + if (error == SUCCESS) { + out_account_json = ffiAccountToJson(account); + wallet_ffi_free_account_data(&account); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::get_account_private( const QString& account_id_hex, - FfiAccount* out_account + QString& out_account_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { return INVALID_ACCOUNT_ID; } - return wallet_ffi_get_account_private(walletHandle, &id, out_account); + FfiAccount account{}; + const WalletFfiError error = wallet_ffi_get_account_private(walletHandle, &id, &account); + if (error == SUCCESS) { + out_account_json = ffiAccountToJson(account); + wallet_ffi_free_account_data(&account); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key( @@ -147,13 +245,19 @@ WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key( WalletFfiError LogosExecutionZoneWalletModule::get_private_account_keys( const QString& account_id_hex, - FfiPrivateAccountKeys* out_keys + QString& out_keys_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { return INVALID_ACCOUNT_ID; } - return wallet_ffi_get_private_account_keys(walletHandle, &id, out_keys); + FfiPrivateAccountKeys keys{}; + const WalletFfiError error = wallet_ffi_get_private_account_keys(walletHandle, &id, &keys); + if (error == SUCCESS) { + out_keys_json = ffiPrivateAccountKeysToJson(keys); + wallet_ffi_free_private_account_keys(&keys); + } + return error; } // === Account Encoding === @@ -207,160 +311,206 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_public( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { return INVALID_ACCOUNT_ID; } - QByteArray amount_byte_array; - if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + uint8_t amount[16]; + if (!hexToU128(amount_le16_hex, &amount)) { qWarning() << "transfer_public: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } - uint8_t amount[16]; - memcpy(amount, amount_byte_array.constData(), 16); - - return wallet_ffi_transfer_public(walletHandle, &fromId, &toId, &amount, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_transfer_public(walletHandle, &fromId, &toId, &amount, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded( const QString& from_hex, - const FfiPrivateAccountKeys* to_keys, + const QString& to_keys_json, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 fromId{}; if (!hexToBytes32(from_hex, &fromId)) { return INVALID_ACCOUNT_ID; } - QByteArray amount_byte_array; - if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { - qWarning() << "transfer_shielded: amount_le16_hex must be 32 hex characters (16 bytes)"; + FfiPrivateAccountKeys toKeys{}; + if (!jsonToFfiPrivateAccountKeys(to_keys_json, &toKeys)) { return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_byte_array.constData(), 16); + if (!hexToU128(amount_le16_hex, &amount)) { + qWarning() << "transfer_shielded: amount_le16_hex must be 32 hex characters (16 bytes)"; + free(const_cast(toKeys.viewing_public_key)); + return SERIALIZATION_ERROR; + } - return wallet_ffi_transfer_shielded(walletHandle, &fromId, to_keys, &amount, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_transfer_shielded(walletHandle, &fromId, &toKeys, &amount, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + + free(const_cast(toKeys.viewing_public_key)); + return error; } WalletFfiError LogosExecutionZoneWalletModule::transfer_deshielded( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { return INVALID_ACCOUNT_ID; } - QByteArray amount_byte_array; - if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + uint8_t amount[16]; + if (!hexToU128(amount_le16_hex, &amount)) { qWarning() << "transfer_deshielded: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } - uint8_t amount[16]; - memcpy(amount, amount_byte_array.constData(), 16); - - return wallet_ffi_transfer_deshielded(walletHandle, &fromId, &toId, &amount, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_transfer_deshielded(walletHandle, &fromId, &toId, &amount, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::transfer_private( const QString& from_hex, - const FfiPrivateAccountKeys* to_keys, + const QString& to_keys_json, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 fromId{}; if (!hexToBytes32(from_hex, &fromId)) { return INVALID_ACCOUNT_ID; } - QByteArray amount_byte_array; - if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { - qWarning() << "transfer_private: amount_le16_hex must be 32 hex characters (16 bytes)"; + FfiPrivateAccountKeys toKeys{}; + if (!jsonToFfiPrivateAccountKeys(to_keys_json, &toKeys)) { return SERIALIZATION_ERROR; } uint8_t amount[16]; - memcpy(amount, amount_byte_array.constData(), 16); + if (!hexToU128(amount_le16_hex, &amount)) { + qWarning() << "transfer_private: amount_le16_hex must be 32 hex characters (16 bytes)"; + free(const_cast(toKeys.viewing_public_key)); + return SERIALIZATION_ERROR; + } - return wallet_ffi_transfer_private(walletHandle, &fromId, to_keys, &amount, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_transfer_private(walletHandle, &fromId, &toKeys, &amount, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + + free(const_cast(toKeys.viewing_public_key)); + return error; } WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { return INVALID_ACCOUNT_ID; } - QByteArray amount_byte_array; - if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + uint8_t amount[16]; + if (!hexToU128(amount_le16_hex, &amount)) { qWarning() << "transfer_shielded_owned: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } - uint8_t amount[16]; - memcpy(amount, amount_byte_array.constData(), 16); - - return wallet_ffi_transfer_shielded_owned(walletHandle, &fromId, &toId, &amount, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_transfer_shielded_owned(walletHandle, &fromId, &toId, &amount, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { return INVALID_ACCOUNT_ID; } - QByteArray amount_byte_array; - if (!hexToBytes(amount_le16_hex, amount_byte_array, 16)) { + uint8_t amount[16]; + if (!hexToU128(amount_le16_hex, &amount)) { qWarning() << "transfer_private_owned: amount_le16_hex must be 32 hex characters (16 bytes)"; return SERIALIZATION_ERROR; } - uint8_t amount[16]; - memcpy(amount, amount_byte_array.constData(), 16); - - return wallet_ffi_transfer_private_owned(walletHandle, &fromId, &toId, &amount, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_transfer_private_owned(walletHandle, &fromId, &toId, &amount, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::register_public_account( const QString& account_id_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { return INVALID_ACCOUNT_ID; } - return wallet_ffi_register_public_account(walletHandle, &id, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_register_public_account(walletHandle, &id, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + return error; } WalletFfiError LogosExecutionZoneWalletModule::register_private_account( const QString& account_id_hex, - FfiTransferResult* out_result + QString& out_result_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { return INVALID_ACCOUNT_ID; } - return wallet_ffi_register_private_account(walletHandle, &id, out_result); + FfiTransferResult result{}; + const WalletFfiError error = wallet_ffi_register_private_account(walletHandle, &id, &result); + if (error == SUCCESS) { + out_result_json = ffiTransferResultToJson(result); + wallet_ffi_free_transfer_result(&result); + } + return error; } // === Wallet Lifecycle === diff --git a/src/logos_execution_zone_wallet_module.h b/src/logos_execution_zone_wallet_module.h index ab3e431..dbcabb3 100644 --- a/src/logos_execution_zone_wallet_module.h +++ b/src/logos_execution_zone_wallet_module.h @@ -33,7 +33,7 @@ public: // Account Management Q_INVOKABLE WalletFfiError create_account_public(QString& out_account_id_hex) override; Q_INVOKABLE WalletFfiError create_account_private(QString& out_account_id_hex) override; - Q_INVOKABLE WalletFfiError list_accounts(FfiAccountList* out_list) override; + Q_INVOKABLE WalletFfiError list_accounts(QJsonArray& out_list) override; // Account Queries Q_INVOKABLE WalletFfiError get_balance( @@ -42,16 +42,16 @@ public: QString& out_balance_le16_hex ) override; Q_INVOKABLE WalletFfiError - get_account_public(const QString& account_id_hex, FfiAccount* out_account) override; + get_account_public(const QString& account_id_hex, QString& out_account_json) override; Q_INVOKABLE WalletFfiError - get_account_private(const QString& account_id_hex, FfiAccount* out_account) override; + get_account_private(const QString& account_id_hex, QString& out_account_json) override; Q_INVOKABLE WalletFfiError get_public_account_key( const QString& account_id_hex, QString& out_public_key_hex ) override; Q_INVOKABLE WalletFfiError get_private_account_keys( const QString& account_id_hex, - FfiPrivateAccountKeys* out_keys + QString& out_keys_json ) override; // Account Encoding @@ -68,42 +68,42 @@ public: const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) override; Q_INVOKABLE WalletFfiError transfer_shielded( const QString& from_hex, - const FfiPrivateAccountKeys* to_keys, + const QString& to_keys_json, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) override; Q_INVOKABLE WalletFfiError transfer_deshielded( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) override; Q_INVOKABLE WalletFfiError transfer_private( const QString& from_hex, - const FfiPrivateAccountKeys* to_keys, + const QString& to_keys_json, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) override; Q_INVOKABLE WalletFfiError transfer_shielded_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) override; Q_INVOKABLE WalletFfiError transfer_private_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - FfiTransferResult* out_result + QString& out_result_json ) override; Q_INVOKABLE WalletFfiError - register_public_account(const QString& account_id_hex, FfiTransferResult* out_result) override; + register_public_account(const QString& account_id_hex, QString& out_result_json) override; Q_INVOKABLE WalletFfiError - register_private_account(const QString& account_id_hex, FfiTransferResult* out_result) override; + register_private_account(const QString& account_id_hex, QString& out_result_json) override; // Wallet Lifecycle Q_INVOKABLE WalletFfiError create_new( From 8dddebc7a84d11b4c2c51d735be0f7d156b3a7a3 Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Wed, 18 Feb 2026 22:18:10 +0100 Subject: [PATCH 5/6] Rename out_ to output_ prefixes. --- src/i_logos_execution_zone_wallet_module.h | 38 +++++----- src/logos_execution_zone_wallet_module.cpp | 88 +++++++++++----------- src/logos_execution_zone_wallet_module.h | 38 +++++----- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/i_logos_execution_zone_wallet_module.h b/src/i_logos_execution_zone_wallet_module.h index 590ac60..cce5132 100644 --- a/src/i_logos_execution_zone_wallet_module.h +++ b/src/i_logos_execution_zone_wallet_module.h @@ -22,86 +22,86 @@ public: // === Logos Execution Zone Wallet === // Account Management - virtual WalletFfiError create_account_public(QString& out_account_id_hex) = 0; - virtual WalletFfiError create_account_private(QString& out_account_id_hex) = 0; - virtual WalletFfiError list_accounts(QJsonArray& out_list) = 0; + virtual WalletFfiError create_account_public(QString& output_account_id_hex) = 0; + virtual WalletFfiError create_account_private(QString& output_account_id_hex) = 0; + virtual WalletFfiError list_accounts(QJsonArray& output_list) = 0; // Account Queries virtual WalletFfiError get_balance( const QString& account_id_hex, bool is_public, - QString& out_balance_le16_hex + QString& output_balance_le16_hex ) = 0; virtual WalletFfiError get_account_public( const QString& account_id_hex, - QString& out_account_json + QString& output_account_json ) = 0; virtual WalletFfiError get_account_private( const QString& account_id_hex, - QString& out_account_json + QString& output_account_json ) = 0; virtual WalletFfiError get_public_account_key( const QString& account_id_hex, - QString& out_public_key_hex + QString& output_public_key_hex ) = 0; virtual WalletFfiError get_private_account_keys( const QString& account_id_hex, - QString& out_keys_json + QString& output_keys_json ) = 0; // Account Encoding virtual QString account_id_to_base58(const QString& account_id_hex) = 0; - virtual WalletFfiError account_id_from_base58(const QString& base58_str, QString& out_account_id_hex) = 0; + virtual WalletFfiError account_id_from_base58(const QString& base58_str, QString& output_account_id_hex) = 0; // Blockchain Synchronisation virtual WalletFfiError sync_to_block(uint64_t block_id) = 0; - virtual WalletFfiError get_last_synced_block(uint64_t* out_block_id) = 0; - virtual WalletFfiError get_current_block_height(uint64_t* out_block_height) = 0; + virtual WalletFfiError get_last_synced_block(uint64_t* output_block_id) = 0; + virtual WalletFfiError get_current_block_height(uint64_t* output_block_height) = 0; // Operations virtual WalletFfiError transfer_public( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) = 0; virtual WalletFfiError transfer_shielded( const QString& from_hex, const QString& to_keys_json, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) = 0; virtual WalletFfiError transfer_deshielded( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) = 0; virtual WalletFfiError transfer_private( const QString& from_hex, const QString& to_keys_json, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) = 0; virtual WalletFfiError transfer_shielded_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) = 0; virtual WalletFfiError transfer_private_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) = 0; virtual WalletFfiError register_public_account( const QString& account_id_hex, - QString& out_result_json + QString& output_result_json ) = 0; virtual WalletFfiError register_private_account( const QString& account_id_hex, - QString& out_result_json + QString& output_result_json ) = 0; // Wallet Lifecycle diff --git a/src/logos_execution_zone_wallet_module.cpp b/src/logos_execution_zone_wallet_module.cpp index 58075ce..d7d21e1 100644 --- a/src/logos_execution_zone_wallet_module.cpp +++ b/src/logos_execution_zone_wallet_module.cpp @@ -91,13 +91,13 @@ static QString ffiPrivateAccountKeysToJson(const FfiPrivateAccountKeys& keys) { return QJsonDocument(QJsonObject::fromVariantMap(map)).toJson(QJsonDocument::Compact); } -static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKeys* out_keys) { +static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKeys* output_keys) { QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); if (!doc.isObject()) return false; const QVariantMap map = doc.object().toVariantMap(); if (map.contains(JsonKeys::NullifierPublicKey)) { - if (!hexToBytes32(map[JsonKeys::NullifierPublicKey].toString(), &out_keys->nullifier_public_key)) return false; + if (!hexToBytes32(map[JsonKeys::NullifierPublicKey].toString(), &output_keys->nullifier_public_key)) return false; } if (map.contains(JsonKeys::ViewingPublicKey)) { @@ -106,11 +106,11 @@ static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKe uint8_t* data = static_cast(malloc(buffer.size())); memcpy(data, buffer.constData(), buffer.size()); - out_keys->viewing_public_key = data; - out_keys->viewing_public_key_len = buffer.size(); + output_keys->viewing_public_key = data; + output_keys->viewing_public_key_len = buffer.size(); } else { - out_keys->viewing_public_key = nullptr; - out_keys->viewing_public_key_len = 0; + output_keys->viewing_public_key = nullptr; + output_keys->viewing_public_key_len = 0; } return true; @@ -143,30 +143,30 @@ void LogosExecutionZoneWalletModule::initLogos(LogosAPI* logosApiInstance) { // === Account Management === -WalletFfiError LogosExecutionZoneWalletModule::create_account_public(QString& out_account_id_hex) { +WalletFfiError LogosExecutionZoneWalletModule::create_account_public(QString& output_account_id_hex) { FfiBytes32 id{}; const WalletFfiError error = wallet_ffi_create_account_public(walletHandle, &id); if (error == SUCCESS) { - out_account_id_hex = bytes32ToHex(id); + output_account_id_hex = bytes32ToHex(id); } return error; } -WalletFfiError LogosExecutionZoneWalletModule::create_account_private(QString& out_account_id_hex) { +WalletFfiError LogosExecutionZoneWalletModule::create_account_private(QString& output_account_id_hex) { FfiBytes32 id{}; const WalletFfiError error = wallet_ffi_create_account_private(walletHandle, &id); if (error == SUCCESS) { - out_account_id_hex = bytes32ToHex(id); + output_account_id_hex = bytes32ToHex(id); } return error; } -WalletFfiError LogosExecutionZoneWalletModule::list_accounts(QJsonArray& out_list) { +WalletFfiError LogosExecutionZoneWalletModule::list_accounts(QJsonArray& output_list) { FfiAccountList list{}; const WalletFfiError error = wallet_ffi_list_accounts(walletHandle, &list); if (error == SUCCESS) { for (uintptr_t i = 0; i < list.count; ++i) { - out_list.append(ffiAccountListEntryToJson(list.entries[i])); + output_list.append(ffiAccountListEntryToJson(list.entries[i])); } wallet_ffi_free_account_list(&list); } @@ -178,7 +178,7 @@ WalletFfiError LogosExecutionZoneWalletModule::list_accounts(QJsonArray& out_lis WalletFfiError LogosExecutionZoneWalletModule::get_balance( const QString& account_id_hex, const bool is_public, - QString& out_balance_le16_hex + QString& output_balance_le16_hex ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { @@ -188,14 +188,14 @@ WalletFfiError LogosExecutionZoneWalletModule::get_balance( uint8_t balance[16] = {0}; const WalletFfiError error = wallet_ffi_get_balance(walletHandle, &id, is_public, &balance); if (error == SUCCESS) { - out_balance_le16_hex = bytesToHex(balance, 16); + output_balance_le16_hex = bytesToHex(balance, 16); } return error; } WalletFfiError LogosExecutionZoneWalletModule::get_account_public( const QString& account_id_hex, - QString& out_account_json + QString& output_account_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { @@ -204,7 +204,7 @@ WalletFfiError LogosExecutionZoneWalletModule::get_account_public( FfiAccount account{}; const WalletFfiError error = wallet_ffi_get_account_public(walletHandle, &id, &account); if (error == SUCCESS) { - out_account_json = ffiAccountToJson(account); + output_account_json = ffiAccountToJson(account); wallet_ffi_free_account_data(&account); } return error; @@ -212,7 +212,7 @@ WalletFfiError LogosExecutionZoneWalletModule::get_account_public( WalletFfiError LogosExecutionZoneWalletModule::get_account_private( const QString& account_id_hex, - QString& out_account_json + QString& output_account_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { @@ -221,7 +221,7 @@ WalletFfiError LogosExecutionZoneWalletModule::get_account_private( FfiAccount account{}; const WalletFfiError error = wallet_ffi_get_account_private(walletHandle, &id, &account); if (error == SUCCESS) { - out_account_json = ffiAccountToJson(account); + output_account_json = ffiAccountToJson(account); wallet_ffi_free_account_data(&account); } return error; @@ -229,7 +229,7 @@ WalletFfiError LogosExecutionZoneWalletModule::get_account_private( WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key( const QString& account_id_hex, - QString& out_public_key_hex + QString& output_public_key_hex ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { @@ -238,14 +238,14 @@ WalletFfiError LogosExecutionZoneWalletModule::get_public_account_key( FfiPublicAccountKey key{}; const WalletFfiError error = wallet_ffi_get_public_account_key(walletHandle, &id, &key); if (error == SUCCESS) { - out_public_key_hex = bytes32ToHex(key.public_key); + output_public_key_hex = bytes32ToHex(key.public_key); } return error; } WalletFfiError LogosExecutionZoneWalletModule::get_private_account_keys( const QString& account_id_hex, - QString& out_keys_json + QString& output_keys_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { @@ -254,7 +254,7 @@ WalletFfiError LogosExecutionZoneWalletModule::get_private_account_keys( FfiPrivateAccountKeys keys{}; const WalletFfiError error = wallet_ffi_get_private_account_keys(walletHandle, &id, &keys); if (error == SUCCESS) { - out_keys_json = ffiPrivateAccountKeysToJson(keys); + output_keys_json = ffiPrivateAccountKeysToJson(keys); wallet_ffi_free_private_account_keys(&keys); } return error; @@ -280,13 +280,13 @@ QString LogosExecutionZoneWalletModule::account_id_to_base58(const QString& acco WalletFfiError LogosExecutionZoneWalletModule::account_id_from_base58( const QString& base58_str, - QString& out_account_id_hex + QString& output_account_id_hex ) { FfiBytes32 id{}; const QByteArray utf8 = base58_str.toUtf8(); const WalletFfiError error = wallet_ffi_account_id_from_base58(utf8.constData(), &id); if (error == SUCCESS) { - out_account_id_hex = bytes32ToHex(id); + output_account_id_hex = bytes32ToHex(id); } return error; } @@ -297,12 +297,12 @@ WalletFfiError LogosExecutionZoneWalletModule::sync_to_block(const uint64_t bloc return wallet_ffi_sync_to_block(walletHandle, block_id); } -WalletFfiError LogosExecutionZoneWalletModule::get_last_synced_block(uint64_t* out_block_id) { - return wallet_ffi_get_last_synced_block(walletHandle, out_block_id); +WalletFfiError LogosExecutionZoneWalletModule::get_last_synced_block(uint64_t* output_block_id) { + return wallet_ffi_get_last_synced_block(walletHandle, output_block_id); } -WalletFfiError LogosExecutionZoneWalletModule::get_current_block_height(uint64_t* out_block_height) { - return wallet_ffi_get_current_block_height(walletHandle, out_block_height); +WalletFfiError LogosExecutionZoneWalletModule::get_current_block_height(uint64_t* output_block_height) { + return wallet_ffi_get_current_block_height(walletHandle, output_block_height); } // === Operations === @@ -311,7 +311,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_public( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { @@ -327,7 +327,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_public( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_transfer_public(walletHandle, &fromId, &toId, &amount, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } return error; @@ -337,7 +337,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded( const QString& from_hex, const QString& to_keys_json, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 fromId{}; if (!hexToBytes32(from_hex, &fromId)) { @@ -359,7 +359,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_transfer_shielded(walletHandle, &fromId, &toKeys, &amount, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } @@ -371,7 +371,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_deshielded( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { @@ -387,7 +387,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_deshielded( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_transfer_deshielded(walletHandle, &fromId, &toId, &amount, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } return error; @@ -397,7 +397,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private( const QString& from_hex, const QString& to_keys_json, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 fromId{}; if (!hexToBytes32(from_hex, &fromId)) { @@ -419,7 +419,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_transfer_private(walletHandle, &fromId, &toKeys, &amount, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } @@ -431,7 +431,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { @@ -447,7 +447,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded_owned( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_transfer_shielded_owned(walletHandle, &fromId, &toId, &amount, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } return error; @@ -457,7 +457,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 fromId{}, toId{}; if (!hexToBytes32(from_hex, &fromId) || !hexToBytes32(to_hex, &toId)) { @@ -473,7 +473,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_transfer_private_owned(walletHandle, &fromId, &toId, &amount, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } return error; @@ -481,7 +481,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private_owned( WalletFfiError LogosExecutionZoneWalletModule::register_public_account( const QString& account_id_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { @@ -490,7 +490,7 @@ WalletFfiError LogosExecutionZoneWalletModule::register_public_account( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_register_public_account(walletHandle, &id, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } return error; @@ -498,7 +498,7 @@ WalletFfiError LogosExecutionZoneWalletModule::register_public_account( WalletFfiError LogosExecutionZoneWalletModule::register_private_account( const QString& account_id_hex, - QString& out_result_json + QString& output_result_json ) { FfiBytes32 id{}; if (!hexToBytes32(account_id_hex, &id)) { @@ -507,7 +507,7 @@ WalletFfiError LogosExecutionZoneWalletModule::register_private_account( FfiTransferResult result{}; const WalletFfiError error = wallet_ffi_register_private_account(walletHandle, &id, &result); if (error == SUCCESS) { - out_result_json = ffiTransferResultToJson(result); + output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } return error; diff --git a/src/logos_execution_zone_wallet_module.h b/src/logos_execution_zone_wallet_module.h index dbcabb3..66a7204 100644 --- a/src/logos_execution_zone_wallet_module.h +++ b/src/logos_execution_zone_wallet_module.h @@ -31,79 +31,79 @@ public: // === Logos Execution Zone Wallet === // Account Management - Q_INVOKABLE WalletFfiError create_account_public(QString& out_account_id_hex) override; - Q_INVOKABLE WalletFfiError create_account_private(QString& out_account_id_hex) override; - Q_INVOKABLE WalletFfiError list_accounts(QJsonArray& out_list) override; + Q_INVOKABLE WalletFfiError create_account_public(QString& output_account_id_hex) override; + Q_INVOKABLE WalletFfiError create_account_private(QString& output_account_id_hex) override; + Q_INVOKABLE WalletFfiError list_accounts(QJsonArray& output_list) override; // Account Queries Q_INVOKABLE WalletFfiError get_balance( const QString& account_id_hex, bool is_public, - QString& out_balance_le16_hex + QString& output_balance_le16_hex ) override; Q_INVOKABLE WalletFfiError - get_account_public(const QString& account_id_hex, QString& out_account_json) override; + get_account_public(const QString& account_id_hex, QString& output_account_json) override; Q_INVOKABLE WalletFfiError - get_account_private(const QString& account_id_hex, QString& out_account_json) override; + get_account_private(const QString& account_id_hex, QString& output_account_json) override; Q_INVOKABLE WalletFfiError get_public_account_key( const QString& account_id_hex, - QString& out_public_key_hex + QString& output_public_key_hex ) override; Q_INVOKABLE WalletFfiError get_private_account_keys( const QString& account_id_hex, - QString& out_keys_json + QString& output_keys_json ) override; // Account Encoding Q_INVOKABLE QString account_id_to_base58(const QString& account_id_hex) override; - Q_INVOKABLE WalletFfiError account_id_from_base58(const QString& base58_str, QString& out_account_id_hex) override; + Q_INVOKABLE WalletFfiError account_id_from_base58(const QString& base58_str, QString& output_account_id_hex) override; // Blockchain Synchronisation Q_INVOKABLE WalletFfiError sync_to_block(uint64_t block_id) override; - Q_INVOKABLE WalletFfiError get_last_synced_block(uint64_t* out_block_id) override; - Q_INVOKABLE WalletFfiError get_current_block_height(uint64_t* out_block_height) override; + Q_INVOKABLE WalletFfiError get_last_synced_block(uint64_t* output_block_id) override; + Q_INVOKABLE WalletFfiError get_current_block_height(uint64_t* output_block_height) override; // Operations Q_INVOKABLE WalletFfiError transfer_public( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) override; Q_INVOKABLE WalletFfiError transfer_shielded( const QString& from_hex, const QString& to_keys_json, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) override; Q_INVOKABLE WalletFfiError transfer_deshielded( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) override; Q_INVOKABLE WalletFfiError transfer_private( const QString& from_hex, const QString& to_keys_json, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) override; Q_INVOKABLE WalletFfiError transfer_shielded_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) override; Q_INVOKABLE WalletFfiError transfer_private_owned( const QString& from_hex, const QString& to_hex, const QString& amount_le16_hex, - QString& out_result_json + QString& output_result_json ) override; Q_INVOKABLE WalletFfiError - register_public_account(const QString& account_id_hex, QString& out_result_json) override; + register_public_account(const QString& account_id_hex, QString& output_result_json) override; Q_INVOKABLE WalletFfiError - register_private_account(const QString& account_id_hex, QString& out_result_json) override; + register_private_account(const QString& account_id_hex, QString& output_result_json) override; // Wallet Lifecycle Q_INVOKABLE WalletFfiError create_new( From 69caefdc54e262436e696998f9a6b4f480f5de26 Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Wed, 18 Feb 2026 22:52:28 +0100 Subject: [PATCH 6/6] Prettify --- justfile | 7 ++- src/i_logos_execution_zone_wallet_module.h | 30 +++-------- src/logos_execution_zone_wallet_module.cpp | 59 +++++++++++++--------- src/logos_execution_zone_wallet_module.h | 30 ++++------- 4 files changed, 55 insertions(+), 71 deletions(-) diff --git a/justfile b/justfile index 6bc153f..c4f661c 100644 --- a/justfile +++ b/justfile @@ -10,12 +10,15 @@ build: configure cmake --build build --parallel --target liblogos-execution-zone-wallet-module clean: - rm -rf build target + rm -rf build result -rebuild: clean configure build +rebuild: clean build nix: nix develop +prettify: + nix shell nixpkgs#clang-tools -c clang-format -i src/**.cpp src/**.h + unicode-logs file: perl -pe 's/\\u([0-9A-Fa-f]{4})/chr(hex($1))/ge' {{file}} | less -R diff --git a/src/i_logos_execution_zone_wallet_module.h b/src/i_logos_execution_zone_wallet_module.h index cce5132..3ba1090 100644 --- a/src/i_logos_execution_zone_wallet_module.h +++ b/src/i_logos_execution_zone_wallet_module.h @@ -32,22 +32,10 @@ public: bool is_public, QString& output_balance_le16_hex ) = 0; - virtual WalletFfiError get_account_public( - const QString& account_id_hex, - QString& output_account_json - ) = 0; - virtual WalletFfiError get_account_private( - const QString& account_id_hex, - QString& output_account_json - ) = 0; - virtual WalletFfiError get_public_account_key( - const QString& account_id_hex, - QString& output_public_key_hex - ) = 0; - virtual WalletFfiError get_private_account_keys( - const QString& account_id_hex, - QString& output_keys_json - ) = 0; + virtual WalletFfiError get_account_public(const QString& account_id_hex, QString& output_account_json) = 0; + virtual WalletFfiError get_account_private(const QString& account_id_hex, QString& output_account_json) = 0; + virtual WalletFfiError get_public_account_key(const QString& account_id_hex, QString& output_public_key_hex) = 0; + virtual WalletFfiError get_private_account_keys(const QString& account_id_hex, QString& output_keys_json) = 0; // Account Encoding virtual QString account_id_to_base58(const QString& account_id_hex) = 0; @@ -95,14 +83,8 @@ public: const QString& amount_le16_hex, QString& output_result_json ) = 0; - virtual WalletFfiError register_public_account( - const QString& account_id_hex, - QString& output_result_json - ) = 0; - virtual WalletFfiError register_private_account( - const QString& account_id_hex, - QString& output_result_json - ) = 0; + virtual WalletFfiError register_public_account(const QString& account_id_hex, QString& output_result_json) = 0; + virtual WalletFfiError register_private_account(const QString& account_id_hex, QString& output_result_json) = 0; // Wallet Lifecycle virtual WalletFfiError create_new( diff --git a/src/logos_execution_zone_wallet_module.cpp b/src/logos_execution_zone_wallet_module.cpp index d7d21e1..1753cef 100644 --- a/src/logos_execution_zone_wallet_module.cpp +++ b/src/logos_execution_zone_wallet_module.cpp @@ -12,31 +12,35 @@ static QString bytesToHex(const uint8_t* data, const size_t length) { } namespace JsonKeys { - static constexpr auto TxHash = "tx_hash"; - static constexpr auto Success = "success"; - static constexpr auto ProgramOwner = "program_owner"; - static constexpr auto Balance = "balance"; - static constexpr auto Nonce = "nonce"; - static constexpr auto Data = "data"; - static constexpr auto NullifierPublicKey = "nullifier_public_key"; - static constexpr auto ViewingPublicKey = "viewing_public_key"; - static constexpr auto AccountId = "account_id"; - static constexpr auto IsPublic = "is_public"; -} +static constexpr auto TxHash = "tx_hash"; +static constexpr auto Success = "success"; +static constexpr auto ProgramOwner = "program_owner"; +static constexpr auto Balance = "balance"; +static constexpr auto Nonce = "nonce"; +static constexpr auto Data = "data"; +static constexpr auto NullifierPublicKey = "nullifier_public_key"; +static constexpr auto ViewingPublicKey = "viewing_public_key"; +static constexpr auto AccountId = "account_id"; +static constexpr auto IsPublic = "is_public"; +} // namespace JsonKeys static bool hexToBytes(const QString& hex, QByteArray& output_bytes, int expectedLength = -1) { QString trimmed_hex = hex.trimmed(); - if (trimmed_hex.startsWith("0x", Qt::CaseInsensitive)) trimmed_hex = trimmed_hex.mid(2); - if (trimmed_hex.size() % 2 != 0) return false; + if (trimmed_hex.startsWith("0x", Qt::CaseInsensitive)) + trimmed_hex = trimmed_hex.mid(2); + if (trimmed_hex.size() % 2 != 0) + return false; const QByteArray decoded = QByteArray::fromHex(trimmed_hex.toLatin1()); - if (expectedLength != -1 && decoded.size() != expectedLength) return false; + if (expectedLength != -1 && decoded.size() != expectedLength) + return false; output_bytes = decoded; return true; } static bool hexToU128(const QString& hex, uint8_t (*output)[16]) { QByteArray buffer; - if (!hexToBytes(hex, buffer, 16)) return false; + if (!hexToBytes(hex, buffer, 16)) + return false; memcpy(output, buffer.constData(), 16); return true; } @@ -46,9 +50,11 @@ static QString bytes32ToHex(const FfiBytes32& bytes) { } static bool hexToBytes32(const QString& hex, FfiBytes32* output_bytes) { - if (output_bytes == nullptr) return false; + if (output_bytes == nullptr) + return false; QByteArray buffer; - if (!hexToBytes(hex, buffer, 32)) return false; + if (!hexToBytes(hex, buffer, 32)) + return false; memcpy(output_bytes->data, buffer.constData(), 32); return true; } @@ -93,17 +99,20 @@ static QString ffiPrivateAccountKeysToJson(const FfiPrivateAccountKeys& keys) { static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKeys* output_keys) { QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); - if (!doc.isObject()) return false; + if (!doc.isObject()) + return false; const QVariantMap map = doc.object().toVariantMap(); - + if (map.contains(JsonKeys::NullifierPublicKey)) { - if (!hexToBytes32(map[JsonKeys::NullifierPublicKey].toString(), &output_keys->nullifier_public_key)) return false; + if (!hexToBytes32(map[JsonKeys::NullifierPublicKey].toString(), &output_keys->nullifier_public_key)) + return false; } if (map.contains(JsonKeys::ViewingPublicKey)) { QByteArray buffer; - if (!hexToBytes(map[JsonKeys::ViewingPublicKey].toString(), buffer)) return false; - + if (!hexToBytes(map[JsonKeys::ViewingPublicKey].toString(), buffer)) + return false; + uint8_t* data = static_cast(malloc(buffer.size())); memcpy(data, buffer.constData(), buffer.size()); output_keys->viewing_public_key = data; @@ -112,7 +121,7 @@ static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKe output_keys->viewing_public_key = nullptr; output_keys->viewing_public_key_len = 0; } - + return true; } @@ -362,7 +371,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded( output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } - + free(const_cast(toKeys.viewing_public_key)); return error; } @@ -422,7 +431,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private( output_result_json = ffiTransferResultToJson(result); wallet_ffi_free_transfer_result(&result); } - + free(const_cast(toKeys.viewing_public_key)); return error; } diff --git a/src/logos_execution_zone_wallet_module.h b/src/logos_execution_zone_wallet_module.h index 66a7204..e8f4e89 100644 --- a/src/logos_execution_zone_wallet_module.h +++ b/src/logos_execution_zone_wallet_module.h @@ -36,27 +36,20 @@ public: Q_INVOKABLE WalletFfiError list_accounts(QJsonArray& output_list) override; // Account Queries - Q_INVOKABLE WalletFfiError get_balance( - const QString& account_id_hex, - bool is_public, - QString& output_balance_le16_hex - ) override; Q_INVOKABLE WalletFfiError - get_account_public(const QString& account_id_hex, QString& output_account_json) override; + get_balance(const QString& account_id_hex, bool is_public, QString& output_balance_le16_hex) override; + Q_INVOKABLE WalletFfiError get_account_public(const QString& account_id_hex, QString& output_account_json) override; Q_INVOKABLE WalletFfiError get_account_private(const QString& account_id_hex, QString& output_account_json) override; - Q_INVOKABLE WalletFfiError get_public_account_key( - const QString& account_id_hex, - QString& output_public_key_hex - ) override; - Q_INVOKABLE WalletFfiError get_private_account_keys( - const QString& account_id_hex, - QString& output_keys_json - ) override; + Q_INVOKABLE WalletFfiError + get_public_account_key(const QString& account_id_hex, QString& output_public_key_hex) override; + Q_INVOKABLE WalletFfiError + get_private_account_keys(const QString& account_id_hex, QString& output_keys_json) override; // Account Encoding Q_INVOKABLE QString account_id_to_base58(const QString& account_id_hex) override; - Q_INVOKABLE WalletFfiError account_id_from_base58(const QString& base58_str, QString& output_account_id_hex) override; + Q_INVOKABLE WalletFfiError + account_id_from_base58(const QString& base58_str, QString& output_account_id_hex) override; // Blockchain Synchronisation Q_INVOKABLE WalletFfiError sync_to_block(uint64_t block_id) override; @@ -106,11 +99,8 @@ public: register_private_account(const QString& account_id_hex, QString& output_result_json) override; // Wallet Lifecycle - Q_INVOKABLE WalletFfiError create_new( - const QString& config_path, - const QString& storage_path, - const QString& password - ) override; + Q_INVOKABLE WalletFfiError + create_new(const QString& config_path, const QString& storage_path, const QString& password) override; Q_INVOKABLE WalletFfiError open(const QString& config_path, const QString& storage_path) override; Q_INVOKABLE WalletFfiError save() override;