@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.
Files changed (132) hide show
  1. package/build/BlockchainConnector.d.ts +48 -0
  2. package/build/BlockchainConnector.js +259 -0
  3. package/build/TIIGenerator.d.ts +21 -0
  4. package/build/TIIGenerator.js +251 -0
  5. package/build/constants.d.ts +7 -0
  6. package/build/constants.js +10 -0
  7. package/build/contracts/ActiveOffersList.json +131 -0
  8. package/build/contracts/ActiveOrdersList.json +74 -0
  9. package/build/contracts/Marks.json +79 -0
  10. package/build/contracts/Offers.json +999 -0
  11. package/build/contracts/Orders.json +984 -0
  12. package/build/contracts/Providers.json +440 -0
  13. package/build/contracts/ProvidersOffers.json +254 -0
  14. package/build/contracts/Staking.json +323 -0
  15. package/build/contracts/Superpro.json +197 -0
  16. package/build/contracts/SuperproToken.json +356 -0
  17. package/build/crypto/Crypto.d.ts +37 -0
  18. package/build/crypto/Crypto.js +181 -0
  19. package/build/crypto/index.d.ts +2 -0
  20. package/build/crypto/index.js +7 -0
  21. package/build/crypto/nodejs/AES.d.ts +24 -0
  22. package/build/crypto/nodejs/AES.js +152 -0
  23. package/build/crypto/nodejs/ARIA.d.ts +24 -0
  24. package/build/crypto/nodejs/ARIA.js +151 -0
  25. package/build/crypto/nodejs/ECIES.d.ts +6 -0
  26. package/build/crypto/nodejs/ECIES.js +94 -0
  27. package/build/crypto/nodejs/NativeCrypto.d.ts +54 -0
  28. package/build/crypto/nodejs/NativeCrypto.js +214 -0
  29. package/build/crypto/nodejs/RSA-Hybrid.d.ts +15 -0
  30. package/build/crypto/nodejs/RSA-Hybrid.js +153 -0
  31. package/build/index.d.ts +65 -0
  32. package/build/index.js +117 -0
  33. package/build/logger.d.ts +4 -0
  34. package/build/logger.js +8 -0
  35. package/build/models/Ballot.d.ts +13 -0
  36. package/build/models/Ballot.js +76 -0
  37. package/build/models/Offer.d.ts +70 -0
  38. package/build/models/Offer.js +273 -0
  39. package/build/models/Order.d.ts +125 -0
  40. package/build/models/Order.js +540 -0
  41. package/build/models/Provider.d.ts +40 -0
  42. package/build/models/Provider.js +167 -0
  43. package/build/models/TCB.d.ts +80 -0
  44. package/build/models/TCB.js +315 -0
  45. package/build/models/TeeOffer.d.ts +118 -0
  46. package/build/models/TeeOffer.js +436 -0
  47. package/build/proto/Compression.d.ts +33 -0
  48. package/build/proto/Compression.js +146 -0
  49. package/build/proto/TRI.d.ts +122 -0
  50. package/build/proto/TRI.js +316 -0
  51. package/build/providers/storage/ChunksDownloadDecorator.d.ts +38 -0
  52. package/build/providers/storage/ChunksDownloadDecorator.js +284 -0
  53. package/build/providers/storage/IStorageProvider.d.ts +17 -0
  54. package/build/providers/storage/IStorageProvider.js +2 -0
  55. package/build/providers/storage/StorjStorageProvider.d.ts +26 -0
  56. package/build/providers/storage/StorjStorageProvider.js +389 -0
  57. package/build/providers/storage/getStorageProvider.d.ts +4 -0
  58. package/build/providers/storage/getStorageProvider.js +16 -0
  59. package/build/staticModels/ActiveOffers.d.ts +29 -0
  60. package/build/staticModels/ActiveOffers.js +144 -0
  61. package/build/staticModels/ActiveOrders.d.ts +21 -0
  62. package/build/staticModels/ActiveOrders.js +120 -0
  63. package/build/staticModels/Consensus.d.ts +63 -0
  64. package/build/staticModels/Consensus.js +373 -0
  65. package/build/staticModels/Epochs.d.ts +23 -0
  66. package/build/staticModels/Epochs.js +97 -0
  67. package/build/staticModels/LastBlocks.d.ts +25 -0
  68. package/build/staticModels/LastBlocks.js +96 -0
  69. package/build/staticModels/Marks.d.ts +13 -0
  70. package/build/staticModels/Marks.js +113 -0
  71. package/build/staticModels/OffersFactory.d.ts +37 -0
  72. package/build/staticModels/OffersFactory.js +227 -0
  73. package/build/staticModels/OrdersFactory.d.ts +137 -0
  74. package/build/staticModels/OrdersFactory.js +539 -0
  75. package/build/staticModels/ProviderRegistry.d.ts +81 -0
  76. package/build/staticModels/ProviderRegistry.js +311 -0
  77. package/build/staticModels/Staking.d.ts +26 -0
  78. package/build/staticModels/Staking.js +132 -0
  79. package/build/staticModels/Superpro.d.ts +20 -0
  80. package/build/staticModels/Superpro.js +99 -0
  81. package/build/staticModels/SuperproToken.d.ts +30 -0
  82. package/build/staticModels/SuperproToken.js +125 -0
  83. package/build/staticModels/Suspicious.d.ts +26 -0
  84. package/build/staticModels/Suspicious.js +99 -0
  85. package/build/staticModels/TeeOffersFactory.d.ts +36 -0
  86. package/build/staticModels/TeeOffersFactory.js +206 -0
  87. package/build/staticModels/Voting.d.ts +35 -0
  88. package/build/staticModels/Voting.js +111 -0
  89. package/build/store.d.ts +12 -0
  90. package/build/store.js +13 -0
  91. package/build/types/Ballot.d.ts +75 -0
  92. package/build/types/Ballot.js +49 -0
  93. package/build/types/Epoch.d.ts +21 -0
  94. package/build/types/Epoch.js +18 -0
  95. package/build/types/Events.d.ts +18 -0
  96. package/build/types/Events.js +2 -0
  97. package/build/types/Marks.d.ts +5 -0
  98. package/build/types/Marks.js +9 -0
  99. package/build/types/Offer.d.ts +63 -0
  100. package/build/types/Offer.js +41 -0
  101. package/build/types/Order.d.ts +61 -0
  102. package/build/types/Order.js +36 -0
  103. package/build/types/Origins.d.ts +12 -0
  104. package/build/types/Origins.js +10 -0
  105. package/build/types/Provider.d.ts +25 -0
  106. package/build/types/Provider.js +19 -0
  107. package/build/types/Staking.d.ts +27 -0
  108. package/build/types/Staking.js +22 -0
  109. package/build/types/Superpro.d.ts +24 -0
  110. package/build/types/Superpro.js +29 -0
  111. package/build/types/TcbData.d.ts +26 -0
  112. package/build/types/TcbData.js +21 -0
  113. package/build/types/TeeOffer.d.ts +22 -0
  114. package/build/types/TeeOffer.js +15 -0
  115. package/build/types/Web3.d.ts +26 -0
  116. package/build/types/Web3.js +2 -0
  117. package/build/types/blockchainConnector/StorageAccess.d.ts +8 -0
  118. package/build/types/blockchainConnector/StorageAccess.js +2 -0
  119. package/build/types/storage/StorageAccess.d.ts +6 -0
  120. package/build/types/storage/StorageAccess.js +2 -0
  121. package/build/types/storage/StorageFileAccess.d.ts +5 -0
  122. package/build/types/storage/StorageFileAccess.js +2 -0
  123. package/build/types/storage/StorageObject.d.ts +8 -0
  124. package/build/types/storage/StorageObject.js +2 -0
  125. package/build/utils/NonceTracker.d.ts +12 -0
  126. package/build/utils/NonceTracker.js +84 -0
  127. package/build/utils/TxManager.d.ts +21 -0
  128. package/build/utils/TxManager.js +159 -0
  129. package/build/utils.d.ts +38 -0
  130. package/build/utils.js +195 -0
  131. package/package.json +68 -0
  132. package/readme.md +40 -0
