capitalisk-dex 18.0.5 → 18.1.1

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.
Files changed (3) hide show
  1. package/index.js +43 -12
  2. package/package.json +1 -1
  3. package/trade-engine.js +18 -2
package/index.js CHANGED
@@ -1266,7 +1266,17 @@ module.exports = class CapitaliskDEXModule {
1266
1266
 
1267
1267
  await Promise.all(
1268
1268
  this.chainSymbols.map(async (chainSymbol) => {
1269
- return this.chainCrypto[chainSymbol].load(channel, this.processedHeights[chainSymbol]);
1269
+ try {
1270
+ await this.chainCrypto[chainSymbol].load(channel, this.processedHeights[chainSymbol]);
1271
+ } catch (error) {
1272
+ throw new Error(
1273
+ `Failed to load ChainCrypto plugin for the ${
1274
+ chainSymbol
1275
+ } blockchain because of error: ${
1276
+ error.stack
1277
+ }`
1278
+ );
1279
+ }
1270
1280
  })
1271
1281
  );
1272
1282
 
@@ -2227,7 +2237,17 @@ module.exports = class CapitaliskDEXModule {
2227
2237
  this.chainSymbols.map(async (chainSymbol) => {
2228
2238
  let chainCrypto = this.chainCrypto[chainSymbol];
2229
2239
  if (chainCrypto.reset) {
2230
- await chainCrypto.reset(this.processedHeights[chainSymbol]);
2240
+ try {
2241
+ await chainCrypto.reset(this.processedHeights[chainSymbol]);
2242
+ } catch (error) {
2243
+ throw new Error(
2244
+ `Failed to reset ChainCrypto plugin for the ${
2245
+ chainSymbol
2246
+ } blockchain because of error: ${
2247
+ error.stack
2248
+ }`
2249
+ );
2250
+ }
2231
2251
  }
2232
2252
  })
2233
2253
  );
@@ -2757,16 +2777,27 @@ module.exports = class CapitaliskDEXModule {
2757
2777
  async execMultisigTransaction(targetChain, transactionData, message, extraTransferData) {
2758
2778
  let chainTimestamp = this._denormalizeTimestamp(targetChain, transactionData.timestamp);
2759
2779
  let chainCrypto = this.chainCrypto[targetChain];
2760
- let {
2761
- transaction: preparedTxn,
2762
- signature: multisigSignaturePacket
2763
- } = await chainCrypto.prepareTransaction({
2764
- recipientAddress: transactionData.recipientAddress,
2765
- amount: transactionData.amount,
2766
- fee: transactionData.fee,
2767
- timestamp: chainTimestamp,
2768
- message
2769
- });
2780
+ let prepareTxnResult;
2781
+
2782
+ try {
2783
+ prepareTxnResult = await chainCrypto.prepareTransaction({
2784
+ recipientAddress: transactionData.recipientAddress,
2785
+ amount: transactionData.amount,
2786
+ fee: transactionData.fee,
2787
+ timestamp: chainTimestamp,
2788
+ message
2789
+ });
2790
+ } catch (error) {
2791
+ throw new Error(
2792
+ `ChainCrypto plugin for the ${
2793
+ targetChain
2794
+ } blockchain failed to execute prepareTransaction because of error: ${
2795
+ error.stack
2796
+ }`
2797
+ );
2798
+ }
2799
+
2800
+ let { transaction: preparedTxn, signature: multisigSignaturePacket } = prepareTxnResult;
2770
2801
 
2771
2802
  let processedSignerAddressSet = new Set([multisigSignaturePacket.signerAddress]);
2772
2803
  preparedTxn.signatures.push(multisigSignaturePacket);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capitalisk-dex",
3
- "version": "18.0.5",
3
+ "version": "18.1.1",
4
4
  "description": "Decentralized exchange module.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/trade-engine.js CHANGED
@@ -47,6 +47,22 @@ class TradeEngine {
47
47
  };
48
48
  }
49
49
 
50
+ _orderComparator(a, b) {
51
+ if (a.expiryHeight > b.expiryHeight) {
52
+ return 1;
53
+ }
54
+ if (a.expiryHeight < b.expiryHeight) {
55
+ return -1;
56
+ }
57
+ if (a.id > b.id) {
58
+ return 1;
59
+ }
60
+ if (a.id < b.id) {
61
+ return -1;
62
+ }
63
+ return 0;
64
+ }
65
+
50
66
  expireBidOrders(heightThreshold) {
51
67
  let expiredOrders = [];
52
68
  for (let [orderId, order] of this._bidMap) {
@@ -59,7 +75,7 @@ class TradeEngine {
59
75
  this._orderMap.delete(orderId);
60
76
  this._removeFromWalletOrderMap(order.sourceWalletAddress, orderId);
61
77
  }
62
- return expiredOrders;
78
+ return expiredOrders.sort((a, b) => this._orderComparator(a, b));
63
79
  }
64
80
 
65
81
  expireAskOrders(heightThreshold) {
@@ -74,7 +90,7 @@ class TradeEngine {
74
90
  this._orderMap.delete(orderId);
75
91
  this._removeFromWalletOrderMap(order.sourceWalletAddress, orderId);
76
92
  }
77
- return expiredOrders;
93
+ return expiredOrders.sort((a, b) => this._orderComparator(a, b));
78
94
  }
79
95
 
80
96
  wasOrderProcessed(orderId, orderSourceChain, orderHeight) {