From c74e024f98a10cb6e217c0eb02921dc2c05e9e76 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 9 Apr 2026 15:11:44 +0200 Subject: [PATCH] Fix asset-aware subaddress balance bindings --- impls/monero.dart/lib/peya.dart | 10 ++++++++-- impls/monero.dart/lib/salvium.dart | 10 ++++++++-- peya_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp | 6 ++++-- .../src/main/cpp/wallet2_api_c.cpp | 6 ++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/impls/monero.dart/lib/peya.dart b/impls/monero.dart/lib/peya.dart index 4e55c1c..e79bd3c 100644 --- a/impls/monero.dart/lib/peya.dart +++ b/impls/monero.dart/lib/peya.dart @@ -1523,9 +1523,10 @@ String SubaddressAccountRow_getBalance( SubaddressAccountRow addressBookRow_ptr) { debugStart?.call('PEYA_SubaddressAccountRow_getBalance'); lib ??= PeyaC(DynamicLibrary.open(libPath)); + final asset_ = 'PEY'.toNativeUtf8().cast(); try { final strPtr = lib! - .PEYA_SubaddressAccountRow_getBalance(addressBookRow_ptr) + .PEYA_SubaddressAccountRow_getBalance(addressBookRow_ptr, asset_) .cast(); final str = strPtr.toDartString(); PEYA_free(strPtr.cast()); @@ -1535,6 +1536,8 @@ String SubaddressAccountRow_getBalance( errorHandler?.call('PEYA_SubaddressAccountRow_getBalance', e); debugEnd?.call('PEYA_SubaddressAccountRow_getBalance'); return ""; + } finally { + calloc.free(asset_); } } @@ -1542,9 +1545,10 @@ String SubaddressAccountRow_getUnlockedBalance( SubaddressAccountRow addressBookRow_ptr) { debugStart?.call('PEYA_SubaddressAccountRow_getUnlockedBalance'); lib ??= PeyaC(DynamicLibrary.open(libPath)); + final asset_ = 'PEY'.toNativeUtf8().cast(); try { final strPtr = lib! - .PEYA_SubaddressAccountRow_getUnlockedBalance(addressBookRow_ptr) + .PEYA_SubaddressAccountRow_getUnlockedBalance(addressBookRow_ptr, asset_) .cast(); final str = strPtr.toDartString(); PEYA_free(strPtr.cast()); @@ -1554,6 +1558,8 @@ String SubaddressAccountRow_getUnlockedBalance( errorHandler?.call('PEYA_SubaddressAccountRow_getUnlockedBalance', e); debugEnd?.call('PEYA_SubaddressAccountRow_getUnlockedBalance'); return ""; + } finally { + calloc.free(asset_); } } diff --git a/impls/monero.dart/lib/salvium.dart b/impls/monero.dart/lib/salvium.dart index fccc557..31cb38e 100644 --- a/impls/monero.dart/lib/salvium.dart +++ b/impls/monero.dart/lib/salvium.dart @@ -1523,9 +1523,10 @@ String SubaddressAccountRow_getBalance( SubaddressAccountRow addressBookRow_ptr) { debugStart?.call('SALVIUM_SubaddressAccountRow_getBalance'); lib ??= SalviumC(DynamicLibrary.open(libPath)); + final asset_ = 'SAL'.toNativeUtf8().cast(); try { final strPtr = lib! - .SALVIUM_SubaddressAccountRow_getBalance(addressBookRow_ptr) + .SALVIUM_SubaddressAccountRow_getBalance(addressBookRow_ptr, asset_) .cast(); final str = strPtr.toDartString(); SALVIUM_free(strPtr.cast()); @@ -1535,6 +1536,8 @@ String SubaddressAccountRow_getBalance( errorHandler?.call('SALVIUM_SubaddressAccountRow_getBalance', e); debugEnd?.call('SALVIUM_SubaddressAccountRow_getBalance'); return ""; + } finally { + calloc.free(asset_); } } @@ -1542,9 +1545,10 @@ String SubaddressAccountRow_getUnlockedBalance( SubaddressAccountRow addressBookRow_ptr) { debugStart?.call('SALVIUM_SubaddressAccountRow_getUnlockedBalance'); lib ??= SalviumC(DynamicLibrary.open(libPath)); + final asset_ = 'SAL'.toNativeUtf8().cast(); try { final strPtr = lib! - .SALVIUM_SubaddressAccountRow_getUnlockedBalance(addressBookRow_ptr) + .SALVIUM_SubaddressAccountRow_getUnlockedBalance(addressBookRow_ptr, asset_) .cast(); final str = strPtr.toDartString(); SALVIUM_free(strPtr.cast()); @@ -1554,6 +1558,8 @@ String SubaddressAccountRow_getUnlockedBalance( errorHandler?.call('SALVIUM_SubaddressAccountRow_getUnlockedBalance', e); debugEnd?.call('SALVIUM_SubaddressAccountRow_getUnlockedBalance'); return ""; + } finally { + calloc.free(asset_); } } diff --git a/peya_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/peya_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index 7b9c3a4..642438f 100644 --- a/peya_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/peya_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -994,7 +994,8 @@ const char* PEYA_SubaddressAccountRow_getLabel(void* subaddressAccountRow_ptr) { const char* PEYA_SubaddressAccountRow_getBalance(void* subaddressAccountRow_ptr, const char* asset) { DEBUG_START() Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast(subaddressAccountRow_ptr); - std::string str = subaddressAccountRow->getBalance("SAL1"); + const std::string requested_asset = asset ? asset : "PEY"; + std::string str = subaddressAccountRow->getBalance(requested_asset); const std::string::size_type size = str.size(); char *buffer = new char[size + 1]; //we need extra char for NUL memcpy(buffer, str.c_str(), size + 1); @@ -1005,7 +1006,8 @@ const char* PEYA_SubaddressAccountRow_getBalance(void* subaddressAccountRow_ptr, const char* PEYA_SubaddressAccountRow_getUnlockedBalance(void* subaddressAccountRow_ptr, const char* asset) { DEBUG_START() Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast(subaddressAccountRow_ptr); - std::string str = subaddressAccountRow->getUnlockedBalance("SAL1"); + const std::string requested_asset = asset ? asset : "PEY"; + std::string str = subaddressAccountRow->getUnlockedBalance(requested_asset); const std::string::size_type size = str.size(); char *buffer = new char[size + 1]; //we need extra char for NUL memcpy(buffer, str.c_str(), size + 1); diff --git a/salvium_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/salvium_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index a9363bc..18d12f8 100644 --- a/salvium_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/salvium_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -994,7 +994,8 @@ const char* SALVIUM_SubaddressAccountRow_getLabel(void* subaddressAccountRow_ptr const char* SALVIUM_SubaddressAccountRow_getBalance(void* subaddressAccountRow_ptr, const char* asset) { DEBUG_START() Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast(subaddressAccountRow_ptr); - std::string str = subaddressAccountRow->getBalance("SAL1"); + const std::string requested_asset = asset ? asset : "SAL"; + std::string str = subaddressAccountRow->getBalance(requested_asset); const std::string::size_type size = str.size(); char *buffer = new char[size + 1]; //we need extra char for NUL memcpy(buffer, str.c_str(), size + 1); @@ -1005,7 +1006,8 @@ const char* SALVIUM_SubaddressAccountRow_getBalance(void* subaddressAccountRow_p const char* SALVIUM_SubaddressAccountRow_getUnlockedBalance(void* subaddressAccountRow_ptr, const char* asset) { DEBUG_START() Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast(subaddressAccountRow_ptr); - std::string str = subaddressAccountRow->getUnlockedBalance("SAL1"); + const std::string requested_asset = asset ? asset : "SAL"; + std::string str = subaddressAccountRow->getUnlockedBalance(requested_asset); const std::string::size_type size = str.size(); char *buffer = new char[size + 1]; //we need extra char for NUL memcpy(buffer, str.c_str(), size + 1);