@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.
- package/dist/swapper/Swapper.d.ts +5 -0
- package/dist/swapper/Swapper.js +40 -31
- package/package.json +1 -1
- package/src/swapper/Swapper.ts +49 -36
|
@@ -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
|
package/dist/swapper/Swapper.js
CHANGED
|
@@ -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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
package/src/swapper/Swapper.ts
CHANGED
|
@@ -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
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
668
|
+
try {
|
|
669
|
+
const _chainInterface: any = chainInterface;
|
|
670
|
+
if(_chainInterface.verifyNetwork!=null) {
|
|
671
|
+
await _chainInterface.verifyNetwork(this.bitcoinNetwork);
|
|
672
|
+
}
|
|
666
673
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
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
|
-
|
|
695
|
-
|
|
696
|
-
)
|
|
697
|
-
}
|
|
703
|
+
)
|
|
704
|
+
}
|
|
698
705
|
|
|
699
|
-
|
|
700
|
-
|
|
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);
|