@super-protocol/sdk-js 0.9.0-beta.2 → 0.10.1-beta.0

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.
@@ -3488,6 +3488,24 @@
3488
3488
  "stateMutability": "nonpayable",
3489
3489
  "type": "function"
3490
3490
  },
3491
+ {
3492
+ "inputs": [
3493
+ {
3494
+ "internalType": "address",
3495
+ "name": "consumer",
3496
+ "type": "address"
3497
+ },
3498
+ {
3499
+ "internalType": "uint256",
3500
+ "name": "orderId",
3501
+ "type": "uint256"
3502
+ }
3503
+ ],
3504
+ "name": "cancelOrderByApp",
3505
+ "outputs": [],
3506
+ "stateMutability": "nonpayable",
3507
+ "type": "function"
3508
+ },
3491
3509
  {
3492
3510
  "inputs": [
3493
3511
  {
@@ -3561,6 +3579,11 @@
3561
3579
  "internalType": "struct OrderArgs",
3562
3580
  "name": "args",
3563
3581
  "type": "tuple"
3582
+ },
3583
+ {
3584
+ "internalType": "bytes32",
3585
+ "name": "externalId",
3586
+ "type": "bytes32"
3564
3587
  }
3565
3588
  ],
3566
3589
  "internalType": "struct OrderInfo",
@@ -3576,11 +3599,6 @@
3576
3599
  "internalType": "bool",
3577
3600
  "name": "suspended",
3578
3601
  "type": "bool"
3579
- },
3580
- {
3581
- "internalType": "bytes32",
3582
- "name": "externalId",
3583
- "type": "bytes32"
3584
3602
  }
3585
3603
  ],
3586
3604
  "name": "createOrder",
@@ -3649,6 +3667,11 @@
3649
3667
  "internalType": "struct OrderArgs",
3650
3668
  "name": "args",
3651
3669
  "type": "tuple"
3670
+ },
3671
+ {
3672
+ "internalType": "bytes32",
3673
+ "name": "externalId",
3674
+ "type": "bytes32"
3652
3675
  }
3653
3676
  ],
3654
3677
  "internalType": "struct OrderInfo",
@@ -3664,11 +3687,6 @@
3664
3687
  "internalType": "bool",
3665
3688
  "name": "suspended",
3666
3689
  "type": "bool"
3667
- },
3668
- {
3669
- "internalType": "bytes32",
3670
- "name": "externalId",
3671
- "type": "bytes32"
3672
3690
  }
3673
3691
  ],
3674
3692
  "name": "createOrderByApp",
@@ -3737,6 +3755,11 @@
3737
3755
  "internalType": "struct OrderArgs",
3738
3756
  "name": "args",
3739
3757
  "type": "tuple"
3758
+ },
3759
+ {
3760
+ "internalType": "bytes32",
3761
+ "name": "externalId",
3762
+ "type": "bytes32"
3740
3763
  }
3741
3764
  ],
3742
3765
  "internalType": "struct OrderInfo",
@@ -3750,11 +3773,6 @@
3750
3773
  "name": "blockParentOrder",
3751
3774
  "type": "bool"
3752
3775
  },
3753
- {
3754
- "internalType": "bytes32",
3755
- "name": "externalId",
3756
- "type": "bytes32"
3757
- },
3758
3776
  {
3759
3777
  "internalType": "uint256",
3760
3778
  "name": "holdSum",
@@ -3837,6 +3855,11 @@
3837
3855
  "internalType": "struct OrderArgs",
3838
3856
  "name": "args",
3839
3857
  "type": "tuple"
3858
+ },
3859
+ {
3860
+ "internalType": "bytes32",
3861
+ "name": "externalId",
3862
+ "type": "bytes32"
3840
3863
  }
3841
3864
  ],
3842
3865
  "internalType": "struct OrderInfo",
@@ -3850,11 +3873,6 @@
3850
3873
  "name": "blockParentOrder",
3851
3874
  "type": "bool"
3852
3875
  },
