@bopen-io/wallet-toolbox 1.7.20-idb-fix.2 → 1.7.20-idb-fix.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bopen-io/wallet-toolbox",
3
- "version": "1.7.20-idb-fix.2",
3
+ "version": "1.7.20-idb-fix.4",
4
4
  "description": "BRC100 conforming wallet, wallet storage and wallet signer components",
5
5
  "main": "./out/src/index.js",
6
6
  "types": "./out/src/index.d.ts",
@@ -744,23 +744,27 @@ export class WalletStorageManager implements sdk.WalletStorage {
744
744
  const identityKey = auth.identityKey
745
745
 
746
746
  const writerSettings = await writer.makeAvailable()
747
+ const isRemoteWriter = writer instanceof StorageClient
747
748
 
748
749
  let inserts = 0,
749
750
  updates = 0
750
751
 
751
- log = await this.runAsSync(async sync => {
752
- const reader = sync
753
- const readerSettings = reader.getSettings()
754
-
752
+ // If writer is remote (StorageClient), we must NOT hold a local IDB transaction
753
+ // across network calls. Instead, do fresh reads for each chunk iteration.
754
+ if (isRemoteWriter && !activeSync) {
755
+ const readerSettings = this.getSettings()
755
756
  log += progLog(`syncToWriter from ${readerSettings.storageName} to ${writerSettings.storageName}\n`)
756
757
 
757
758
  let i = -1
758
759
  for (;;) {
759
760
  i++
761
+ // Network call to remote writer - OK, no local transaction held
760
762
  const ss = await EntitySyncState.fromStorage(writer, identityKey, readerSettings)
761
763
  const args = ss.makeRequestSyncChunkArgs(identityKey, writerSettings.storageIdentityKey)
762
- const chunk = await reader.getSyncChunk(args)
764
+ // Fresh local read - brief transaction that completes before network call
765
+ const chunk = await this.runAsSync(async sync => sync.getSyncChunk(args))
763
766
  log += EntitySyncState.syncChunkSummary(chunk)
767
+ // Network call to remote writer - OK, no local transaction held
764
768
  const r = await writer.processSyncChunk(args, chunk)
765
769
  inserts += r.inserts
766
770
  updates += r.updates
@@ -768,8 +772,31 @@ export class WalletStorageManager implements sdk.WalletStorage {
768
772
  if (r.done) break
769
773
  }
770
774
  log += progLog(`syncToWriter complete: ${inserts} inserts, ${updates} updates\n`)
771
- return log
772
- }, activeSync)
775
+ } else {
776
+ // Writer is local or we have an active sync context - use original approach
777
+ log = await this.runAsSync(async sync => {
778
+ const reader = sync
779
+ const readerSettings = reader.getSettings()
780
+
781
+ log += progLog(`syncToWriter from ${readerSettings.storageName} to ${writerSettings.storageName}\n`)
782
+
783
+ let i = -1
784
+ for (;;) {
785
+ i++
786
+ const ss = await EntitySyncState.fromStorage(writer, identityKey, readerSettings)
787
+ const args = ss.makeRequestSyncChunkArgs(identityKey, writerSettings.storageIdentityKey)
788
+ const chunk = await reader.getSyncChunk(args)
789
+ log += EntitySyncState.syncChunkSummary(chunk)
790
+ const r = await writer.processSyncChunk(args, chunk)
791
+ inserts += r.inserts
792
+ updates += r.updates
793
+ log += progLog(`chunk ${i} inserted ${r.inserts} updated ${r.updates} ${r.maxUpdated_at}\n`)
794
+ if (r.done) break
795
+ }
796
+ log += progLog(`syncToWriter complete: ${inserts} inserts, ${updates} updates\n`)
797
+ return log
798
+ }, activeSync)
799
+ }
773
800
 
774
801
  return { inserts, updates, log }
775
802
  }