@super-protocol/sdk-js 0.12.8-beta.2 → 0.13.0-beta.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/TIIGenerator.js +16 -14
- package/build/connectors/BlockchainConnector.d.ts +1 -1
- package/build/connectors/BlockchainConnector.js +6 -4
- package/build/contracts/app.json +3581 -1393
- package/build/crypto/Crypto.d.ts +3 -3
- package/build/crypto/Crypto.js +3 -3
- package/build/crypto/nodejs/AES.d.ts +1 -1
- package/build/crypto/nodejs/AES.js +1 -1
- package/build/crypto/nodejs/ARIA.d.ts +1 -1
- package/build/crypto/nodejs/ARIA.js +1 -1
- package/build/index.d.ts +15 -15
- package/build/index.js +20 -22
- package/build/models/Offer.d.ts +47 -4
- package/build/models/Offer.js +159 -21
- package/build/models/Order.d.ts +29 -17
- package/build/models/Order.js +103 -74
- package/build/models/Provider.js +4 -2
- package/build/models/TeeOffer.d.ts +92 -11
- package/build/models/TeeOffer.js +305 -53
- package/build/providers/storage/ChunksDownloadDecorator.d.ts +0 -2
- package/build/providers/storage/ChunksDownloadDecorator.js +0 -3
- package/build/providers/storage/IStorageProvider.d.ts +0 -2
- package/build/providers/storage/StorjStorageProvider.d.ts +0 -2
- package/build/providers/storage/StorjStorageProvider.js +0 -15
- package/build/staticModels/Deposits.d.ts +71 -0
- package/build/staticModels/Deposits.js +303 -0
- package/build/staticModels/Offers.d.ts +58 -0
- package/build/staticModels/{OffersFactory.js → Offers.js} +115 -14
- package/build/staticModels/{OrdersFactory.d.ts → Orders.d.ts} +36 -43
- package/build/staticModels/{OrdersFactory.js → Orders.js} +103 -125
- package/build/staticModels/ProviderRegistry.d.ts +1 -1
- package/build/staticModels/ProviderRegistry.js +1 -1
- package/build/staticModels/Superpro.d.ts +2 -2
- package/build/staticModels/Superpro.js +1 -1
- package/build/staticModels/TeeOffers.d.ts +101 -0
- package/build/staticModels/TeeOffers.js +455 -0
- package/build/types/DepositInfo.d.ts +10 -0
- package/build/types/DepositInfo.js +9 -0
- package/build/types/Events.d.ts +0 -12
- package/build/types/HardwareInfo.d.ts +19 -0
- package/build/types/HardwareInfo.js +10 -0
- package/build/types/Offer.d.ts +0 -7
- package/build/types/Offer.js +0 -3
- package/build/types/OptionInfo.d.ts +10 -0
- package/build/types/OptionInfo.js +9 -0
- package/build/types/Order.d.ts +5 -1
- package/build/types/SlotInfo.d.ts +12 -0
- package/build/types/SlotInfo.js +10 -0
- package/build/types/SlotUsage.d.ts +16 -0
- package/build/types/SlotUsage.js +15 -0
- package/build/types/Superpro.d.ts +0 -14
- package/build/types/Superpro.js +1 -16
- package/build/types/TeeOfferInfo.d.ts +31 -0
- package/build/types/{TeeOffer.js → TeeOfferInfo.js} +2 -4
- package/build/types/TeeOfferOption.d.ts +21 -0
- package/build/types/TeeOfferOption.js +11 -0
- package/build/types/TeeOfferSlot.d.ts +22 -0
- package/build/types/TeeOfferSlot.js +11 -0
- package/build/types/ValueOfferSlot.d.ts +29 -0
- package/build/types/ValueOfferSlot.js +13 -0
- package/build/utils.d.ts +1 -0
- package/build/utils.js +5 -1
- package/package.json +1 -1
- package/build/models/Ballot.d.ts +0 -13
- package/build/models/Ballot.js +0 -70
- package/build/staticModels/OffersFactory.d.ts +0 -32
- package/build/staticModels/Staking.d.ts +0 -20
- package/build/staticModels/Staking.js +0 -116
- package/build/staticModels/TeeOffersFactory.d.ts +0 -36
- package/build/staticModels/TeeOffersFactory.js +0 -211
- package/build/staticModels/Voting.d.ts +0 -29
- package/build/staticModels/Voting.js +0 -91
- package/build/types/Ballot.d.ts +0 -75
- package/build/types/Ballot.js +0 -49
- package/build/types/Staking.d.ts +0 -27
- package/build/types/Staking.js +0 -22
- package/build/types/TeeOffer.d.ts +0 -25
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { BlockInfo, TransactionOptions } from "../types/Web3";
|
|
2
|
+
import { TeeOfferInfo } from "../types/TeeOfferInfo";
|
|
3
|
+
import { OfferCreatedEvent } from "../types/Events";
|
|
4
|
+
import { TeeOfferOption } from "../types/TeeOfferOption";
|
|
5
|
+
declare class TeeOffers {
|
|
6
|
+
private static readonly logger;
|
|
7
|
+
static teeOffers?: string[];
|
|
8
|
+
static get address(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Function for fetching list of all TEE offers addresses
|
|
11
|
+
*/
|
|
12
|
+
static getAll(): Promise<string[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates new TEE offer
|
|
15
|
+
* @param providerAuthorityAccount - address of authority account of provider
|
|
16
|
+
* @param teeOfferInfo - data of new TEE offer
|
|
17
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
18
|
+
*/
|
|
19
|
+
static create(providerAuthorityAccount: string, teeOfferInfo: TeeOfferInfo, externalId?: string, enabled?: boolean, transactionOptions?: TransactionOptions): Promise<void>;
|
|
20
|
+
static getByExternalId(creator: string, externalId: string): Promise<OfferCreatedEvent>;
|
|
21
|
+
/**
|
|
22
|
+
* Function for fetching TEE offer id by TEE deviceId
|
|
23
|
+
* @param deviceId - unque TEE device id (unparsed, from blockchain)
|
|
24
|
+
* @returns TEE offer id
|
|
25
|
+
*/
|
|
26
|
+
static getByDeviceId(deviceId: string): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Function for fetching total count of tee offer slots
|
|
29
|
+
*/
|
|
30
|
+
static getSlotsCount(): Promise<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Function for fetching whether tee offer option exists or not
|
|
33
|
+
* @param optionId - Option ID
|
|
34
|
+
*/
|
|
35
|
+
static isOptionExists(optionId: string): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Function for fetching total count of options
|
|
38
|
+
*/
|
|
39
|
+
static getOptionsCount(): Promise<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Function for fetching tee offer option by id
|
|
42
|
+
* @param optionId - Option ID
|
|
43
|
+
*/
|
|
44
|
+
static getOptionById(optionId: string): Promise<TeeOfferOption>;
|
|
45
|
+
/**
|
|
46
|
+
* Function for adding event listeners on onSlotAdded event in contract
|
|
47
|
+
* @param creator - creator address
|
|
48
|
+
* @param callback - function for processing created order
|
|
49
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
50
|
+
*/
|
|
51
|
+
static onSlotAdded(callback: onTeeSlotAddedCallback, creator?: string): () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Function for adding event listeners on onSlotUpdated event in contract
|
|
54
|
+
* @param callback - function for processing created order
|
|
55
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
56
|
+
*/
|
|
57
|
+
static onSlotUpdated(callback: onTeeSlotUpdatedCallback): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Function for adding event listeners on onSlotDeleted event in contract
|
|
60
|
+
* @param callback - function for processing created order
|
|
61
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
62
|
+
*/
|
|
63
|
+
static onSlotDeleted(callback: onTeeSlotDeletedCallback): () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Function for adding event listeners on OptionAdded event in contract
|
|
66
|
+
* @param creator - creator address
|
|
67
|
+
* @param callback - function for processing created order
|
|
68
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
69
|
+
*/
|
|
70
|
+
static onOptionAdded(callback: onTeeOptionAddedCallback, creator?: string): () => void;
|
|
71
|
+
/**
|
|
72
|
+
* Function for adding event listeners on OptionUpdated event in contract
|
|
73
|
+
* @param teeOfferId - tee offer id
|
|
74
|
+
* @param callback - function for processing created order
|
|
75
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
76
|
+
*/
|
|
77
|
+
static onOptionUpdated(callback: onTeeOptionUpdatedCallback, teeOfferId?: string): () => void;
|
|
78
|
+
/**
|
|
79
|
+
* Function for adding event listeners on OptionDeleted event in contract
|
|
80
|
+
* @param teeOfferId - tee offer id
|
|
81
|
+
* @param callback - function for processing created order
|
|
82
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
83
|
+
*/
|
|
84
|
+
static onOptionDeleted(callback: onTeeOptionDeletedCallback, teeOfferId?: string): () => void;
|
|
85
|
+
/**
|
|
86
|
+
* Function for adding event listeners on TEE offer created event in TEE offers factory contract
|
|
87
|
+
* @param callback - function for processing created TEE offer
|
|
88
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
89
|
+
*/
|
|
90
|
+
static onCreated(callback: onTeeOfferCreatedCallback): () => void;
|
|
91
|
+
static onViolationRateChanged(callback: onTeeViolationRateChangedCallback): () => void;
|
|
92
|
+
}
|
|
93
|
+
export type onTeeOfferCreatedCallback = (offerId: string, creator: string, externalId: string, block?: BlockInfo) => void;
|
|
94
|
+
export type onTeeViolationRateChangedCallback = (offerId: string, providerAuth: string, violationRate: number, block?: BlockInfo) => void;
|
|
95
|
+
export type onTeeOptionAddedCallback = (creator: string, teeOfferId: string, optionId: string, externalId: string, block?: BlockInfo) => void;
|
|
96
|
+
export type onTeeOptionUpdatedCallback = (teeOfferId: string, optionId: string, block?: BlockInfo) => void;
|
|
97
|
+
export type onTeeOptionDeletedCallback = (teeOfferId: string, optionId: string, block?: BlockInfo) => void;
|
|
98
|
+
export type onTeeSlotAddedCallback = (creator: string, offerId: string, slotId: string, externalId: string, block?: BlockInfo) => void;
|
|
99
|
+
export type onTeeSlotUpdatedCallback = (offerId: string, slotId: string, block?: BlockInfo) => void;
|
|
100
|
+
export type onTeeSlotDeletedCallback = (offerId: string, slotId: string, block?: BlockInfo) => void;
|
|
101
|
+
export default TeeOffers;
|
|
@@ -0,0 +1,455 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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 utils_1 = require("../utils");
|
|
44
|
+
var utils_2 = require("ethers/lib/utils");
|
|
45
|
+
var utils_3 = require("../utils");
|
|
46
|
+
var TeeOfferInfo_1 = require("../types/TeeOfferInfo");
|
|
47
|
+
var Offer_1 = require("../types/Offer");
|
|
48
|
+
var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
|
|
49
|
+
var Superpro_1 = __importDefault(require("./Superpro"));
|
|
50
|
+
var TxManager_1 = __importDefault(require("../utils/TxManager"));
|
|
51
|
+
var BlockchainEventsListener_1 = __importDefault(require("../connectors/BlockchainEventsListener"));
|
|
52
|
+
var TeeOffers = /** @class */ (function () {
|
|
53
|
+
function TeeOffers() {
|
|
54
|
+
}
|
|
55
|
+
Object.defineProperty(TeeOffers, "address", {
|
|
56
|
+
get: function () {
|
|
57
|
+
return Superpro_1.default.address;
|
|
58
|
+
},
|
|
59
|
+
enumerable: false,
|
|
60
|
+
configurable: true
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Function for fetching list of all TEE offers addresses
|
|
64
|
+
*/
|
|
65
|
+
TeeOffers.getAll = function () {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var contract, count, teeOfffersSet, offerId, offerType;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
72
|
+
return [4 /*yield*/, contract.methods.getOffersTotalCount().call()];
|
|
73
|
+
case 1:
|
|
74
|
+
count = _a.sent();
|
|
75
|
+
this.teeOffers = this.teeOffers || [];
|
|
76
|
+
teeOfffersSet = new Set(this.teeOffers);
|
|
77
|
+
offerId = teeOfffersSet.size + 1;
|
|
78
|
+
_a.label = 2;
|
|
79
|
+
case 2:
|
|
80
|
+
if (!(offerId <= count)) return [3 /*break*/, 5];
|
|
81
|
+
return [4 /*yield*/, contract.methods.getOfferType(offerId).call()];
|
|
82
|
+
case 3:
|
|
83
|
+
offerType = (_a.sent());
|
|
84
|
+
if (offerType === Offer_1.OfferType.TeeOffer) {
|
|
85
|
+
teeOfffersSet.add(offerId.toString());
|
|
86
|
+
}
|
|
87
|
+
_a.label = 4;
|
|
88
|
+
case 4:
|
|
89
|
+
++offerId;
|
|
90
|
+
return [3 /*break*/, 2];
|
|
91
|
+
case 5:
|
|
92
|
+
this.teeOffers = Array.from(teeOfffersSet);
|
|
93
|
+
return [2 /*return*/, this.teeOffers];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Creates new TEE offer
|
|
100
|
+
* @param providerAuthorityAccount - address of authority account of provider
|
|
101
|
+
* @param teeOfferInfo - data of new TEE offer
|
|
102
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
103
|
+
*/
|
|
104
|
+
TeeOffers.create = function (providerAuthorityAccount, teeOfferInfo, externalId, enabled, transactionOptions) {
|
|
105
|
+
if (externalId === void 0) { externalId = "default"; }
|
|
106
|
+
if (enabled === void 0) { enabled = true; }
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
var contract, teeOfferInfoParams, formattedExternalId;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
contract = BlockchainConnector_1.default.getInstance().getContract(transactionOptions);
|
|
113
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
114
|
+
teeOfferInfoParams = (0, utils_1.objectToTuple)(teeOfferInfo, TeeOfferInfo_1.TeeOfferInfoStructure);
|
|
115
|
+
formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
|
|
116
|
+
return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createTeeOffer, [providerAuthorityAccount, teeOfferInfoParams, formattedExternalId, enabled], transactionOptions)];
|
|
117
|
+
case 1:
|
|
118
|
+
_a.sent();
|
|
119
|
+
return [2 /*return*/];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
TeeOffers.getByExternalId = function (creator, externalId) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
var contract, filter, foundIds, notFound, response;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
131
|
+
filter = {
|
|
132
|
+
creator: creator,
|
|
133
|
+
externalId: (0, utils_2.formatBytes32String)(externalId),
|
|
134
|
+
};
|
|
135
|
+
return [4 /*yield*/, contract.getPastEvents("TeeOfferCreated", { filter: filter })];
|
|
136
|
+
case 1:
|
|
137
|
+
foundIds = _a.sent();
|
|
138
|
+
notFound = {
|
|
139
|
+
creator: creator,
|
|
140
|
+
externalId: externalId,
|
|
141
|
+
offerId: "-1",
|
|
142
|
+
};
|
|
143
|
+
response = foundIds.length > 0 ? foundIds[0].returnValues : notFound;
|
|
144
|
+
return [2 /*return*/, response];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Function for fetching TEE offer id by TEE deviceId
|
|
151
|
+
* @param deviceId - unque TEE device id (unparsed, from blockchain)
|
|
152
|
+
* @returns TEE offer id
|
|
153
|
+
*/
|
|
154
|
+
TeeOffers.getByDeviceId = function (deviceId) {
|
|
155
|
+
var contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
156
|
+
var fromattedDeviceId = (0, utils_3.packDevicId)(deviceId);
|
|
157
|
+
return contract.methods.getTeeOfferByDeviceId(fromattedDeviceId).call();
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Function for fetching total count of tee offer slots
|
|
161
|
+
*/
|
|
162
|
+
TeeOffers.getSlotsCount = function () {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var contract;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
switch (_a.label) {
|
|
167
|
+
case 0:
|
|
168
|
+
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
169
|
+
return [4 /*yield*/, contract.methods.getTeeOffersSlotsCount().call()];
|
|
170
|
+
case 1: return [2 /*return*/, +(_a.sent())];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Function for fetching whether tee offer option exists or not
|
|
177
|
+
* @param optionId - Option ID
|
|
178
|
+
*/
|
|
179
|
+
TeeOffers.isOptionExists = function (optionId) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
var contract;
|
|
182
|
+
return __generator(this, function (_a) {
|
|
183
|
+
switch (_a.label) {
|
|
184
|
+
case 0:
|
|
185
|
+
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
186
|
+
return [4 /*yield*/, contract.methods.isOptionExists(optionId).call()];
|
|
187
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Function for fetching total count of options
|
|
194
|
+
*/
|
|
195
|
+
TeeOffers.getOptionsCount = function () {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
var contract;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
202
|
+
return [4 /*yield*/, contract.methods.getOptionsCount().call()];
|
|
203
|
+
case 1: return [2 /*return*/, +(_a.sent())];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Function for fetching tee offer option by id
|
|
210
|
+
* @param optionId - Option ID
|
|
211
|
+
*/
|
|
212
|
+
TeeOffers.getOptionById = function (optionId) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
+
var contract;
|
|
215
|
+
return __generator(this, function (_a) {
|
|
216
|
+
switch (_a.label) {
|
|
217
|
+
case 0:
|
|
218
|
+
contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
219
|
+
return [4 /*yield*/, contract.methods.getOptionById(optionId).call()];
|
|
220
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Function for adding event listeners on onSlotAdded event in contract
|
|
227
|
+
* @param creator - creator address
|
|
228
|
+
* @param callback - function for processing created order
|
|
229
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
230
|
+
*/
|
|
231
|
+
TeeOffers.onSlotAdded = function (callback, creator) {
|
|
232
|
+
var _this = this;
|
|
233
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
234
|
+
var logger = this.logger.child({ method: "onTeeSlotAdded" });
|
|
235
|
+
var subscription = contract.events
|
|
236
|
+
.TeeSlotAdded()
|
|
237
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
238
|
+
return __generator(this, function (_a) {
|
|
239
|
+
if (creator && event.returnValues.creator != creator) {
|
|
240
|
+
return [2 /*return*/];
|
|
241
|
+
}
|
|
242
|
+
callback(event.returnValues.creator, event.returnValues.offerId, event.returnValues.slotId, (0, utils_2.parseBytes32String)(event.returnValues.externalId), {
|
|
243
|
+
index: event.blockNumber,
|
|
244
|
+
hash: event.blockHash,
|
|
245
|
+
});
|
|
246
|
+
return [2 /*return*/];
|
|
247
|
+
});
|
|
248
|
+
}); })
|
|
249
|
+
.on("error", function (error, receipt) {
|
|
250
|
+
if (receipt)
|
|
251
|
+
return;
|
|
252
|
+
logger.warn(error);
|
|
253
|
+
});
|
|
254
|
+
return function () { return subscription.unsubscribe(); };
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Function for adding event listeners on onSlotUpdated event in contract
|
|
258
|
+
* @param callback - function for processing created order
|
|
259
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
260
|
+
*/
|
|
261
|
+
TeeOffers.onSlotUpdated = function (callback) {
|
|
262
|
+
var _this = this;
|
|
263
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
264
|
+
var logger = this.logger.child({ method: "onTeeSlotUpdated" });
|
|
265
|
+
var subscription = contract.events
|
|
266
|
+
.TeeSlotUpdated()
|
|
267
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
268
|
+
return __generator(this, function (_a) {
|
|
269
|
+
callback(event.returnValues.offerId, event.returnValues.slotId, {
|
|
270
|
+
index: event.blockNumber,
|
|
271
|
+
hash: event.blockHash,
|
|
272
|
+
});
|
|
273
|
+
return [2 /*return*/];
|
|
274
|
+
});
|
|
275
|
+
}); })
|
|
276
|
+
.on("error", function (error, receipt) {
|
|
277
|
+
if (receipt)
|
|
278
|
+
return;
|
|
279
|
+
logger.warn(error);
|
|
280
|
+
});
|
|
281
|
+
return function () { return subscription.unsubscribe(); };
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Function for adding event listeners on onSlotDeleted event in contract
|
|
285
|
+
* @param callback - function for processing created order
|
|
286
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
287
|
+
*/
|
|
288
|
+
TeeOffers.onSlotDeleted = function (callback) {
|
|
289
|
+
var _this = this;
|
|
290
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
291
|
+
var logger = this.logger.child({ method: "onTeeSlotDeleted" });
|
|
292
|
+
var subscription = contract.events
|
|
293
|
+
.TeeSlotDeleted()
|
|
294
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
295
|
+
return __generator(this, function (_a) {
|
|
296
|
+
callback(event.returnValues.offerId, event.returnValues.slotId, {
|
|
297
|
+
index: event.blockNumber,
|
|
298
|
+
hash: event.blockHash,
|
|
299
|
+
});
|
|
300
|
+
return [2 /*return*/];
|
|
301
|
+
});
|
|
302
|
+
}); })
|
|
303
|
+
.on("error", function (error, receipt) {
|
|
304
|
+
if (receipt)
|
|
305
|
+
return;
|
|
306
|
+
logger.warn(error);
|
|
307
|
+
});
|
|
308
|
+
return function () { return subscription.unsubscribe(); };
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Function for adding event listeners on OptionAdded event in contract
|
|
312
|
+
* @param creator - creator address
|
|
313
|
+
* @param callback - function for processing created order
|
|
314
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
315
|
+
*/
|
|
316
|
+
TeeOffers.onOptionAdded = function (callback, creator) {
|
|
317
|
+
var _this = this;
|
|
318
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
319
|
+
var logger = this.logger.child({ method: "onTeeOptionAddedCallback" });
|
|
320
|
+
var subscription = contract.events
|
|
321
|
+
.OptionAdded()
|
|
322
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
323
|
+
return __generator(this, function (_a) {
|
|
324
|
+
if (creator && event.returnValues.creator != creator) {
|
|
325
|
+
return [2 /*return*/];
|
|
326
|
+
}
|
|
327
|
+
callback(event.returnValues.creator, event.returnValues.teeOfferId, event.returnValues.optionId, (0, utils_2.parseBytes32String)(event.returnValues.externalId), {
|
|
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;
|
|
337
|
+
logger.warn(error);
|
|
338
|
+
});
|
|
339
|
+
return function () { return subscription.unsubscribe(); };
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Function for adding event listeners on OptionUpdated event in contract
|
|
343
|
+
* @param teeOfferId - tee offer id
|
|
344
|
+
* @param callback - function for processing created order
|
|
345
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
346
|
+
*/
|
|
347
|
+
TeeOffers.onOptionUpdated = function (callback, teeOfferId) {
|
|
348
|
+
var _this = this;
|
|
349
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
350
|
+
var logger = this.logger.child({ method: "onTeeOptionUpdatedCallback" });
|
|
351
|
+
var subscription = contract.events
|
|
352
|
+
.OptionUpdated()
|
|
353
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
354
|
+
return __generator(this, function (_a) {
|
|
355
|
+
if (teeOfferId && event.returnValues.teeOfferId != teeOfferId) {
|
|
356
|
+
return [2 /*return*/];
|
|
357
|
+
}
|
|
358
|
+
callback(event.returnValues.teeOfferId, event.returnValues.optionId, {
|
|
359
|
+
index: event.blockNumber,
|
|
360
|
+
hash: event.blockHash,
|
|
361
|
+
});
|
|
362
|
+
return [2 /*return*/];
|
|
363
|
+
});
|
|
364
|
+
}); })
|
|
365
|
+
.on("error", function (error, receipt) {
|
|
366
|
+
if (receipt)
|
|
367
|
+
return;
|
|
368
|
+
logger.warn(error);
|
|
369
|
+
});
|
|
370
|
+
return function () { return subscription.unsubscribe(); };
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Function for adding event listeners on OptionDeleted event in contract
|
|
374
|
+
* @param teeOfferId - tee offer id
|
|
375
|
+
* @param callback - function for processing created order
|
|
376
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
377
|
+
*/
|
|
378
|
+
TeeOffers.onOptionDeleted = function (callback, teeOfferId) {
|
|
379
|
+
var _this = this;
|
|
380
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
381
|
+
var logger = this.logger.child({ method: "onTeeOptionDeletedCallback" });
|
|
382
|
+
var subscription = contract.events
|
|
383
|
+
.OptionDeleted()
|
|
384
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
385
|
+
return __generator(this, function (_a) {
|
|
386
|
+
if (teeOfferId && event.returnValues.teeOfferId != teeOfferId) {
|
|
387
|
+
return [2 /*return*/];
|
|
388
|
+
}
|
|
389
|
+
callback(event.returnValues.teeOfferId, event.returnValues.optionId, {
|
|
390
|
+
index: event.blockNumber,
|
|
391
|
+
hash: event.blockHash,
|
|
392
|
+
});
|
|
393
|
+
return [2 /*return*/];
|
|
394
|
+
});
|
|
395
|
+
}); })
|
|
396
|
+
.on("error", function (error, receipt) {
|
|
397
|
+
if (receipt)
|
|
398
|
+
return;
|
|
399
|
+
logger.warn(error);
|
|
400
|
+
});
|
|
401
|
+
return function () { return subscription.unsubscribe(); };
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Function for adding event listeners on TEE offer created event in TEE offers factory contract
|
|
405
|
+
* @param callback - function for processing created TEE offer
|
|
406
|
+
* @returns unsubscribe - unsubscribe function from event
|
|
407
|
+
*/
|
|
408
|
+
TeeOffers.onCreated = function (callback) {
|
|
409
|
+
var _this = this;
|
|
410
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
411
|
+
var logger = this.logger.child({ method: "onTeeOfferCreated" });
|
|
412
|
+
var subscription = contract.events
|
|
413
|
+
.TeeOfferCreated()
|
|
414
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
415
|
+
return __generator(this, function (_a) {
|
|
416
|
+
callback(event.returnValues.offerId, event.returnValues.creator, (0, utils_2.parseBytes32String)(event.returnValues.externalId), {
|
|
417
|
+
index: event.blockNumber,
|
|
418
|
+
hash: event.blockHash,
|
|
419
|
+
});
|
|
420
|
+
return [2 /*return*/];
|
|
421
|
+
});
|
|
422
|
+
}); })
|
|
423
|
+
.on("error", function (error, receipt) {
|
|
424
|
+
if (receipt)
|
|
425
|
+
return; // Used to avoid logging of transaction rejected
|
|
426
|
+
logger.warn(error);
|
|
427
|
+
});
|
|
428
|
+
return function () { return subscription.unsubscribe(); };
|
|
429
|
+
};
|
|
430
|
+
TeeOffers.onViolationRateChanged = function (callback) {
|
|
431
|
+
var _this = this;
|
|
432
|
+
var contract = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
433
|
+
var logger = this.logger.child({ method: "onTeeOfferViolationRateChanged" });
|
|
434
|
+
var subscription = contract.events
|
|
435
|
+
.TeeOfferViolationRateChanged()
|
|
436
|
+
.on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
437
|
+
return __generator(this, function (_a) {
|
|
438
|
+
callback(event.returnValues.offerId, event.returnValues.providerAuth, event.returnValues.violationRate, {
|
|
439
|
+
index: event.blockNumber,
|
|
440
|
+
hash: event.blockHash,
|
|
441
|
+
});
|
|
442
|
+
return [2 /*return*/];
|
|
443
|
+
});
|
|
444
|
+
}); })
|
|
445
|
+
.on("error", function (error, receipt) {
|
|
446
|
+
if (receipt)
|
|
447
|
+
return; // Used to avoid logging of transaction rejected
|
|
448
|
+
logger.warn(error);
|
|
449
|
+
});
|
|
450
|
+
return function () { return subscription.unsubscribe(); };
|
|
451
|
+
};
|
|
452
|
+
TeeOffers.logger = logger_1.default.child({ className: "TeeOffers" });
|
|
453
|
+
return TeeOffers;
|
|
454
|
+
}());
|
|
455
|
+
exports.default = TeeOffers;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DepositInfoStructure = void 0;
|
|
4
|
+
// Order of keys and type conversion functions for this object in blockchain contract
|
|
5
|
+
exports.DepositInfoStructure = {
|
|
6
|
+
amount: Number,
|
|
7
|
+
totalLocked: Number,
|
|
8
|
+
profit: Number,
|
|
9
|
+
};
|
package/build/types/Events.d.ts
CHANGED
|
@@ -7,18 +7,6 @@ export type OrderCreatedEvent = {
|
|
|
7
7
|
consumer: string;
|
|
8
8
|
externalId: string;
|
|
9
9
|
offerId: string;
|
|
10
|
-
orderId: string;
|
|
11
|
-
};
|
|
12
|
-
export type SubOrderCreatedEvent = {
|
|
13
|
-
consumer: string;
|
|
14
|
-
externalId: string;
|
|
15
|
-
subOfferId: string;
|
|
16
|
-
subOrderId: string;
|
|
17
10
|
parentOrderId: string;
|
|
18
|
-
};
|
|
19
|
-
export type WorkflowCreatedEvent = {
|
|
20
|
-
consumer: string;
|
|
21
|
-
externalId: string;
|
|
22
|
-
offerId: string;
|
|
23
11
|
orderId: string;
|
|
24
12
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OptionInfo } from "./OptionInfo";
|
|
2
|
+
import { SlotInfo } from "./SlotInfo";
|
|
3
|
+
export declare const HardwareInfoStructure: {
|
|
4
|
+
slotInfo: {
|
|
5
|
+
cpuCores: NumberConstructor;
|
|
6
|
+
ram: NumberConstructor;
|
|
7
|
+
hdd: NumberConstructor;
|
|
8
|
+
ssd: NumberConstructor;
|
|
9
|
+
};
|
|
10
|
+
optionInfo: {
|
|
11
|
+
bandwidth: StringConstructor;
|
|
12
|
+
traffic: StringConstructor;
|
|
13
|
+
externalPort: StringConstructor;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type HardwareInfo = {
|
|
17
|
+
slotInfo: SlotInfo;
|
|
18
|
+
optionInfo: OptionInfo;
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HardwareInfoStructure = void 0;
|
|
4
|
+
var OptionInfo_1 = require("./OptionInfo");
|
|
5
|
+
var SlotInfo_1 = require("./SlotInfo");
|
|
6
|
+
// Order of keys and type conversion functions for this object in blockchain contract
|
|
7
|
+
exports.HardwareInfoStructure = {
|
|
8
|
+
slotInfo: SlotInfo_1.SlotInfoStructure,
|
|
9
|
+
optionInfo: OptionInfo_1.OptionInfoStructure,
|
|
10
|
+
};
|
package/build/types/Offer.d.ts
CHANGED
|
@@ -23,13 +23,10 @@ export declare const OfferInfoStructure: {
|
|
|
23
23
|
offerType: typeof OfferType;
|
|
24
24
|
cancelable: BooleanConstructor;
|
|
25
25
|
description: StringConstructor;
|
|
26
|
-
holdSum: StringConstructor;
|
|
27
26
|
restrictions: {
|
|
28
27
|
offers: StringConstructor[];
|
|
29
28
|
types: (typeof OfferType)[];
|
|
30
29
|
};
|
|
31
|
-
properties: StringConstructor;
|
|
32
|
-
maxDurationTimeMinutes: NumberConstructor;
|
|
33
30
|
input: StringConstructor;
|
|
34
31
|
output: StringConstructor;
|
|
35
32
|
allowedArgs: StringConstructor;
|
|
@@ -45,10 +42,7 @@ export type OfferInfo = {
|
|
|
45
42
|
offerType: OfferType;
|
|
46
43
|
cancelable: boolean;
|
|
47
44
|
description: string;
|
|
48
|
-
holdSum: string;
|
|
49
45
|
restrictions: OfferRestrictions;
|
|
50
|
-
properties: string;
|
|
51
|
-
maxDurationTimeMinutes: number;
|
|
52
46
|
input: string;
|
|
53
47
|
output: string;
|
|
54
48
|
allowedArgs: string;
|
|
@@ -57,5 +51,4 @@ export type OfferInfo = {
|
|
|
57
51
|
resultResource: string;
|
|
58
52
|
linkage: string;
|
|
59
53
|
hash: string;
|
|
60
|
-
enabled: boolean;
|
|
61
54
|
};
|
package/build/types/Offer.js
CHANGED
|
@@ -26,10 +26,7 @@ exports.OfferInfoStructure = {
|
|
|
26
26
|
offerType: OfferType,
|
|
27
27
|
cancelable: Boolean,
|
|
28
28
|
description: String,
|
|
29
|
-
holdSum: String,
|
|
30
29
|
restrictions: exports.OfferRestrictionsStructure,
|
|
31
|
-
properties: String,
|
|
32
|
-
maxDurationTimeMinutes: Number,
|
|
33
30
|
input: String,
|
|
34
31
|
output: String,
|
|
35
32
|
allowedArgs: String,
|