@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.
- package/build/BlockchainConnector.d.ts +48 -0
- package/build/BlockchainConnector.js +259 -0
- package/build/TIIGenerator.d.ts +21 -0
- package/build/TIIGenerator.js +251 -0
- package/build/constants.d.ts +7 -0
- package/build/constants.js +10 -0
- package/build/contracts/ActiveOffersList.json +131 -0
- package/build/contracts/ActiveOrdersList.json +74 -0
- package/build/contracts/Marks.json +79 -0
- package/build/contracts/Offers.json +999 -0
- package/build/contracts/Orders.json +984 -0
- package/build/contracts/Providers.json +440 -0
- package/build/contracts/ProvidersOffers.json +254 -0
- package/build/contracts/Staking.json +323 -0
- package/build/contracts/Superpro.json +197 -0
- package/build/contracts/SuperproToken.json +356 -0
- package/build/crypto/Crypto.d.ts +37 -0
- package/build/crypto/Crypto.js +181 -0
- package/build/crypto/index.d.ts +2 -0
- package/build/crypto/index.js +7 -0
- package/build/crypto/nodejs/AES.d.ts +24 -0
- package/build/crypto/nodejs/AES.js +152 -0
- package/build/crypto/nodejs/ARIA.d.ts +24 -0
- package/build/crypto/nodejs/ARIA.js +151 -0
- package/build/crypto/nodejs/ECIES.d.ts +6 -0
- package/build/crypto/nodejs/ECIES.js +94 -0
- package/build/crypto/nodejs/NativeCrypto.d.ts +54 -0
- package/build/crypto/nodejs/NativeCrypto.js +214 -0
- package/build/crypto/nodejs/RSA-Hybrid.d.ts +15 -0
- package/build/crypto/nodejs/RSA-Hybrid.js +153 -0
- package/build/index.d.ts +65 -0
- package/build/index.js +117 -0
- package/build/logger.d.ts +4 -0
- package/build/logger.js +8 -0
- package/build/models/Ballot.d.ts +13 -0
- package/build/models/Ballot.js +76 -0
- package/build/models/Offer.d.ts +70 -0
- package/build/models/Offer.js +273 -0
- package/build/models/Order.d.ts +125 -0
- package/build/models/Order.js +540 -0
- package/build/models/Provider.d.ts +40 -0
- package/build/models/Provider.js +167 -0
- package/build/models/TCB.d.ts +80 -0
- package/build/models/TCB.js +315 -0
- package/build/models/TeeOffer.d.ts +118 -0
- package/build/models/TeeOffer.js +436 -0
- package/build/proto/Compression.d.ts +33 -0
- package/build/proto/Compression.js +146 -0
- package/build/proto/TRI.d.ts +122 -0
- package/build/proto/TRI.js +316 -0
- package/build/providers/storage/ChunksDownloadDecorator.d.ts +38 -0
- package/build/providers/storage/ChunksDownloadDecorator.js +284 -0
- package/build/providers/storage/IStorageProvider.d.ts +17 -0
- package/build/providers/storage/IStorageProvider.js +2 -0
- package/build/providers/storage/StorjStorageProvider.d.ts +26 -0
- package/build/providers/storage/StorjStorageProvider.js +389 -0
- package/build/providers/storage/getStorageProvider.d.ts +4 -0
- package/build/providers/storage/getStorageProvider.js +16 -0
- package/build/staticModels/ActiveOffers.d.ts +29 -0
- package/build/staticModels/ActiveOffers.js +144 -0
- package/build/staticModels/ActiveOrders.d.ts +21 -0
- package/build/staticModels/ActiveOrders.js +120 -0
- package/build/staticModels/Consensus.d.ts +63 -0
- package/build/staticModels/Consensus.js +373 -0
- package/build/staticModels/Epochs.d.ts +23 -0
- package/build/staticModels/Epochs.js +97 -0
- package/build/staticModels/LastBlocks.d.ts +25 -0
- package/build/staticModels/LastBlocks.js +96 -0
- package/build/staticModels/Marks.d.ts +13 -0
- package/build/staticModels/Marks.js +113 -0
- package/build/staticModels/OffersFactory.d.ts +37 -0
- package/build/staticModels/OffersFactory.js +227 -0
- package/build/staticModels/OrdersFactory.d.ts +137 -0
- package/build/staticModels/OrdersFactory.js +539 -0
- package/build/staticModels/ProviderRegistry.d.ts +81 -0
- package/build/staticModels/ProviderRegistry.js +311 -0
- package/build/staticModels/Staking.d.ts +26 -0
- package/build/staticModels/Staking.js +132 -0
- package/build/staticModels/Superpro.d.ts +20 -0
- package/build/staticModels/Superpro.js +99 -0
- package/build/staticModels/SuperproToken.d.ts +30 -0
- package/build/staticModels/SuperproToken.js +125 -0
- package/build/staticModels/Suspicious.d.ts +26 -0
- package/build/staticModels/Suspicious.js +99 -0
- package/build/staticModels/TeeOffersFactory.d.ts +36 -0
- package/build/staticModels/TeeOffersFactory.js +206 -0
- package/build/staticModels/Voting.d.ts +35 -0
- package/build/staticModels/Voting.js +111 -0
- package/build/store.d.ts +12 -0
- package/build/store.js +13 -0
- package/build/types/Ballot.d.ts +75 -0
- package/build/types/Ballot.js +49 -0
- package/build/types/Epoch.d.ts +21 -0
- package/build/types/Epoch.js +18 -0
- package/build/types/Events.d.ts +18 -0
- package/build/types/Events.js +2 -0
- package/build/types/Marks.d.ts +5 -0
- package/build/types/Marks.js +9 -0
- package/build/types/Offer.d.ts +63 -0
- package/build/types/Offer.js +41 -0
- package/build/types/Order.d.ts +61 -0
- package/build/types/Order.js +36 -0
- package/build/types/Origins.d.ts +12 -0
- package/build/types/Origins.js +10 -0
- package/build/types/Provider.d.ts +25 -0
- package/build/types/Provider.js +19 -0
- package/build/types/Staking.d.ts +27 -0
- package/build/types/Staking.js +22 -0
- package/build/types/Superpro.d.ts +24 -0
- package/build/types/Superpro.js +29 -0
- package/build/types/TcbData.d.ts +26 -0
- package/build/types/TcbData.js +21 -0
- package/build/types/TeeOffer.d.ts +22 -0
- package/build/types/TeeOffer.js +15 -0
- package/build/types/Web3.d.ts +26 -0
- package/build/types/Web3.js +2 -0
- package/build/types/blockchainConnector/StorageAccess.d.ts +8 -0
- package/build/types/blockchainConnector/StorageAccess.js +2 -0
- package/build/types/storage/StorageAccess.d.ts +6 -0
- package/build/types/storage/StorageAccess.js +2 -0
- package/build/types/storage/StorageFileAccess.d.ts +5 -0
- package/build/types/storage/StorageFileAccess.js +2 -0
- package/build/types/storage/StorageObject.d.ts +8 -0
- package/build/types/storage/StorageObject.js +2 -0
- package/build/utils/NonceTracker.d.ts +12 -0
- package/build/utils/NonceTracker.js +84 -0
- package/build/utils/TxManager.d.ts +21 -0
- package/build/utils/TxManager.js +159 -0
- package/build/utils.d.ts +38 -0
- package/build/utils.js +195 -0
- package/package.json +68 -0
- package/readme.md +40 -0
|
@@ -0,0 +1,167 @@
|
|
|
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 logger_1 = __importDefault(require("../logger"));
|
|
43
|
+
var Providers_json_1 = __importDefault(require("../contracts/Providers.json"));
|
|
44
|
+
var ProvidersOffers_json_1 = __importDefault(require("../contracts/ProvidersOffers.json"));
|
|
45
|
+
var store_1 = __importDefault(require("../store"));
|
|
46
|
+
var utils_1 = require("../utils");
|
|
47
|
+
var Provider_1 = require("../types/Provider");
|
|
48
|
+
var Origins_1 = require("../types/Origins");
|
|
49
|
+
var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
50
|
+
var Provider = /** @class */ (function () {
|
|
51
|
+
function Provider(providerId) {
|
|
52
|
+
(0, utils_1.checkIfInitialized)();
|
|
53
|
+
this.providerId = providerId;
|
|
54
|
+
if (!Provider.contractProviders || !Provider.contractProvidersOffers) {
|
|
55
|
+
Provider.contractProviders = new store_1.default.web3.eth.Contract(Providers_json_1.default.abi, Superpro_1.default.address);
|
|
56
|
+
Provider.contractProvidersOffers = new store_1.default.web3.eth.Contract(ProvidersOffers_json_1.default.abi, Superpro_1.default.address);
|
|
57
|
+
}
|
|
58
|
+
this.logger = logger_1.default.child({
|
|
59
|
+
className: "Provider",
|
|
60
|
+
providerId: this.providerId.toString(),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Function for fetching provider info from blockchain
|
|
65
|
+
*/
|
|
66
|
+
Provider.prototype.getInfo = function () {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var providerInfoParams;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
71
|
+
case 0: return [4 /*yield*/, Provider.contractProviders.methods.getProviderInfo(this.providerId).call()];
|
|
72
|
+
case 1:
|
|
73
|
+
providerInfoParams = _a.sent();
|
|
74
|
+
this.providerInfo = (0, utils_1.tupleToObject)(providerInfoParams, Provider_1.ProviderInfoStructure);
|
|
75
|
+
return [2 /*return*/, this.providerInfo];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Function for fetching provider authority address from blockchain
|
|
82
|
+
*/
|
|
83
|
+
Provider.prototype.getAuthority = function () {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
return [2 /*return*/, this.providerId.toString()];
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Function for fetching all value offers for this provider
|
|
92
|
+
*/
|
|
93
|
+
Provider.prototype.getValueOffers = function () {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
var _a;
|
|
96
|
+
return __generator(this, function (_b) {
|
|
97
|
+
switch (_b.label) {
|
|
98
|
+
case 0:
|
|
99
|
+
_a = this;
|
|
100
|
+
return [4 /*yield*/, Provider.contractProvidersOffers.methods.getProviderValueOffers(this.providerId).call()];
|
|
101
|
+
case 1:
|
|
102
|
+
_a.valueOffers = _b.sent();
|
|
103
|
+
return [2 /*return*/, this.valueOffers];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Function for fetching all TEE offers for this provider
|
|
110
|
+
*/
|
|
111
|
+
Provider.prototype.getTeeOffers = function () {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var _a;
|
|
114
|
+
return __generator(this, function (_b) {
|
|
115
|
+
switch (_b.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
_a = this;
|
|
118
|
+
return [4 /*yield*/, Provider.contractProvidersOffers.methods.getProviderTeeOffers(this.providerId).call()];
|
|
119
|
+
case 1:
|
|
120
|
+
_a.teeOffers = _b.sent();
|
|
121
|
+
return [2 /*return*/, this.teeOffers];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Function for fetching violationRate for this provider
|
|
128
|
+
*/
|
|
129
|
+
Provider.prototype.getViolationRate = function () {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var _a;
|
|
132
|
+
return __generator(this, function (_b) {
|
|
133
|
+
switch (_b.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
_a = this;
|
|
136
|
+
return [4 /*yield*/, Provider.contractProviders.methods.getProviderViolationRate(this.providerId).call()];
|
|
137
|
+
case 1:
|
|
138
|
+
_a.violationRate = _b.sent();
|
|
139
|
+
return [2 /*return*/, this.violationRate];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
|
|
146
|
+
*/
|
|
147
|
+
Provider.prototype.getOrigins = function () {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var origins;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0: return [4 /*yield*/, Provider.contractProviders.methods.getProviderOrigins(this.providerId).call()];
|
|
153
|
+
case 1:
|
|
154
|
+
origins = _a.sent();
|
|
155
|
+
// Converts blockchain array into object
|
|
156
|
+
origins = (0, utils_1.tupleToObject)(origins, Origins_1.OriginsStructure);
|
|
157
|
+
// Convert blockchain time seconds to js time milliseconds
|
|
158
|
+
origins.createdDate = +origins.createdDate * 1000;
|
|
159
|
+
origins.modifiedDate = +origins.modifiedDate * 1000;
|
|
160
|
+
return [2 /*return*/, (this.origins = origins)];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
return Provider;
|
|
166
|
+
}());
|
|
167
|
+
exports.default = Provider;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { PublicData, LType, TcbEpochInfo } from "../types/TcbData";
|
|
2
|
+
import { TransactionOptions } from "../types/Web3";
|
|
3
|
+
import { TcbStatus } from "./../types/Epoch";
|
|
4
|
+
declare class TCB {
|
|
5
|
+
address: string;
|
|
6
|
+
private contract;
|
|
7
|
+
private logger;
|
|
8
|
+
L1?: string[];
|
|
9
|
+
L2?: string[];
|
|
10
|
+
L1_statusess?: number[];
|
|
11
|
+
L2_statusess?: number[];
|
|
12
|
+
epoch?: TcbEpochInfo;
|
|
13
|
+
positive?: number;
|
|
14
|
+
negative?: number;
|
|
15
|
+
quote?: string;
|
|
16
|
+
constructor(address: string);
|
|
17
|
+
/**
|
|
18
|
+
* Function for fetching number of TCB's to request for verifying from LastBlocksTable
|
|
19
|
+
*/
|
|
20
|
+
needL1toCompleted(): Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Function for fetching number of TCB's to request for verifying from SuspiciousBlocksTable
|
|
23
|
+
*/
|
|
24
|
+
needL2toCompleted(): Promise<number>;
|
|
25
|
+
/**
|
|
26
|
+
* Function for fetching list of TCBs from LastBlocksTable formed for veirifying
|
|
27
|
+
*/
|
|
28
|
+
getL1(): Promise<string[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Function for fetching list of TCBs from SuspiciousBlocksTable formed for veirifying
|
|
31
|
+
*/
|
|
32
|
+
getL2(): Promise<string[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Function for fetching the given marks for recruited TCBs from the LastBlocksTable
|
|
35
|
+
*/
|
|
36
|
+
getL1Marks(): Promise<number[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Function for fetching the given marks for recruited TCBs from the SuspiciousBlocksTable
|
|
39
|
+
*/
|
|
40
|
+
getL2Marks(): Promise<number[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Function for fetching TCB status
|
|
43
|
+
*/
|
|
44
|
+
getTcbStatus(): Promise<TcbStatus>;
|
|
45
|
+
/**
|
|
46
|
+
* Function for fetching calimed amount of TCB reward
|
|
47
|
+
*/
|
|
48
|
+
getPaidAmount(): Promise<number>;
|
|
49
|
+
/**
|
|
50
|
+
* Add processed TCB data to smart-contract
|
|
51
|
+
* @param used - struct of 'processed' data
|
|
52
|
+
* @param quote - data generated from Enclave
|
|
53
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
54
|
+
*/
|
|
55
|
+
addData(pb: PublicData, quote: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
56
|
+
getEpochInfo(): Promise<TcbEpochInfo>;
|
|
57
|
+
/**
|
|
58
|
+
* Function for fetching marks of TCB (from Consensus)
|
|
59
|
+
*/
|
|
60
|
+
getOwnMarks(): Promise<{
|
|
61
|
+
positive: number;
|
|
62
|
+
negative: number;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Function for fetching used TCB data
|
|
66
|
+
*/
|
|
67
|
+
getPublicData(): Promise<PublicData>;
|
|
68
|
+
/**
|
|
69
|
+
* Function for fetching stored TCB data
|
|
70
|
+
*/
|
|
71
|
+
getQuote(): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Append marks for selected TCBs
|
|
74
|
+
* @param lType - type of appending marks
|
|
75
|
+
* @param marks - list of marks
|
|
76
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
77
|
+
*/
|
|
78
|
+
addMarks(lType: LType, marks: number[], transactionOptions?: TransactionOptions): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
export default TCB;
|
|
@@ -0,0 +1,315 @@
|
|
|
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 logger_1 = __importDefault(require("../logger"));
|
|
43
|
+
// import TcbJSON from "../contracts/TCB.json";
|
|
44
|
+
var Offers_json_1 = __importDefault(require("../contracts/Offers.json"));
|
|
45
|
+
var store_1 = __importDefault(require("../store"));
|
|
46
|
+
var TcbData_1 = require("../types/TcbData");
|
|
47
|
+
var utils_1 = require("../utils");
|
|
48
|
+
var Suspicious_1 = __importDefault(require("../staticModels/Suspicious"));
|
|
49
|
+
var LastBlocks_1 = __importDefault(require("../staticModels/LastBlocks"));
|
|
50
|
+
var utils_2 = require("ethers/lib/utils");
|
|
51
|
+
var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
52
|
+
var TxManager_1 = __importDefault(require("../utils/TxManager"));
|
|
53
|
+
var TCB = /** @class */ (function () {
|
|
54
|
+
function TCB(address) {
|
|
55
|
+
(0, utils_1.checkIfInitialized)();
|
|
56
|
+
this.address = address;
|
|
57
|
+
// this.contract = new store.web3!.eth.Contract(<AbiItem[]>TcbJSON.abi, address);
|
|
58
|
+
// TODO: stub
|
|
59
|
+
this.contract = new store_1.default.web3.eth.Contract(Offers_json_1.default.abi, Superpro_1.default.address);
|
|
60
|
+
this.logger = logger_1.default.child({ className: "TCB", address: address });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Function for fetching number of TCB's to request for verifying from LastBlocksTable
|
|
64
|
+
*/
|
|
65
|
+
TCB.prototype.needL1toCompleted = function () {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var lbtSzie, l1Completed;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0: return [4 /*yield*/, LastBlocks_1.default.count()];
|
|
71
|
+
case 1:
|
|
72
|
+
lbtSzie = _a.sent();
|
|
73
|
+
return [4 /*yield*/, this.contract.methods.needL1toCompleted(lbtSzie).call()];
|
|
74
|
+
case 2:
|
|
75
|
+
l1Completed = _a.sent();
|
|
76
|
+
return [2 /*return*/, l1Completed];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Function for fetching number of TCB's to request for verifying from SuspiciousBlocksTable
|
|
83
|
+
*/
|
|
84
|
+
TCB.prototype.needL2toCompleted = function () {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var sbtSize, l2Completed;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0: return [4 /*yield*/, Suspicious_1.default.count()];
|
|
90
|
+
case 1:
|
|
91
|
+
sbtSize = _a.sent();
|
|
92
|
+
return [4 /*yield*/, this.contract.methods.needL2toCompleted(sbtSize).call()];
|
|
93
|
+
case 2:
|
|
94
|
+
l2Completed = _a.sent();
|
|
95
|
+
return [2 /*return*/, l2Completed];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Function for fetching list of TCBs from LastBlocksTable formed for veirifying
|
|
102
|
+
*/
|
|
103
|
+
TCB.prototype.getL1 = function () {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var _a;
|
|
106
|
+
return __generator(this, function (_b) {
|
|
107
|
+
switch (_b.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
_a = this;
|
|
110
|
+
return [4 /*yield*/, this.contract.methods.getL1().call()];
|
|
111
|
+
case 1:
|
|
112
|
+
_a.L1 = _b.sent();
|
|
113
|
+
return [2 /*return*/, this.L1];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Function for fetching list of TCBs from SuspiciousBlocksTable formed for veirifying
|
|
120
|
+
*/
|
|
121
|
+
TCB.prototype.getL2 = function () {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
var _a;
|
|
124
|
+
return __generator(this, function (_b) {
|
|
125
|
+
switch (_b.label) {
|
|
126
|
+
case 0:
|
|
127
|
+
_a = this;
|
|
128
|
+
return [4 /*yield*/, this.contract.methods.getL2().call()];
|
|
129
|
+
case 1:
|
|
130
|
+
_a.L2 = _b.sent();
|
|
131
|
+
return [2 /*return*/, this.L2];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Function for fetching the given marks for recruited TCBs from the LastBlocksTable
|
|
138
|
+
*/
|
|
139
|
+
TCB.prototype.getL1Marks = function () {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
+
var _a;
|
|
142
|
+
return __generator(this, function (_b) {
|
|
143
|
+
switch (_b.label) {
|
|
144
|
+
case 0:
|
|
145
|
+
_a = this;
|
|
146
|
+
return [4 /*yield*/, this.contract.methods.getL1Marks().call()];
|
|
147
|
+
case 1:
|
|
148
|
+
_a.L1_statusess = _b.sent();
|
|
149
|
+
return [2 /*return*/, this.L1_statusess];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Function for fetching the given marks for recruited TCBs from the SuspiciousBlocksTable
|
|
156
|
+
*/
|
|
157
|
+
TCB.prototype.getL2Marks = function () {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
+
var _a;
|
|
160
|
+
return __generator(this, function (_b) {
|
|
161
|
+
switch (_b.label) {
|
|
162
|
+
case 0:
|
|
163
|
+
_a = this;
|
|
164
|
+
return [4 /*yield*/, this.contract.methods.getL2Marks().call()];
|
|
165
|
+
case 1:
|
|
166
|
+
_a.L2_statusess = _b.sent();
|
|
167
|
+
return [2 /*return*/, this.L2_statusess];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Function for fetching TCB status
|
|
174
|
+
*/
|
|
175
|
+
TCB.prototype.getTcbStatus = function () {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
177
|
+
return __generator(this, function (_a) {
|
|
178
|
+
switch (_a.label) {
|
|
179
|
+
case 0: return [4 /*yield*/, this.contract.methods.getTcbStatus().call()];
|
|
180
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Function for fetching calimed amount of TCB reward
|
|
187
|
+
*/
|
|
188
|
+
TCB.prototype.getPaidAmount = function () {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
+
return __generator(this, function (_a) {
|
|
191
|
+
switch (_a.label) {
|
|
192
|
+
case 0: return [4 /*yield*/, this.contract.methods.getPaidAmount().call()];
|
|
193
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Add processed TCB data to smart-contract
|
|
200
|
+
* @param used - struct of 'processed' data
|
|
201
|
+
* @param quote - data generated from Enclave
|
|
202
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
203
|
+
*/
|
|
204
|
+
TCB.prototype.addData = function (pb, quote, transactionOptions) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
var fromattedDeviceId;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
211
|
+
fromattedDeviceId = (0, utils_2.formatBytes32String)((Buffer.from(pb.deviceID, 'hex')).toString('base64'));
|
|
212
|
+
return [4 /*yield*/, TxManager_1.default.execute(this.contract.methods.addData, [pb.benchmark, pb.properties, fromattedDeviceId, quote], transactionOptions)];
|
|
213
|
+
case 1:
|
|
214
|
+
_a.sent();
|
|
215
|
+
return [2 /*return*/];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
TCB.prototype.getEpochInfo = function () {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
+
var epoch;
|
|
223
|
+
return __generator(this, function (_a) {
|
|
224
|
+
switch (_a.label) {
|
|
225
|
+
case 0: return [4 /*yield*/, this.contract.methods.getEpochInfo().call()];
|
|
226
|
+
case 1:
|
|
227
|
+
epoch = _a.sent();
|
|
228
|
+
this.epoch = (0, utils_1.tupleToObject)(epoch, TcbData_1.TcbEpochInfoStructure);
|
|
229
|
+
return [2 /*return*/, this.epoch];
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Function for fetching marks of TCB (from Consensus)
|
|
236
|
+
*/
|
|
237
|
+
TCB.prototype.getOwnMarks = function () {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
+
var _a, positive, negative;
|
|
240
|
+
return __generator(this, function (_b) {
|
|
241
|
+
switch (_b.label) {
|
|
242
|
+
case 0: return [4 /*yield*/, this.contract.methods.getOwnMarks().call()];
|
|
243
|
+
case 1:
|
|
244
|
+
_a = _b.sent(), positive = _a[0], negative = _a[1];
|
|
245
|
+
this.positive = positive;
|
|
246
|
+
this.negative = negative;
|
|
247
|
+
return [2 /*return*/, {
|
|
248
|
+
positive: positive,
|
|
249
|
+
negative: negative,
|
|
250
|
+
}];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Function for fetching used TCB data
|
|
257
|
+
*/
|
|
258
|
+
TCB.prototype.getPublicData = function () {
|
|
259
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
260
|
+
var publicDataParams, publicData;
|
|
261
|
+
return __generator(this, function (_a) {
|
|
262
|
+
switch (_a.label) {
|
|
263
|
+
case 0: return [4 /*yield*/, this.contract.methods.getPublicData().call()];
|
|
264
|
+
case 1:
|
|
265
|
+
publicDataParams = _a.sent();
|
|
266
|
+
publicData = (0, utils_1.tupleToObject)(publicDataParams, TcbData_1.PublicDataStructure);
|
|
267
|
+
publicData.deviceID = (Buffer.from((0, utils_2.parseBytes32String)(publicData.deviceID), 'base64')).toString('hex');
|
|
268
|
+
return [2 /*return*/, publicData];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Function for fetching stored TCB data
|
|
275
|
+
*/
|
|
276
|
+
TCB.prototype.getQuote = function () {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
278
|
+
var _a;
|
|
279
|
+
return __generator(this, function (_b) {
|
|
280
|
+
switch (_b.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
_a = this;
|
|
283
|
+
return [4 /*yield*/, this.contract.methods.getQuote().call()];
|
|
284
|
+
case 1:
|
|
285
|
+
_a.quote = _b.sent();
|
|
286
|
+
return [2 /*return*/, this.quote];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Append marks for selected TCBs
|
|
293
|
+
* @param lType - type of appending marks
|
|
294
|
+
* @param marks - list of marks
|
|
295
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
296
|
+
*/
|
|
297
|
+
TCB.prototype.addMarks = function (lType, marks, transactionOptions) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
299
|
+
return __generator(this, function (_a) {
|
|
300
|
+
switch (_a.label) {
|
|
301
|
+
case 0:
|
|
302
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
303
|
+
if (!(marks.length > 0)) return [3 /*break*/, 2];
|
|
304
|
+
return [4 /*yield*/, TxManager_1.default.execute(this.contract.methods.addMarks, [lType, marks], transactionOptions)];
|
|
305
|
+
case 1:
|
|
306
|
+
_a.sent();
|
|
307
|
+
_a.label = 2;
|
|
308
|
+
case 2: return [2 /*return*/];
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
return TCB;
|
|
314
|
+
}());
|
|
315
|
+
exports.default = TCB;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { TeeOfferInfo } from "../types/TeeOffer";
|
|
2
|
+
import { TransactionOptions } from "../types/Web3";
|
|
3
|
+
import { OfferType } from "../types/Offer";
|
|
4
|
+
import { Origins } from "../types/Origins";
|
|
5
|
+
declare class TeeOffer {
|
|
6
|
+
private static contract;
|
|
7
|
+
private logger;
|
|
8
|
+
id: string;
|
|
9
|
+
violationRate?: number;
|
|
10
|
+
totalLocked?: number;
|
|
11
|
+
offerInfo?: TeeOfferInfo;
|
|
12
|
+
type?: OfferType;
|
|
13
|
+
providerAuthority?: string;
|
|
14
|
+
provider?: string;
|
|
15
|
+
disabledAfter?: number;
|
|
16
|
+
tcb?: string;
|
|
17
|
+
closingPrice?: string;
|
|
18
|
+
tlbAddedTime?: number;
|
|
19
|
+
tcbAddedTime?: number;
|
|
20
|
+
origins?: Origins;
|
|
21
|
+
isCancelable?: boolean;
|
|
22
|
+
constructor(offerId: string);
|
|
23
|
+
/**
|
|
24
|
+
* @returns True if offer is cancelable.
|
|
25
|
+
*/
|
|
26
|
+
isOfferCancelable(): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if contract has been initialized, if not - initialize contract
|
|
29
|
+
*/
|
|
30
|
+
private checkInitTeeOffer;
|
|
31
|
+
/**
|
|
32
|
+
* Function for fetching TEE offer info from blockchain
|
|
33
|
+
*/
|
|
34
|
+
getInfo(): Promise<TeeOfferInfo>;
|
|
35
|
+
/**
|
|
36
|
+
* Function for fetching TEE offer provider from blockchain
|
|
37
|
+
*/
|
|
38
|
+
getProvider(): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Function for fetching TEE offer provider authority account from blockchain
|
|
41
|
+
*/
|
|
42
|
+
getProviderAuthority(): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Fetch offer type from blockchain (works for TEE and Value offers)
|
|
45
|
+
*/
|
|
46
|
+
getOfferType(): Promise<OfferType>;
|
|
47
|
+
/**
|
|
48
|
+
* Function for fetching offer provider from blockchain
|
|
49
|
+
*/
|
|
50
|
+
getDisabledAfter(): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Function for fetching tcb provider from blockchain
|
|
53
|
+
*/
|
|
54
|
+
getTcb(): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Function for fetching TLB provider from blockchain
|
|
57
|
+
*/
|
|
58
|
+
getTlb(): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Function for offer closing price calculation
|
|
61
|
+
*/
|
|
62
|
+
getClosingPrice(startDate: number): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Function for fetching last TLB addition time for this TEE offer
|
|
65
|
+
*/
|
|
66
|
+
getLastTlbAddedTime(): Promise<number>;
|
|
67
|
+
/**
|
|
68
|
+
* Function for fetching last TCB addition time for this TEE offer
|
|
69
|
+
*/
|
|
70
|
+
getLastTcbAddedTime(): Promise<number>;
|
|
71
|
+
/**
|
|
72
|
+
* Function for fetching violationRate for this TEE offer
|
|
73
|
+
*/
|
|
74
|
+
getViolationRate(): Promise<number>;
|
|
75
|
+
/**
|
|
76
|
+
* Function for fetching amount of total locked tokens
|
|
77
|
+
*/
|
|
78
|
+
getTotalLocked(): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
|
|
81
|
+
*/
|
|
82
|
+
getOrigins(): Promise<Origins>;
|
|
83
|
+
/**
|
|
84
|
+
* Updates TLB in order info
|
|
85
|
+
* @param tlb - new TLB
|
|
86
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
87
|
+
*/
|
|
88
|
+
addTlb(tlb: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Updates name in order info
|
|
91
|
+
* @param name - new name
|
|
92
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
93
|
+
*/
|
|
94
|
+
setName(name: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Updates description in order info
|
|
97
|
+
* @param description - new description
|
|
98
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
99
|
+
*/
|
|
100
|
+
setDescription(description: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Updates argsPublicKey and argsPublicKeyAlgo in order info
|
|
103
|
+
* @param argsPublicKey - new argsPublicKey
|
|
104
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
105
|
+
*/
|
|
106
|
+
setKeys(argsPublicKey: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Function for disabling TEE offer
|
|
109
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
110
|
+
*/
|
|
111
|
+
disable(transactionOptions?: TransactionOptions): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Function for enabling TEE offer
|
|
114
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
115
|
+
*/
|
|
116
|
+
enable(transactionOptions?: TransactionOptions): Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
export default TeeOffer;
|