@super-protocol/sdk-js 0.13.0-beta.0 → 0.13.0-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.
@@ -58,6 +58,7 @@ var SlotInfo_1 = require("../types/SlotInfo");
58
58
  var OptionInfo_1 = require("../types/OptionInfo");
59
59
  var SlotUsage_1 = require("../types/SlotUsage");
60
60
  var utils_2 = require("ethers/lib/utils");
61
+ var TeeOffers_1 = __importDefault(require("../staticModels/TeeOffers"));
61
62
  var Offer = /** @class */ (function () {
62
63
  function Offer(offerId) {
63
64
  this.id = offerId;
@@ -313,13 +314,20 @@ var Offer = /** @class */ (function () {
313
314
  */
314
315
  Offer.prototype.getSlotById = function (slotId) {
315
316
  return __awaiter(this, void 0, void 0, function () {
316
- var slot;
317
- return __generator(this, function (_a) {
318
- switch (_a.label) {
317
+ var slot, _a, _b, _c;
318
+ return __generator(this, function (_d) {
319
+ switch (_d.label) {
319
320
  case 0: return [4 /*yield*/, Offer.contract.methods.getValueOfferSlotById(this.id, slotId).call()];
320
321
  case 1:
321
- slot = _a.sent();
322
- return [2 /*return*/, (0, utils_1.tupleToObject)(slot, ValueOfferSlot_1.ValueOfferSlotStructure)];
322
+ slot = _d.sent();
323
+ slot = (0, utils_1.tupleToObject)(slot, ValueOfferSlot_1.ValueOfferSlotStructure);
324
+ _a = slot;
325
+ _b = utils_1.unpackSlotInfo;
326
+ _c = [slot.info];
327
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
328
+ case 2:
329
+ _a.info = _b.apply(void 0, _c.concat([_d.sent()]));
330
+ return [2 /*return*/, slot];
323
331
  }
324
332
  });
325
333
  });
@@ -332,13 +340,29 @@ var Offer = /** @class */ (function () {
332
340
  */
333
341
  Offer.prototype.getSlots = function (begin, end) {
334
342
  return __awaiter(this, void 0, void 0, function () {
335
- var slot;
336
- return __generator(this, function (_a) {
337
- switch (_a.label) {
343
+ var slots, _i, slots_1, slot, _a, _b, _c;
344
+ return __generator(this, function (_d) {
345
+ switch (_d.label) {
338
346
  case 0: return [4 /*yield*/, Offer.contract.methods.getValueOfferSlots(this.id, begin, end).call()];
339
347
  case 1:
340
- slot = _a.sent();
341
- return [2 /*return*/, (0, utils_1.tupleToObjectsArray)(slot, ValueOfferSlot_1.ValueOfferSlotStructure)];
348
+ slots = _d.sent();
349
+ slots = (0, utils_1.tupleToObjectsArray)(slots, ValueOfferSlot_1.ValueOfferSlotStructure);
350
+ _i = 0, slots_1 = slots;
351
+ _d.label = 2;
352
+ case 2:
353
+ if (!(_i < slots_1.length)) return [3 /*break*/, 5];
354
+ slot = slots_1[_i];
355
+ _a = slot;
356
+ _b = utils_1.unpackSlotInfo;
357
+ _c = [slot.info];
358
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
359
+ case 3:
360
+ _a.info = _b.apply(void 0, _c.concat([_d.sent()]));
361
+ _d.label = 4;
362
+ case 4:
363
+ _i++;
364
+ return [3 /*break*/, 2];
365
+ case 5: return [2 /*return*/, slots];
342
366
  }
343
367
  });
344
368
  });
@@ -353,19 +377,24 @@ var Offer = /** @class */ (function () {
353
377
  Offer.prototype.addSlot = function (slotInfo, optionInfo, slotUsage, externalId, transactionOptions) {
354
378
  if (externalId === void 0) { externalId = "default"; }
355
379
  return __awaiter(this, void 0, void 0, function () {
356
- var contract, slotInfoTuple, optionInfoTuple, slotUsageTuple, formattedExternalId;
357
- return __generator(this, function (_a) {
358
- switch (_a.label) {
380
+ var contract, _a, _b, slotInfoTuple, optionInfoTuple, slotUsageTuple, formattedExternalId;
381
+ return __generator(this, function (_c) {
382
+ switch (_c.label) {
359
383
  case 0:
360
384
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
361
385
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
386
+ _a = utils_1.packSlotInfo;
387
+ _b = [slotInfo];
388
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
389
+ case 1:
390
+ slotInfo = _a.apply(void 0, _b.concat([_c.sent()]));
362
391
  slotInfoTuple = (0, utils_1.objectToTuple)(slotInfo, SlotInfo_1.SlotInfoStructure);
363
392
  optionInfoTuple = (0, utils_1.objectToTuple)(optionInfo, OptionInfo_1.OptionInfoStructure);
364
393
  slotUsageTuple = (0, utils_1.objectToTuple)(slotUsage, SlotUsage_1.SlotUsageStructure);
365
394
  formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
366
395
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.addValueOfferSlot, [this.id, formattedExternalId, slotInfoTuple, optionInfoTuple, slotUsageTuple], transactionOptions)];
367
- case 1:
368
- _a.sent();
396
+ case 2:
397
+ _c.sent();
369
398
  return [2 /*return*/];
370
399
  }
371
400
  });
@@ -380,18 +409,23 @@ var Offer = /** @class */ (function () {
380
409
  */
381
410
  Offer.prototype.updateSlot = function (slotId, newSlotInfo, newOptionInfo, newUsage, transactionOptions) {
382
411
  return __awaiter(this, void 0, void 0, function () {
383
- var contract, newSlotInfoTuple, newOptionInfoTuple, newSlotUsageTuple;
384
- return __generator(this, function (_a) {
385
- switch (_a.label) {
412
+ var contract, _a, _b, newSlotInfoTuple, newOptionInfoTuple, newSlotUsageTuple;
413
+ return __generator(this, function (_c) {
414
+ switch (_c.label) {
386
415
  case 0:
387
416
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
388
417
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
418
+ _a = utils_1.packSlotInfo;
419
+ _b = [newSlotInfo];
420
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
421
+ case 1:
422
+ newSlotInfo = _a.apply(void 0, _b.concat([_c.sent()]));
389
423
  newSlotInfoTuple = (0, utils_1.objectToTuple)(newSlotInfo, SlotInfo_1.SlotInfoStructure);
390
424
  newOptionInfoTuple = (0, utils_1.objectToTuple)(newOptionInfo, OptionInfo_1.OptionInfoStructure);
391
425
  newSlotUsageTuple = (0, utils_1.objectToTuple)(newUsage, SlotUsage_1.SlotUsageStructure);
392
426
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.updateValueOfferSlot, [this.id, slotId, newSlotInfoTuple, newOptionInfoTuple, newSlotUsageTuple], transactionOptions)];
393
- case 1:
394
- _a.sent();
427
+ case 2:
428
+ _c.sent();
395
429
  return [2 /*return*/];
396
430
  }
397
431
  });
@@ -26,6 +26,10 @@ declare class Order {
26
26
  * Check if order is in `processing` state
27
27
  */
28
28
  isOrderProcessing(): Promise<boolean>;
29
+ /**
30
+ * Function for fetching order price
31
+ */
32
+ calculateCurrentPrice(): Promise<string>;
29
33
  /**
30
34
  * Function for fetching order info from blockchain
31
35
  */
@@ -43,10 +47,6 @@ declare class Order {
43
47
  * Function for fetching parent order from blockchain
44
48
  */
45
49
  getParentOrder(): Promise<string>;
46
- /**
47
- * Function for fetching order deposit spent from blockchain
48
- */
49
- getDepositSpent(): Promise<string>;
50
50
  /**
51
51
  * Function for fetching order options deposit spent from blockchain
52
52
  */
@@ -98,10 +98,6 @@ declare class Order {
98
98
  * Updates order price
99
99
  */
100
100
  updateOrderPrice(price: string, transactionOptions?: TransactionOptions): Promise<void>;
101
- /**
102
- * Sets deposit spent
103
- */
104
- setDepositSpent(value: string, transactionOptions?: TransactionOptions): Promise<void>;
105
101
  /**
106
102
  * Sets options deposit spent
107
103
  */
@@ -110,6 +110,19 @@ var Order = /** @class */ (function () {
110
110
  });
111
111
  });
112
112
  };
113
+ /**
114
+ * Function for fetching order price
115
+ */
116
+ Order.prototype.calculateCurrentPrice = function () {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0: return [4 /*yield*/, Order.contract.methods.calculateOrderCurrentPrice(this.id).call()];
121
+ case 1: return [2 /*return*/, _a.sent()];
122
+ }
123
+ });
124
+ });
125
+ };
113
126
  /**
114
127
  * Function for fetching order info from blockchain
115
128
  */
@@ -197,16 +210,6 @@ var Order = /** @class */ (function () {
197
210
  });
198
211
  });
199
212
  };
200
- /**
201
- * Function for fetching order deposit spent from blockchain
202
- */
203
- Order.prototype.getDepositSpent = function () {
204
- return __awaiter(this, void 0, void 0, function () {
205
- return __generator(this, function (_a) {
206
- return [2 /*return*/, Order.contract.methods.getOrderDepositSpent(this.id).call()];
207
- });
208
- });
209
- };
210
213
  /**
211
214
  * Function for fetching order options deposit spent from blockchain
212
215
  */
@@ -365,24 +368,6 @@ var Order = /** @class */ (function () {
365
368
  });
366
369
  });
367
370
  };
368
- /**
369
- * Sets deposit spent
370
- */
371
- Order.prototype.setDepositSpent = function (value, transactionOptions) {
372
- return __awaiter(this, void 0, void 0, function () {
373
- return __generator(this, function (_a) {
374
- switch (_a.label) {
375
- case 0:
376
- transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
377
- (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
378
- return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.setDepositSpent, [this.id, value], transactionOptions)];
379
- case 1:
380
- _a.sent();
381
- return [2 /*return*/];
382
- }
383
- });
384
- });
385
- };
386
371
  /**
387
372
  * Sets options deposit spent
388
373
  */
@@ -637,9 +622,6 @@ var Order = /** @class */ (function () {
637
622
  __decorate([
638
623
  (0, utils_1.incrementMethodCall)()
639
624
  ], Order.prototype, "getParentOrder", null);
640
- __decorate([
641
- (0, utils_1.incrementMethodCall)()
642
- ], Order.prototype, "getDepositSpent", null);
643
625
  __decorate([
644
626
  (0, utils_1.incrementMethodCall)()
645
627
  ], Order.prototype, "getOptionsDepositSpent", null);
@@ -676,9 +658,6 @@ var Order = /** @class */ (function () {
676
658
  __decorate([
677
659
  (0, utils_1.incrementMethodCall)()
678
660
  ], Order.prototype, "updateOrderPrice", null);
679
- __decorate([
680
- (0, utils_1.incrementMethodCall)()
681
- ], Order.prototype, "setDepositSpent", null);
682
661
  __decorate([
683
662
  (0, utils_1.incrementMethodCall)()
684
663
  ], Order.prototype, "setOptionsDepositSpent", null);
@@ -25,6 +25,7 @@ declare class TeeOffer {
25
25
  tcbAddedTime?: number;
26
26
  origins?: Origins;
27
27
  isCancelable?: boolean;
28
+ cpuDenominator?: number;
28
29
  constructor(offerId: string);
29
30
  /**
30
31
  * Function for fetching offer status from the blockchain
@@ -60,6 +60,7 @@ var OptionInfo_1 = require("../types/OptionInfo");
60
60
  var SlotUsage_1 = require("../types/SlotUsage");
61
61
  var utils_2 = require("ethers/lib/utils");
62
62
  var SlotInfo_1 = require("../types/SlotInfo");
63
+ var TeeOffers_1 = __importDefault(require("../staticModels/TeeOffers"));
63
64
  var TeeOffer = /** @class */ (function () {
64
65
  function TeeOffer(offerId) {
65
66
  this.id = offerId;
@@ -109,13 +110,17 @@ var TeeOffer = /** @class */ (function () {
109
110
  */
110
111
  TeeOffer.prototype.getInfo = function () {
111
112
  return __awaiter(this, void 0, void 0, function () {
112
- var _a, teeOfferInfoParams;
113
- return __generator(this, function (_b) {
114
- switch (_b.label) {
113
+ var _a, teeOfferInfoParams, _b;
114
+ return __generator(this, function (_c) {
115
+ switch (_c.label) {
115
116
  case 0: return [4 /*yield*/, TeeOffer.contract.methods.getTeeOffer(this.id).call()];
116
117
  case 1:
117
- _a = _b.sent(), teeOfferInfoParams = _a[2];
118
+ _a = _c.sent(), teeOfferInfoParams = _a[2];
118
119
  this.offerInfo = (0, utils_1.tupleToObject)(teeOfferInfoParams, TeeOfferInfo_1.TeeOfferInfoStructure);
120
+ _b = this.offerInfo;
121
+ return [4 /*yield*/, TeeOffers_1.default.unpackHardwareInfo(this.offerInfo.hardwareInfo)];
122
+ case 2:
123
+ _b.hardwareInfo = _c.sent();
119
124
  return [2 /*return*/, this.offerInfo];
120
125
  }
121
126
  });
@@ -132,7 +137,9 @@ var TeeOffer = /** @class */ (function () {
132
137
  case 0: return [4 /*yield*/, TeeOffer.contract.methods.getTeeOfferHardwareInfo(this.id).call()];
133
138
  case 1:
134
139
  hardwareInfo = _a.sent();
135
- return [2 /*return*/, (0, utils_1.tupleToObject)(hardwareInfo, HardwareInfo_1.HardwareInfoStructure)];
140
+ hardwareInfo = (0, utils_1.tupleToObject)(hardwareInfo, HardwareInfo_1.HardwareInfoStructure);
141
+ return [4 /*yield*/, TeeOffers_1.default.unpackHardwareInfo(hardwareInfo)];
142
+ case 2: return [2 /*return*/, _a.sent()];
136
143
  }
137
144
  });
138
145
  });
@@ -280,13 +287,20 @@ var TeeOffer = /** @class */ (function () {
280
287
  */
281
288
  TeeOffer.prototype.getSlotById = function (slotId) {
282
289
  return __awaiter(this, void 0, void 0, function () {
283
- var slot;
284
- return __generator(this, function (_a) {
285
- switch (_a.label) {
290
+ var slot, _a, _b, _c;
291
+ return __generator(this, function (_d) {
292
+ switch (_d.label) {
286
293
  case 0: return [4 /*yield*/, TeeOffer.contract.methods.getTeeOfferSlotById(this.id, slotId).call()];
287
294
  case 1:
288
- slot = _a.sent();
289
- return [2 /*return*/, (0, utils_1.tupleToObject)(slot, TeeOfferSlot_1.TeeOfferSlotStructure)];
295
+ slot = _d.sent();
296
+ slot = (0, utils_1.tupleToObject)(slot, TeeOfferSlot_1.TeeOfferSlotStructure);
297
+ _a = slot;
298
+ _b = utils_1.unpackSlotInfo;
299
+ _c = [slot.info];
300
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
301
+ case 2:
302
+ _a.info = _b.apply(void 0, _c.concat([_d.sent()]));
303
+ return [2 /*return*/, slot];
290
304
  }
291
305
  });
292
306
  });
@@ -299,13 +313,29 @@ var TeeOffer = /** @class */ (function () {
299
313
  */
300
314
  TeeOffer.prototype.getSlots = function (begin, end) {
301
315
  return __awaiter(this, void 0, void 0, function () {
302
- var slots;
303
- return __generator(this, function (_a) {
304
- switch (_a.label) {
316
+ var slots, _i, slots_1, slot, _a, _b, _c;
317
+ return __generator(this, function (_d) {
318
+ switch (_d.label) {
305
319
  case 0: return [4 /*yield*/, TeeOffer.contract.methods.getTeeOfferSlots(this.id, begin, end).call()];
306
320
  case 1:
307
- slots = _a.sent();
308
- return [2 /*return*/, (0, utils_1.tupleToObjectsArray)(slots, TeeOfferSlot_1.TeeOfferSlotStructure)];
321
+ slots = _d.sent();
322
+ slots = (0, utils_1.tupleToObjectsArray)(slots, TeeOfferSlot_1.TeeOfferSlotStructure);
323
+ _i = 0, slots_1 = slots;
324
+ _d.label = 2;
325
+ case 2:
326
+ if (!(_i < slots_1.length)) return [3 /*break*/, 5];
327
+ slot = slots_1[_i];
328
+ _a = slot;
329
+ _b = utils_1.unpackSlotInfo;
330
+ _c = [slot.info];
331
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
332
+ case 3:
333
+ _a.info = _b.apply(void 0, _c.concat([_d.sent()]));
334
+ _d.label = 4;
335
+ case 4:
336
+ _i++;
337
+ return [3 /*break*/, 2];
338
+ case 5: return [2 /*return*/, slots];
309
339
  }
310
340
  });
311
341
  });
@@ -319,18 +349,23 @@ var TeeOffer = /** @class */ (function () {
319
349
  TeeOffer.prototype.addSlot = function (info, usage, externalId, transactionOptions) {
320
350
  if (externalId === void 0) { externalId = "default"; }
321
351
  return __awaiter(this, void 0, void 0, function () {
322
- var contract, infoTuple, usageTuple, formattedExternalId;
323
- return __generator(this, function (_a) {
324
- switch (_a.label) {
352
+ var contract, _a, _b, infoTuple, usageTuple, formattedExternalId;
353
+ return __generator(this, function (_c) {
354
+ switch (_c.label) {
325
355
  case 0:
326
356
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
327
357
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
358
+ _a = utils_1.packSlotInfo;
359
+ _b = [info];
360
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
361
+ case 1:
362
+ info = _a.apply(void 0, _b.concat([_c.sent()]));
328
363
  infoTuple = (0, utils_1.objectToTuple)(info, SlotInfo_1.SlotInfoStructure);
329
364
  usageTuple = (0, utils_1.objectToTuple)(usage, SlotUsage_1.SlotUsageStructure);
330
365
  formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
331
366
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.addTeeOfferSlot, [this.id, formattedExternalId, infoTuple, usageTuple], transactionOptions)];
332
- case 1:
333
- _a.sent();
367
+ case 2:
368
+ _c.sent();
334
369
  return [2 /*return*/];
335
370
  }
336
371
  });
@@ -345,17 +380,22 @@ var TeeOffer = /** @class */ (function () {
345
380
  */
346
381
  TeeOffer.prototype.updateSlot = function (slotId, newInfo, newUsage, transactionOptions) {
347
382
  return __awaiter(this, void 0, void 0, function () {
348
- var contract, newInfoTuple, newUsageTuple;
349
- return __generator(this, function (_a) {
350
- switch (_a.label) {
383
+ var contract, _a, _b, newInfoTuple, newUsageTuple;
384
+ return __generator(this, function (_c) {
385
+ switch (_c.label) {
351
386
  case 0:
352
387
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
353
388
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
389
+ _a = utils_1.packSlotInfo;
390
+ _b = [newInfo];
391
+ return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
392
+ case 1:
393
+ newInfo = _a.apply(void 0, _b.concat([_c.sent()]));
354
394
  newInfoTuple = (0, utils_1.objectToTuple)(newInfo, SlotInfo_1.SlotInfoStructure);
355
395
  newUsageTuple = (0, utils_1.objectToTuple)(newUsage, SlotUsage_1.SlotUsageStructure);
356
396
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.updateTeeOfferSlot, [this.id, slotId, newInfoTuple, newUsageTuple], transactionOptions)];
357
- case 1:
358
- _a.sent();
397
+ case 2:
398
+ _c.sent();
359
399
  return [2 /*return*/];
360
400
  }
361
401
  });
@@ -608,9 +648,12 @@ var TeeOffer = /** @class */ (function () {
608
648
  case 0:
609
649
  transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitTeeOffer(transactionOptions);
610
650
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
651
+ return [4 /*yield*/, TeeOffers_1.default.packHardwareInfo(newHardwareInfo)];
652
+ case 1:
653
+ newHardwareInfo = _a.sent();
611
654
  newHardwareInfoTuple = (0, utils_1.objectToTuple)(newHardwareInfo, TeeOfferInfo_1.TeeOfferInfoStructure);
612
655
  return [4 /*yield*/, TxManager_1.default.execute(TeeOffer.contract.methods.setTeeOfferHardwareInfo, [this.id, newHardwareInfoTuple], transactionOptions)];
613
- case 1:
656
+ case 2:
614
657
  _a.sent();
615
658
  return [2 /*return*/];
616
659
  }
@@ -79,13 +79,6 @@ declare class Orders {
79
79
  * @returns unsubscribe - unsubscribe function from event
80
80
  */
81
81
  static onDepositRefilled(callback: onOrderDepositRefilledCallback, consumer?: string, orderId?: string): () => void;
82
- /**
83
- * Function for adding event listeners on order price updated event in orders contract
84
- * @param callback - function for processing order price updated event
85
- * @param orderId - order id
86
- * @returns unsubscribe - unsubscribe function from event
87
- */
88
- static onPriceUpdated(callback: onOrderPriceUpdatedCallback, orderId?: string): () => void;
89
82
  /**
90
83
  * Function for adding event listeners on order changed withdrawn event in orders contract
91
84
  * @param callback - function for processing order changed withdrawn event
@@ -109,14 +102,6 @@ declare class Orders {
109
102
  * @returns unsubscribe - unsubscribe function from event
110
103
  */
111
104
  static onAwaitingPaymentChanged(callback: onOrderAwaitingPaymentChangedCallback, consumer?: string, orderId?: string): () => void;
112
- /**
113
- * Function for adding event listeners on order deposit spent event in orders contract
114
- * @param callback - function for processing order deposit spent event
115
- * @param consumer - order creator address
116
- * @param orderId - order id
117
- * @returns unsubscribe - unsubscribe function from event
118
- */
119
- static onDepositSpentChanged(callback: onOrderDepositSpentChangedCallback, consumer?: string, orderId?: string): () => void;
120
105
  /**
121
106
  * Function for adding event listeners on order encrypted result updated event in orders contract
122
107
  * @param callback - function for processing order encrypted result updated event
@@ -144,12 +129,10 @@ declare class Orders {
144
129
  }
145
130
  export type onOrderStartedCallback = (orderId: string, consumer: string, block?: BlockInfo) => void;
146
131
  export type onOrdersStatusUpdatedCallback = (orderId: string, status: OrderStatus, block?: BlockInfo) => void;
147
- export type onOrderPriceUpdatedCallback = (orderId: string, price: string, block?: BlockInfo) => void;
148
132
  export type onOrderCreatedCallback = (consumer: string, externalId: string, offerId: string, parentOrderId: string, orderId: string, block?: BlockInfo) => void;
149
133
  export type onOrderDepositRefilledCallback = (orderId: string, consumer: string, amount: string, block?: BlockInfo) => void;
150
134
  export type onOrderChangedWithdrawnCallback = (orderId: string, consumer: string, change: string, block?: BlockInfo) => void;
151
135
  export type onOrderProfitWithdrawnCallback = (orderId: string, tokenReceiver: string, profit: string, block?: BlockInfo) => void;
152
- export type onOrderDepositSpentChangedCallback = (orderId: string, consumer: string, spent: string, block?: BlockInfo) => void;
153
136
  export type onOrderAwaitingPaymentChangedCallback = (orderId: string, consumer: string, awaitingPaymentFlag: boolean, block?: BlockInfo) => void;
154
137
  export type onOrderEncryptedResultUpdatedCallback = (orderId: string, consumer: string, encryptedResult: string, block?: BlockInfo) => void;
155
138
  export type onOrderOptionsDepositSpentChangedCallback = (consumer: string, orderId: string, value: string, block?: BlockInfo) => void;
@@ -389,37 +389,6 @@ var Orders = /** @class */ (function () {
389
389
  });
390
390
  return function () { return subscription.unsubscribe(); };
391
391
  };
392
- /**
393
- * Function for adding event listeners on order price updated event in orders contract
394
- * @param callback - function for processing order price updated event
395
- * @param orderId - order id
396
- * @returns unsubscribe - unsubscribe function from event
397
- */
398
- Orders.onPriceUpdated = function (callback, orderId) {
399
- var _this = this;
400
- var contract = BlockchainEventsListener_1.default.getInstance().getContract();
401
- var logger = this.logger.child({ method: "onOrderPriceUpdated" });
402
- var subscription = contract.events
403
- .OrderPriceUpdated()
404
- .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
405
- return __generator(this, function (_a) {
406
- if (orderId && event.returnValues.orderId != orderId) {
407
- return [2 /*return*/];
408
- }
409
- callback(event.returnValues.orderId, event.returnValues.price, {
410
- index: event.blockNumber,
411
- hash: event.blockHash,
412
- });
413
- return [2 /*return*/];
414
- });
415
- }); })
416
- .on("error", function (error, receipt) {
417
- if (receipt)
418
- return; // Used to avoid logging of transaction rejected
419
- logger.warn(error);
420
- });
421
- return function () { return subscription.unsubscribe(); };
422
- };
423
392
  /**
424
393
  * Function for adding event listeners on order changed withdrawn event in orders contract
425
394
  * @param callback - function for processing order changed withdrawn event
@@ -521,41 +490,6 @@ var Orders = /** @class */ (function () {
521
490
  });
522
491
  return function () { return subscription.unsubscribe(); };
523
492
  };
524
- /**
525
- * Function for adding event listeners on order deposit spent event in orders contract
526
- * @param callback - function for processing order deposit spent event
527
- * @param consumer - order creator address
528
- * @param orderId - order id
529
- * @returns unsubscribe - unsubscribe function from event
530
- */
531
- Orders.onDepositSpentChanged = function (callback, consumer, orderId) {
532
- var _this = this;
533
- var contract = BlockchainEventsListener_1.default.getInstance().getContract();
534
- var logger = this.logger.child({ method: "onOrderDepositSpentChanged" });
535
- var subscription = contract.events
536
- .OrderDepositSpentChanged()
537
- .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
538
- return __generator(this, function (_a) {
539
- if (orderId && event.returnValues.orderId != orderId) {
540
- return [2 /*return*/];
541
- }
542
- if (consumer && event.returnValues.consumer != consumer) {
543
- return [2 /*return*/];
544
- }
545
- callback(event.returnValues.orderId, event.returnValues.consumer, event.returnValues.value, {
546
- index: event.blockNumber,
547
- hash: event.blockHash,
548
- });
549
- return [2 /*return*/];
550
- });
551
- }); })
552
- .on("error", function (error, receipt) {
553
- if (receipt)
554
- return; // Used to avoid logging of transaction rejected
555
- logger.warn(error);
556
- });
557
- return function () { return subscription.unsubscribe(); };
558
- };
559
493
  /**
560
494
  * Function for adding event listeners on order encrypted result updated event in orders contract
561
495
  * @param callback - function for processing order encrypted result updated event
@@ -2,10 +2,15 @@ import { BlockInfo, TransactionOptions } from "../types/Web3";
2
2
  import { TeeOfferInfo } from "../types/TeeOfferInfo";
3
3
  import { OfferCreatedEvent } from "../types/Events";
4
4
  import { TeeOfferOption } from "../types/TeeOfferOption";
5
+ import { HardwareInfo } from "../types/HardwareInfo";
5
6
  declare class TeeOffers {
7
+ private static cpuDenominator?;
6
8
  private static readonly logger;
7
9
  static teeOffers?: string[];
8
10
  static get address(): string;
11
+ static packHardwareInfo(hw: HardwareInfo): Promise<HardwareInfo>;
12
+ static unpackHardwareInfo(hw: HardwareInfo): Promise<HardwareInfo>;
13
+ static getDenominator(): Promise<number>;
9
14
  /**
10
15
  * Function for fetching list of all TEE offers addresses
11
16
  */
@@ -59,6 +59,56 @@ var TeeOffers = /** @class */ (function () {
59
59
  enumerable: false,
60
60
  configurable: true
61
61
  });
62
+ TeeOffers.packHardwareInfo = function (hw) {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var _a, _b;
65
+ return __generator(this, function (_c) {
66
+ switch (_c.label) {
67
+ case 0:
68
+ _a = hw.slotInfo;
69
+ _b = _a.cpuCores;
70
+ return [4 /*yield*/, TeeOffers.getDenominator()];
71
+ case 1:
72
+ _a.cpuCores = _b * _c.sent();
73
+ return [2 /*return*/, hw];
74
+ }
75
+ });
76
+ });
77
+ };
78
+ TeeOffers.unpackHardwareInfo = function (hw) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ var _a, _b;
81
+ return __generator(this, function (_c) {
82
+ switch (_c.label) {
83
+ case 0:
84
+ _a = hw.slotInfo;
85
+ _b = _a.cpuCores;
86
+ return [4 /*yield*/, TeeOffers.getDenominator()];
87
+ case 1:
88
+ _a.cpuCores = _b / _c.sent();
89
+ return [2 /*return*/, hw];
90
+ }
91
+ });
92
+ });
93
+ };
94
+ TeeOffers.getDenominator = function () {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var contract, _a;
97
+ return __generator(this, function (_b) {
98
+ switch (_b.label) {
99
+ case 0:
100
+ if (!!this.cpuDenominator) return [3 /*break*/, 2];
101
+ contract = BlockchainConnector_1.default.getInstance().getContract();
102
+ _a = this;
103
+ return [4 /*yield*/, contract.methods.getCpuDenominator().call()];
104
+ case 1:
105
+ _a.cpuDenominator = +(_b.sent());
106
+ _b.label = 2;
107
+ case 2: return [2 /*return*/, this.cpuDenominator];
108
+ }
109
+ });
110
+ });
111
+ };
62
112
  /**
63
113
  * Function for fetching list of all TEE offers addresses
64
114
  */
@@ -105,17 +155,23 @@ var TeeOffers = /** @class */ (function () {
105
155
  if (externalId === void 0) { externalId = "default"; }
106
156
  if (enabled === void 0) { enabled = true; }
107
157
  return __awaiter(this, void 0, void 0, function () {
108
- var contract, teeOfferInfoParams, formattedExternalId;
109
- return __generator(this, function (_a) {
110
- switch (_a.label) {
158
+ var contract, _a, teeOfferInfoParams, formattedExternalId;
159
+ return __generator(this, function (_b) {
160
+ switch (_b.label) {
111
161
  case 0:
112
162
  contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
113
163
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
164
+ // Converts offer info to array of arrays (used in blockchain)
165
+ _a = teeOfferInfo;
166
+ return [4 /*yield*/, TeeOffers.packHardwareInfo(teeOfferInfo.hardwareInfo)];
167
+ case 1:
168
+ // Converts offer info to array of arrays (used in blockchain)
169
+ _a.hardwareInfo = _b.sent();
114
170
  teeOfferInfoParams = (0, utils_1.objectToTuple)(teeOfferInfo, TeeOfferInfo_1.TeeOfferInfoStructure);
115
171
  formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
116
172
  return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createTeeOffer, [providerAuthorityAccount, teeOfferInfoParams, formattedExternalId, enabled], transactionOptions)];
117
- case 1:
118
- _a.sent();
173
+ case 2:
174
+ _b.sent();
119
175
  return [2 /*return*/];
120
176
  }
121
177
  });
@@ -4,8 +4,7 @@ export declare const HardwareInfoStructure: {
4
4
  slotInfo: {
5
5
  cpuCores: NumberConstructor;
6
6
  ram: NumberConstructor;
7
- hdd: NumberConstructor;
8
- ssd: NumberConstructor;
7
+ diskUsage: NumberConstructor;
9
8
  };
10
9
  optionInfo: {
11
10
  bandwidth: StringConstructor;