3853
- {
3854
- "internalType": "bytes32",
3855
- "name": "externalId",
3856
- "type": "bytes32"
3857
- },
3858
3876
  {
3859
3877
  "internalType": "uint256",
3860
3878
  "name": "holdSum",
@@ -4099,6 +4117,24 @@
4099
4117
  "stateMutability": "nonpayable",
4100
4118
  "type": "function"
4101
4119
  },
4120
+ {
4121
+ "inputs": [
4122
+ {
4123
+ "internalType": "address",
4124
+ "name": "consumer",
4125
+ "type": "address"
4126
+ },
4127
+ {
4128
+ "internalType": "uint256",
4129
+ "name": "orderId",
4130
+ "type": "uint256"
4131
+ }
4132
+ ],
4133
+ "name": "withdrawChangeByApp",
4134
+ "outputs": [],
4135
+ "stateMutability": "nonpayable",
4136
+ "type": "function"
4137
+ },
4102
4138
  {
4103
4139
  "inputs": [
4104
4140
  {
@@ -4270,6 +4306,11 @@
4270
4306
  "internalType": "struct OrderArgs",
4271
4307
  "name": "args",
4272
4308
  "type": "tuple"
4309
+ },
4310
+ {
4311
+ "internalType": "bytes32",
4312
+ "name": "externalId",
4313
+ "type": "bytes32"
4273
4314
  }
4274
4315
  ],
4275
4316
  "internalType": "struct OrderInfo",
@@ -5920,6 +5961,19 @@
5920
5961
  "name": "WorkflowCreated",
5921
5962
  "type": "event"
5922
5963
  },
5964
+ {
5965
+ "inputs": [
5966
+ {
5967
+ "internalType": "uint256",
5968
+ "name": "parentOrderId",
5969
+ "type": "uint256"
5970
+ }
5971
+ ],
5972
+ "name": "cancelWorkflow",
5973
+ "outputs": [],
5974
+ "stateMutability": "nonpayable",
5975
+ "type": "function"
5976
+ },
5923
5977
  {
5924
5978
  "inputs": [
5925
5979
  {
@@ -5970,6 +6024,11 @@
5970
6024
  "internalType": "struct OrderArgs",
5971
6025
  "name": "args",
5972
6026
  "type": "tuple"
6027
+ },
6028
+ {
6029
+ "internalType": "bytes32",
6030
+ "name": "externalId",
6031
+ "type": "bytes32"
5973
6032
  }
5974
6033
  ],
5975
6034
  "internalType": "struct OrderInfo",
@@ -5981,11 +6040,6 @@
5981
6040
  "name": "holdDeposit",
5982
6041
  "type": "uint256"
5983
6042
  },
5984
- {
5985
- "internalType": "bytes32",
5986
- "name": "externalId",
5987
- "type": "bytes32"
5988
- },
5989
6043
  {
5990
6044
  "components": [
5991
6045
  {
@@ -6034,6 +6088,11 @@
6034
6088
  "internalType": "struct OrderArgs",
6035
6089
  "name": "args",
6036
6090
  "type": "tuple"
6091
+ },
6092
+ {
6093
+ "internalType": "bytes32",
6094
+ "name": "externalId",
6095
+ "type": "bytes32"
6037
6096
  }
6038
6097
  ],
6039
6098
  "internalType": "struct OrderInfo[]",
@@ -6046,6 +6105,19 @@
6046
6105
  "stateMutability": "nonpayable",
6047
6106
  "type": "function"
6048
6107
  },
