@super-protocol/sdk-js 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/TIIGenerator.js +129 -239
- package/build/connectors/BaseConnector.js +17 -47
- package/build/connectors/BlockchainConnector.js +222 -348
- package/build/connectors/BlockchainEventsListener.js +38 -92
- package/build/contracts/app.json +466 -35
- package/build/crypto/Crypto.js +63 -135
- package/build/crypto/index.js +1 -1
- package/build/crypto/nodejs/AES.js +62 -119
- package/build/crypto/nodejs/ARIA.js +61 -118
- package/build/crypto/nodejs/ECIES.js +51 -87
- package/build/crypto/nodejs/NativeCrypto.js +64 -118
- package/build/crypto/nodejs/RSA-Hybrid.js +54 -113
- package/build/index.d.ts +5 -0
- package/build/index.js +14 -2
- package/build/logger.d.ts +3 -1
- package/build/logger.js +2 -2
- package/build/models/EtlModel.js +65 -114
- package/build/models/Offer.js +227 -462
- package/build/models/Order.d.ts +4 -0
- package/build/models/Order.js +326 -559
- package/build/models/Provider.d.ts +2 -0
- package/build/models/Provider.js +74 -153
- package/build/models/TCB.js +67 -171
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +389 -731
- package/build/proto/Compression.js +20 -21
- package/build/proto/TRI.js +46 -50
- package/build/proto/TeeProperties.js +60 -66
- package/build/providers/storage/ChunksDownloadDecorator.js +125 -235
- package/build/providers/storage/S3StorageProvider.js +173 -298
- package/build/providers/storage/StorageAdapter.d.ts +60 -0
- package/build/providers/storage/StorageAdapter.js +317 -0
- package/build/providers/storage/StorageContentWriter.d.ts +39 -0
- package/build/providers/storage/StorageContentWriter.js +181 -0
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +20 -0
- package/build/providers/storage/StorageKeyValueAdapter.js +152 -0
- package/build/providers/storage/StorageMetadataReader.d.ts +19 -0
- package/build/providers/storage/StorageMetadataReader.js +65 -0
- package/build/providers/storage/StorjAdapter.d.ts +19 -0
- package/build/providers/storage/StorjAdapter.js +62 -0
- package/build/providers/storage/StorjStorageProvider.js +138 -315
- package/build/providers/storage/getStorageProvider.js +7 -7
- package/build/providers/storage/types.d.ts +7 -0
- package/build/providers/storage/types.js +2 -0
- package/build/staticModels/ActiveOffers.js +32 -100
- package/build/staticModels/ActiveOrders.js +42 -120
- package/build/staticModels/BaseStaticModel.js +7 -10
- package/build/staticModels/Consensus.d.ts +4 -1
- package/build/staticModels/Consensus.js +164 -220
- package/build/staticModels/Deposits.js +109 -201
- package/build/staticModels/Marks.js +21 -82
- package/build/staticModels/ModelPackager.js +34 -84
- package/build/staticModels/Offers.js +140 -266
- package/build/staticModels/Orders.d.ts +1 -0
- package/build/staticModels/Orders.js +286 -429
- package/build/staticModels/ProviderRegistry.js +114 -225
- package/build/staticModels/Superpro.js +17 -63
- package/build/staticModels/SuperproToken.js +90 -169
- package/build/staticModels/TeeOffers.js +220 -416
- package/build/store.js +2 -2
- package/build/types/HardwareInfo.js +2 -2
- package/build/types/Order.js +4 -4
- package/build/types/Provider.js +1 -1
- package/build/types/TeeOfferInfo.js +1 -1
- package/build/types/TeeOfferOption.js +2 -2
- package/build/types/TeeOfferSlot.js +2 -2
- package/build/types/ValueOfferSlot.js +3 -3
- package/build/utils/Monitoring.js +24 -28
- package/build/utils/NonceTracker.js +56 -121
- package/build/utils/PubSub.d.ts +9 -0
- package/build/utils/PubSub.js +36 -0
- package/build/utils/TxManager.js +121 -215
- package/build/utils/compressors/GzipCompressor.js +13 -50
- package/build/utils/compressors/UncompressedCompressor.js +10 -13
- package/build/utils/helpers/tryWithInterval.js +34 -78
- package/build/utils/resourceLoaders/BaseResourceLoader.js +26 -78
- package/build/utils/resourceLoaders/StorageProviderLoader.js +33 -97
- package/build/utils/resourceLoaders/UrlResourceLoader.js +29 -93
- package/build/utils/resourceLoaders/getResourceLoader.js +6 -6
- package/build/utils.js +60 -105
- package/package.json +4 -1
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,539 +8,358 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
9
|
});
|
|
25
10
|
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
13
|
};
|
|
56
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
15
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
16
|
+
const utils_1 = require("../utils");
|
|
17
|
+
const utils_2 = require("ethers/lib/utils");
|
|
18
|
+
const utils_3 = require("../utils");
|
|
19
|
+
const TeeOfferInfo_1 = require("../types/TeeOfferInfo");
|
|
20
|
+
const Offer_1 = require("../types/Offer");
|
|
21
|
+
const BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
|
|
22
|
+
const Superpro_1 = __importDefault(require("./Superpro"));
|
|
23
|
+
const TxManager_1 = __importDefault(require("../utils/TxManager"));
|
|
24
|
+
const BlockchainEventsListener_1 = __importDefault(require("../connectors/BlockchainEventsListener"));
|
|
25
|
+
const BaseStaticModel_1 = require("./BaseStaticModel");
|
|
26
|
+
class TeeOffers extends BaseStaticModel_1.StaticModel {
|
|
27
|
+
static get address() {
|
|
28
|
+
return Superpro_1.default.address;
|
|
72
29
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
enumerable: false,
|
|
78
|
-
configurable: true
|
|
79
|
-
});
|
|
80
|
-
TeeOffers.packHardwareInfo = function (hw) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var _a, _b;
|
|
83
|
-
return __generator(this, function (_c) {
|
|
84
|
-
switch (_c.label) {
|
|
85
|
-
case 0:
|
|
86
|
-
_a = hw.slotInfo;
|
|
87
|
-
_b = _a.cpuCores;
|
|
88
|
-
return [4 /*yield*/, TeeOffers.getDenominator()];
|
|
89
|
-
case 1:
|
|
90
|
-
_a.cpuCores = _b * _c.sent();
|
|
91
|
-
return [2 /*return*/, hw];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
30
|
+
static packHardwareInfo(hw) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
hw.slotInfo.cpuCores *= yield TeeOffers.getDenominator();
|
|
33
|
+
return hw;
|
|
94
34
|
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
switch (_c.label) {
|
|
101
|
-
case 0:
|
|
102
|
-
_a = hw.slotInfo;
|
|
103
|
-
_b = _a.cpuCores;
|
|
104
|
-
return [4 /*yield*/, TeeOffers.getDenominator()];
|
|
105
|
-
case 1:
|
|
106
|
-
_a.cpuCores = _b / _c.sent();
|
|
107
|
-
return [2 /*return*/, hw];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
35
|
+
}
|
|
36
|
+
static unpackHardwareInfo(hw) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
hw.slotInfo.cpuCores /= yield TeeOffers.getDenominator();
|
|
39
|
+
return hw;
|
|
110
40
|
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
120
|
-
_a = this;
|
|
121
|
-
return [4 /*yield*/, contract.methods.getCpuDenominator().call()];
|
|
122
|
-
case 1:
|
|
123
|
-
_a.cpuDenominator = +(_b.sent());
|
|
124
|
-
_b.label = 2;
|
|
125
|
-
case 2: return [2 /*return*/, this.cpuDenominator];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
41
|
+
}
|
|
42
|
+
static getDenominator() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (!this.cpuDenominator) {
|
|
45
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
46
|
+
this.cpuDenominator = +(yield contract.methods.getCpuDenominator().call());
|
|
47
|
+
}
|
|
48
|
+
return this.cpuDenominator;
|
|
128
49
|
});
|
|
129
|
-
}
|
|
50
|
+
}
|
|
130
51
|
/**
|
|
131
52
|
* Function for fetching list of all TEE offers addresses
|
|
132
53
|
*/
|
|
133
|
-
|
|
134
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.teeOffers = this.teeOffers || [];
|
|
144
|
-
teeOfffersSet = new Set(this.teeOffers);
|
|
145
|
-
offerId = teeOfffersSet.size + 1;
|
|
146
|
-
_a.label = 2;
|
|
147
|
-
case 2:
|
|
148
|
-
if (!(offerId <= count)) return [3 /*break*/, 5];
|
|
149
|
-
return [4 /*yield*/, contract.methods.getOfferType(offerId).call()];
|
|
150
|
-
case 3:
|
|
151
|
-
offerType = (_a.sent());
|
|
152
|
-
if (offerType === Offer_1.OfferType.TeeOffer) {
|
|
153
|
-
teeOfffersSet.add(offerId.toString());
|
|
154
|
-
}
|
|
155
|
-
_a.label = 4;
|
|
156
|
-
case 4:
|
|
157
|
-
++offerId;
|
|
158
|
-
return [3 /*break*/, 2];
|
|
159
|
-
case 5:
|
|
160
|
-
this.teeOffers = Array.from(teeOfffersSet);
|
|
161
|
-
return [2 /*return*/, this.teeOffers];
|
|
54
|
+
static getAll() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
57
|
+
const count = yield contract.methods.getOffersTotalCount().call();
|
|
58
|
+
this.teeOffers = this.teeOffers || [];
|
|
59
|
+
const teeOfffersSet = new Set(this.teeOffers);
|
|
60
|
+
for (let offerId = teeOfffersSet.size + 1; offerId <= count; ++offerId) {
|
|
61
|
+
const offerType = (yield contract.methods.getOfferType(offerId).call());
|
|
62
|
+
if (offerType === Offer_1.OfferType.TeeOffer) {
|
|
63
|
+
teeOfffersSet.add(offerId.toString());
|
|
162
64
|
}
|
|
163
|
-
}
|
|
65
|
+
}
|
|
66
|
+
this.teeOffers = Array.from(teeOfffersSet);
|
|
67
|
+
return this.teeOffers;
|
|
164
68
|
});
|
|
165
|
-
}
|
|
69
|
+
}
|
|
166
70
|
/**
|
|
167
71
|
* Creates new TEE offer
|
|
168
72
|
* @param providerAuthorityAccount - address of authority account of provider
|
|
169
73
|
* @param teeOfferInfo - data of new TEE offer
|
|
170
74
|
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
171
75
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
182
|
-
// Converts offer info to array of arrays (used in blockchain)
|
|
183
|
-
_a = teeOfferInfo;
|
|
184
|
-
return [4 /*yield*/, TeeOffers.packHardwareInfo(teeOfferInfo.hardwareInfo)];
|
|
185
|
-
case 1:
|
|
186
|
-
// Converts offer info to array of arrays (used in blockchain)
|
|
187
|
-
_a.hardwareInfo = _b.sent();
|
|
188
|
-
teeOfferInfoParams = (0, utils_1.objectToTuple)(teeOfferInfo, TeeOfferInfo_1.TeeOfferInfoStructure);
|
|
189
|
-
formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
|
|
190
|
-
return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createTeeOffer, [providerAuthorityAccount, teeOfferInfoParams, formattedExternalId, enabled], transactionOptions)];
|
|
191
|
-
case 2:
|
|
192
|
-
_b.sent();
|
|
193
|
-
return [2 /*return*/];
|
|
194
|
-
}
|
|
195
|
-
});
|
|
76
|
+
static create(providerAuthorityAccount, teeOfferInfo, externalId = "default", enabled = true, transactionOptions) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
|
|
79
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
80
|
+
// Converts offer info to array of arrays (used in blockchain)
|
|
81
|
+
teeOfferInfo.hardwareInfo = yield TeeOffers.packHardwareInfo(teeOfferInfo.hardwareInfo);
|
|
82
|
+
const teeOfferInfoParams = (0, utils_1.objectToTuple)(teeOfferInfo, TeeOfferInfo_1.TeeOfferInfoStructure);
|
|
83
|
+
const formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
|
|
84
|
+
yield TxManager_1.default.execute(contract.methods.createTeeOffer, [providerAuthorityAccount, teeOfferInfoParams, formattedExternalId, enabled], transactionOptions);
|
|
196
85
|
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
creator: creator,
|
|
214
|
-
externalId: externalId,
|
|
215
|
-
offerId: "-1",
|
|
216
|
-
};
|
|
217
|
-
response = foundIds.length > 0 ? foundIds[0].returnValues : notFound;
|
|
218
|
-
return [2 /*return*/, response];
|
|
219
|
-
}
|
|
220
|
-
});
|
|
86
|
+
}
|
|
87
|
+
static getByExternalId(creator, externalId) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
90
|
+
const filter = {
|
|
91
|
+
creator,
|
|
92
|
+
externalId: (0, utils_2.formatBytes32String)(externalId),
|
|
93
|
+
};
|
|
94
|
+
const foundIds = yield contract.getPastEvents("TeeOfferCreated", { filter });
|
|
95
|
+
const notFound = {
|
|
96
|
+
creator,
|
|
97
|
+
externalId,
|
|
98
|
+
offerId: "-1",
|
|
99
|
+
};
|
|
100
|
+
const response = foundIds.length > 0 ? foundIds[0].returnValues : notFound;
|
|
101
|
+
return response;
|
|
221
102
|
});
|
|
222
|
-
}
|
|
103
|
+
}
|
|
223
104
|
/**
|
|
224
105
|
* Function for fetching TEE offer id by TEE deviceId
|
|
225
106
|
* @param deviceId - unque TEE device id (unparsed, from blockchain)
|
|
226
107
|
* @returns TEE offer id
|
|
227
108
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
109
|
+
static getByDeviceId(deviceId) {
|
|
110
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
111
|
+
const fromattedDeviceId = (0, utils_3.packDevicId)(deviceId);
|
|
231
112
|
return contract.methods.getTeeOfferByDeviceId(fromattedDeviceId).call();
|
|
232
|
-
}
|
|
113
|
+
}
|
|
233
114
|
/**
|
|
234
115
|
* Function for fetching total count of tee offer slots
|
|
235
116
|
*/
|
|
236
|
-
|
|
237
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
-
|
|
239
|
-
return
|
|
240
|
-
switch (_a.label) {
|
|
241
|
-
case 0:
|
|
242
|
-
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
243
|
-
return [4 /*yield*/, contract.methods.getTeeOffersSlotsCount().call()];
|
|
244
|
-
case 1: return [2 /*return*/, +(_a.sent())];
|
|
245
|
-
}
|
|
246
|
-
});
|
|
117
|
+
static getSlotsCount() {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
120
|
+
return +(yield contract.methods.getTeeOffersSlotsCount().call());
|
|
247
121
|
});
|
|
248
|
-
}
|
|
122
|
+
}
|
|
249
123
|
/**
|
|
250
124
|
* Function for fetching whether tee offer option exists or not
|
|
251
125
|
* @param optionId - Option ID
|
|
252
126
|
*/
|
|
253
|
-
|
|
254
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
-
|
|
256
|
-
return
|
|
257
|
-
switch (_a.label) {
|
|
258
|
-
case 0:
|
|
259
|
-
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
260
|
-
return [4 /*yield*/, contract.methods.isOptionExists(optionId).call()];
|
|
261
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
262
|
-
}
|
|
263
|
-
});
|
|
127
|
+
static isOptionExists(optionId) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
130
|
+
return yield contract.methods.isOptionExists(optionId).call();
|
|
264
131
|
});
|
|
265
|
-
}
|
|
132
|
+
}
|
|
266
133
|
/**
|
|
267
134
|
* Function for fetching total count of options
|
|
268
135
|
*/
|
|
269
|
-
|
|
270
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
271
|
-
|
|
272
|
-
return
|
|
273
|
-
switch (_a.label) {
|
|
274
|
-
case 0:
|
|
275
|
-
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
276
|
-
return [4 /*yield*/, contract.methods.getOptionsCount().call()];
|
|
277
|
-
case 1: return [2 /*return*/, +(_a.sent())];
|
|
278
|
-
}
|
|
279
|
-
});
|
|
136
|
+
static getOptionsCount() {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
139
|
+
return +(yield contract.methods.getOptionsCount().call());
|
|
280
140
|
});
|
|
281
|
-
}
|
|
141
|
+
}
|
|
282
142
|
/**
|
|
283
143
|
* Function for fetching tee offer option by id
|
|
284
144
|
* @param optionId - Option ID
|
|
285
145
|
*/
|
|
286
|
-
|
|
287
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
-
|
|
289
|
-
return
|
|
290
|
-
switch (_a.label) {
|
|
291
|
-
case 0:
|
|
292
|
-
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
293
|
-
return [4 /*yield*/, contract.methods.getOptionById(optionId).call()];
|
|
294
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
295
|
-
}
|
|
296
|
-
});
|
|
146
|
+
static getOptionById(optionId) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
149
|
+
return yield contract.methods.getOptionById(optionId).call();
|
|
297
150
|
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
filter.externalId = (0, utils_2.formatBytes32String)(filter.externalId);
|
|
306
|
-
return [4 /*yield*/, this.getPastEvents("TeeSlotAdded", filter, fromBlock, toBlock)];
|
|
307
|
-
case 1:
|
|
308
|
-
foundEvents = _a.sent();
|
|
309
|
-
response = foundEvents.length ? foundEvents[0].returnValues : null;
|
|
310
|
-
return [2 /*return*/, response];
|
|
311
|
-
}
|
|
312
|
-
});
|
|
151
|
+
}
|
|
152
|
+
static getSlotByExternalId(filter, fromBlock, toBlock) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
filter.externalId = (0, utils_2.formatBytes32String)(filter.externalId);
|
|
155
|
+
const foundEvents = yield this.getPastEvents("TeeSlotAdded", filter, fromBlock, toBlock);
|
|
156
|
+
const response = foundEvents.length ? foundEvents[0].returnValues : null;
|
|
157
|
+
return response;
|
|
313
158
|
});
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
filter.externalId = (0, utils_2.formatBytes32String)(filter.externalId);
|
|
322
|
-
return [4 /*yield*/, this.getPastEvents("OptionAdded", filter, fromBlock, toBlock)];
|
|
323
|
-
case 1:
|
|
324
|
-
foundEvents = _a.sent();
|
|
325
|
-
response = foundEvents.length ? foundEvents[0].returnValues : null;
|
|
326
|
-
return [2 /*return*/, response];
|
|
327
|
-
}
|
|
328
|
-
});
|
|
159
|
+
}
|
|
160
|
+
static getOptionByExternalId(filter, fromBlock, toBlock) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
filter.externalId = (0, utils_2.formatBytes32String)(filter.externalId);
|
|
163
|
+
const foundEvents = yield this.getPastEvents("OptionAdded", filter, fromBlock, toBlock);
|
|
164
|
+
const response = foundEvents.length ? foundEvents[0].returnValues : null;
|
|
165
|
+
return response;
|
|
329
166
|
});
|
|
330
|
-
}
|
|
167
|
+
}
|
|
331
168
|
/**
|
|
332
169
|
* Function for adding event listeners on onSlotAdded event in contract
|
|
333
170
|
* @param creator - creator address
|
|
334
171
|
* @param callback - function for processing created order
|
|
335
172
|
* @returns unsubscribe - unsubscribe function from event
|
|
336
173
|
*/
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
var subscription = contract.events
|
|
174
|
+
static onSlotAdded(callback, creator) {
|
|
175
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
176
|
+
const logger = this.logger.child({ method: "onTeeSlotAdded" });
|
|
177
|
+
const subscription = contract.events
|
|
342
178
|
.TeeSlotAdded()
|
|
343
|
-
.on("data",
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
hash: event.blockHash,
|
|
351
|
-
});
|
|
352
|
-
return [2 /*return*/];
|
|
179
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
if (creator && event.returnValues.creator != creator) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
callback(event.returnValues.creator, event.returnValues.offerId, event.returnValues.slotId, (0, utils_2.parseBytes32String)(event.returnValues.externalId), {
|
|
184
|
+
index: event.blockNumber,
|
|
185
|
+
hash: event.blockHash,
|
|
353
186
|
});
|
|
354
|
-
})
|
|
355
|
-
.on("error",
|
|
187
|
+
}))
|
|
188
|
+
.on("error", (error, receipt) => {
|
|
356
189
|
if (receipt)
|
|
357
190
|
return;
|
|
358
191
|
logger.warn(error);
|
|
359
192
|
});
|
|
360
|
-
return
|
|
361
|
-
}
|
|
193
|
+
return () => subscription.unsubscribe();
|
|
194
|
+
}
|
|
362
195
|
/**
|
|
363
196
|
* Function for adding event listeners on onSlotUpdated event in contract
|
|
364
197
|
* @param callback - function for processing created order
|
|
365
198
|
* @returns unsubscribe - unsubscribe function from event
|
|
366
199
|
*/
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
var subscription = contract.events
|
|
200
|
+
static onSlotUpdated(callback) {
|
|
201
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
202
|
+
const logger = this.logger.child({ method: "onTeeSlotUpdated" });
|
|
203
|
+
const subscription = contract.events
|
|
372
204
|
.TeeSlotUpdated()
|
|
373
|
-
.on("data",
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
hash: event.blockHash,
|
|
378
|
-
});
|
|
379
|
-
return [2 /*return*/];
|
|
205
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
callback(event.returnValues.offerId, event.returnValues.slotId, {
|
|
207
|
+
index: event.blockNumber,
|
|
208
|
+
hash: event.blockHash,
|
|
380
209
|
});
|
|
381
|
-
})
|
|
382
|
-
.on("error",
|
|
210
|
+
}))
|
|
211
|
+
.on("error", (error, receipt) => {
|
|
383
212
|
if (receipt)
|
|
384
213
|
return;
|
|
385
214
|
logger.warn(error);
|
|
386
215
|
});
|
|
387
|
-
return
|
|
388
|
-
}
|
|
216
|
+
return () => subscription.unsubscribe();
|
|
217
|
+
}
|
|
389
218
|
/**
|
|
390
219
|
* Function for adding event listeners on onSlotDeleted event in contract
|
|
391
220
|
* @param callback - function for processing created order
|
|
392
221
|
* @returns unsubscribe - unsubscribe function from event
|
|
393
222
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
var subscription = contract.events
|
|
223
|
+
static onSlotDeleted(callback) {
|
|
224
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
225
|
+
const logger = this.logger.child({ method: "onTeeSlotDeleted" });
|
|
226
|
+
const subscription = contract.events
|
|
399
227
|
.TeeSlotDeleted()
|
|
400
|
-
.on("data",
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
hash: event.blockHash,
|
|
405
|
-
});
|
|
406
|
-
return [2 /*return*/];
|
|
228
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
callback(event.returnValues.offerId, event.returnValues.slotId, {
|
|
230
|
+
index: event.blockNumber,
|
|
231
|
+
hash: event.blockHash,
|
|
407
232
|
});
|
|
408
|
-
})
|
|
409
|
-
.on("error",
|
|
233
|
+
}))
|
|
234
|
+
.on("error", (error, receipt) => {
|
|
410
235
|
if (receipt)
|
|
411
236
|
return;
|
|
412
237
|
logger.warn(error);
|
|
413
238
|
});
|
|
414
|
-
return
|
|
415
|
-
}
|
|
239
|
+
return () => subscription.unsubscribe();
|
|
240
|
+
}
|
|
416
241
|
/**
|
|
417
242
|
* Function for adding event listeners on OptionAdded event in contract
|
|
418
243
|
* @param creator - creator address
|
|
419
244
|
* @param callback - function for processing created order
|
|
420
245
|
* @returns unsubscribe - unsubscribe function from event
|
|
421
246
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
var subscription = contract.events
|
|
247
|
+
static onOptionAdded(callback, creator) {
|
|
248
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
249
|
+
const logger = this.logger.child({ method: "onTeeOptionAddedCallback" });
|
|
250
|
+
const subscription = contract.events
|
|
427
251
|
.OptionAdded()
|
|
428
|
-
.on("data",
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
hash: event.blockHash,
|
|
436
|
-
});
|
|
437
|
-
return [2 /*return*/];
|
|
252
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
if (creator && event.returnValues.creator != creator) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
callback(event.returnValues.creator, event.returnValues.teeOfferId, event.returnValues.optionId, (0, utils_2.parseBytes32String)(event.returnValues.externalId), {
|
|
257
|
+
index: event.blockNumber,
|
|
258
|
+
hash: event.blockHash,
|
|
438
259
|
});
|
|
439
|
-
})
|
|
440
|
-
.on("error",
|
|
260
|
+
}))
|
|
261
|
+
.on("error", (error, receipt) => {
|
|
441
262
|
if (receipt)
|
|
442
263
|
return;
|
|
443
264
|
logger.warn(error);
|
|
444
265
|
});
|
|
445
|
-
return
|
|
446
|
-
}
|
|
266
|
+
return () => subscription.unsubscribe();
|
|
267
|
+
}
|
|
447
268
|
/**
|
|
448
269
|
* Function for adding event listeners on OptionUpdated event in contract
|
|
449
270
|
* @param teeOfferId - tee offer id
|
|
450
271
|
* @param callback - function for processing created order
|
|
451
272
|
* @returns unsubscribe - unsubscribe function from event
|
|
452
273
|
*/
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
var subscription = contract.events
|
|
274
|
+
static onOptionUpdated(callback, teeOfferId) {
|
|
275
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
276
|
+
const logger = this.logger.child({ method: "onTeeOptionUpdatedCallback" });
|
|
277
|
+
const subscription = contract.events
|
|
458
278
|
.OptionUpdated()
|
|
459
|
-
.on("data",
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
hash: event.blockHash,
|
|
467
|
-
});
|
|
468
|
-
return [2 /*return*/];
|
|
279
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
if (teeOfferId && event.returnValues.teeOfferId != teeOfferId) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
callback(event.returnValues.teeOfferId, event.returnValues.optionId, {
|
|
284
|
+
index: event.blockNumber,
|
|
285
|
+
hash: event.blockHash,
|
|
469
286
|
});
|
|
470
|
-
})
|
|
471
|
-
.on("error",
|
|
287
|
+
}))
|
|
288
|
+
.on("error", (error, receipt) => {
|
|
472
289
|
if (receipt)
|
|
473
290
|
return;
|
|
474
291
|
logger.warn(error);
|
|
475
292
|
});
|
|
476
|
-
return
|
|
477
|
-
}
|
|
293
|
+
return () => subscription.unsubscribe();
|
|
294
|
+
}
|
|
478
295
|
/**
|
|
479
296
|
* Function for adding event listeners on OptionDeleted event in contract
|
|
480
297
|
* @param teeOfferId - tee offer id
|
|
481
298
|
* @param callback - function for processing created order
|
|
482
299
|
* @returns unsubscribe - unsubscribe function from event
|
|
483
300
|
*/
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
var subscription = contract.events
|
|
301
|
+
static onOptionDeleted(callback, teeOfferId) {
|
|
302
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
303
|
+
const logger = this.logger.child({ method: "onTeeOptionDeletedCallback" });
|
|
304
|
+
const subscription = contract.events
|
|
489
305
|
.OptionDeleted()
|
|
490
|
-
.on("data",
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
hash: event.blockHash,
|
|
498
|
-
});
|
|
499
|
-
return [2 /*return*/];
|
|
306
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
307
|
+
if (teeOfferId && event.returnValues.teeOfferId != teeOfferId) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
callback(event.returnValues.teeOfferId, event.returnValues.optionId, {
|
|
311
|
+
index: event.blockNumber,
|
|
312
|
+
hash: event.blockHash,
|
|
500
313
|
});
|
|
501
|
-
})
|
|
502
|
-
.on("error",
|
|
314
|
+
}))
|
|
315
|
+
.on("error", (error, receipt) => {
|
|
503
316
|
if (receipt)
|
|
504
317
|
return;
|
|
505
318
|
logger.warn(error);
|
|
506
319
|
});
|
|
507
|
-
return
|
|
508
|
-
}
|
|
320
|
+
return () => subscription.unsubscribe();
|
|
321
|
+
}
|
|
509
322
|
/**
|
|
510
323
|
* Function for adding event listeners on TEE offer created event in TEE offers factory contract
|
|
511
324
|
* @param callback - function for processing created TEE offer
|
|
512
325
|
* @returns unsubscribe - unsubscribe function from event
|
|
513
326
|
*/
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
var subscription = contract.events
|
|
327
|
+
static onCreated(callback) {
|
|
328
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
329
|
+
const logger = this.logger.child({ method: "onTeeOfferCreated" });
|
|
330
|
+
const subscription = contract.events
|
|
519
331
|
.TeeOfferCreated()
|
|
520
|
-
.on("data",
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
hash: event.blockHash,
|
|
525
|
-
});
|
|
526
|
-
return [2 /*return*/];
|
|
332
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
333
|
+
callback(event.returnValues.offerId, event.returnValues.creator, (0, utils_2.parseBytes32String)(event.returnValues.externalId), {
|
|
334
|
+
index: event.blockNumber,
|
|
335
|
+
hash: event.blockHash,
|
|
527
336
|
});
|
|
528
|
-
})
|
|
529
|
-
.on("error",
|
|
337
|
+
}))
|
|
338
|
+
.on("error", (error, receipt) => {
|
|
530
339
|
if (receipt)
|
|
531
340
|
return; // Used to avoid logging of transaction rejected
|
|
532
341
|
logger.warn(error);
|
|
533
342
|
});
|
|
534
|
-
return
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
var subscription = contract.events
|
|
343
|
+
return () => subscription.unsubscribe();
|
|
344
|
+
}
|
|
345
|
+
static onViolationRateChanged(callback) {
|
|
346
|
+
const contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
347
|
+
const logger = this.logger.child({ method: "onTeeOfferViolationRateChanged" });
|
|
348
|
+
const subscription = contract.events
|
|
541
349
|
.TeeOfferViolationRateChanged()
|
|
542
|
-
.on("data",
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
hash: event.blockHash,
|
|
547
|
-
});
|
|
548
|
-
return [2 /*return*/];
|
|
350
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
351
|
+
callback(event.returnValues.offerId, event.returnValues.providerAuth, event.returnValues.violationRate, {
|
|
352
|
+
index: event.blockNumber,
|
|
353
|
+
hash: event.blockHash,
|
|
549
354
|
});
|
|
550
|
-
})
|
|
551
|
-
.on("error",
|
|
355
|
+
}))
|
|
356
|
+
.on("error", (error, receipt) => {
|
|
552
357
|
if (receipt)
|
|
553
358
|
return; // Used to avoid logging of transaction rejected
|
|
554
359
|
logger.warn(error);
|
|
555
360
|
});
|
|
556
|
-
return
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}(BaseStaticModel_1.StaticModel));
|
|
361
|
+
return () => subscription.unsubscribe();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
TeeOffers.logger = logger_1.default.child({ className: "TeeOffers" });
|
|
561
365
|
exports.default = TeeOffers;
|