@super-protocol/sdk-js 0.6.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.
Files changed (132) hide show
  1. package/build/BlockchainConnector.d.ts +48 -0
  2. package/build/BlockchainConnector.js +259 -0
  3. package/build/TIIGenerator.d.ts +21 -0
  4. package/build/TIIGenerator.js +251 -0
  5. package/build/constants.d.ts +7 -0
  6. package/build/constants.js +10 -0
  7. package/build/contracts/ActiveOffersList.json +131 -0
  8. package/build/contracts/ActiveOrdersList.json +74 -0
  9. package/build/contracts/Marks.json +79 -0
  10. package/build/contracts/Offers.json +999 -0
  11. package/build/contracts/Orders.json +984 -0
  12. package/build/contracts/Providers.json +440 -0
  13. package/build/contracts/ProvidersOffers.json +254 -0
  14. package/build/contracts/Staking.json +323 -0
  15. package/build/contracts/Superpro.json +197 -0
  16. package/build/contracts/SuperproToken.json +356 -0
  17. package/build/crypto/Crypto.d.ts +37 -0
  18. package/build/crypto/Crypto.js +181 -0
  19. package/build/crypto/index.d.ts +2 -0
  20. package/build/crypto/index.js +7 -0
  21. package/build/crypto/nodejs/AES.d.ts +24 -0
  22. package/build/crypto/nodejs/AES.js +152 -0
  23. package/build/crypto/nodejs/ARIA.d.ts +24 -0
  24. package/build/crypto/nodejs/ARIA.js +151 -0
  25. package/build/crypto/nodejs/ECIES.d.ts +6 -0
  26. package/build/crypto/nodejs/ECIES.js +94 -0
  27. package/build/crypto/nodejs/NativeCrypto.d.ts +54 -0
  28. package/build/crypto/nodejs/NativeCrypto.js +214 -0
  29. package/build/crypto/nodejs/RSA-Hybrid.d.ts +15 -0
  30. package/build/crypto/nodejs/RSA-Hybrid.js +153 -0
  31. package/build/index.d.ts +65 -0
  32. package/build/index.js +117 -0
  33. package/build/logger.d.ts +4 -0
  34. package/build/logger.js +8 -0
  35. package/build/models/Ballot.d.ts +13 -0
  36. package/build/models/Ballot.js +76 -0
  37. package/build/models/Offer.d.ts +70 -0
  38. package/build/models/Offer.js +273 -0
  39. package/build/models/Order.d.ts +125 -0
  40. package/build/models/Order.js +540 -0
  41. package/build/models/Provider.d.ts +40 -0
  42. package/build/models/Provider.js +167 -0
  43. package/build/models/TCB.d.ts +80 -0
  44. package/build/models/TCB.js +315 -0
  45. package/build/models/TeeOffer.d.ts +118 -0
  46. package/build/models/TeeOffer.js +436 -0
  47. package/build/proto/Compression.d.ts +33 -0
  48. package/build/proto/Compression.js +146 -0
  49. package/build/proto/TRI.d.ts +122 -0
  50. package/build/proto/TRI.js +316 -0
  51. package/build/providers/storage/ChunksDownloadDecorator.d.ts +38 -0
  52. package/build/providers/storage/ChunksDownloadDecorator.js +284 -0
  53. package/build/providers/storage/IStorageProvider.d.ts +17 -0
  54. package/build/providers/storage/IStorageProvider.js +2 -0
  55. package/build/providers/storage/StorjStorageProvider.d.ts +26 -0
  56. package/build/providers/storage/StorjStorageProvider.js +389 -0
  57. package/build/providers/storage/getStorageProvider.d.ts +4 -0
  58. package/build/providers/storage/getStorageProvider.js +16 -0
  59. package/build/staticModels/ActiveOffers.d.ts +29 -0
  60. package/build/staticModels/ActiveOffers.js +144 -0
  61. package/build/staticModels/ActiveOrders.d.ts +21 -0
  62. package/build/staticModels/ActiveOrders.js +120 -0
  63. package/build/staticModels/Consensus.d.ts +63 -0
  64. package/build/staticModels/Consensus.js +373 -0
  65. package/build/staticModels/Epochs.d.ts +23 -0
  66. package/build/staticModels/Epochs.js +97 -0
  67. package/build/staticModels/LastBlocks.d.ts +25 -0
  68. package/build/staticModels/LastBlocks.js +96 -0
  69. package/build/staticModels/Marks.d.ts +13 -0
  70. package/build/staticModels/Marks.js +113 -0
  71. package/build/staticModels/OffersFactory.d.ts +37 -0
  72. package/build/staticModels/OffersFactory.js +227 -0
  73. package/build/staticModels/OrdersFactory.d.ts +137 -0
  74. package/build/staticModels/OrdersFactory.js +539 -0
  75. package/build/staticModels/ProviderRegistry.d.ts +81 -0
  76. package/build/staticModels/ProviderRegistry.js +311 -0
  77. package/build/staticModels/Staking.d.ts +26 -0
  78. package/build/staticModels/Staking.js +132 -0
  79. package/build/staticModels/Superpro.d.ts +20 -0
  80. package/build/staticModels/Superpro.js +99 -0
  81. package/build/staticModels/SuperproToken.d.ts +30 -0
  82. package/build/staticModels/SuperproToken.js +125 -0
  83. package/build/staticModels/Suspicious.d.ts +26 -0
  84. package/build/staticModels/Suspicious.js +99 -0
  85. package/build/staticModels/TeeOffersFactory.d.ts +36 -0
  86. package/build/staticModels/TeeOffersFactory.js +206 -0
  87. package/build/staticModels/Voting.d.ts +35 -0
  88. package/build/staticModels/Voting.js +111 -0
  89. package/build/store.d.ts +12 -0
  90. package/build/store.js +13 -0
  91. package/build/types/Ballot.d.ts +75 -0
  92. package/build/types/Ballot.js +49 -0
  93. package/build/types/Epoch.d.ts +21 -0
  94. package/build/types/Epoch.js +18 -0
  95. package/build/types/Events.d.ts +18 -0
  96. package/build/types/Events.js +2 -0
  97. package/build/types/Marks.d.ts +5 -0
  98. package/build/types/Marks.js +9 -0
  99. package/build/types/Offer.d.ts +63 -0
  100. package/build/types/Offer.js +41 -0
  101. package/build/types/Order.d.ts +61 -0
  102. package/build/types/Order.js +36 -0
  103. package/build/types/Origins.d.ts +12 -0
  104. package/build/types/Origins.js +10 -0
  105. package/build/types/Provider.d.ts +25 -0
  106. package/build/types/Provider.js +19 -0
  107. package/build/types/Staking.d.ts +27 -0
  108. package/build/types/Staking.js +22 -0
  109. package/build/types/Superpro.d.ts +24 -0
  110. package/build/types/Superpro.js +29 -0
  111. package/build/types/TcbData.d.ts +26 -0
  112. package/build/types/TcbData.js +21 -0
  113. package/build/types/TeeOffer.d.ts +22 -0
  114. package/build/types/TeeOffer.js +15 -0
  115. package/build/types/Web3.d.ts +26 -0
  116. package/build/types/Web3.js +2 -0
  117. package/build/types/blockchainConnector/StorageAccess.d.ts +8 -0
  118. package/build/types/blockchainConnector/StorageAccess.js +2 -0
  119. package/build/types/storage/StorageAccess.d.ts +6 -0
  120. package/build/types/storage/StorageAccess.js +2 -0
  121. package/build/types/storage/StorageFileAccess.d.ts +5 -0
  122. package/build/types/storage/StorageFileAccess.js +2 -0
  123. package/build/types/storage/StorageObject.d.ts +8 -0
  124. package/build/types/storage/StorageObject.js +2 -0
  125. package/build/utils/NonceTracker.d.ts +12 -0
  126. package/build/utils/NonceTracker.js +84 -0
  127. package/build/utils/TxManager.d.ts +21 -0
  128. package/build/utils/TxManager.js +159 -0
  129. package/build/utils.d.ts +38 -0
  130. package/build/utils.js +195 -0
  131. package/package.json +68 -0
  132. package/readme.md +40 -0
