@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,76 @@
|
|
|
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 BallotJSON from "../contracts/Ballot.json";
|
|
44
|
+
var Offers_json_1 = __importDefault(require("../contracts/Offers.json"));
|
|
45
|
+
var store_1 = __importDefault(require("../store"));
|
|
46
|
+
var utils_1 = require("../utils");
|
|
47
|
+
var Ballot_1 = require("../types/Ballot");
|
|
48
|
+
var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
49
|
+
var Ballot = /** @class */ (function () {
|
|
50
|
+
function Ballot(address) {
|
|
51
|
+
(0, utils_1.checkIfInitialized)();
|
|
52
|
+
this.address = address;
|
|
53
|
+
// this.contract = new store.web3!.eth.Contract(<AbiItem[]>BallotJSON.abi, address);
|
|
54
|
+
// TODO: stub
|
|
55
|
+
this.contract = new store_1.default.web3.eth.Contract(Offers_json_1.default.abi, Superpro_1.default.address);
|
|
56
|
+
this.logger = logger_1.default.child({ className: "Ballot", address: address });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Function for fetching order info from blockchain
|
|
60
|
+
*/
|
|
61
|
+
Ballot.prototype.getBallotInfo = function () {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var ballotInfoParams;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0: return [4 /*yield*/, this.contract.methods.getInfo().call()];
|
|
67
|
+
case 1:
|
|
68
|
+
ballotInfoParams = _a.sent();
|
|
69
|
+
return [2 /*return*/, (this.ballotInfo = (0, utils_1.tupleToObject)(ballotInfoParams, Ballot_1.BallotInfoStructure))];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
return Ballot;
|
|
75
|
+
}());
|
|
76
|
+
exports.default = Ballot;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { OfferInfo, OfferType } from "../types/Offer";
|
|
2
|
+
import { TransactionOptions } from "../types/Web3";
|
|
3
|
+
import { Origins } from "../types/Origins";
|
|
4
|
+
declare class Offer {
|
|
5
|
+
private static contract;
|
|
6
|
+
private logger;
|
|
7
|
+
offerInfo?: OfferInfo;
|
|
8
|
+
provider?: string;
|
|
9
|
+
type?: OfferType;
|
|
10
|
+
providerAuthority?: string;
|
|
11
|
+
origins?: Origins;
|
|
12
|
+
id: string;
|
|
13
|
+
disabledAfter?: number;
|
|
14
|
+
closingPrice?: string;
|
|
15
|
+
constructor(offerId: string);
|
|
16
|
+
/**
|
|
17
|
+
* Checks if contract has been initialized, if not - initialize contract
|
|
18
|
+
*/
|
|
19
|
+
private checkInitOffer;
|
|
20
|
+
/**
|
|
21
|
+
* Function for fetching offer info from blockchain
|
|
22
|
+
*/
|
|
23
|
+
getInfo(): Promise<OfferInfo>;
|
|
24
|
+
/**
|
|
25
|
+
* Function for fetching offer provider from blockchain (works for TEE and Value offers)
|
|
26
|
+
*/
|
|
27
|
+
getProvider(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Fetch offer type from blockchain (works for TEE and Value offers)
|
|
30
|
+
*/
|
|
31
|
+
getOfferType(): Promise<OfferType>;
|
|
32
|
+
/**
|
|
33
|
+
* Function for fetching TEE offer provider authority account from blockchain
|
|
34
|
+
*/
|
|
35
|
+
getProviderAuthority(): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
|
|
38
|
+
*/
|
|
39
|
+
getOrigins(): Promise<Origins>;
|
|
40
|
+
/**
|
|
41
|
+
* Function for offer closing price calculation
|
|
42
|
+
*/
|
|
43
|
+
getClosingPrice(startDate: number, orderPrice: string): Promise<string>;
|
|
44
|
+
isOfferExists(): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Function for disabling offer
|
|
47
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
48
|
+
*/
|
|
49
|
+
disable(transactionOptions?: TransactionOptions): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Function for enabling offer
|
|
52
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
53
|
+
*/
|
|
54
|
+
enable(transactionOptions?: TransactionOptions): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if offer (offerAddress) match restrictions in this offer
|
|
57
|
+
* @param offerAddress - address of offer what needs to be checked
|
|
58
|
+
*/
|
|
59
|
+
isRestrictionsPermitThatOffer(offerAddress: string): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if this offer contains restrictions of a certain type
|
|
62
|
+
* @param type - address of offer what needs to be checked
|
|
63
|
+
*/
|
|
64
|
+
isRestrictedByOfferType(type: OfferType): Promise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* Function for fetching offer provider from blockchain
|
|
67
|
+
*/
|
|
68
|
+
getDisabledAfter(): Promise<number>;
|
|
69
|
+
}
|
|
70
|
+
export default Offer;
|
|
@@ -0,0 +1,273 @@
|
|
|
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 Offers_json_1 = __importDefault(require("../contracts/Offers.json"));
|
|
44
|
+
var store_1 = __importDefault(require("../store"));
|
|
45
|
+
var utils_1 = require("../utils");
|
|
46
|
+
var Offer_1 = require("../types/Offer");
|
|
47
|
+
var Origins_1 = require("../types/Origins");
|
|
48
|
+
var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
49
|
+
var TxManager_1 = __importDefault(require("../utils/TxManager"));
|
|
50
|
+
var Offer = /** @class */ (function () {
|
|
51
|
+
function Offer(offerId) {
|
|
52
|
+
(0, utils_1.checkIfInitialized)();
|
|
53
|
+
this.id = offerId;
|
|
54
|
+
if (!Offer.contract) {
|
|
55
|
+
Offer.contract = new store_1.default.web3.eth.Contract(Offers_json_1.default.abi, Superpro_1.default.address);
|
|
56
|
+
}
|
|
57
|
+
this.logger = logger_1.default.child({ className: "Offer", offerId: this.id });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks if contract has been initialized, if not - initialize contract
|
|
61
|
+
*/
|
|
62
|
+
Offer.prototype.checkInitOffer = function (transactionOptions) {
|
|
63
|
+
if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
|
|
64
|
+
(0, utils_1.checkIfInitialized)();
|
|
65
|
+
return new transactionOptions.web3.eth.Contract(Offers_json_1.default.abi, Superpro_1.default.address);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Function for fetching offer info from blockchain
|
|
70
|
+
*/
|
|
71
|
+
Offer.prototype.getInfo = function () {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var _a, orderInfoParams;
|
|
74
|
+
return __generator(this, function (_b) {
|
|
75
|
+
switch (_b.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, Offer.contract.methods.getValueOffer(this.id).call()];
|
|
77
|
+
case 1:
|
|
78
|
+
_a = _b.sent(), orderInfoParams = _a[2];
|
|
79
|
+
return [2 /*return*/, (this.offerInfo = (0, utils_1.tupleToObject)(orderInfoParams, Offer_1.OfferInfoStructure))];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Function for fetching offer provider from blockchain (works for TEE and Value offers)
|
|
86
|
+
*/
|
|
87
|
+
Offer.prototype.getProvider = function () {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var _a;
|
|
90
|
+
return __generator(this, function (_b) {
|
|
91
|
+
switch (_b.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
_a = this;
|
|
94
|
+
return [4 /*yield*/, Offer.contract.methods.getOfferProviderAuthority(this.id).call()];
|
|
95
|
+
case 1:
|
|
96
|
+
_a.provider = _b.sent();
|
|
97
|
+
return [2 /*return*/, this.provider];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Fetch offer type from blockchain (works for TEE and Value offers)
|
|
104
|
+
*/
|
|
105
|
+
Offer.prototype.getOfferType = function () {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var _a;
|
|
108
|
+
return __generator(this, function (_b) {
|
|
109
|
+
switch (_b.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
_a = this;
|
|
112
|
+
return [4 /*yield*/, Offer.contract.methods.getOfferType(this.id).call()];
|
|
113
|
+
case 1:
|
|
114
|
+
_a.type = _b.sent();
|
|
115
|
+
return [2 /*return*/, this.type];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Function for fetching TEE offer provider authority account from blockchain
|
|
122
|
+
*/
|
|
123
|
+
Offer.prototype.getProviderAuthority = function () {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
var _a;
|
|
126
|
+
return __generator(this, function (_b) {
|
|
127
|
+
switch (_b.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
_a = this;
|
|
130
|
+
return [4 /*yield*/, Offer.contract.methods.getOfferProviderAuthority(this.id).call()];
|
|
131
|
+
case 1:
|
|
132
|
+
_a.providerAuthority = _b.sent();
|
|
133
|
+
return [2 /*return*/, this.providerAuthority];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
|
|
140
|
+
*/
|
|
141
|
+
Offer.prototype.getOrigins = function () {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
+
var origins;
|
|
144
|
+
return __generator(this, function (_a) {
|
|
145
|
+
switch (_a.label) {
|
|
146
|
+
case 0: return [4 /*yield*/, Offer.contract.methods.getOfferOrigins(this.id).call()];
|
|
147
|
+
case 1:
|
|
148
|
+
origins = _a.sent();
|
|
149
|
+
// Converts blockchain array into object
|
|
150
|
+
origins = (0, utils_1.tupleToObject)(origins, Origins_1.OriginsStructure);
|
|
151
|
+
// Convert blockchain time seconds to js time milliseconds
|
|
152
|
+
origins.createdDate = +origins.createdDate * 1000;
|
|
153
|
+
origins.modifiedDate = +origins.modifiedDate * 1000;
|
|
154
|
+
return [2 /*return*/, (this.origins = origins)];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Function for offer closing price calculation
|
|
161
|
+
*/
|
|
162
|
+
Offer.prototype.getClosingPrice = function (startDate, orderPrice) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var _a;
|
|
165
|
+
return __generator(this, function (_b) {
|
|
166
|
+
switch (_b.label) {
|
|
167
|
+
case 0:
|
|
168
|
+
_a = this;
|
|
169
|
+
return [4 /*yield*/, Offer.contract.methods.getOfferClosingPrice(this.id, startDate, orderPrice).call()];
|
|
170
|
+
case 1:
|
|
171
|
+
_a.closingPrice = _b.sent();
|
|
172
|
+
return [2 /*return*/, this.closingPrice];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
Offer.prototype.isOfferExists = function () {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
switch (_a.label) {
|
|
181
|
+
case 0: return [4 /*yield*/, Offer.contract.methods.isOfferExists(this.id).call()];
|
|
182
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Function for disabling offer
|
|
189
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
190
|
+
*/
|
|
191
|
+
Offer.prototype.disable = function (transactionOptions) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
switch (_a.label) {
|
|
195
|
+
case 0:
|
|
196
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOffer(transactionOptions);
|
|
197
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
198
|
+
return [4 /*yield*/, TxManager_1.default.execute(Offer.contract.methods.disableOffer, [this.id], transactionOptions)];
|
|
199
|
+
case 1:
|
|
200
|
+
_a.sent();
|
|
201
|
+
return [2 /*return*/];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Function for enabling offer
|
|
208
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
209
|
+
*/
|
|
210
|
+
Offer.prototype.enable = function (transactionOptions) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
212
|
+
return __generator(this, function (_a) {
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOffer(transactionOptions);
|
|
216
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
217
|
+
return [4 /*yield*/, TxManager_1.default.execute(Offer.contract.methods.enableOffer, [this.id], transactionOptions)];
|
|
218
|
+
case 1:
|
|
219
|
+
_a.sent();
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Checks if offer (offerAddress) match restrictions in this offer
|
|
227
|
+
* @param offerAddress - address of offer what needs to be checked
|
|
228
|
+
*/
|
|
229
|
+
Offer.prototype.isRestrictionsPermitThatOffer = function (offerAddress) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
+
return __generator(this, function (_a) {
|
|
232
|
+
switch (_a.label) {
|
|
233
|
+
case 0: return [4 /*yield*/, Offer.contract.methods.isOfferRestrictionsPermitOtherOffer(this.id, +offerAddress).call()];
|
|
234
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Checks if this offer contains restrictions of a certain type
|
|
241
|
+
* @param type - address of offer what needs to be checked
|
|
242
|
+
*/
|
|
243
|
+
Offer.prototype.isRestrictedByOfferType = function (type) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
+
return __generator(this, function (_a) {
|
|
246
|
+
switch (_a.label) {
|
|
247
|
+
case 0: return [4 /*yield*/, Offer.contract.methods.isOfferRestrictedByOfferType(this.id, type).call()];
|
|
248
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Function for fetching offer provider from blockchain
|
|
255
|
+
*/
|
|
256
|
+
Offer.prototype.getDisabledAfter = function () {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var _a;
|
|
259
|
+
return __generator(this, function (_b) {
|
|
260
|
+
switch (_b.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
_a = this;
|
|
263
|
+
return [4 /*yield*/, Offer.contract.methods.getOfferDisabledAfter(this.id).call()];
|
|
264
|
+
case 1:
|
|
265
|
+
_a.disabledAfter = +(_b.sent());
|
|
266
|
+
return [2 /*return*/, this.disabledAfter];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
return Offer;
|
|
272
|
+
}());
|
|
273
|
+
exports.default = Offer;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { OrderInfo, OrderResult, ExtendedOrderInfo, OrderStatus } from "../types/Order";
|
|
2
|
+
import { TransactionOptions } from "../types/Web3";
|
|
3
|
+
import { Origins } from "../types/Origins";
|
|
4
|
+
import { SubOrderCreatedEvent } from "../types/Events";
|
|
5
|
+
declare class Order {
|
|
6
|
+
private static contract;
|
|
7
|
+
private logger;
|
|
8
|
+
orderInfo?: OrderInfo;
|
|
9
|
+
orderResult?: OrderResult;
|
|
10
|
+
subOrders?: string[];
|
|
11
|
+
parentOrder?: string;
|
|
12
|
+
consumer?: string;
|
|
13
|
+
origins?: Origins;
|
|
14
|
+
startDate?: number;
|
|
15
|
+
id: string;
|
|
16
|
+
constructor(orderId: string);
|
|
17
|
+
/**
|
|
18
|
+
* Checks if contract has been initialized, if not - initialize contract
|
|
19
|
+
*/
|
|
20
|
+
private checkInitOrder;
|
|
21
|
+
/**
|
|
22
|
+
* Check if order exist
|
|
23
|
+
*/
|
|
24
|
+
isExist(): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Function for fetching order info from blockchain
|
|
27
|
+
*/
|
|
28
|
+
getOrderInfo(): Promise<OrderInfo>;
|
|
29
|
+
getConsumer(): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Function for fetching order result from blockchain
|
|
32
|
+
*/
|
|
33
|
+
getOrderResult(): Promise<OrderResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Function for fetching sub orders from blockchain
|
|
36
|
+
*/
|
|
37
|
+
getSubOrders(): Promise<string[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Function for fetching parent order from blockchain
|
|
40
|
+
*/
|
|
41
|
+
getParentOrder(): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Function for fetching order deposit spent from blockchain
|
|
44
|
+
*/
|
|
45
|
+
getDepositSpent(): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
|
|
48
|
+
*/
|
|
49
|
+
getOrigins(): Promise<Origins>;
|
|
50
|
+
/**
|
|
51
|
+
* Function for fetching parent order from blockchain
|
|
52
|
+
*/
|
|
53
|
+
getAwaitingPayment(): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Function for fetching start of processing date
|
|
56
|
+
*/
|
|
57
|
+
getStartDate(): Promise<number>;
|
|
58
|
+
/**
|
|
59
|
+
* Function for fetching parent order from blockchain
|
|
60
|
+
*/
|
|
61
|
+
setAwaitingPayment(value: boolean, transactionOptions?: TransactionOptions): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Updates order price
|
|
64
|
+
*/
|
|
65
|
+
updateOrderPrice(price: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Sets deposit spent
|
|
68
|
+
*/
|
|
69
|
+
setDepositSpent(value: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Function for updating status of contract
|
|
72
|
+
*/
|
|
73
|
+
updateStatus(status: OrderStatus, price?: number, transactionOptions?: TransactionOptions): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Function for updating status of contract
|
|
76
|
+
*/
|
|
77
|
+
cancelOrder(transactionOptions?: TransactionOptions): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Starts suspended order
|
|
80
|
+
*/
|
|
81
|
+
start(transactionOptions?: TransactionOptions): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Updates order result
|
|
84
|
+
*/
|
|
85
|
+
updateOrderResult(encryptedResult?: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Completes order
|
|
88
|
+
*/
|
|
89
|
+
complete(status: OrderStatus, encryptedResult?: string, encryptedError?: string, // for SDK compatibility
|
|
90
|
+
transactionOptions?: TransactionOptions): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Function for creating sub orders for current order
|
|
93
|
+
* @param subOrderInfo - order info for new subOrder
|
|
94
|
+
* @param blocking - is sub order blocking
|
|
95
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
96
|
+
* @returns {Promise<void>} - Does not return address of created contract!
|
|
97
|
+
*/
|
|
98
|
+
createSubOrder(subOrderInfo: OrderInfo, blocking: boolean, externalId?: string, holdSum?: string, transactionOptions?: TransactionOptions): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Function for creating pack of sub orders (wokflow) for current order
|
|
101
|
+
* @param {Array<subOrderInfo>} - orders info for new subOrders
|
|
102
|
+
* @param transactionOptions - object what contains action account and web3 instance
|
|
103
|
+
* @returns {Promise<string[]>} - tx hashes
|
|
104
|
+
*/
|
|
105
|
+
createSubOrders(subOrdersInfo: ExtendedOrderInfo[], transactionOptions: TransactionOptions): Promise<string[]>;
|
|
106
|
+
getSubOrder(consumer: string, externalId: string): Promise<SubOrderCreatedEvent>;
|
|
107
|
+
/**
|
|
108
|
+
* Function for withdrawing profit from order
|
|
109
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
110
|
+
*/
|
|
111
|
+
withdrawProfit(transactionOptions?: TransactionOptions): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Function for withdrawing change from order
|
|
114
|
+
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
115
|
+
*/
|
|
116
|
+
withdrawChange(transactionOptions?: TransactionOptions): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Function for adding event listeners to contract events
|
|
119
|
+
* @param callback - function for processing each order related with event
|
|
120
|
+
* @return unsubscribe - function unsubscribing from event
|
|
121
|
+
*/
|
|
122
|
+
onOrderStatusUpdated(callback: onOrderStatusUpdatedCallback): () => void;
|
|
123
|
+
}
|
|
124
|
+
export declare type onOrderStatusUpdatedCallback = (status: OrderStatus) => void;
|
|
125
|
+
export default Order;
|