6108
+ {
6109
+ "inputs": [
6110
+ {
6111
+ "internalType": "uint256",
6112
+ "name": "parentOrderId",
6113
+ "type": "uint256"
6114
+ }
6115
+ ],
6116
+ "name": "withdrawWorkflowChange",
6117
+ "outputs": [],
6118
+ "stateMutability": "nonpayable",
6119
+ "type": "function"
6120
+ },
6049
6121
  {
6050
6122
  "anonymous": false,
6051
6123
  "inputs": [
@@ -7594,6 +7666,24 @@
7594
7666
  "stateMutability": "nonpayable",
7595
7667
  "type": "function"
7596
7668
  },
7669
+ {
7670
+ "inputs": [
7671
+ {
7672
+ "internalType": "address",
7673
+ "name": "consumer",
7674
+ "type": "address"
7675
+ },
7676
+ {
7677
+ "internalType": "uint256",
7678
+ "name": "orderId",
7679
+ "type": "uint256"
7680
+ }
7681
+ ],
7682
+ "name": "cancelOrderByApp",
7683
+ "outputs": [],
7684
+ "stateMutability": "nonpayable",
7685
+ "type": "function"
7686
+ },
7597
7687
  {
7598
7688
  "inputs": [
7599
7689
  {
@@ -7649,6 +7739,11 @@
7649
7739
  "internalType": "struct OrderArgs",
7650
7740
  "name": "args",
7651
7741
  "type": "tuple"
7742
+ },
7743
+ {
7744
+ "internalType": "bytes32",
7745
+ "name": "externalId",
7746
+ "type": "bytes32"
7652
7747
  }
7653
7748
  ],
7654
7749
  "internalType": "struct OrderInfo",
@@ -7664,11 +7759,6 @@
7664
7759
  "internalType": "bool",
7665
7760
  "name": "suspended",
7666
7761
  "type": "bool"
7667
- },
7668
- {
7669
- "internalType": "bytes32",
7670
- "name": "externalId",
7671
- "type": "bytes32"
7672
7762
  }
7673
7763
  ],
7674
7764
  "name": "createOrderByApp",
@@ -7742,6 +7832,11 @@
7742
7832
  "internalType": "struct OrderArgs",
7743
7833
  "name": "args",
7744
7834
  "type": "tuple"
7835
+ },
7836
+ {
7837
+ "internalType": "bytes32",
7838
+ "name": "externalId",
7839
+ "type": "bytes32"
7745
7840
  }
7746
7841
  ],
7747
7842
  "internalType": "struct OrderInfo",
@@ -7755,11 +7850,6 @@
7755
7850
  "name": "blockParentOrder",
7756
7851
  "type": "bool"
7757
7852
  },
7758
- {
7759
- "internalType": "bytes32",
7760
- "name": "externalId",
7761
- "type": "bytes32"
7762
- },
7763
7853
  {
7764
7854
  "internalType": "uint256",
7765
7855
  "name": "holdSum",
@@ -7845,6 +7935,11 @@
7845
7935
  "internalType": "struct OrderArgs",
7846
7936
  "name": "args",
7847
7937
  "type": "tuple"
7938
+ },
7939
+ {
7940
+ "internalType": "bytes32",
7941
+ "name": "externalId",
7942
+ "type": "bytes32"
7848
7943
  }
7849
7944
  ],
7850
7945
  "internalType": "struct OrderInfo",
@@ -7890,6 +7985,24 @@
7890
7985
  "stateMutability": "nonpayable",
7891
7986
  "type": "function"
7892
7987
  },
