@atomiqlabs/sdk 8.9.2 → 8.9.3

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.
@@ -150,6 +150,11 @@ export type SwapperOptions = {
150
150
  certificate: string;
151
151
  privateKey: string;
152
152
  };
153
+ /**
154
+ * If you set the option to `true` the chains for which the RPC is unresponsive are skipped and not initialized
155
+ * letting the swapper continue with only the available chains with responsive RPCs
156
+ */
157
+ gracefullyHandleChainErrors?: boolean;
153
158
  };
154
159
  /**
155
160
  * Type representing multiple blockchain configurations
@@ -246,39 +246,48 @@ class Swapper extends events_1.EventEmitter {
246
246
  for (let chainIdentifier in this._chains) {
247
247
  chainPromises.push((async () => {
248
248
  const { chainInterface, versionedContracts, unifiedChainEvents, unifiedSwapStorage, wrappers, reviver } = this._chains[chainIdentifier];
249
- const _chainInterface = chainInterface;
250
- if (_chainInterface.verifyNetwork != null) {
251
- await _chainInterface.verifyNetwork(this.bitcoinNetwork);
252
- }
253
- for (let contractVersion in versionedContracts) {
254
- await versionedContracts[contractVersion].swapContract.start();
255
- this.logger.debug("init(): Intialized swap contract: " + chainIdentifier + ` version: ${contractVersion}`);
249
+ try {
250
+ const _chainInterface = chainInterface;
251
+ if (_chainInterface.verifyNetwork != null) {
252
+ await _chainInterface.verifyNetwork(this.bitcoinNetwork);
253
+ }
254
+ for (let contractVersion in versionedContracts) {
255
+ await versionedContracts[contractVersion].swapContract.start();
256
+ this.logger.debug("init(): Intialized swap contract: " + chainIdentifier + ` version: ${contractVersion}`);
257
+ }
258
+ await unifiedSwapStorage.init();
259
+ if (unifiedSwapStorage.storage instanceof IndexedDBUnifiedStorage_1.IndexedDBUnifiedStorage) {
260
+ //Try to migrate the data here
261
+ const storagePrefix = chainIdentifier === "SOLANA" ?
262
+ "SOLv4-" + this.bitcoinNetwork + "-Swaps-" :
263
+ "atomiqsdk-" + this.bitcoinNetwork + chainIdentifier + "-Swaps-";
264
+ await unifiedSwapStorage.storage.tryMigrate([
265
+ [storagePrefix + "FromBTC", SwapType_1.SwapType.FROM_BTC],
266
+ [storagePrefix + "FromBTCLN", SwapType_1.SwapType.FROM_BTCLN],
267
+ [storagePrefix + "ToBTC", SwapType_1.SwapType.TO_BTC],
268
+ [storagePrefix + "ToBTCLN", SwapType_1.SwapType.TO_BTCLN]
269
+ ], (obj) => {
270
+ const swap = reviver(obj);
271
+ if (swap._randomNonce == null) {
272
+ const oldIdentifierHash = swap.getId();
273
+ swap._randomNonce = (0, Utils_1.randomBytes)(16).toString("hex");
274
+ const newIdentifierHash = swap.getId();
275
+ this.logger.info("init(): Found older swap version without randomNonce, replacing, old hash: " + oldIdentifierHash +
276
+ " new hash: " + newIdentifierHash);
277
+ }
278
+ return swap;
279
+ });
280
+ }
281
+ await unifiedChainEvents.start(this.options.noEvents);
282
+ this.logger.debug("init(): Initialized events: " + chainIdentifier);
256
283
  }
257
- await unifiedSwapStorage.init();
258
- if (unifiedSwapStorage.storage instanceof IndexedDBUnifiedStorage_1.IndexedDBUnifiedStorage) {
259
- //Try to migrate the data here
260
- const storagePrefix = chainIdentifier === "SOLANA" ?
261
- "SOLv4-" + this.bitcoinNetwork + "-Swaps-" :
262
- "atomiqsdk-" + this.bitcoinNetwork + chainIdentifier + "-Swaps-";
263
- await unifiedSwapStorage.storage.tryMigrate([
264
- [storagePrefix + "FromBTC", SwapType_1.SwapType.FROM_BTC],
265
- [storagePrefix + "FromBTCLN", SwapType_1.SwapType.FROM_BTCLN],
266
- [storagePrefix + "ToBTC", SwapType_1.SwapType.TO_BTC],
267
- [storagePrefix + "ToBTCLN", SwapType_1.SwapType.TO_BTCLN]
268
- ], (obj) => {
269
- const swap = reviver(obj);
270
- if (swap._randomNonce == null) {
271
- const oldIdentifierHash = swap.getId();
272
- swap._randomNonce = (0, Utils_1.randomBytes)(16).toString("hex");
273
- const newIdentifierHash = swap.getId();
274
- this.logger.info("init(): Found older swap version without randomNonce, replacing, old hash: " + oldIdentifierHash +
275
- " new hash: " + newIdentifierHash);
276
- }
277
- return swap;
278
- });
284
+ catch (e) {
285
+ if (!this.options.gracefullyHandleChainErrors)
286
+ throw e;
287
+ this.logger.error(`init(): Failed to initialize ${chainIdentifier} (skipped): `, e);
288
+ delete this._chains[chainIdentifier];
289
+ return;
279
290
  }
280
- await unifiedChainEvents.start(this.options.noEvents);
281
- this.logger.debug("init(): Intialized events: " + chainIdentifier);
282
291
  for (let key in wrappers) {
283
292
  // this.logger.debug("init(): Initializing "+SwapType[key]+": "+chainIdentifier);
284
293
  await wrappers[key].init(this.options.noTimers, this.options.dontCheckPastSwaps);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/sdk",
3
- "version": "8.9.2",
3
+ "version": "8.9.3",
4
4
  "description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -180,7 +180,13 @@ export type SwapperOptions = {
180
180
  signedKeyBasedAuth?: {
181
181
  certificate: string,
182
182
  privateKey: string
183
- }
183
+ },
184
+
185
+ /**
186
+ * If you set the option to `true` the chains for which the RPC is unresponsive are skipped and not initialized
187
+ * letting the swapper continue with only the available chains with responsive RPCs
188
+ */
189
+ gracefullyHandleChainErrors?: boolean,
184
190
  };