@@ -0,0 +1,539 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var store_1 = __importDefault(require("../store"));
43
+ var logger_1 = __importDefault(require("../logger"));
44
+ var Orders_json_1 = __importDefault(require("../contracts/Orders.json"));
45
+ var utils_1 = require("../utils");
46
+ var Order_1 = require("../types/Order");
47
+ var utils_2 = require("ethers/lib/utils");
48
+ var Superpro_1 = __importDefault(require("./Superpro"));
49
+ var TxManager_1 = __importDefault(require("../utils/TxManager"));
50
+ var OrdersFactory = /** @class */ (function () {
51
+ function OrdersFactory() {
52
+ }
53
+ Object.defineProperty(OrdersFactory, "address", {
54
+ get: function () {
55
+ return Superpro_1.default.address;
56
+ },
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ /**
61
+ * Checks if contract has been initialized, if not - initialize contract
62
+ */
63
+ OrdersFactory.checkInit = function (transactionOptions) {
64
+ if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
65
+ (0, utils_1.checkIfInitialized)();
66
+ return new transactionOptions.web3.eth.Contract(Orders_json_1.default.abi, Superpro_1.default.address);
67
+ }
68
+ if (this.contract)
69
+ return this.contract;
70
+ (0, utils_1.checkIfInitialized)();
71
+ this.logger = logger_1.default.child({
72
+ className: "OrdersFactory",
73
+ address: Superpro_1.default.address,
74
+ });
75
+ return (this.contract = new store_1.default.web3.eth.Contract(Orders_json_1.default.abi, Superpro_1.default.address));
76
+ };
77
+ /**
78
+ * Function for fetching list of all orders addresses
79
+ * @returns list of orders addresses
80
+ */
81
+ OrdersFactory.getAllOrders = function () {
82
+ var _a;
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var ordersSet, ordersCount, orderId;
85
+ return __generator(this, function (_b) {
86
+ switch (_b.label) {
87
+ case 0:
88
+ this.checkInit();
89
+ this.orders = (_a = this.orders) !== null && _a !== void 0 ? _a : [];
90
+ ordersSet = new Set(this.orders);
91
+ return [4 /*yield*/, this.contract.methods.getOrdersCount().call()];
92
+ case 1:
93
+ ordersCount = _b.sent();
94
+ for (orderId = ordersSet.size + 1; orderId <= ordersCount; orderId++) {
95
+ ordersSet.add(orderId.toString());
96
+ }
97
+ this.orders = Array.from(ordersSet);
98
+ return [2 /*return*/, this.orders];
99
+ }
100
+ });
101
+ });
102
+ };
103
+ /**
104
+ * Function for fetching orders count
105
+ */
106
+ OrdersFactory.getOrdersCount = function () {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var _a;
109
+ return __generator(this, function (_b) {
110
+ switch (_b.label) {
111
+ case 0:
112
+ this.checkInit();
113
+ _a = Number;
114
+ return [4 /*yield*/, this.contract.methods.getOrdersCount().call()];
115
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
116
+ }
117
+ });
118
+ });
119
+ };
120
+ /**
121
+ * Function for fetching order hold deposit for specific order
122
+ * @param orderAddress - address of order for fetching hold deposit
123
+ */
124
+ OrdersFactory.getOrderHoldDeposit = function (orderAddress) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ return __generator(this, function (_a) {
127
+ switch (_a.label) {
128
+ case 0:
129
+ this.checkInit();
130
+ return [4 /*yield*/, this.contract.methods.getOrderHoldDeposit(orderAddress).call()];
131
+ case 1: return [2 /*return*/, _a.sent()];
132
+ }
133
+ });
134
+ });
135
+ };
136
+ /**
137
+ * Function for creating orders
138
+ * @param orderInfo - order info for new order
139
+ * @param suspended - is orders suspended
140
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
141
+ * @returns {Promise<void>} - Does not return address of created contract!
142
+ */
143
+ OrdersFactory.createOrder = function (orderInfo, holdDeposit, suspended, externalId, transactionOptions) {
144
+ if (holdDeposit === void 0) { holdDeposit = '0'; }
145
+ if (suspended === void 0) { suspended = false; }
146
+ if (externalId === void 0) { externalId = "default"; }
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var contract, orderInfoArguments, formattedExternalId;
149
+ return __generator(this, function (_a) {
150
+ switch (_a.label) {
151
+ case 0:
152
+ contract = this.checkInit(transactionOptions);
153
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
154
+ orderInfoArguments = (0, utils_1.objectToTuple)(orderInfo, Order_1.OrderInfoStructure);
155
+ formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
156
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createOrder, [orderInfoArguments, holdDeposit, suspended, formattedExternalId], transactionOptions)];
157
+ case 1:
158
+ _a.sent();
159
+ return [2 /*return*/];
160
+ }
161
+ });
162
+ });
163
+ };
164
+ OrdersFactory.getOrder = function (consumer, externalId) {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ var contract, filter, foundIds, notFound, response;
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0:
170
+ contract = this.checkInit();
171
+ filter = {
172
+ consumer: consumer,
173
+ externalId: (0, utils_2.formatBytes32String)(externalId),
174
+ };
175
+ return [4 /*yield*/, contract.getPastEvents("OrderCreated", { filter: filter })];
176
+ case 1:
177
+ foundIds = _a.sent();
178
+ notFound = {
179
+ consumer: consumer,
180
+ externalId: externalId,
181
+ offerId: '-1',
182
+ orderId: '-1',
183
+ };
184
+ response = foundIds.length > 0 ? foundIds[0].returnValues : notFound;
185
+ return [2 /*return*/, response];
186
+ }
187
+ });
188
+ });
189
+ };
190
+ /**
191
+ * Function for refilling order deposit
192
+ * @param orderAddress - address of order
193
+ * @param amount - amount of tokens to refilling
194
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
195
+ */
196
+ OrdersFactory.refillOrderDeposit = function (orderAddress, amount, transactionOptions) {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var contract;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ contract = this.checkInit(transactionOptions);
203
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
204
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.refillOrder, [orderAddress, amount], transactionOptions)];
205
+ case 1:
206
+ _a.sent();
207
+ return [2 /*return*/];
208
+ }
209
+ });
210
+ });
211
+ };
212
+ /**
213
+ * Function for adding event listeners on order created event in orders factory contract
214
+ * @param callback - function for processing created order
215
+ * @returns unsubscribe - unsubscribe function from event
216
+ */
217
+ OrdersFactory.onOrderCreated = function (callback) {
218
+ var _this = this;
219
+ this.checkInit();
220
+ var logger = this.logger.child({ method: "onOrderCreated" });
221
+ var subscription = this.contract.events
222
+ .OrderCreated()
223
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
224
+ return __generator(this, function (_a) {
225
+ //consumer: string, externalId: string, offerId: string, orderId: string
226
+ callback(event.returnValues.consumer, (0, utils_2.parseBytes32String)(event.returnValues.externalId), event.returnValues.offerId, event.returnValues.orderId);
227
+ return [2 /*return*/];
228
+ });
229
+ }); })
230
+ .on("error", function (error, receipt) {
231
+ if (receipt)
232
+ return; // Used to avoid logging of transaction rejected
233
+ logger.warn(error);
234
+ });
235
+ return function () { return subscription.unsubscribe(); };
236
+ };
237
+ /**
238
+ * Function for adding event listeners on suborder created event in orders contract
239
+ * @param callback - function for processing created suborder
240
+ * @param parentOrderId - parent order id
241
+ * @return unsubscribe - unsubscribe function from event
242
+ */
243
+ OrdersFactory.onSubOrderCreated = function (callback, parentOrderId) {
244
+ var _this = this;
245
+ this.checkInit();
246
+ var logger = this.logger.child({ method: "onSubOrderCreated" });
247
+ var subscription = this.contract.events
248
+ .SubOrderCreated()
249
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
250
+ return __generator(this, function (_a) {
251
+ if (parentOrderId && event.returnValues.parentOrderId != parentOrderId) {
252
+ return [2 /*return*/];
253
+ }
254
+ callback(event.returnValues.parentOrderId, event.returnValues.subOrderId);
255
+ return [2 /*return*/];
256
+ });
257
+ }); })
258
+ .on("error", function (error, receipt) {
259
+ if (receipt)
260
+ return; // Used to avoid logging of transaction rejected
261
+ logger.warn(error);
262
+ });
263
+ return function () { return subscription.unsubscribe(); };
264
+ };
265
+ /**
266
+ * Function for adding event listeners on order started event in orders contract
267
+ * @param callback - function for processing suborder filled event
268
+ * @param orderId - order id
269
+ * @returns unsubscribe - unsubscribe function from event
270
+ */
271
+ OrdersFactory.onOrderStarted = function (callback, orderId) {
272
+ var _this = this;
273
+ this.checkInit();
274
+ var logger = this.logger.child({ method: "onOrderStarted" });
275
+ var subscription = this.contract.events
276
+ .OrderStarted()
277
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
278
+ return __generator(this, function (_a) {
279
+ if (orderId && event.returnValues.orderId != orderId) {
280
+ return [2 /*return*/];
281
+ }
282
+ callback(event.returnValues.orderId, event.returnValues.consumer);
283
+ return [2 /*return*/];
284
+ });
285
+ }); })
286
+ .on("error", function (error, receipt) {
287
+ if (receipt)
288
+ return; // Used to avoid logging of transaction rejected
289
+ logger.warn(error);
290
+ });
291
+ return function () { return subscription.unsubscribe(); };
292
+ };
293
+ /**
294
+ * Function for adding event listeners on order updated status event in orders contract
295
+ * @param callback - function for processing order updated status event
296
+ * @param orderId - order id
297
+ * @returns unsubscribe - unsubscribe function from event
298
+ */
299
+ OrdersFactory.onOrdersStatusUpdated = function (callback, orderId) {
300
+ var _this = this;
301
+ this.checkInit();
302
+ var logger = this.logger.child({ method: "onOrdersStatusUpdated" });
303
+ var subscription = this.contract.events
304
+ .OrderStatusUpdated()
305
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
306
+ return __generator(this, function (_a) {
307
+ if (orderId && event.returnValues.orderId != orderId) {
308
+ return [2 /*return*/];
309
+ }
310
+ callback(event.returnValues.orderId, event.returnValues.status);
311
+ return [2 /*return*/];
312
+ });
313
+ }); })
314
+ .on("error", function (error, receipt) {
315
+ if (receipt)
316
+ return; // Used to avoid logging of transaction rejected
317
+ logger.warn(error);
318
+ });
319
+ return function () { return subscription.unsubscribe(); };
320
+ };
321
+ /**
322
+ * Function for adding event listeners on order refilled event in orders contract
323
+ * @param callback - function for processing order refilled event
324
+ * @param consumer - consumer address
325
+ * @param orderId - order id
326
+ * @returns unsubscribe - unsubscribe function from event
327
+ */
328
+ OrdersFactory.onOrderDepositRefilled = function (callback, consumer, orderId) {
329
+ var _this = this;
330
+ this.checkInit();
331
+ var logger = this.logger.child({ method: "onOrderDepositRefilled" });
332
+ var subscription = this.contract.events
333
+ .OrderDepositRefilled()
334
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
335
+ return __generator(this, function (_a) {
336
+ if (orderId && event.returnValues.orderId != orderId) {
337
+ return [2 /*return*/];
338
+ }
339
+ if (consumer && event.returnValues.consumer != consumer) {
340
+ return [2 /*return*/];
341
+ }
342
+ callback(event.returnValues.orderId, event.returnValues.consumer, event.returnValues.amount);
343
+ return [2 /*return*/];
344
+ });
345
+ }); })
346
+ .on("error", function (error, receipt) {
347
+ if (receipt)
348
+ return; // Used to avoid logging of transaction rejected
349
+ logger.warn(error);
350
+ });
351
+ return function () { return subscription.unsubscribe(); };
352
+ };
353
+ /**
354
+ * Function for adding event listeners on order price updated event in orders contract
355
+ * @param callback - function for processing order price updated event
356
+ * @param orderId - order id
357
+ * @returns unsubscribe - unsubscribe function from event
358
+ */
359
+ OrdersFactory.onOrderPriceUpdated = function (callback, orderId) {
360
+ var _this = this;
361
+ this.checkInit();
362
+ var logger = this.logger.child({ method: "onOrderPriceUpdated" });
363
+ var subscription = this.contract.events
364
+ .OrderPriceUpdated()
365
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
366
+ return __generator(this, function (_a) {
367
+ if (orderId && event.returnValues.orderId != orderId) {
368
+ return [2 /*return*/];
369
+ }
370
+ callback(event.returnValues.orderId, event.returnValues.price);
371
+ return [2 /*return*/];
372
+ });
373
+ }); })
374
+ .on("error", function (error, receipt) {
375
+ if (receipt)
376
+ return; // Used to avoid logging of transaction rejected
377
+ logger.warn(error);
378
+ });
379
+ return function () { return subscription.unsubscribe(); };
380
+ };
381
+ /**
382
+ * Function for adding event listeners on order changed withdrawn event in orders contract
383
+ * @param callback - function for processing order changed withdrawn event
384
+ * @param orderId - order id
385
+ * @returns unsubscribe - unsubscribe function from event
386
+ */
387
+ OrdersFactory.onOrderChangedWithdrawn = function (callback, orderId) {
388
+ var _this = this;
389
+ this.checkInit();
390
+ var logger = this.logger.child({ method: "onOrderChangedWithdrawn" });
391
+ var subscription = this.contract.events
392
+ .OrderChangedWithdrawn()
393
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
394
+ return __generator(this, function (_a) {
395
+ if (orderId && event.returnValues.orderId != orderId) {
396
+ return [2 /*return*/];
397
+ }
398
+ callback(event.returnValues.orderId, event.returnValues.consumer, event.returnValues.change);
399
+ return [2 /*return*/];
400
+ });
401
+ }); })
402
+ .on("error", function (error, receipt) {
403
+ if (receipt)
404
+ return; // Used to avoid logging of transaction rejected
405
+ logger.warn(error);
406
+ });
407
+ return function () { return subscription.unsubscribe(); };
408
+ };
409
+ /**
410
+ * Function for adding event listeners on order changed refunded event in orders contract
411
+ * @param callback - function for processing order changed refunded event
412
+ * @param tokenReceiver - token receiver address
413
+ * @param orderId - order id
414
+ * @returns unsubscribe - unsubscribe function from event
415
+ */
416
+ OrdersFactory.onOrderProfitWithdrawn = function (callback, orderId, tokenReceiver) {
417
+ var _this = this;
418
+ this.checkInit();
419
+ var logger = this.logger.child({ method: "onOrderProfitWithdrawn" });
420
+ var subscription = this.contract.events
421
+ .OrderProfitWithdrawn()
422
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
423
+ return __generator(this, function (_a) {
424
+ if (orderId && event.returnValues.orderId != orderId) {
425
+ return [2 /*return*/];
426
+ }
427
+ if (tokenReceiver && event.returnValues.tokenReceiver != tokenReceiver) {
428
+ return [2 /*return*/];
429
+ }
430
+ callback(event.returnValues.orderId, event.returnValues.tokenReceiver, event.returnValues.profit);
431
+ return [2 /*return*/];
432
+ });
433
+ }); })
434
+ .on("error", function (error, receipt) {
435
+ if (receipt)
436
+ return; // Used to avoid logging of transaction rejected
437
+ logger.warn(error);
438
+ });
439
+ return function () { return subscription.unsubscribe(); };
440
+ };
441
+ /**
442
+ * Function for adding event listeners on order awaiting payment event in orders contract
443
+ * @param callback - function for processing order awaiting payment event
444
+ * @param consumer - order creator address
445
+ * @param orderId - order id
446
+ * @returns unsubscribe - unsubscribe function from event
447
+ */
448
+ OrdersFactory.onOrderAwaitingPaymentChanged = function (callback, consumer, orderId) {
449
+ var _this = this;
450
+ this.checkInit();
451
+ var logger = this.logger.child({ method: "onOrderAwaitingPaymentChanged" });
452
+ var subscription = this.contract.events
453
+ .OrderAwaitingPaymentChanged()
454
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
455
+ return __generator(this, function (_a) {
456
+ if (orderId && event.returnValues.orderId != orderId) {
457
+ return [2 /*return*/];
458
+ }
459
+ if (consumer && event.returnValues.consumer != consumer) {
460
+ return [2 /*return*/];
461
+ }
462
+ callback(event.returnValues.orderId, event.returnValues.consumer, event.returnValues.awaitingPayment);
463
+ return [2 /*return*/];
464
+ });
465
+ }); })
466
+ .on("error", function (error, receipt) {
467
+ if (receipt)
468
+ return; // Used to avoid logging of transaction rejected
469
+ logger.warn(error);
470
+ });
471
+ return function () { return subscription.unsubscribe(); };
472
+ };
473
+ /**
474
+ * Function for adding event listeners on order deposit spent event in orders contract
475
+ * @param callback - function for processing order deposit spent event
476
+ * @param consumer - order creator address
477
+ * @param orderId - order id
478
+ * @returns unsubscribe - unsubscribe function from event
479
+ */
480
+ OrdersFactory.onOrderDepositSpentChanged = function (callback, consumer, orderId) {
481
+ var _this = this;
482
+ this.checkInit();
483
+ var logger = this.logger.child({ method: "onOrderDepositSpentChanged" });
484
+ var subscription = this.contract.events
485
+ .OrderDepositSpentChanged()
486
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
487
+ return __generator(this, function (_a) {
488
+ if (orderId && event.returnValues.orderId != orderId) {
489
+ return [2 /*return*/];
490
+ }
491
+ if (consumer && event.returnValues.consumer != consumer) {
492
+ return [2 /*return*/];
493
+ }
494
+ callback(event.returnValues.orderId, event.returnValues.consumer, event.returnValues.value);
495
+ return [2 /*return*/];
496
+ });
497
+ }); })
498
+ .on("error", function (error, receipt) {
499
+ if (receipt)
500
+ return; // Used to avoid logging of transaction rejected
501
+ logger.warn(error);
502
+ });
503
+ return function () { return subscription.unsubscribe(); };
504
+ };
505
+ /**
506
+ * Function for adding event listeners on order encrypted result updated event in orders contract
507
+ * @param callback - function for processing order encrypted result updated event
508
+ * @param consumer - order creator address
509
+ * @param orderId - order id
510
+ * @returns unsubscribe - unsubscribe function from event
511
+ */
512
+ OrdersFactory.onOrderEncryptedResultUpdated = function (callback, consumer, orderId) {
513
+ var _this = this;
514
+ this.checkInit();
515
+ var logger = this.logger.child({ method: "onOrderEncryptedResultUpdated" });
516
+ var subscription = this.contract.events
517
+ .OrderEncryptedResultUpdated()
518
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
519
+ return __generator(this, function (_a) {
520
+ if (orderId && event.returnValues.orderId != orderId) {
521
+ return [2 /*return*/];
522
+ }
523
+ if (consumer && event.returnValues.consumer != consumer) {
524
+ return [2 /*return*/];
525
+ }
526
+ callback(event.returnValues.orderId, event.returnValues.consumer, event.returnValues.encryptedResult);
527
+ return [2 /*return*/];
528
+ });
529
+ }); })
530
+ .on("error", function (error, receipt) {
531
+ if (receipt)
532
+ return; // Used to avoid logging of transaction rejected
533
+ logger.warn(error);
534
+ });
535
+ return function () { return subscription.unsubscribe(); };
536
+ };
537
+ return OrdersFactory;
538
+ }());
539
+ exports.default = OrdersFactory;
@@ -0,0 +1,81 @@
1
+ import { ProviderInfo } from "../types/Provider";
2
+ import { BigNumber } from "ethers";
3
+ import { TransactionOptions } from "../types/Web3";
4
+ declare class ProviderRegistry {
5
+ private static contract;
6
+ private static logger;
7
+ static providers?: string[];
8
+ /**
9
+ * Checks if contract has been initialized, if not - initialize contract
10
+ */
11
+ private static checkInitProviders;
12
+ private static checkInitProvidersOffers;
13
+ /**
14
+ * Function for fetching list of all providers addresses
15
+ */
16
+ static getAllProviders(): Promise<string[]>;
17
+ /**
18
+ * Fetch provider address by provider authority account
19
+ */
20
+ static get(providerAuthority: string): Promise<string>;
21
+ /**
22
+ * Fetch provider security deposit by provider authority account
23
+ */
24
+ static getSecurityDeposit(providerAuthority: string): Promise<string>;
25
+ /**
26
+ * Reg new provider
27
+ * @param providerInfo - data of new provider
28
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
29
+ */
30
+ static registerProvider(providerInfo: ProviderInfo, externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
31
+ /**
32
+ * Refills security deposit for provider
33
+ * Call this function with provider authority account (in transactionOptions)
34
+ * @param amount - amount of additional tokens
35
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
36
+ */
37
+ static refillSecurityDeposit(amount: string, transactionOptions?: TransactionOptions): Promise<void>;
38
+ /**
39
+ * Return security deposit for provider
40
+ * Call this function with provider authority account (in transactionOptions)
41
+ * @param amount - amount of tokens to return
42
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
43
+ */
44
+ static returnSecurityDeposit(amount: string, transactionOptions?: TransactionOptions): Promise<void>;
45
+ /**
46
+ * Function for adding event listeners on provider registered event in provider registry
47
+ * @param callback - function for processing new provider
48
+ * @return unsubscribe - unsubscribe function from event
49
+ */
50
+ static onProviderRegistered(callback: onProviderRegisteredCallback): () => void;
51
+ /**
52
+ * Function for adding event listeners on provider modified event in provider registry
53
+ * @param callback - function for processing modified provider
54
+ * @returns unsubscribe - unsubscribe function from event
55
+ */
56
+ static onProviderModified(callback: onProviderModifiedCallback): () => void;
57
+ /**
58
+ * Function for adding event listeners on provider violation rate incremented event in provider registry
59
+ * @param callback - function for processing new violation rate
60
+ * @returns unsubscribe - unsubscribe function from event
61
+ */
62
+ static onProviderViolationRateIncremented(callback: onProviderViolationRateIncrementedCallback): () => void;
63
+ /**
64
+ * Function for adding event listeners on provider security deposit refilled event in provider registry
65
+ * @param callback - function for processing refilled security deposit
66
+ * @returns unsubscribe - unsubscribe function from event
67
+ */
68
+ static onProviderSecurityDepoRefilled(callback: onProviderSecurityDepoRefilledCallback): () => void;
69
+ /**
70
+ * Function for adding event listeners on provider security deposit unlocked event in provider registry
71
+ * @param callback - function for processing unlocked security deposit
72
+ * @returns unsubscribe - unsubscribe function from event
73
+ */
74
+ static onProviderSecurityDepoUnlocked(callback: onProviderSecurityDepoUnlockedCallback): () => void;
75
+ }
76
+ export declare type onProviderRegisteredCallback = (address: string) => void;
77
+ export declare type onProviderModifiedCallback = (address: string) => void;
78
+ export declare type onProviderViolationRateIncrementedCallback = (address: string, newViolationRate: BigNumber) => void;
79
+ export declare type onProviderSecurityDepoRefilledCallback = (address: string, amount: string) => void;
80
+ export declare type onProviderSecurityDepoUnlockedCallback = (address: string, amount: string) => void;
81
+ export default ProviderRegistry;