7988
+ {
7989
+ "inputs": [
7990
+ {
7991
+ "internalType": "address",
7992
+ "name": "sender",
7993
+ "type": "address"
7994
+ },
7995
+ {
7996
+ "internalType": "uint256",
7997
+ "name": "orderId",
7998
+ "type": "uint256"
7999
+ }
8000
+ ],
8001
+ "name": "withdrawChangeByApp",
8002
+ "outputs": [],
8003
+ "stateMutability": "nonpayable",
8004
+ "type": "function"
8005
+ },
7893
8006
  {
7894
8007
  "inputs": [
7895
8008
  {
@@ -7991,6 +8104,11 @@
7991
8104
  "internalType": "struct OrderArgs",
7992
8105
  "name": "args",
7993
8106
  "type": "tuple"
8107
+ },
8108
+ {
8109
+ "internalType": "bytes32",
8110
+ "name": "externalId",
8111
+ "type": "bytes32"
7994
8112
  }
7995
8113
  ],
7996
8114
  "internalType": "struct OrderInfo",
@@ -107,7 +107,7 @@ declare class Order {
107
107
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
108
108
  * @returns {Promise<void>} - Does not return id of created sub order!
109
109
  */
110
- createSubOrder(subOrderInfo: OrderInfo, blocking: boolean, externalId?: string, holdSum?: string, transactionOptions?: TransactionOptions): Promise<void>;
110
+ createSubOrder(subOrderInfo: OrderInfo, blocking: boolean, holdSum?: string, transactionOptions?: TransactionOptions): Promise<void>;
111
111
  /**
112
112
  * Function for creating pack of sub orders (wokflow) for current order
113
113
  * @param subOrdersInfo - orders info for new subOrders
@@ -408,21 +408,19 @@ var Order = /** @class */ (function () {
408
408
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
409
409
  * @returns {Promise<void>} - Does not return id of created sub order!
410
410
  */
411
- Order.prototype.createSubOrder = function (subOrderInfo, blocking, externalId, holdSum, transactionOptions) {
412
- if (externalId === void 0) { externalId = "default"; }
411
+ Order.prototype.createSubOrder = function (subOrderInfo, blocking, holdSum, transactionOptions) {
413
412
  if (holdSum === void 0) { holdSum = '0'; }
414
413
  return __awaiter(this, void 0, void 0, function () {
415
- var tupleSubOrder, formattedExternalId, params;
414
+ var tupleSubOrder, params;
416
415
  return __generator(this, function (_a) {
417
416
  switch (_a.label) {
418
417
  case 0:
419
418
  transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
420
419
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
420
+ subOrderInfo.externalId = (0, utils_2.formatBytes32String)(subOrderInfo.externalId);
421
421
  tupleSubOrder = (0, utils_1.objectToTuple)(subOrderInfo, Order_1.OrderInfoStructure);
422
- formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
423
422
  params = {
424
423
  blockParentOrder: blocking,
425
- externalId: formattedExternalId,
426
424
  holdSum: holdSum,
427
425
  };
428
426
  return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.createSubOrder, [this.id, tupleSubOrder, params], transactionOptions)];
@@ -451,11 +449,10 @@ var Order = /** @class */ (function () {
451
449
  batch = new transactionOptions.web3.BatchRequest();
452
450
  promises = subOrdersInfo.map(function (subOrderInfo) {
453
451
  return new Promise(function (res, rej) {
452
+ subOrderInfo.externalId = (0, utils_2.formatBytes32String)(subOrderInfo.externalId);
454
453
  var tupleSubOrder = (0, utils_1.objectToTuple)(subOrderInfo, Order_1.OrderInfoStructure);
455
- var formattedExternalId = (0, utils_2.formatBytes32String)(subOrderInfo.externalId);
456
454
  var params = {
457
455
  blockParentOrder: subOrderInfo.blocking,
458
- externalId: formattedExternalId,
459
456
  holdSum: subOrderInfo.holdSum,
460
457
  };
461
458
  var request = Order.contract.methods.createSubOrder(_this.id, tupleSubOrder, params).send.request({
@@ -26,7 +26,7 @@ declare class OrdersFactory {
26
26
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
27
27
  * @returns {Promise<void>} - Does not return id of created order!
28
28
  */
29
- static createOrder(orderInfo: OrderInfo, holdDeposit?: string, suspended?: boolean, externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
29
+ static createOrder(orderInfo: OrderInfo, holdDeposit?: string, suspended?: boolean, transactionOptions?: TransactionOptions): Promise<void>;
30
30
  static getOrder(consumer: string, externalId: string): Promise<OrderCreatedEvent>;
31
31
  /**
32
32
  * Function for create workflow
@@ -36,7 +36,7 @@ declare class OrdersFactory {
36
36
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
37
37
  * @returns {Promise<void>} - Does not return id of created order!
38
38
  */
39
- static createWorkflow(perentOrderInfo: OrderInfo, subOrdersInfo: OrderInfo[], holdDeposit?: string, externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
39
+ static createWorkflow(perentOrderInfo: OrderInfo, subOrdersInfo: OrderInfo[], holdDeposit?: string, transactionOptions?: TransactionOptions): Promise<void>;
40
40
  /**
41
41
  * Function for refilling order deposit
42
42
  * @param orderId - order id
@@ -123,20 +123,19 @@ var OrdersFactory = /** @class */ (function () {
123
123
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
124
124
  * @returns {Promise<void>} - Does not return id of created order!
125
125
  */
126
- OrdersFactory.createOrder = function (orderInfo, holdDeposit, suspended, externalId, transactionOptions) {
126
+ OrdersFactory.createOrder = function (orderInfo, holdDeposit, suspended, transactionOptions) {
127
127
  if (holdDeposit === void 0) { holdDeposit = "0"; }
128
128
  if (suspended === void 0) { suspended = false; }
129
- if (externalId === void 0) { externalId = "default"; }
130
129
  return __awaiter(this, void 0, void 0, function () {
131
- var contract, orderInfoArguments, formattedExternalId;
130
+ var contract, orderInfoArguments;
132
131
  return __generator(this, function (_a) {
133
132
  switch (_a.label) {
134
133
  case 0:
135
134
  contract = BlockchainConnector_1.default.getContractInstance(transactionOptions);
136
135
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
136
+ orderInfo.externalId = (0, utils_2.formatBytes32String)(orderInfo.externalId);
137
137
  orderInfoArguments = (0, utils_1.objectToTuple)(orderInfo, Order_1.OrderInfoStructure);
138
- formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
139
- return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createOrder, [orderInfoArguments, holdDeposit, suspended, formattedExternalId], transactionOptions)];
138
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createOrder, [orderInfoArguments, holdDeposit, suspended], transactionOptions)];
140
139
  case 1:
141
140
  _a.sent();
142
141
  return [2 /*return*/];
@@ -178,20 +177,20 @@ var OrdersFactory = /** @class */ (function () {
178
177
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
179
178
  * @returns {Promise<void>} - Does not return id of created order!
180
179
  */
181
- OrdersFactory.createWorkflow = function (perentOrderInfo, subOrdersInfo, holdDeposit, externalId, transactionOptions) {
180
+ OrdersFactory.createWorkflow = function (perentOrderInfo, subOrdersInfo, holdDeposit, transactionOptions) {
182
181
  if (holdDeposit === void 0) { holdDeposit = "0"; }
183
- if (externalId === void 0) { externalId = "default"; }
184
182
  return __awaiter(this, void 0, void 0, function () {
185
- var contract, perentOrderInfoArgs, formattedExternalId, subOrdersInfoArgs;
183
+ var contract, perentOrderInfoArgs, subOrdersInfoArgs;
186
184
  return __generator(this, function (_a) {
187
185
  switch (_a.label) {
188
186
  case 0:
189
187
  contract = BlockchainConnector_1.default.getContractInstance(transactionOptions);
190
188
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
189
+ perentOrderInfo.externalId = (0, utils_2.formatBytes32String)(perentOrderInfo.externalId);
191
190
  perentOrderInfoArgs = (0, utils_1.objectToTuple)(perentOrderInfo, Order_1.OrderInfoStructure);
192
- formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
191
+ subOrdersInfo.forEach(function (o) { return o.externalId = (0, utils_2.formatBytes32String)(o.externalId); });
193
192
  subOrdersInfoArgs = (0, utils_1.objectToTuple)(subOrdersInfo, Order_1.OrderInfoStructureArray);
194
- return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createWorkflow, [perentOrderInfoArgs, holdDeposit, formattedExternalId, subOrdersInfoArgs], transactionOptions)];
193
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createWorkflow, [perentOrderInfoArgs, holdDeposit, subOrdersInfoArgs], transactionOptions)];
195
194
  case 1:
196
195
  _a.sent();
197
196
  return [2 /*return*/];
@@ -30,6 +30,7 @@ export declare const OrderInfoStructure: {
30
30
  inputOffers: StringConstructor[];
31
31
  selectedOffers: StringConstructor[];
32
32
  };
33
+ externalId: StringConstructor;
33
34
  };
34
35
  export declare const OrderInfoStructureArray: {
35
36
  offer: StringConstructor;
@@ -42,6 +43,7 @@ export declare const OrderInfoStructureArray: {
42
43
  inputOffers: StringConstructor[];
43
44
  selectedOffers: StringConstructor[];
44
45
  };
46
+ externalId: StringConstructor;
45
47
  }[];
46
48
  export declare type OrderInfo = {
47
49
  offer: string;
@@ -50,10 +52,10 @@ export declare type OrderInfo = {
50
52
  encryptedArgs: string;
51
53
  status: OrderStatus;
52
54
  args: OrderArgs;
55
+ externalId: string;
53
56
  };
54
57
  export declare type ExtendedOrderInfo = OrderInfo & {
55
58
  blocking: boolean;
56
- externalId: string;
57
59
  holdSum: string;
58
60
  };
59
61
  export declare const OrderResultStructure: {
@@ -68,6 +70,5 @@ export declare type OrderResult = {
68
70
  };
69
71
  export declare type SubOrderParams = {
70
72
  blockParentOrder: Boolean;
71
- externalId: string;
72
73
  holdSum: string;
73
74
  };
@@ -27,6 +27,7 @@ exports.OrderInfoStructure = {
27
27
  encryptedArgs: String,
28
28
  status: OrderStatus,
29
29
  args: exports.OrderArgsStructure,
30
+ externalId: String,
30
31
  };
31
32
  // Array of order info structures
32
33
  exports.OrderInfoStructureArray = [exports.OrderInfoStructure];
@@ -6,6 +6,7 @@ declare class NonceTracker {
6
6
  constructor(web3: Web3);
7
7
  initAccount(address: string): Promise<void>;
8
8
  isManaged(address: string): boolean;
9
+ reinitialize(): Promise<void>;
9
10
  private checkAccount;
10
11
  getNonce(address: string): number;
11
12
  consumeNonce(address: string): number;
@@ -71,6 +71,32 @@ var NonceTracker = /** @class */ (function () {
71
71
  NonceTracker.prototype.isManaged = function (address) {
72
72
  return address in this.store;
73
73
  };
74
+ NonceTracker.prototype.reinitialize = function () {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var _this = this;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0: return [4 /*yield*/, Promise.all(Object.keys(this.store).map(function (address) { return __awaiter(_this, void 0, void 0, function () {
80
+ var txCount;
81
+ return __generator(this, function (_a) {
82
+ switch (_a.label) {
83
+ case 0: return [4 /*yield*/, this.web3.eth.getTransactionCount(address)];
84
+ case 1:
85
+ txCount = _a.sent();
86
+ NonceTracker.logger.trace("Account ".concat(address, " has been reinitialized with nonce: ").concat(txCount));
87
+ this.store[address] = txCount;
88
+ return [2 /*return*/];
89
+ }
90
+ });
91
+ }); }))];
92
+ case 1:
93
+ _a.sent();
94
+ NonceTracker.logger.trace("All accounts has been reinitialized");
95
+ return [2 /*return*/];
96
+ }
97
+ });
98
+ });
99
+ };
74
100
  NonceTracker.prototype.checkAccount = function (address) {
75
101
  if (this.isManaged(address)) {
76
102
  return;
@@ -12,10 +12,16 @@ declare class TxManager {
12
12
  private static web3;
13
13
  private static nonceTracker;
14
14
  private static logger;
15
+ private static transactionsOnHold;
16
+ private static countOfPendingTransactions;
15
17
  static init(web3: Web3): void;
16
18
  private static checkIfInitialized;
17
19
  static initAccount(address: string): Promise<void>;
18
20
  static execute(method: (...args: ArgumentsType) => MethodReturnType, args: ArgumentsType, transactionOptions?: TransactionOptions, to?: string): Promise<TransactionReceipt>;
19
21
  static publishTransaction(txData: Record<string, any>, transactionOptions?: TransactionOptions, transactionCall?: MethodReturnType): Promise<TransactionReceipt>;
22
+ private static onStartPublishing;
23
+ private static onError;
24
+ private static onFinishPublishing;
25
+ private static waitForPendingTransactions;
20
26
  }
21
27
  export default TxManager;
@@ -92,39 +92,42 @@ var TxManager = /** @class */ (function () {
92
92
  };
93
93
  TxManager.publishTransaction = function (txData, transactionOptions, transactionCall) {
94
94
  return __awaiter(this, void 0, void 0, function () {
95
- var web3, options, estimatedGas, e_1, signingKey, signed;
95
+ var web3, options, estimatedGas, e_1, signingKey, signed, data, data, e_2;
96
96
  return __generator(this, function (_a) {
97
97
  switch (_a.label) {
98
98
  case 0:
99
99
  this.checkIfInitialized();
100
100
  (0, utils_1.checkIfInitialized)();
101
101
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
102
+ return [4 /*yield*/, this.onStartPublishing()];
103
+ case 1:
104
+ _a.sent();
102
105
  web3 = (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) || this.web3;
103
106
  return [4 /*yield*/, (0, utils_1.createTransactionOptions)(__assign({}, transactionOptions))];
104
- case 1:
107
+ case 2:
105
108
  options = _a.sent();
106
109
  if (!options.from) {
107
110
  throw Error("From account is undefined. You should pass it to transactionOptions or init action account.");
108
111
  }
109
112
  txData = __assign(__assign({}, options), txData);
110
- if (!transactionCall) return [3 /*break*/, 6];
113
+ if (!transactionCall) return [3 /*break*/, 7];
111
114
  estimatedGas = void 0;
112
- _a.label = 2;
113
- case 2:
114
- _a.trys.push([2, 4, , 5]);
115
- return [4 /*yield*/, transactionCall.estimateGas(txData)];
115
+ _a.label = 3;
116
116
  case 3:
117
- estimatedGas = _a.sent();
118
- return [3 /*break*/, 5];
117
+ _a.trys.push([3, 5, , 6]);
118
+ return [4 /*yield*/, transactionCall.estimateGas(txData)];
119
119
  case 4:
120
+ estimatedGas = _a.sent();
121
+ return [3 /*break*/, 6];
122
+ case 5:
120
123
  e_1 = _a.sent();
121
124
  TxManager.logger.debug({ error: e_1 }, "Fail to calculate estimated gas");
122
125
  estimatedGas = constants_1.defaultGasLimit;
123
- return [3 /*break*/, 5];
124
- case 5:
125
- txData.gas = Math.ceil(estimatedGas * store_1.default.gasLimitMultiplier);
126
- _a.label = 6;
126
+ return [3 /*break*/, 6];
127
127
  case 6:
128
+ txData.gas = Math.ceil(estimatedGas * store_1.default.gasLimitMultiplier);
129
+ _a.label = 7;
130
+ case 7:
128
131
  // TODO: Consider a better way to organize different strategies for publishing transactions.
129
132
  if (!(0, utils_1.checkForUsingExternalTxManager)(transactionOptions)) {
130
133
  if (this.nonceTracker.isManaged(options.from)) {
@@ -132,9 +135,12 @@ var TxManager = /** @class */ (function () {
132
135
  }
133
136
  }
134
137
  signingKey = store_1.default.keys[options.from];
135
- if (!signingKey) return [3 /*break*/, 8];
138
+ _a.label = 8;
139
+ case 8:
140
+ _a.trys.push([8, 14, , 16]);
141
+ if (!signingKey) return [3 /*break*/, 11];
136
142
  return [4 /*yield*/, web3.eth.accounts.signTransaction(txData, signingKey)];
137
- case 7:
143
+ case 9:
138
144
  signed = _a.sent();
139
145
  if (!signed.rawTransaction) {
140
146
  throw new Error("Failed to sign transaction");
@@ -143,17 +149,98 @@ var TxManager = /** @class */ (function () {
143
149
  txHash: signed.transactionHash,
144
150
  txData: lodash_1.default.omit(txData, ["data"]),
145
151
  }, "Publishing signed transaction");
146
- return [2 /*return*/, web3.eth.sendSignedTransaction(signed.rawTransaction)];
147
- case 8:
152
+ return [4 /*yield*/, web3.eth.sendSignedTransaction(signed.rawTransaction)];
153
+ case 10:
154
+ data = _a.sent();
155
+ this.onFinishPublishing();
156
+ return [2 /*return*/, data];
157
+ case 11:
148
158
  TxManager.logger.debug({
149
159
  txData: lodash_1.default.omit(txData, ["data"]),
150
160
  }, "Publishing unsigned transaction");
151
- return [2 /*return*/, web3.eth.sendTransaction(txData)];
161
+ return [4 /*yield*/, web3.eth.sendTransaction(txData)];
162
+ case 12:
163
+ data = _a.sent();
164
+ this.onFinishPublishing();
165
+ return [2 /*return*/, data];
166
+ case 13: return [3 /*break*/, 16];
167
+ case 14:
168
+ e_2 = _a.sent();
169
+ TxManager.logger.error(e_2, "Error during transaction execution");
170
+ return [4 /*yield*/, this.onError()];
171
+ case 15:
172
+ _a.sent();
173
+ throw e_2;
174
+ case 16: return [2 /*return*/];
175
+ }
176
+ });
177
+ });
178
+ };
179
+ TxManager.onStartPublishing = function () {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ return __generator(this, function (_a) {
182
+ switch (_a.label) {
183
+ case 0:
184
+ this.countOfPendingTransactions++;
185
+ if (!this.transactionsOnHold)
186
+ return [2 /*return*/];
187
+ return [4 /*yield*/, this.waitForPendingTransactions()];
188
+ case 1:
189
+ _a.sent();
190
+ return [2 /*return*/];
191
+ }
192
+ });
193
+ });
194
+ };
195
+ TxManager.onError = function () {
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ return __generator(this, function (_a) {
198
+ switch (_a.label) {
199
+ case 0:
200
+ this.countOfPendingTransactions--;
201
+ if (this.countOfPendingTransactions === 0)
202
+ return [2 /*return*/];
203
+ this.transactionsOnHold = [];
204
+ return [4 /*yield*/, this.waitForPendingTransactions()];
205
+ case 1:
206
+ _a.sent();
207
+ return [2 /*return*/];
208
+ }
209
+ });
210
+ });
211
+ };
212
+ TxManager.onFinishPublishing = function () {
213
+ var _this = this;
214
+ this.countOfPendingTransactions--;
215
+ if (this.countOfPendingTransactions === 0 && this.transactionsOnHold) {
216
+ this.nonceTracker.reinitialize().then(function () {
217
+ var _a;
218
+ (_a = _this.transactionsOnHold) === null || _a === void 0 ? void 0 : _a.forEach(function (callback) { return callback(); });
219
+ _this.transactionsOnHold = undefined;
220
+ });
221
+ }
222
+ };
223
+ TxManager.waitForPendingTransactions = function () {
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ var _this = this;
226
+ return __generator(this, function (_a) {
227
+ switch (_a.label) {
228
+ case 0: return [4 /*yield*/, new Promise(function (resolve) {
229
+ if (!_this.transactionsOnHold)
230
+ return resolve();
231
+ _this.transactionsOnHold.push(function () {
232
+ resolve();
233
+ });
234
+ })];
235
+ case 1:
236
+ _a.sent();
237
+ return [2 /*return*/];
152
238
  }
153
239
  });
154
240
  });
155
241
  };
156
242
  TxManager.logger = logger_1.default.child({ className: "TxManager" });
243
+ TxManager.countOfPendingTransactions = 0;
157
244
  return TxManager;
158
245
  }());
159
246
  exports.default = TxManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.9.0-beta.2",
3
+ "version": "0.10.1-beta.0",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [