@super-protocol/sdk-js 0.12.9-beta.0 → 0.12.9-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -359,7 +359,7 @@ var BlockchainConnector = /** @class */ (function (_super) {
359
359
  BlockchainConnector.prototype.getTransactions = function (addresses, startBlock, lastBlock, batchSize) {
360
360
  if (batchSize === void 0) { batchSize = constants_1.BLOCK_SIZE_TO_FETCH_TRANSACTION; }
361
361
  return __awaiter(this, void 0, void 0, function () {
362
- var blockchainLastBlock, transactionsByAddress, batch, getBlock, batchLastBlock, blockNumber, blocks;
362
+ var blockchainLastBlock, transactionsByAddress, validAddresses, batch, getBlock, batchLastBlock, blockNumber, blocks;
363
363
  return __generator(this, function (_a) {
364
364
  switch (_a.label) {
365
365
  case 0:
@@ -377,7 +377,14 @@ var BlockchainConnector = /** @class */ (function (_super) {
377
377
  startBlock = Math.max(lastBlock - 1000, 0);
378
378
  }
379
379
  transactionsByAddress = {};
380
- addresses.forEach(function (address) { return (transactionsByAddress[address] = []); });
380
+ validAddresses = addresses.filter(function (address) { var _a; return (_a = store_1.default.web3Https) === null || _a === void 0 ? void 0 : _a.utils.isAddress(address); });
381
+ if (!validAddresses.length) {
382
+ return [2 /*return*/, {
383
+ transactionsByAddress: transactionsByAddress,
384
+ lastBlock: lastBlock,
385
+ }];
386
+ }
387
+ validAddresses.forEach(function (address) { return (transactionsByAddress[address] = []); });
381
388
  _a.label = 2;
382
389
  case 2:
383
390
  if (!(startBlock <= lastBlock)) return [3 /*break*/, 4];
@@ -389,15 +396,15 @@ var BlockchainConnector = /** @class */ (function (_super) {
389
396
  }
390
397
  return [4 /*yield*/, this.executeBatchAsync(batch)];
391
398
  case 3:
392
- blocks = _a.sent();
399
+ blocks = (_a.sent());
393
400
  blocks.forEach(function (block) {
394
401
  if (!(block === null || block === void 0 ? void 0 : block.transactions))
395
402
  return;
396
403
  block.transactions.forEach(function (transaction) {
397
404
  var address = null;
398
- if (addresses.includes(transaction.from))
405
+ if (validAddresses.includes(transaction.from))
399
406
  address = transaction.from;
400
- else if (transaction.to && addresses.includes(transaction.to))
407
+ else if (transaction.to && validAddresses.includes(transaction.to))
401
408
  address = transaction.to;
402
409
  if (address) {
403
410
  transactionsByAddress[address].push(__assign(__assign({}, transaction), { timestamp: +block.timestamp * 1000, input: transaction.input }));
@@ -1,6 +1,6 @@
1
1
  export declare const defaultBlockchainUrl = "http://127.0.0.1:8545";
2
2
  export declare const defaultGasLimit = 7000000;
3
- export declare const defaultGasPrice = "3000000000";
3
+ export declare const defaultGasPrice = "30000000000";
4
4
  export declare const defaultGasPriceMultiplier = 1;
5
5
  export declare const defaultGasLimitMultiplier = 1.2;
6
6
  export declare const ONE_DAY: number;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.POLYGON_MATIC_EVENT_PATH = exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = exports.ONE_DAY = exports.defaultGasLimitMultiplier = exports.defaultGasPriceMultiplier = exports.defaultGasPrice = exports.defaultGasLimit = exports.defaultBlockchainUrl = void 0;
4
4
  exports.defaultBlockchainUrl = "http://127.0.0.1:8545";
5
5
  exports.defaultGasLimit = 7000000;
6
- exports.defaultGasPrice = "3000000000";
6
+ exports.defaultGasPrice = "30000000000";
7
7
  exports.defaultGasPriceMultiplier = 1;
8
8
  exports.defaultGasLimitMultiplier = 1.2;
9
9
  exports.ONE_DAY = 24 * 60 * 60;
@@ -1,5 +1,5 @@
1
1
  import { TransactionOptions } from "../types/Web3";
2
- import { TcbData, TcbStatus, PublicData, TcbVerifiedStatus } from "../types/Consensus";
2
+ import { TcbData, TcbStatus, TcbPublicData, TcbVerifiedStatus } from "../types/Consensus";
3
3
  declare class TCB {
4
4
  tcbId: string;
5
5
  private contract;
@@ -14,7 +14,7 @@ declare class TCB {
14
14
  * @param marks - list of marks
15
15
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
16
16
  */
17
- addToSupply(pb: PublicData, quote: string, marks: TcbVerifiedStatus[], transactionOptions?: TransactionOptions): Promise<void>;
17
+ addToSupply(pb: TcbPublicData, quote: string, marks: TcbVerifiedStatus[], transactionOptions?: TransactionOptions): Promise<void>;
18
18
  /**
19
19
  * Assign TCB from SuspiciousBlocks table to check
20
20
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
@@ -1,12 +1,19 @@
1
1
  import { EpochInfo } from "../types/Consensus";
2
2
  import { GetTcbRequest } from "@super-protocol/dto-js";
3
- import { TransactionOptions } from "../types/Web3";
3
+ import { TransactionOptions, BlockInfo } from "../types/Web3";
4
4
  import { ConsensusConstants } from "../types/Consensus";
5
5
  declare class Consensus {
6
+ private static readonly logger;
7
+ private static tcbIds;
6
8
  static get address(): string;
7
9
  private static initializeTcbAndAssignBlocks;
8
10
  static initializeTcb(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<void>;
9
11
  static isTcbCreationAvailable(teeOfferId: string): Promise<boolean>;
12
+ /**
13
+ * Function for fetching list of all tcb ids
14
+ * @returns list of tcb ids
15
+ */
16
+ static getAllTcbs(): Promise<string[]>;
10
17
  /**
11
18
  * Function initialize TCB and returns list of anothers' TCB for their checking
12
19
  * @param teeOfferId - id of TEE offer
@@ -31,5 +38,15 @@ declare class Consensus {
31
38
  static getLastBlockTable(): Promise<string[]>;
32
39
  static getLastBlockTableSize(): Promise<string[]>;
33
40
  static getConstants(): Promise<ConsensusConstants>;
41
+ static onTcbBanned(callback: onTcbBannedCallback): () => void;
42
+ static onTcbCompleted(callback: onTcbCompletedCallback): () => void;
43
+ static onTcbInitialized(callback: onTcbInitializedCallback): () => void;
44
+ static onTcbBenchmarkChanged(callback: onTcbBenchmarkChangedCallback): () => void;
45
+ static onRewardsClaimed(callback: onRewardsClaimedCallback): () => void;
34
46
  }
47
+ export type onRewardsClaimedCallback = (tcbId: string, amount: string, claimer: string, block?: BlockInfo) => void;
48
+ export type onTcbBenchmarkChangedCallback = (tcbId: string, provider: string, block?: BlockInfo) => void;
49
+ export type onTcbInitializedCallback = (tcbId: string, provider: string, block?: BlockInfo) => void;
50
+ export type onTcbCompletedCallback = (tcbId: string, provider: string, block?: BlockInfo) => void;
51
+ export type onTcbBannedCallback = (tcbId: string, provider: string, block?: BlockInfo) => void;
35
52
  export default Consensus;
@@ -40,9 +40,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var TCB_1 = __importDefault(require("../models/TCB"));
43
+ var logger_1 = __importDefault(require("../logger"));
43
44
  var utils_1 = require("../utils");
44
45
  var Superpro_1 = __importDefault(require("./Superpro"));
45
46
  var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
47
+ var BlockchainEventsListener_1 = __importDefault(require("../connectors/BlockchainEventsListener"));
46
48
  var TxManager_1 = __importDefault(require("../utils/TxManager"));
47
49
  var Consensus_1 = require("../types/Consensus");
48
50
  var Consensus = /** @class */ (function () {
@@ -111,6 +113,31 @@ var Consensus = /** @class */ (function () {
111
113
  });
112
114
  });
113
115
  };
116
+ /**
117
+ * Function for fetching list of all tcb ids
118
+ * @returns list of tcb ids
119
+ */
120
+ Consensus.getAllTcbs = function () {
121
+ var _a;
122
+ return __awaiter(this, void 0, void 0, function () {
123
+ var contract, tcbSet, tcbsCount, tcbId;
124
+ return __generator(this, function (_b) {
125
+ switch (_b.label) {
126
+ case 0:
127
+ contract = BlockchainConnector_1.default.getInstance().getContract();
128
+ tcbSet = new Set((_a = this.tcbIds) !== null && _a !== void 0 ? _a : []);
129
+ return [4 /*yield*/, contract.methods.getTcbsCount().call()];
130
+ case 1:
131
+ tcbsCount = _b.sent();
132
+ for (tcbId = tcbSet.size + 1; tcbId <= tcbsCount; tcbId++) {
133
+ tcbSet.add(tcbId.toString());
134
+ }
135
+ this.tcbIds = Array.from(tcbSet);
136
+ return [2 /*return*/, this.tcbIds];
137
+ }
138
+ });
139
+ });
140
+ };
114
141
  /**
115
142
  * Function initialize TCB and returns list of anothers' TCB for their checking
116
143
  * @param teeOfferId - id of TEE offer
@@ -265,6 +292,119 @@ var Consensus = /** @class */ (function () {
265
292
  });
266
293
  });
267
294
  };
295
+ // TODO: get locked rewards info
296
+ // TODO: claim avaliable rewards
297
+ Consensus.onTcbBanned = function (callback) {
298
+ var _this = this;
299
+ var contract = BlockchainEventsListener_1.default.getInstance().getContract();
300
+ var logger = this.logger.child({ method: "onTcbBanned" });
301
+ var subscription = contract.events
302
+ .TcbBanned()
303
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
304
+ return __generator(this, function (_a) {
305
+ callback(event.returnValues.tcbId, event.returnValues.provider, {
306
+ index: event.blockNumber,
307
+ hash: event.blockHash,
308
+ });
309
+ return [2 /*return*/];
310
+ });
311
+ }); })
312
+ .on("error", function (error, receipt) {
313
+ if (receipt)
314
+ return; // Used to avoid logging of transaction rejected
315
+ logger.warn(error);
316
+ });
317
+ return function () { return subscription.unsubscribe(); };
318
+ };
319
+ Consensus.onTcbCompleted = function (callback) {
320
+ var _this = this;
321
+ var contract = BlockchainEventsListener_1.default.getInstance().getContract();
322
+ var logger = this.logger.child({ method: "onTcbCompleted" });
323
+ var subscription = contract.events
324
+ .TcbCompleted()
325
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
326
+ return __generator(this, function (_a) {
327
+ callback(event.returnValues.tcbId, event.returnValues.provider, {
328
+ index: event.blockNumber,
329
+ hash: event.blockHash,
330
+ });
331
+ return [2 /*return*/];
332
+ });
333
+ }); })
334
+ .on("error", function (error, receipt) {
335
+ if (receipt)
336
+ return; // Used to avoid logging of transaction rejected
337
+ logger.warn(error);
338
+ });
339
+ return function () { return subscription.unsubscribe(); };
340
+ };
341
+ Consensus.onTcbInitialized = function (callback) {
342
+ var _this = this;
343
+ var contract = BlockchainEventsListener_1.default.getInstance().getContract();
344
+ var logger = this.logger.child({ method: "onTcbInitialized" });
345
+ var subscription = contract.events
346
+ .TcbInitialized()
347
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
348
+ return __generator(this, function (_a) {
349
+ callback(event.returnValues.tcbId, event.returnValues.provider, {
350
+ index: event.blockNumber,
351
+ hash: event.blockHash,
352
+ });
353
+ return [2 /*return*/];
354
+ });
355
+ }); })
356
+ .on("error", function (error, receipt) {
357
+ if (receipt)
358
+ return; // Used to avoid logging of transaction rejected
359
+ logger.warn(error);
360
+ });
361
+ return function () { return subscription.unsubscribe(); };
362
+ };
363
+ Consensus.onTcbBenchmarkChanged = function (callback) {
364
+ var _this = this;
365
+ var contract = BlockchainEventsListener_1.default.getInstance().getContract();
366
+ var logger = this.logger.child({ method: "onTcbBenchmarkChanged" });
367
+ var subscription = contract.events
368
+ .TcbBenchmarkChanged()
369
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
370
+ return __generator(this, function (_a) {
371
+ callback(event.returnValues.tcbId, event.returnValues.provider, {
372
+ index: event.blockNumber,
373
+ hash: event.blockHash,
374
+ });
375
+ return [2 /*return*/];
376
+ });
377
+ }); })
378
+ .on("error", function (error, receipt) {
379
+ if (receipt)
380
+ return; // Used to avoid logging of transaction rejected
381
+ logger.warn(error);
382
+ });
383
+ return function () { return subscription.unsubscribe(); };
384
+ };
385
+ Consensus.onRewardsClaimed = function (callback) {
386
+ var _this = this;
387
+ var contract = BlockchainEventsListener_1.default.getInstance().getContract();
388
+ var logger = this.logger.child({ method: "onRewardsClaimed" });
389
+ var subscription = contract.events
390
+ .RewardsClaimed()
391
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
392
+ return __generator(this, function (_a) {
393
+ callback(event.returnValues.tcbId, event.returnValues.amount, event.returnValues.claimer, {
394
+ index: event.blockNumber,
395
+ hash: event.blockHash,
396
+ });
397
+ return [2 /*return*/];
398
+ });
399
+ }); })
400
+ .on("error", function (error, receipt) {
401
+ if (receipt)
402
+ return; // Used to avoid logging of transaction rejected
403
+ logger.warn(error);
404
+ });
405
+ return function () { return subscription.unsubscribe(); };
406
+ };
407
+ Consensus.logger = logger_1.default.child({ className: "Consensus" });
268
408
  return Consensus;
