@bsv/wallet-toolbox 1.6.16 → 1.6.18

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": "@bsv/wallet-toolbox",
3
- "version": "1.6.16",
3
+ "version": "1.6.18",
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",
@@ -54,7 +54,7 @@ export class WalletError extends Error implements WalletErrorObject {
54
54
  *
55
55
  */
56
56
  static fromUnknown(err: unknown): WalletError {
57
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ if (err instanceof WalletError) return err
58
58
  let name = 'WERR_UNKNOWN'
59
59
  let message = ''
60
60
  let stack: string | undefined
@@ -15,6 +15,7 @@ import { SingleWriterMultiReaderLock } from './util/SingleWriterMultiReaderLock'
15
15
  import { ChaintracksFsApi } from './Api/ChaintracksFsApi'
16
16
  import { randomBytesBase64, wait } from '../../../utility/utilityHelpers'
17
17
  import { WalletError } from '../../../sdk/WalletError'
18
+ import { CWIStyleWalletManager } from '../../../CWIStyleWalletManager'
18
19
 
19
20
  export class Chaintracks implements ChaintracksManagementApi {
20
21
  static createOptions(chain: Chain): ChaintracksOptions {
@@ -328,6 +329,7 @@ export class Chaintracks implements ChaintracksManagementApi {
328
329
 
329
330
  let done = false
330
331
  for (; !done; ) {
332
+ let bulkSyncError: WalletError | undefined
331
333
  for (const bulk of this.bulkIngestors) {
332
334
  try {
333
335
  const r = await bulk.synchronize(presentHeight, before, newLiveHeaders)
@@ -344,23 +346,33 @@ export class Chaintracks implements ChaintracksManagementApi {
344
346
  done = true
345
347
  break
346
348
  }
347
- } catch (uerr: unknown) {
348
- console.error(uerr)
349
+ } catch (eu: unknown) {
350
+ const e = (bulkSyncError = WalletError.fromUnknown(eu))
351
+ this.log(`bulk sync error: ${e.message}`)
352
+ if (!this.available)
353
+ // During initial startup, bulk ingestors must be available.
354
+ break
349
355
  }
350
356
  }
357
+ if (!bulkDone && !this.available && bulkSyncError) {
358
+ this.startupError = bulkSyncError
359
+ break
360
+ }
351
361
  if (bulkDone) break
352
362
  }
353
363
 
354
- this.liveHeaders.unshift(...newLiveHeaders)
364
+ if (!this.startupError) {
365
+ this.liveHeaders.unshift(...newLiveHeaders)
355
366
 
356
- added = after.bulk.above(initialRanges.bulk)
367
+ added = after.bulk.above(initialRanges.bulk)
357
368
 
358
- this.log(`syncBulkStorage done
369
+ this.log(`syncBulkStorage done
359
370
  Before sync: bulk ${initialRanges.bulk}, live ${initialRanges.live}
360
371
  After sync: bulk ${after.bulk}, live ${after.live}
361
372
  ${added.length} headers added to bulk storage
362
373
  ${this.liveHeaders.length} headers forwarded to live header storage
363
374
  `)
375
+ }
364
376
  }
365
377
 
366
378
  private async getMissingBlockHeader(hash: string): Promise<BlockHeader | undefined> {
@@ -468,6 +480,7 @@ export class Chaintracks implements ChaintracksManagementApi {
468
480
  else
469
481
  // While still not available, the makeAvailable write lock is held.
470
482
  await this.syncBulkStorageNoLock(presentHeight, before)
483
+ if (this.startupError) throw this.startupError
471
484
  }
472
485
 
473
486
  let count = 0