From 7514d851cec10d122f09f5a3072a50a185401e5f Mon Sep 17 00:00:00 2001 From: cyan Date: Sun, 21 Jul 2024 02:43:09 +0200 Subject: [PATCH] store() on bad network (#1543) * fix: for storing on bad network connection. * feat from standup * fix missing declaration * remove forcing trusted daemon flag [skip ci] --------- Co-authored-by: OmarHatem --- cw_monero/lib/api/wallet.dart | 16 +++++++++++++++- cw_wownero/lib/api/wallet.dart | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 59eeb1498..6ca9cd1bb 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -121,9 +121,23 @@ void setRecoveringFromSeed({required bool isRecovery}) => monero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery); final storeMutex = Mutex(); + + +int lastStorePointer = 0; +int lastStoreHeight = 0; void storeSync() async { - await storeMutex.acquire(); final addr = wptr!.address; + final synchronized = await Isolate.run(() { + return monero.Wallet_synchronized(Pointer.fromAddress(addr)); + }); + if (lastStorePointer == wptr!.address && + lastStoreHeight + 5000 < monero.Wallet_blockChainHeight(wptr!) && + !synchronized) { + return; + } + lastStorePointer = wptr!.address; + lastStoreHeight = monero.Wallet_blockChainHeight(wptr!); + await storeMutex.acquire(); await Isolate.run(() { monero.Wallet_store(Pointer.fromAddress(addr)); }); diff --git a/cw_wownero/lib/api/wallet.dart b/cw_wownero/lib/api/wallet.dart index 6a7550d84..96822dfe4 100644 --- a/cw_wownero/lib/api/wallet.dart +++ b/cw_wownero/lib/api/wallet.dart @@ -126,9 +126,22 @@ void setRecoveringFromSeed({required bool isRecovery}) => wownero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery); final storeMutex = Mutex(); + +int lastStorePointer = 0; +int lastStoreHeight = 0; void storeSync() async { - await storeMutex.acquire(); final addr = wptr!.address; + final synchronized = await Isolate.run(() { + return wownero.Wallet_synchronized(Pointer.fromAddress(addr)); + }); + if (lastStorePointer == wptr!.address && + lastStoreHeight + 5000 < wownero.Wallet_blockChainHeight(wptr!) && + !synchronized) { + return; + } + lastStorePointer = wptr!.address; + lastStoreHeight = wownero.Wallet_blockChainHeight(wptr!); + await storeMutex.acquire(); Isolate.run(() { wownero.Wallet_store(Pointer.fromAddress(addr)); });