269
409
  }());
270
410
  exports.default = Consensus;
@@ -201,6 +201,7 @@ var OrdersFactory = /** @class */ (function () {
201
201
  foundIds = _a.sent();
202
202
  notFound = __assign(__assign({}, filter), { offerId: "-1", orderId: "-1" });
203
203
  response = foundIds.length > 0 ? foundIds[0].returnValues : notFound;
204
+ response.externalId = (0, utils_1.parseBytes32String)(response.externalId);
204
205
  return [2 /*return*/, response];
205
206
  }
206
207
  });
@@ -10,7 +10,7 @@ export declare const PublicDataStructure: {
10
10
  benchmark: NumberConstructor;
11
11
  properties: StringConstructor;
12
12
  };
13
- export type PublicData = {
13
+ export type TcbPublicData = {
14
14
  teeOffer?: string;
15
15
  deviceID: string;
16
16
  benchmark: number;
@@ -30,7 +30,7 @@ export declare const UtilityDataStructure: {
30
30
  checked: BooleanConstructor;
31
31
  rewardClaimed: BooleanConstructor;
32
32
  };
33
- export type UtilityData = {
33
+ export type TcbUtilityData = {
34
34
  checkingBlocks: [string];
35
35
  checkingBlockMarks: [TcbVerifiedStatus];
36
36
  lastBlocksTakenAmount: number;
@@ -90,8 +90,8 @@ export type TcbData = {
90
90
  quote: string;
91
91
  timeInitialized: number;
92
92
  timeAdded: number;
93
- publicData: PublicData;
94
- utilData: UtilityData;
93
+ publicData: TcbPublicData;
94
+ utilData: TcbUtilityData;
95
95
  status: TcbStatus;
96
96
  };
97
97
  export type EpochInfo = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.12.9-beta.0",
3
+ "version": "0.12.9-beta.3",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [