From f3ede0515fbeea99bb90354690c03ba86b1e99b5 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 14 Jan 2025 16:48:32 -0600 Subject: [PATCH 1/2] Only fetch full monero transactions via ffi if required --- lib/wallets/wallet/impl/monero_wallet.dart | 6 +-- lib/wallets/wallet/impl/wownero_wallet.dart | 6 +-- .../intermediate/lib_monero_wallet.dart | 42 +++++++++++++++---- pubspec.lock | 4 +- scripts/app_config/templates/pubspec.template | 2 +- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/wallets/wallet/impl/monero_wallet.dart b/lib/wallets/wallet/impl/monero_wallet.dart index d890e06e1..f1de036aa 100644 --- a/lib/wallets/wallet/impl/monero_wallet.dart +++ b/lib/wallets/wallet/impl/monero_wallet.dart @@ -61,11 +61,11 @@ class MoneroWallet extends LibMoneroWallet { bool walletExists(String path) => lib_monero.MoneroWallet.isWalletExist(path); @override - void loadWallet({ + Future loadWallet({ required String path, required String password, - }) { - libMoneroWallet = lib_monero.MoneroWallet.loadWallet( + }) async { + libMoneroWallet = await lib_monero.MoneroWallet.loadWallet( path: path, password: password, ); diff --git a/lib/wallets/wallet/impl/wownero_wallet.dart b/lib/wallets/wallet/impl/wownero_wallet.dart index 09a9d4c5d..81407f837 100644 --- a/lib/wallets/wallet/impl/wownero_wallet.dart +++ b/lib/wallets/wallet/impl/wownero_wallet.dart @@ -97,11 +97,11 @@ class WowneroWallet extends LibMoneroWallet { lib_monero.WowneroWallet.isWalletExist(path); @override - void loadWallet({ + Future loadWallet({ required String path, required String password, - }) { - libMoneroWallet = lib_monero.WowneroWallet.loadWallet( + }) async { + libMoneroWallet = await lib_monero.WowneroWallet.loadWallet( path: path, password: password, ); diff --git a/lib/wallets/wallet/intermediate/lib_monero_wallet.dart b/lib/wallets/wallet/intermediate/lib_monero_wallet.dart index 423e8c70b..8ab9efcc8 100644 --- a/lib/wallets/wallet/intermediate/lib_monero_wallet.dart +++ b/lib/wallets/wallet/intermediate/lib_monero_wallet.dart @@ -137,7 +137,7 @@ abstract class LibMoneroWallet int currentKnownChainHeight = 0; double highestPercentCached = 0; - void loadWallet({required String path, required String password}); + Future loadWallet({required String path, required String password}); Future getCreatedWallet({ required String path, @@ -206,7 +206,7 @@ abstract class LibMoneroWallet throw Exception("Password not found $e, $s"); } - loadWallet(path: path, password: password); + await loadWallet(path: path, password: password); _setListener(); @@ -329,7 +329,7 @@ abstract class LibMoneroWallet } catch (e, s) { throw Exception("Password not found $e, $s"); } - loadWallet(path: path, password: password); + await loadWallet(path: path, password: password); final wallet = libMoneroWallet!; return (wallet.getAddress().value, wallet.getPrivateViewKey()); } @@ -565,7 +565,26 @@ abstract class LibMoneroWallet return; } - final transactions = await base.getTxs(refresh: true); + final localTxids = await mainDB.isar.transactionV2s + .where() + .walletIdEqualTo(walletId) + .filter() + .heightGreaterThan(0) + .txidProperty() + .findAll(); + + final allTxids = await base.getAllTxids(refresh: true); + + final txidsToFetch = allTxids.toSet().difference(localTxids.toSet()); + + if (txidsToFetch.isEmpty) { + return; + } + + final transactions = await base.getTxs( + txids: txidsToFetch, + refresh: false, + ); final allOutputs = await base.getOutputs(includeSpent: true, refresh: true); @@ -692,7 +711,7 @@ abstract class LibMoneroWallet fractionDigits: cryptoCurrency.fractionDigits, ); } else { - final transactions = await libMoneroWallet!.getTxs(refresh: true); + final transactions = await libMoneroWallet!.getAllTxs(refresh: true); BigInt transactionBalance = BigInt.zero; for (final tx in transactions) { if (!tx.isSpend) { @@ -790,8 +809,15 @@ abstract class LibMoneroWallet } } - void onNewBlock(int nodeHeight) { - // do something? + void onNewBlock(int nodeHeight) async { + try { + await updateTransactions(); + } catch (e, s) { + Logging.instance.log( + "onNewBlock(): $e\n$s", + level: LogLevel.Warning, + ); + } } final _utxosUpdateLock = Mutex(); @@ -1161,7 +1187,7 @@ abstract class LibMoneroWallet try { int highestIndex = -1; - final entries = await libMoneroWallet?.getTxs(refresh: true); + final entries = await libMoneroWallet?.getAllTxs(refresh: true); if (entries != null) { for (final element in entries) { if (!element.isSpend) { diff --git a/pubspec.lock b/pubspec.lock index 760ef2066..6a4e5316b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -436,10 +436,10 @@ packages: dependency: "direct main" description: name: cs_monero - sha256: "8b2c1451d8eb09fc2a1248ecd652f2332343946a1d622b2f623b74d5f999c8d5" + sha256: ed81d9e74ea71a8b8b0bfed07a284e14b6e5f4d0dbde774735f9f0a9ab60b7fb url: "https://pub.dev" source: hosted - version: "1.0.0-pre.1" + version: "1.0.0-pre.2" cs_monero_flutter_libs: dependency: "direct main" description: diff --git a/scripts/app_config/templates/pubspec.template b/scripts/app_config/templates/pubspec.template index e052525ae..46c98e8ef 100644 --- a/scripts/app_config/templates/pubspec.template +++ b/scripts/app_config/templates/pubspec.template @@ -202,7 +202,7 @@ dependencies: blockchain_utils: ^3.3.0 on_chain: ^4.0.1 cbor: ^6.3.3 - cs_monero: 1.0.0-pre.1 + cs_monero: 1.0.0-pre.2 cs_monero_flutter_libs: 1.0.0-pre.0 monero_rpc: ^2.0.0 digest_auth: ^1.0.1 From 2a94951e9baac00a2fe2bba06be3a3aea9926b58 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 14 Jan 2025 16:50:22 -0600 Subject: [PATCH 2/2] update test --- test/services/node_service_test.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/services/node_service_test.dart b/test/services/node_service_test.dart index cb402deed..2fac42b96 100644 --- a/test/services/node_service_test.dart +++ b/test/services/node_service_test.dart @@ -270,7 +270,11 @@ void main() { final service = NodeService(secureStorageInterface: fakeStore); final currentLength = service.nodes.length; - final editedNode = nodeA.copyWith(name: "Some new kind of name"); + final editedNode = nodeA.copyWith( + name: "Some new kind of name", + loginName: null, + trusted: null, + ); await service.edit(editedNode, "123456", true);