@super-protocol/sdk-js 0.12.8-beta.2 → 0.12.9-beta.2

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.
@@ -359,7 +359,7 @@ var BlockchainConnector = /** @class */ (function (_super) {
359
359
  BlockchainConnector.prototype.getTransactions = function (addresses, startBlock, lastBlock, batchSize) {
360
360
  if (batchSize === void 0) { batchSize = constants_1.BLOCK_SIZE_TO_FETCH_TRANSACTION; }
361
361
  return __awaiter(this, void 0, void 0, function () {
362
- var blockchainLastBlock, transactionsByAddress, batch, getBlock, batchLastBlock, blockNumber, blocks;
362
+ var blockchainLastBlock, transactionsByAddress, validAddresses, batch, getBlock, batchLastBlock, blockNumber, blocks;
363
363
  return __generator(this, function (_a) {
364
364
  switch (_a.label) {
365
365
  case 0:
@@ -377,7 +377,14 @@ var BlockchainConnector = /** @class */ (function (_super) {
377
377
  startBlock = Math.max(lastBlock - 1000, 0);
378
378
  }
379
379
  transactionsByAddress = {};
380
- addresses.forEach(function (address) { return (transactionsByAddress[address] = []); });
380
+ validAddresses = addresses.filter(function (address) { var _a; return (_a = store_1.default.web3Https) === null || _a === void 0 ? void 0 : _a.utils.isAddress(address); });
381
+ if (!validAddresses.length) {
382
+ return [2 /*return*/, {
383
+ transactionsByAddress: transactionsByAddress,
384
+ lastBlock: lastBlock,
385
+ }];
386
+ }
387
+ validAddresses.forEach(function (address) { return (transactionsByAddress[address] = []); });
381
388
  _a.label = 2;
382
389
  case 2:
383
390
  if (!(startBlock <= lastBlock)) return [3 /*break*/, 4];
@@ -389,15 +396,15 @@ var BlockchainConnector = /** @class */ (function (_super) {
389
396
  }
390
397
  return [4 /*yield*/, this.executeBatchAsync(batch)];
391
398
  case 3:
392
- blocks = _a.sent();
399
+ blocks = (_a.sent());
393
400
  blocks.forEach(function (block) {
394
401
  if (!(block === null || block === void 0 ? void 0 : block.transactions))
395
402
  return;
396
403
  block.transactions.forEach(function (transaction) {
397
404
  var address = null;
398
- if (addresses.includes(transaction.from))
405
+ if (validAddresses.includes(transaction.from))
399
406
  address = transaction.from;
400
- else if (transaction.to && addresses.includes(transaction.to))
407
+ else if (transaction.to && validAddresses.includes(transaction.to))
401
408
  address = transaction.to;
402
409
  if (address) {
403
410
  transactionsByAddress[address].push(__assign(__assign({}, transaction), { timestamp: +block.timestamp * 1000, input: transaction.input }));
@@ -1,6 +1,6 @@
1
1
  export declare const defaultBlockchainUrl = "http://127.0.0.1:8545";
2
2
  export declare const defaultGasLimit = 7000000;
3
- export declare const defaultGasPrice = "3000000000";
3
+ export declare const defaultGasPrice = "30000000000";
4
4
  export declare const defaultGasPriceMultiplier = 1;
5
5
  export declare const defaultGasLimitMultiplier = 1.2;
6
6
  export declare const ONE_DAY: number;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.POLYGON_MATIC_EVENT_PATH = exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = exports.ONE_DAY = exports.defaultGasLimitMultiplier = exports.defaultGasPriceMultiplier = exports.defaultGasPrice = exports.defaultGasLimit = exports.defaultBlockchainUrl = void 0;
4
4
  exports.defaultBlockchainUrl = "http://127.0.0.1:8545";
5
5
  exports.defaultGasLimit = 7000000;
6
- exports.defaultGasPrice = "3000000000";
6
+ exports.defaultGasPrice = "30000000000";
7
7
  exports.defaultGasPriceMultiplier = 1;
8
8
  exports.defaultGasLimitMultiplier = 1.2;
9
9
  exports.ONE_DAY = 24 * 60 * 60;
@@ -32,7 +32,7 @@ declare class OrdersFactory {
32
32
  * @returns {Promise<void>} - Does not return id of created order!
33
33
  */
34
34
  static createOrder(orderInfo: OrderInfo, holdDeposit?: string, suspended?: boolean, transactionOptions?: TransactionOptions): Promise<void>;
35
- static getOrder(consumer: string, externalId: string): Promise<OrderCreatedEvent>;
35
+ static getOrder(consumer?: string, externalId?: string, fromBlock?: number | string, toBlock?: number | string): Promise<OrderCreatedEvent>;
36
36
  /**
37
37
  * Function for create workflow
38
38
  * @param parentOrderInfo - order info for new order
@@ -56,10 +56,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
56
56
  return (mod && mod.__esModule) ? mod : { "default": mod };
57
57
  };
58
58
  Object.defineProperty(exports, "__esModule", { value: true });
59
+ var utils_1 = require("ethers/lib/utils");
59
60
  var logger_1 = __importDefault(require("../logger"));
60
- var utils_1 = require("../utils");
61
+ var utils_2 = require("../utils");
61
62
  var Order_1 = require("../types/Order");
62
- var utils_2 = require("ethers/lib/utils");
63
63
  var Superpro_1 = __importDefault(require("./Superpro"));
64
64
  var TxManager_1 = __importDefault(require("../utils/TxManager"));
65
65
  var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
@@ -167,9 +167,9 @@ var OrdersFactory = /** @class */ (function () {
167
167
  switch (_a.label) {
168
168
  case 0:
169
169
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
170
- (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
171
- preparedInfo = __assign(__assign({}, orderInfo), { externalId: (0, utils_2.formatBytes32String)(orderInfo.externalId) });
172
- orderInfoArguments = (0, utils_1.objectToTuple)(preparedInfo, Order_1.OrderInfoStructure);
170
+ (0, utils_2.checkIfActionAccountInitialized)(transactionOptions);
171
+ preparedInfo = __assign(__assign({}, orderInfo), { externalId: (0, utils_1.formatBytes32String)(orderInfo.externalId) });
172
+ orderInfoArguments = (0, utils_2.objectToTuple)(preparedInfo, Order_1.OrderInfoStructure);
173
173
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createOrder, [orderInfoArguments, holdDeposit, suspended], transactionOptions)];
174
174
  case 1:
175
175
  _a.sent();
@@ -178,27 +178,30 @@ var OrdersFactory = /** @class */ (function () {
178
178
  });
179
179
  });
180
180
  };
181
- OrdersFactory.getOrder = function (consumer, externalId) {
181
+ OrdersFactory.getOrder = function (consumer, externalId, fromBlock, toBlock) {
182
+ if (consumer === void 0) { consumer = ""; }
183
+ if (externalId === void 0) { externalId = ""; }
182
184
  return __awaiter(this, void 0, void 0, function () {
183
- var contract, filter, foundIds, notFound, response;
185
+ var contract, filter, options, foundIds, notFound, response;
184
186
  return __generator(this, function (_a) {
185
187
  switch (_a.label) {
186
188
  case 0:
187
189
  contract = BlockchainConnector_1.default.getInstance().getContract();
188
190
  filter = {
189
191
  consumer: consumer,
190
- externalId: (0, utils_2.formatBytes32String)(externalId),
192
+ externalId: (0, utils_1.formatBytes32String)(externalId),
191
193
  };
192
- return [4 /*yield*/, contract.getPastEvents("OrderCreated", { filter: filter })];
194
+ options = { filter: filter };
195
+ if (fromBlock)
196
+ options.fromBlock = fromBlock;
197
+ if (toBlock)
198
+ options.toBlock = toBlock;
199
+ return [4 /*yield*/, contract.getPastEvents("OrderCreated", options)];
193
200
  case 1:
194
201
  foundIds = _a.sent();
195
- notFound = {
196
- consumer: consumer,
197
- externalId: externalId,
198
- offerId: "-1",
199
- orderId: "-1",
200
- };
202
+ notFound = __assign(__assign({}, filter), { offerId: "-1", orderId: "-1" });
201
203
  response = foundIds.length > 0 ? foundIds[0].returnValues : notFound;
204
+ response.externalId = (0, utils_1.parseBytes32String)(response.externalId);
202
205
  return [2 /*return*/, response];
203
206
  }
204
207
  });
@@ -220,11 +223,11 @@ var OrdersFactory = /** @class */ (function () {
220
223
  switch (_a.label) {
221
224
  case 0:
222
225
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
223
- (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
224
- preparedInfo = __assign(__assign({}, parentOrderInfo), { externalId: (0, utils_2.formatBytes32String)(parentOrderInfo.externalId) });
225
- parentOrderInfoArgs = (0, utils_1.objectToTuple)(preparedInfo, Order_1.OrderInfoStructure);
226
- preparedSubOrdersInfo = subOrdersInfo.map(function (o) { return (__assign(__assign({}, o), { externalId: (0, utils_2.formatBytes32String)(o.externalId) })); });
227
- subOrdersInfoArgs = (0, utils_1.objectToTuple)(preparedSubOrdersInfo, Order_1.OrderInfoStructureArray);
226
+ (0, utils_2.checkIfActionAccountInitialized)(transactionOptions);
227
+ preparedInfo = __assign(__assign({}, parentOrderInfo), { externalId: (0, utils_1.formatBytes32String)(parentOrderInfo.externalId) });
228
+ parentOrderInfoArgs = (0, utils_2.objectToTuple)(preparedInfo, Order_1.OrderInfoStructure);
229
+ preparedSubOrdersInfo = subOrdersInfo.map(function (o) { return (__assign(__assign({}, o), { externalId: (0, utils_1.formatBytes32String)(o.externalId) })); });
230
+ subOrdersInfoArgs = (0, utils_2.objectToTuple)(preparedSubOrdersInfo, Order_1.OrderInfoStructureArray);
228
231
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createWorkflow, [parentOrderInfoArgs, holdDeposit, subOrdersInfoArgs], transactionOptions)];
229
232
  case 1:
230
233
  _a.sent();
@@ -245,7 +248,7 @@ var OrdersFactory = /** @class */ (function () {
245
248
  switch (_a.label) {
246
249
  case 0:
247
250
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
248
- (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
251
+ (0, utils_2.checkIfActionAccountInitialized)(transactionOptions);
249
252
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.cancelWorkflow, [perentOrderId], transactionOptions)];
250
253
  case 1:
251
254
  _a.sent();
@@ -266,7 +269,7 @@ var OrdersFactory = /** @class */ (function () {
266
269
  switch (_a.label) {
267
270
  case 0:
268
271
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
269
- (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
272
+ (0, utils_2.checkIfActionAccountInitialized)(transactionOptions);
270
273
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.withdrawWorkflowChange, [parentOrderId], transactionOptions)];
271
274
  case 1:
272
275
  _a.sent();
@@ -288,7 +291,7 @@ var OrdersFactory = /** @class */ (function () {
288
291
  switch (_a.label) {
289
292
  case 0:
290
293
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
291
- (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
294
+ (0, utils_2.checkIfActionAccountInitialized)(transactionOptions);
292
295
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.refillOrder, [orderId, amount], transactionOptions)];
293
296
  case 1:
294
297
  _a.sent();
@@ -311,7 +314,7 @@ var OrdersFactory = /** @class */ (function () {
311
314
  .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
312
315
  return __generator(this, function (_a) {
313
316
  //consumer: string, externalId: string, offerId: string, orderId: string
314
- callback(event.returnValues.consumer, (0, utils_2.parseBytes32String)(event.returnValues.externalId), event.returnValues.offerId, event.returnValues.orderId, {
317
+ callback(event.returnValues.consumer, (0, utils_1.parseBytes32String)(event.returnValues.externalId), event.returnValues.offerId, event.returnValues.orderId, {
315
318
  index: event.blockNumber,
316
319
  hash: event.blockHash,
317
320
  });
@@ -339,7 +342,7 @@ var OrdersFactory = /** @class */ (function () {
339
342
  .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
340
343
  return __generator(this, function (_a) {
341
344
  //consumer: string, externalId: string, offerId: string, orderId: string
342
- callback(event.returnValues.consumer, (0, utils_2.parseBytes32String)(event.returnValues.externalId), event.returnValues.offerId, event.returnValues.orderId, {
345
+ callback(event.returnValues.consumer, (0, utils_1.parseBytes32String)(event.returnValues.externalId), event.returnValues.offerId, event.returnValues.orderId, {
343
346
  index: event.blockNumber,
344
347
  hash: event.blockHash,
345
348
  });
@@ -685,13 +688,13 @@ var OrdersFactory = /** @class */ (function () {
685
688
  };
686
689
  OrdersFactory.logger = logger_1.default.child({ className: "OrdersFactory" });
687
690
  __decorate([
688
- (0, utils_1.incrementMethodCall)()
691
+ (0, utils_2.incrementMethodCall)()
689
692
  ], OrdersFactory, "createOrder", null);
690
693
  __decorate([
691
- (0, utils_1.incrementMethodCall)()
694
+ (0, utils_2.incrementMethodCall)()
692
695
  ], OrdersFactory, "getOrder", null);
693
696
  __decorate([
694
- (0, utils_1.incrementMethodCall)()
697
+ (0, utils_2.incrementMethodCall)()
695
698
  ], OrdersFactory, "createWorkflow", null);
696
699
  return OrdersFactory;
697
700
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.12.8-beta.2",
3
+ "version": "0.12.9-beta.2",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [