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 <omarh.ismail1@gmail.com>
cyan committed
Jul 21, 2024 at 02:43 UTC
7514d851cec10d122f09f5a3072a50a185401e5f
2 files changed
+29
-2
cw_monero/lib/api/wallet.dart
+15
-1
@@ -121,9 +121,23 @@ void setRecoveringFromSeed({required bool isRecovery}) =>
121
monero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery);
122
123
final storeMutex = Mutex();
124
+
125
+
126
+int lastStorePointer = 0;
127
+int lastStoreHeight = 0;
128
void storeSync() async {
125
- await storeMutex.acquire();
129
final addr = wptr!.address;
130
+ final synchronized = await Isolate.run(() {
131
+ return monero.Wallet_synchronized(Pointer.fromAddress(addr));
132
+ });
133
+ if (lastStorePointer == wptr!.address &&
134
+ lastStoreHeight + 5000 < monero.Wallet_blockChainHeight(wptr!) &&
135
+ !synchronized) {
136
+ return;
137
+ }
138
+ lastStorePointer = wptr!.address;
139
+ lastStoreHeight = monero.Wallet_blockChainHeight(wptr!);
140
+ await storeMutex.acquire();
141
await Isolate.run(() {
142
monero.Wallet_store(Pointer.fromAddress(addr));
143
});
cw_wownero/lib/api/wallet.dart
+14
-1
@@ -126,9 +126,22 @@ void setRecoveringFromSeed({required bool isRecovery}) =>
126
wownero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery);
127
128
final storeMutex = Mutex();
129
+
130
+int lastStorePointer = 0;
131
+int lastStoreHeight = 0;
132
void storeSync() async {
130
- await storeMutex.acquire();
133
final addr = wptr!.address;
134
+ final synchronized = await Isolate.run(() {
135
+ return wownero.Wallet_synchronized(Pointer.fromAddress(addr));
136
+ });
137
+ if (lastStorePointer == wptr!.address &&
138
+ lastStoreHeight + 5000 < wownero.Wallet_blockChainHeight(wptr!) &&
139
+ !synchronized) {
140
+ return;
141
+ }
142
+ lastStorePointer = wptr!.address;
143
+ lastStoreHeight = wownero.Wallet_blockChainHeight(wptr!);
144
+ await storeMutex.acquire();
145
Isolate.run(() {
146
wownero.Wallet_store(Pointer.fromAddress(addr));
147
});