185
191
 
186
192
  /**
@@ -659,45 +665,52 @@ export class Swapper<T extends MultiChain> extends EventEmitter<{
659
665
  reviver
660
666
  } = this._chains[chainIdentifier];
661
667
 
662
- const _chainInterface: any = chainInterface;
663
- if(_chainInterface.verifyNetwork!=null) {
664
- await _chainInterface.verifyNetwork(this.bitcoinNetwork);
665
- }
668
+ try {
669
+ const _chainInterface: any = chainInterface;
670
+ if(_chainInterface.verifyNetwork!=null) {
671
+ await _chainInterface.verifyNetwork(this.bitcoinNetwork);
672
+ }
666
673
 
667
- for(let contractVersion in versionedContracts) {
668
- await versionedContracts[contractVersion].swapContract.start();
669
- this.logger.debug("init(): Intialized swap contract: "+chainIdentifier+` version: ${contractVersion}`);
670
- }
674
+ for(let contractVersion in versionedContracts) {
675
+ await versionedContracts[contractVersion].swapContract.start();
676
+ this.logger.debug("init(): Intialized swap contract: "+chainIdentifier+` version: ${contractVersion}`);
677
+ }
671
678
 
672
- await unifiedSwapStorage.init();
673
- if(unifiedSwapStorage.storage instanceof IndexedDBUnifiedStorage) {
674
- //Try to migrate the data here
675
- const storagePrefix = chainIdentifier==="SOLANA" ?
676
- "SOLv4-"+this.bitcoinNetwork+"-Swaps-" :
677
- "atomiqsdk-"+this.bitcoinNetwork+chainIdentifier+"-Swaps-";
678
- await unifiedSwapStorage.storage.tryMigrate(
679
- [
680
- [storagePrefix+"FromBTC", SwapType.FROM_BTC],
681
- [storagePrefix+"FromBTCLN", SwapType.FROM_BTCLN],
682
- [storagePrefix+"ToBTC", SwapType.TO_BTC],
683
- [storagePrefix+"ToBTCLN", SwapType.TO_BTCLN]
684
- ],
685
- (obj: any) => {
686
- const swap = reviver(obj);
687
- if(swap._randomNonce==null) {
688
- const oldIdentifierHash = swap.getId();
689
- swap._randomNonce = randomBytes(16).toString("hex");
690
- const newIdentifierHash = swap.getId();
691
- this.logger.info("init(): Found older swap version without randomNonce, replacing, old hash: "+oldIdentifierHash+
692
- " new hash: "+newIdentifierHash);
679
+ await unifiedSwapStorage.init();
680
+ if(unifiedSwapStorage.storage instanceof IndexedDBUnifiedStorage) {
681
+ //Try to migrate the data here
682
+ const storagePrefix = chainIdentifier==="SOLANA" ?
683
+ "SOLv4-"+this.bitcoinNetwork+"-Swaps-" :
684
+ "atomiqsdk-"+this.bitcoinNetwork+chainIdentifier+"-Swaps-";
685
+ await unifiedSwapStorage.storage.tryMigrate(
686
+ [
687
+ [storagePrefix+"FromBTC", SwapType.FROM_BTC],
688
+ [storagePrefix+"FromBTCLN", SwapType.FROM_BTCLN],
689
+ [storagePrefix+"ToBTC", SwapType.TO_BTC],
690
+ [storagePrefix+"ToBTCLN", SwapType.TO_BTCLN]
691
+ ],
692
+ (obj: any) => {
693
+ const swap = reviver(obj);
694
+ if(swap._randomNonce==null) {
695
+ const oldIdentifierHash = swap.getId();
696
+ swap._randomNonce = randomBytes(16).toString("hex");
697
+ const newIdentifierHash = swap.getId();
698
+ this.logger.info("init(): Found older swap version without randomNonce, replacing, old hash: "+oldIdentifierHash+
699
+ " new hash: "+newIdentifierHash);
700
+ }
701
+ return swap;
693
702
  }
694
- return swap;
695
- }
696
- )
697
- }
703
+ )
704
+ }
698
705
 
699
- await unifiedChainEvents.start(this.options.noEvents);
700
- this.logger.debug("init(): Intialized events: "+chainIdentifier);
706
+ await unifiedChainEvents.start(this.options.noEvents);
707
+ this.logger.debug("init(): Initialized events: "+chainIdentifier);
708
+ } catch (e) {
709
+ if(!this.options.gracefullyHandleChainErrors) throw e;
710
+ this.logger.error(`init(): Failed to initialize ${chainIdentifier} (skipped): `, e);
711
+ delete this._chains[chainIdentifier];
712
+ return;
713
+ }
701
714
 
702
715
  for(let key in wrappers) {
703
716
  // this.logger.debug("init(): Initializing "+SwapType[key]+": "+chainIdentifier);