@@ -0,0 +1,25 @@
1
+ import { TransactionOptions } from "../types/Web3";
2
+ declare class LastBlocks {
3
+ static address: string;
4
+ private static contract;
5
+ private static logger;
6
+ /**
7
+ * Checks if contract has been initialized, if not - initialize contract
8
+ */
9
+ private static checkInit;
10
+ /**
11
+ * Function generates a list of blocks to be checked in a random way
12
+ * @param tcbAddress - TCB into which other TCBs are recruited from tables for verification
13
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
14
+ */
15
+ static getRandomL1(tcbAddress: string, transactionOptions?: TransactionOptions): Promise<void>;
16
+ /**
17
+ * Function for fetching TCB last blocks list
18
+ */
19
+ static listAll(): Promise<string[]>;
20
+ /**
21
+ * Function for fetching TCB last blocks list size
22
+ */
23
+ static count(): Promise<number>;
24
+ }
25
+ export default LastBlocks;
@@ -0,0 +1,96 @@
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 LastBlocksJSON from "../contracts/LastBlocks.json";
44
+ var utils_1 = require("../utils");
45
+ var LastBlocks = /** @class */ (function () {
46
+ function LastBlocks() {
47
+ }
48
+ /**
49
+ * Checks if contract has been initialized, if not - initialize contract
50
+ */
51
+ LastBlocks.checkInit = function (transactionOptions) {
52
+ if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
53
+ (0, utils_1.checkIfInitialized)();
54
+ // return new transactionOptions.web3.eth.Contract(<AbiItem[]>LastBlocksJSON.abi, this.address);
55
+ }
56
+ if (this.contract)
57
+ return this.contract;
58
+ (0, utils_1.checkIfInitialized)();
59
+ this.logger = logger_1.default.child({ className: "LastBlocks" });
60
+ // return this.contract = new store.web3!.eth.Contract(<AbiItem[]>LastBlocksJSON.abi, this.address);
61
+ };
62
+ /**
63
+ * Function generates a list of blocks to be checked in a random way
64
+ * @param tcbAddress - TCB into which other TCBs are recruited from tables for verification
65
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
66
+ */
67
+ LastBlocks.getRandomL1 = function (tcbAddress, transactionOptions) {
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ return __generator(this, function (_a) {
70
+ return [2 /*return*/];
71
+ });
72
+ });
73
+ };
74
+ /**
75
+ * Function for fetching TCB last blocks list
76
+ */
77
+ LastBlocks.listAll = function () {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ return __generator(this, function (_a) {
80
+ return [2 /*return*/, []];
81
+ });
82
+ });
83
+ };
84
+ /**
85
+ * Function for fetching TCB last blocks list size
86
+ */
87
+ LastBlocks.count = function () {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ return __generator(this, function (_a) {
90
+ return [2 /*return*/, 0];
91
+ });
92
+ });
93
+ };
94
+ return LastBlocks;
95
+ }());
96
+ exports.default = LastBlocks;
@@ -0,0 +1,13 @@
1
+ import { Mark } from "../types/Marks";
2
+ declare class Marks {
3
+ private static contract;
4
+ static get address(): string;
5
+ /**
6
+ * Checks if contract has been initialized, if not - initialize contract
7
+ */
8
+ private static checkInit;
9
+ static getProviderMarks(providerAddress: string): Promise<void>;
10
+ static getOrderMark(orderId: string): Promise<void>;
11
+ static setOrderMark(orderId: string, mark: Mark): Promise<void>;
12
+ }
13
+ export default Marks;
@@ -0,0 +1,113 @@
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 store_1 = __importDefault(require("../store"));
43
+ var utils_1 = require("../utils");
44
+ var Superpro_1 = __importDefault(require("./Superpro"));
45
+ var Marks_json_1 = __importDefault(require("../contracts/Marks.json"));
46
+ var Marks = /** @class */ (function () {
47
+ function Marks() {
48
+ }
49
+ Object.defineProperty(Marks, "address", {
50
+ get: function () {
51
+ return Superpro_1.default.address;
52
+ },
53
+ enumerable: false,
54
+ configurable: true
55
+ });
56
+ /**
57
+ * Checks if contract has been initialized, if not - initialize contract
58
+ */
59
+ Marks.checkInit = function (transactionOptions) {
60
+ if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
61
+ (0, utils_1.checkIfInitialized)();
62
+ return new transactionOptions.web3.eth.Contract(Marks_json_1.default.abi, Superpro_1.default.address);
63
+ }
64
+ if (this.contract)
65
+ return this.contract;
66
+ (0, utils_1.checkIfInitialized)();
67
+ return this.contract = new store_1.default.web3.eth.Contract(Marks_json_1.default.abi, Superpro_1.default.address);
68
+ };
69
+ Marks.getProviderMarks = function (providerAddress) {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ this.checkInit();
75
+ return [4 /*yield*/, this.contract.methods.getProviderMarks(providerAddress).call()];
76
+ case 1:
77
+ _a.sent();
78
+ return [2 /*return*/];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ Marks.getOrderMark = function (orderId) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ this.checkInit();
89
+ return [4 /*yield*/, this.contract.methods.getOrderMark(orderId).call()];
90
+ case 1:
91
+ _a.sent();
92
+ return [2 /*return*/];
93
+ }
94
+ });
95
+ });
96
+ };
97
+ Marks.setOrderMark = function (orderId, mark) {
98
+ return __awaiter(this, void 0, void 0, function () {
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0:
102
+ this.checkInit();
103
+ return [4 /*yield*/, this.contract.methods.setOrderMark(orderId, mark).call()];
104
+ case 1:
105
+ _a.sent();
106
+ return [2 /*return*/];
107
+ }
108
+ });
109
+ });
110
+ };
111
+ return Marks;
112
+ }());
113
+ exports.default = Marks;
@@ -0,0 +1,37 @@
1
+ import { OfferInfoV1, OfferType } from "../types/Offer";
2
+ import { TransactionOptions } from "../types/Web3";
3
+ import { OfferCreatedEvent } from "../types/Events";
4
+ declare class OffersFactory {
5
+ private static contract;
6
+ private static logger;
7
+ static offers?: string[];
8
+ static get address(): string;
9
+ /**
10
+ * Checks if contract has been initialized, if not - initialize contract
11
+ */
12
+ private static checkInit;
13
+ /**
14
+ * Function for fetching list of all offers addresses
15
+ */
16
+ static getAllOffers(): Promise<string[]>;
17
+ /**
18
+ * Creates new offer
19
+ * @param providerAuthorityAccount - address of authority account of provider
20
+ * @param offerInfo - data of new offer
21
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
22
+ */
23
+ static createOffer(providerAuthorityAccount: string, offerInfoV1: OfferInfoV1, externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
24
+ static getOffer(creator: string, externalId: string): Promise<OfferCreatedEvent>;
25
+ /**
26
+ * Function for adding event listeners on offer created event in offers factory contract
27
+ * @param callback - function for processing created offer
28
+ * @return unsubscribe - unsubscribe function from event
29
+ */
30
+ static onOfferCreated(callback: onOfferCreatedCallback): () => void;
31
+ static onOfferEnabled(callback: onOfferEnabledCallback): () => void;
32
+ static onOfferDisabled(callback: onOfferDisbledCallback): () => void;
33
+ }
34
+ export declare type onOfferCreatedCallback = (address: string, creator: string, externalId: string) => void;
35
+ export declare type onOfferEnabledCallback = (providerAuth: string, address: string, offerType: OfferType) => void;
36
+ export declare type onOfferDisbledCallback = (providerAuth: string, address: string, offerType: OfferType) => void;
37
+ export default OffersFactory;
@@ -0,0 +1,227 @@
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 store_1 = __importDefault(require("../store"));
43
+ var logger_1 = __importDefault(require("../logger"));
44
+ var Offers_json_1 = __importDefault(require("../contracts/Offers.json"));
45
+ var utils_1 = require("../utils");
46
+ var Offer_1 = require("../types/Offer");
47
+ var utils_2 = require("ethers/lib/utils");
48
+ var Superpro_1 = __importDefault(require("./Superpro"));
49
+ var TxManager_1 = __importDefault(require("../utils/TxManager"));
50
+ var OffersFactory = /** @class */ (function () {
51
+ function OffersFactory() {
52
+ }
53
+ Object.defineProperty(OffersFactory, "address", {
54
+ get: function () {
55
+ return Superpro_1.default.address;
56
+ },
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ /**
61
+ * Checks if contract has been initialized, if not - initialize contract
62
+ */
63
+ OffersFactory.checkInit = function (transactionOptions) {
64
+ if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
65
+ (0, utils_1.checkIfInitialized)();
66
+ return new transactionOptions.web3.eth.Contract(Offers_json_1.default.abi, Superpro_1.default.address);
67
+ }
68
+ if (this.contract)
69
+ return this.contract;
70
+ (0, utils_1.checkIfInitialized)();
71
+ this.logger = logger_1.default.child({ className: "OffersFactory" });
72
+ return (this.contract = new store_1.default.web3.eth.Contract(Offers_json_1.default.abi, Superpro_1.default.address));
73
+ };
74
+ /**
75
+ * Function for fetching list of all offers addresses
76
+ */
77
+ OffersFactory.getAllOffers = function () {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ var count, offersSet, offerId, offerType;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ this.checkInit();
84
+ return [4 /*yield*/, this.contract.methods.getOffersTotalCount().call()];
85
+ case 1:
86
+ count = _a.sent();
87
+ this.offers = this.offers || [];
88
+ offersSet = new Set(this.offers);
89
+ offerId = offersSet.size + 1;
90
+ _a.label = 2;
91
+ case 2:
92
+ if (!(offerId <= count)) return [3 /*break*/, 5];
93
+ return [4 /*yield*/, this.contract.methods.getOfferType(offerId).call()];
94
+ case 3:
95
+ offerType = (_a.sent());
96
+ if (offerType !== Offer_1.OfferType.TeeOffer) {
97
+ offersSet.add(offerId.toString());
98
+ }
99
+ _a.label = 4;
100
+ case 4:
101
+ ++offerId;
102
+ return [3 /*break*/, 2];
103
+ case 5:
104
+ this.offers = Array.from(offersSet);
105
+ return [2 /*return*/, this.offers];
106
+ }
107
+ });
108
+ });
109
+ };
110
+ /**
111
+ * Creates new offer
112
+ * @param providerAuthorityAccount - address of authority account of provider
113
+ * @param offerInfo - data of new offer
114
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
115
+ */
116
+ OffersFactory.createOffer = function (providerAuthorityAccount, offerInfoV1, externalId, transactionOptions) {
117
+ if (externalId === void 0) { externalId = "default"; }
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var contract, offerInfo, offerInfoParams, formattedExternalId;
120
+ return __generator(this, function (_a) {
121
+ switch (_a.label) {
122
+ case 0:
123
+ contract = this.checkInit(transactionOptions);
124
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
125
+ delete offerInfoV1.disabledAfter;
126
+ offerInfo = offerInfoV1;
127
+ offerInfoParams = (0, utils_1.objectToTuple)(offerInfo, Offer_1.OfferInfoStructure);
128
+ formattedExternalId = (0, utils_2.formatBytes32String)(externalId);
129
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.createValueOffer, [providerAuthorityAccount, offerInfoParams, formattedExternalId], transactionOptions)];
130
+ case 1:
131
+ _a.sent();
132
+ return [2 /*return*/];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ OffersFactory.getOffer = function (creator, externalId) {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var contract, filter, foundIds, response;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0:
143
+ contract = this.checkInit();
144
+ filter = {
145
+ creator: creator,
146
+ externalId: (0, utils_2.formatBytes32String)(externalId),
147
+ };
148
+ return [4 /*yield*/, contract.getPastEvents("OfferCreated", { filter: filter })];
149
+ case 1:
150
+ foundIds = _a.sent();
151
+ response = foundIds.length > 0
152
+ ? foundIds[0].returnValues
153
+ : {
154
+ creator: creator,
155
+ externalId: externalId,
156
+ offerId: '-1',
157
+ };
158
+ return [2 /*return*/, response];
159
+ }
160
+ });
161
+ });
162
+ };
163
+ /**
164
+ * Function for adding event listeners on offer created event in offers factory contract
165
+ * @param callback - function for processing created offer
166
+ * @return unsubscribe - unsubscribe function from event
167
+ */
168
+ OffersFactory.onOfferCreated = function (callback) {
169
+ var _this = this;
170
+ this.checkInit();
171
+ var logger = this.logger.child({ method: "onOfferCreated" });
172
+ var subscription = this.contract.events
173
+ .OfferCreated()
174
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
175
+ return __generator(this, function (_a) {
176
+ callback(event.returnValues.offerId, event.returnValues.creator, event.returnValues.externalId);
177
+ return [2 /*return*/];
178
+ });
179
+ }); })
180
+ .on("error", function (error, receipt) {
181
+ if (receipt)
182
+ return; // Used to avoid logging of transaction rejected
183
+ logger.warn(error);
184
+ });
185
+ return function () { return subscription.unsubscribe(); };
186
+ };
187
+ OffersFactory.onOfferEnabled = function (callback) {
188
+ var _this = this;
189
+ this.checkInit();
190
+ var logger = this.logger.child({ method: "onOfferEnabled" });
191
+ var subscription = this.contract.events
192
+ .OfferEnabled()
193
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
194
+ return __generator(this, function (_a) {
195
+ callback(event.returnValues.providerAuth, event.returnValues.offerId, event.returnValues.offerType);
196
+ return [2 /*return*/];
197
+ });
198
+ }); })
199
+ .on("error", function (error, receipt) {
200
+ if (receipt)
201
+ return; // Used to avoid logging of transaction rejected
202
+ logger.warn(error);
203
+ });
204
+ return function () { return subscription.unsubscribe(); };
205
+ };
206
+ OffersFactory.onOfferDisabled = function (callback) {
207
+ var _this = this;
208
+ this.checkInit();
209
+ var logger = this.logger.child({ method: "onOfferDisabled" });
210
+ var subscription = this.contract.events
211
+ .OfferEnabled()
212
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
213
+ return __generator(this, function (_a) {
214
+ callback(event.returnValues.providerAuth, event.returnValues.offerId, event.returnValues.offerType);
215
+ return [2 /*return*/];
216
+ });
217
+ }); })
218
+ .on("error", function (error, receipt) {
219
+ if (receipt)
220
+ return; // Used to avoid logging of transaction rejected
221
+ logger.warn(error);
222
+ });
223
+ return function () { return subscription.unsubscribe(); };
224
+ };
225
+ return OffersFactory;
226
+ }());
227
+ exports.default = OffersFactory;
@@ -0,0 +1,137 @@
1
+ import { OrderInfo, OrderStatus } from "../types/Order";
2
+ import { TransactionOptions } from "../types/Web3";
3
+ import { OrderCreatedEvent } from "../types/Events";
4
+ declare class OrdersFactory {
5
+ private static contract;
6
+ private static activeOrders;
7
+ private static logger;
8
+ static orders?: string[];
9
+ static get address(): string;
10
+ /**
11
+ * Checks if contract has been initialized, if not - initialize contract
12
+ */
13
+ private static checkInit;
14
+ /**
15
+ * Function for fetching list of all orders addresses
16
+ * @returns list of orders addresses
17
+ */
18
+ static getAllOrders(): Promise<string[]>;
19
+ /**
20
+ * Function for fetching orders count
21
+ */
22
+ static getOrdersCount(): Promise<number>;
23
+ /**
24
+ * Function for fetching order hold deposit for specific order
25
+ * @param orderAddress - address of order for fetching hold deposit
26
+ */
27
+ static getOrderHoldDeposit(orderAddress: string): Promise<string>;
28
+ /**
29
+ * Function for creating orders
30
+ * @param orderInfo - order info for new order
31
+ * @param suspended - is orders suspended
32
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
33
+ * @returns {Promise<void>} - Does not return address of created contract!
34
+ */
35
+ static createOrder(orderInfo: OrderInfo, holdDeposit?: string, suspended?: boolean, externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
36
+ static getOrder(consumer: string, externalId: string): Promise<OrderCreatedEvent>;
37
+ /**
38
+ * Function for refilling order deposit
39
+ * @param orderAddress - address of order
40
+ * @param amount - amount of tokens to refilling
41
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
42
+ */
43
+ static refillOrderDeposit(orderAddress: string, amount: string, transactionOptions?: TransactionOptions): Promise<void>;
44
+ /**
45
+ * Function for adding event listeners on order created event in orders factory contract
46
+ * @param callback - function for processing created order
47
+ * @returns unsubscribe - unsubscribe function from event
48
+ */
49
+ static onOrderCreated(callback: onOrderCreatedCallback): () => void;
50
+ /**
51
+ * Function for adding event listeners on suborder created event in orders contract
52
+ * @param callback - function for processing created suborder
53
+ * @param parentOrderId - parent order id
54
+ * @return unsubscribe - unsubscribe function from event
55
+ */
56
+ static onSubOrderCreated(callback: onSubOrderCreatedCallback, parentOrderId?: string): () => void;
57
+ /**
58
+ * Function for adding event listeners on order started event in orders contract
59
+ * @param callback - function for processing suborder filled event
60
+ * @param orderId - order id
61
+ * @returns unsubscribe - unsubscribe function from event
62
+ */
63
+ static onOrderStarted(callback: onOrderStartedCallback, orderId?: string): () => void;
64
+ /**
65
+ * Function for adding event listeners on order updated status event in orders contract
66
+ * @param callback - function for processing order updated status event
67
+ * @param orderId - order id
68
+ * @returns unsubscribe - unsubscribe function from event
69
+ */
70
+ static onOrdersStatusUpdated(callback: onOrdersStatusUpdatedCallback, orderId?: string): () => void;
71
+ /**
72
+ * Function for adding event listeners on order refilled event in orders contract
73
+ * @param callback - function for processing order refilled event
74
+ * @param consumer - consumer address
75
+ * @param orderId - order id
76
+ * @returns unsubscribe - unsubscribe function from event
77
+ */
78
+ static onOrderDepositRefilled(callback: onOrderDepositRefilledCallback, consumer?: string, orderId?: string): () => void;
79
+ /**
80
+ * Function for adding event listeners on order price updated event in orders contract
81
+ * @param callback - function for processing order price updated event
82
+ * @param orderId - order id
83
+ * @returns unsubscribe - unsubscribe function from event
84
+ */
85
+ static onOrderPriceUpdated(callback: onOrderPriceUpdatedCallback, orderId?: string): () => void;
86
+ /**
87
+ * Function for adding event listeners on order changed withdrawn event in orders contract
88
+ * @param callback - function for processing order changed withdrawn event
89
+ * @param orderId - order id
90
+ * @returns unsubscribe - unsubscribe function from event
91
+ */
92
+ static onOrderChangedWithdrawn(callback: onOrderChangedWithdrawnCallback, orderId?: string): () => void;
93
+ /**
94
+ * Function for adding event listeners on order changed refunded event in orders contract
95
+ * @param callback - function for processing order changed refunded event
96
+ * @param tokenReceiver - token receiver address
97
+ * @param orderId - order id
98
+ * @returns unsubscribe - unsubscribe function from event
99
+ */
100
+ static onOrderProfitWithdrawn(callback: onOrderProfitWithdrawnCallback, orderId?: string, tokenReceiver?: string): () => void;
101
+ /**
102
+ * Function for adding event listeners on order awaiting payment event in orders contract
103
+ * @param callback - function for processing order awaiting payment event
104
+ * @param consumer - order creator address
105
+ * @param orderId - order id
106
+ * @returns unsubscribe - unsubscribe function from event
107
+ */
108
+ static onOrderAwaitingPaymentChanged(callback: onOrderAwaitingPaymentChangedCallback, consumer?: string, orderId?: string): () => void;
109
+ /**
110
+ * Function for adding event listeners on order deposit spent event in orders contract
111
+ * @param callback - function for processing order deposit spent event
112
+ * @param consumer - order creator address
113
+ * @param orderId - order id
114
+ * @returns unsubscribe - unsubscribe function from event
115
+ */
116
+ static onOrderDepositSpentChanged(callback: onOrderDepositSpentChangedCallback, consumer?: string, orderId?: string): () => void;
117
+ /**
118
+ * Function for adding event listeners on order encrypted result updated event in orders contract
119
+ * @param callback - function for processing order encrypted result updated event
120
+ * @param consumer - order creator address
121
+ * @param orderId - order id
122
+ * @returns unsubscribe - unsubscribe function from event
123
+ */
124
+ static onOrderEncryptedResultUpdated(callback: onOrderEncryptedResultUpdatedCallback, consumer?: string, orderId?: string): () => void;
125
+ }
126
+ export declare type onOrderCreatedCallback = (consumer: string, externalId: string, offerId: string, orderId: string) => void;
127
+ export declare type onSubOrderCreatedCallback = (parentOrderId: string, subOrderId: string) => void;
128
+ export declare type onOrderStartedCallback = (orderId: string, consumer: string) => void;
129
+ export declare type onOrdersStatusUpdatedCallback = (orderId: string, status: OrderStatus) => void;
130
+ export declare type onOrderDepositRefilledCallback = (orderId: string, consumer: string, amount: string) => void;
131
+ export declare type onOrderPriceUpdatedCallback = (orderId: string, price: string) => void;
132
+ export declare type onOrderChangedWithdrawnCallback = (orderId: string, consumer: string, change: string) => void;
133
+ export declare type onOrderProfitWithdrawnCallback = (orderId: string, tokenReceiver: string, profit: string) => void;
134
+ export declare type onOrderDepositSpentChangedCallback = (orderId: string, consumer: string, spent: string) => void;
135
+ export declare type onOrderAwaitingPaymentChangedCallback = (orderId: string, consumer: string, awaitingPaymentFlag: boolean) => void;
136
+ export declare type onOrderEncryptedResultUpdatedCallback = (orderId: string, consumer: string, encryptedResult: string) => void;
137
+ export default OrdersFactory;