@super-protocol/sdk-js 0.15.0 → 0.15.2-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 +129 -239
- package/build/connectors/BaseConnector.js +17 -47
- package/build/connectors/BlockchainConnector.js +222 -348
- package/build/connectors/BlockchainEventsListener.js +38 -92
- package/build/contracts/app.json +466 -35
- package/build/crypto/Crypto.js +63 -135
- package/build/crypto/index.js +1 -1
- package/build/crypto/nodejs/AES.js +62 -119
- package/build/crypto/nodejs/ARIA.js +61 -118
- package/build/crypto/nodejs/ECIES.js +51 -87
- package/build/crypto/nodejs/NativeCrypto.js +64 -118
- package/build/crypto/nodejs/RSA-Hybrid.js +54 -113
- package/build/index.d.ts +5 -0
- package/build/index.js +14 -2
- package/build/logger.d.ts +3 -1
- package/build/logger.js +2 -2
- package/build/models/EtlModel.js +65 -114
- package/build/models/Offer.js +227 -462
- package/build/models/Order.d.ts +4 -0
- package/build/models/Order.js +326 -559
- package/build/models/Provider.d.ts +2 -0
- package/build/models/Provider.js +74 -153
- package/build/models/TCB.js +67 -171
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +389 -731
- package/build/proto/Compression.js +20 -21
- package/build/proto/TRI.js +46 -50
- package/build/proto/TeeProperties.js +60 -66
- package/build/providers/storage/ChunksDownloadDecorator.d.ts +1 -1
- package/build/providers/storage/ChunksDownloadDecorator.js +125 -235
- package/build/providers/storage/IStorageProvider.d.ts +1 -1
- package/build/providers/storage/S3StorageProvider.js +173 -298
- package/build/providers/storage/StorageAdapter.d.ts +60 -0
- package/build/providers/storage/StorageAdapter.js +322 -0
- package/build/providers/storage/StorageContentWriter.d.ts +46 -0
- package/build/providers/storage/StorageContentWriter.js +182 -0
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +23 -0
- package/build/providers/storage/StorageKeyValueAdapter.js +157 -0
- package/build/providers/storage/StorageMetadataReader.d.ts +20 -0
- package/build/providers/storage/StorageMetadataReader.js +67 -0
- package/build/providers/storage/StorjAdapter.d.ts +19 -0
- package/build/providers/storage/StorjAdapter.js +73 -0
- package/build/providers/storage/StorjStorageProvider.js +138 -315
- package/build/providers/storage/getStorageProvider.js +7 -7
- package/build/providers/storage/types.d.ts +7 -0
- package/build/providers/storage/types.js +2 -0
- package/build/staticModels/ActiveOffers.js +32 -100
- package/build/staticModels/ActiveOrders.js +42 -120
- package/build/staticModels/BaseStaticModel.js +7 -10
- package/build/staticModels/Consensus.d.ts +4 -1
- package/build/staticModels/Consensus.js +164 -220
- package/build/staticModels/Deposits.js +109 -201
- package/build/staticModels/Marks.js +21 -82
- package/build/staticModels/ModelPackager.js +34 -84
- package/build/staticModels/Offers.js +140 -266
- package/build/staticModels/Orders.d.ts +1 -0
- package/build/staticModels/Orders.js +286 -429
- package/build/staticModels/ProviderRegistry.js +114 -225
- package/build/staticModels/Superpro.js +17 -63
- package/build/staticModels/SuperproToken.js +90 -169
- package/build/staticModels/TeeOffers.js +220 -416
- package/build/store.js +2 -2
- package/build/types/HardwareInfo.js +2 -2
- package/build/types/Order.js +4 -4
- package/build/types/Provider.js +1 -1
- package/build/types/TeeOfferInfo.js +1 -1
- package/build/types/TeeOfferOption.js +2 -2
- package/build/types/TeeOfferSlot.js +2 -2
- package/build/types/ValueOfferSlot.js +3 -3
- package/build/utils/Monitoring.js +24 -28
- package/build/utils/NonceTracker.js +56 -121
- package/build/utils/PubSub.d.ts +9 -0
- package/build/utils/PubSub.js +36 -0
- package/build/utils/TxManager.js +121 -215
- package/build/utils/compressors/GzipCompressor.js +13 -50
- package/build/utils/compressors/UncompressedCompressor.js +10 -13
- package/build/utils/helpers/tryWithInterval.js +34 -78
- package/build/utils/resourceLoaders/BaseResourceLoader.js +26 -78
- package/build/utils/resourceLoaders/StorageProviderLoader.js +33 -97
- package/build/utils/resourceLoaders/UrlResourceLoader.js +29 -93
- package/build/utils/resourceLoaders/getResourceLoader.js +6 -6
- package/build/utils.js +60 -105
- package/package.json +4 -1
package/build/models/Order.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -25,53 +14,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
25
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
15
|
});
|
|
27
16
|
};
|
|
28
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
29
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
30
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
-
function step(op) {
|
|
33
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
-
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;
|
|
36
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
-
switch (op[0]) {
|
|
38
|
-
case 0: case 1: t = op; break;
|
|
39
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
-
default:
|
|
43
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
-
if (t[2]) _.ops.pop();
|
|
48
|
-
_.trys.pop(); continue;
|
|
49
|
-
}
|
|
50
|
-
op = body.call(thisArg, _);
|
|
51
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
56
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
57
19
|
};
|
|
58
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
21
|
+
const Order_1 = require("../types/Order");
|
|
22
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
23
|
+
const app_json_1 = __importDefault(require("../contracts/app.json"));
|
|
24
|
+
const store_1 = __importDefault(require("../store"));
|
|
25
|
+
const utils_1 = require("../utils");
|
|
26
|
+
const Origins_1 = require("../types/Origins");
|
|
27
|
+
const utils_2 = require("ethers/lib/utils");
|
|
28
|
+
const BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
|
|
29
|
+
const Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
30
|
+
const TxManager_1 = __importDefault(require("../utils/TxManager"));
|
|
31
|
+
const BlockchainEventsListener_1 = __importDefault(require("../connectors/BlockchainEventsListener"));
|
|
32
|
+
const TeeOffers_1 = __importDefault(require("../staticModels/TeeOffers"));
|
|
33
|
+
const helpers_1 = require("../utils/helpers");
|
|
34
|
+
const constants_1 = require("../constants");
|
|
35
|
+
class Order {
|
|
36
|
+
constructor(orderId) {
|
|
75
37
|
this.id = orderId;
|
|
76
38
|
if (!Order.contract) {
|
|
77
39
|
Order.contract = BlockchainConnector_1.default.getInstance().getContract();
|
|
@@ -81,456 +43,288 @@ var Order = /** @class */ (function () {
|
|
|
81
43
|
/**
|
|
82
44
|
* Checks if contract has been initialized, if not - initialize contract
|
|
83
45
|
*/
|
|
84
|
-
|
|
46
|
+
checkInitOrder(transactionOptions) {
|
|
85
47
|
if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
|
|
86
48
|
return new transactionOptions.web3.eth.Contract(app_json_1.default.abi, Superpro_1.default.address);
|
|
87
49
|
}
|
|
88
|
-
}
|
|
50
|
+
}
|
|
89
51
|
/**
|
|
90
52
|
* Check if order exist
|
|
91
53
|
*/
|
|
92
|
-
|
|
93
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
-
return
|
|
95
|
-
switch (_a.label) {
|
|
96
|
-
case 0: return [4 /*yield*/, Order.contract.methods.isOrderValid(this.id).call()];
|
|
97
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
54
|
+
isExist() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return yield Order.contract.methods.isOrderValid(this.id).call();
|
|
100
57
|
});
|
|
101
|
-
}
|
|
58
|
+
}
|
|
102
59
|
/**
|
|
103
60
|
* Check if order is in `processing` state
|
|
104
61
|
*/
|
|
105
|
-
|
|
106
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
-
return
|
|
108
|
-
switch (_a.label) {
|
|
109
|
-
case 0: return [4 /*yield*/, Order.contract.methods.isOrderProcessing(this.id).call()];
|
|
110
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
62
|
+
isOrderProcessing() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return yield Order.contract.methods.isOrderProcessing(this.id).call();
|
|
113
65
|
});
|
|
114
|
-
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Function for fetching avaliable for unlock order profit.
|
|
69
|
+
*/
|
|
70
|
+
isOrderProfitAvailable() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const [, profit] = yield Order.contract.methods.isOrderProfitAvailable(this.id).call();
|
|
73
|
+
return profit;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
115
76
|
/**
|
|
116
77
|
* Function for fetching order price
|
|
117
78
|
*/
|
|
118
|
-
|
|
119
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
-
return
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0: return [4 /*yield*/, Order.contract.methods.calculateOrderCurrentPrice(this.id).call()];
|
|
123
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
79
|
+
calculateCurrentPrice() {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
return yield Order.contract.methods.calculateOrderCurrentPrice(this.id).call();
|
|
126
82
|
});
|
|
127
|
-
}
|
|
83
|
+
}
|
|
128
84
|
/**
|
|
129
85
|
* Function for fetching order info from blockchain
|
|
130
86
|
*/
|
|
131
|
-
|
|
132
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!(_a.sent())) {
|
|
139
|
-
throw Error("Order ".concat(this.id, " does not exist"));
|
|
140
|
-
}
|
|
141
|
-
return [4 /*yield*/, Order.contract.methods.getOrder(this.id).call()];
|
|
142
|
-
case 2:
|
|
143
|
-
orderInfoParams = _a.sent();
|
|
144
|
-
return [2 /*return*/, (this.orderInfo = (0, utils_1.tupleToObject)(orderInfoParams[1], Order_1.OrderInfoStructure))];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
87
|
+
getOrderInfo() {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
if (!(yield this.checkIfOrderExistsWithInterval())) {
|
|
90
|
+
throw Error(`Order ${this.id} does not exist`);
|
|
91
|
+
}
|
|
92
|
+
const orderInfoParams = yield Order.contract.methods.getOrder(this.id).call();
|
|
93
|
+
return (this.orderInfo = (0, utils_1.tupleToObject)(orderInfoParams[1], Order_1.OrderInfoStructure));
|
|
147
94
|
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return { isResultOk: exists };
|
|
161
|
-
},
|
|
162
|
-
retryInterval: constants_1.BLOCKCHAIN_CALL_RETRY_INTERVAL,
|
|
163
|
-
retryMax: constants_1.BLOCKCHAIN_CALL_RETRY_ATTEMPTS,
|
|
164
|
-
})];
|
|
165
|
-
case 1:
|
|
166
|
-
offerExists = _a.sent();
|
|
167
|
-
return [2 /*return*/, offerExists];
|
|
168
|
-
}
|
|
95
|
+
}
|
|
96
|
+
checkIfOrderExistsWithInterval() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const offerExists = yield (0, helpers_1.tryWithInterval)({
|
|
99
|
+
handler: () => this.isExist(),
|
|
100
|
+
checkResult: (exists) => {
|
|
101
|
+
if (!exists)
|
|
102
|
+
this.logger.debug(`Order ${this.id} exists: ${exists}`);
|
|
103
|
+
return { isResultOk: exists };
|
|
104
|
+
},
|
|
105
|
+
retryInterval: constants_1.BLOCKCHAIN_CALL_RETRY_INTERVAL,
|
|
106
|
+
retryMax: constants_1.BLOCKCHAIN_CALL_RETRY_ATTEMPTS,
|
|
169
107
|
});
|
|
108
|
+
return offerExists;
|
|
170
109
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
case 0: return [4 /*yield*/, Order.contract.methods.getOrder(this.id).call()];
|
|
178
|
-
case 1:
|
|
179
|
-
orderInfoParams = _a.sent();
|
|
180
|
-
this.consumer = orderInfoParams[0];
|
|
181
|
-
return [2 /*return*/, this.consumer];
|
|
182
|
-
}
|
|
183
|
-
});
|
|
110
|
+
}
|
|
111
|
+
getConsumer() {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const orderInfoParams = yield Order.contract.methods.getOrder(this.id).call();
|
|
114
|
+
this.consumer = orderInfoParams[0];
|
|
115
|
+
return this.consumer;
|
|
184
116
|
});
|
|
185
|
-
}
|
|
117
|
+
}
|
|
186
118
|
/**
|
|
187
119
|
* Function for fetching order result from blockchain
|
|
188
120
|
*/
|
|
189
|
-
|
|
190
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
191
|
-
|
|
192
|
-
return
|
|
193
|
-
switch (_a.label) {
|
|
194
|
-
case 0: return [4 /*yield*/, Order.contract.methods.getOrder(this.id).call()];
|
|
195
|
-
case 1:
|
|
196
|
-
orderInfoParams = _a.sent();
|
|
197
|
-
return [2 /*return*/, (this.orderResult = (0, utils_1.tupleToObject)([orderInfoParams[2][0], orderInfoParams[2][1]], Order_1.OrderResultStructure))];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
121
|
+
getOrderResult() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const orderInfoParams = yield Order.contract.methods.getOrder(this.id).call();
|
|
124
|
+
return (this.orderResult = (0, utils_1.tupleToObject)([orderInfoParams[2][0], orderInfoParams[2][1]], Order_1.OrderResultStructure));
|
|
200
125
|
});
|
|
201
|
-
}
|
|
126
|
+
}
|
|
202
127
|
/**
|
|
203
128
|
* Function for fetching sub orders from blockchain
|
|
204
129
|
*/
|
|
205
|
-
|
|
206
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
207
|
-
|
|
208
|
-
return
|
|
209
|
-
switch (_b.label) {
|
|
210
|
-
case 0:
|
|
211
|
-
_a = this;
|
|
212
|
-
return [4 /*yield*/, Order.contract.methods.getOrderSubOrders(this.id).call()];
|
|
213
|
-
case 1:
|
|
214
|
-
_a.subOrders = _b.sent();
|
|
215
|
-
return [2 /*return*/, this.subOrders];
|
|
216
|
-
}
|
|
217
|
-
});
|
|
130
|
+
getSubOrders() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
this.subOrders = yield Order.contract.methods.getOrderSubOrders(this.id).call();
|
|
133
|
+
return this.subOrders;
|
|
218
134
|
});
|
|
219
|
-
}
|
|
135
|
+
}
|
|
220
136
|
/**
|
|
221
137
|
* Function for fetching parent order from blockchain
|
|
222
138
|
*/
|
|
223
|
-
|
|
224
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
|
|
226
|
-
return
|
|
227
|
-
switch (_b.label) {
|
|
228
|
-
case 0:
|
|
229
|
-
_a = this;
|
|
230
|
-
return [4 /*yield*/, Order.contract.methods.getOrderParentOrder(this.id).call()];
|
|
231
|
-
case 1:
|
|
232
|
-
_a.parentOrder = _b.sent();
|
|
233
|
-
return [2 /*return*/, this.parentOrder];
|
|
234
|
-
}
|
|
235
|
-
});
|
|
139
|
+
getParentOrder() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
this.parentOrder = yield Order.contract.methods.getOrderParentOrder(this.id).call();
|
|
142
|
+
return this.parentOrder;
|
|
236
143
|
});
|
|
237
|
-
}
|
|
144
|
+
}
|
|
238
145
|
/**
|
|
239
146
|
* Function for fetching order options deposit spent from blockchain
|
|
240
147
|
*/
|
|
241
|
-
|
|
242
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
-
return
|
|
244
|
-
return [2 /*return*/, Order.contract.methods.getOptionsDepositSpent(this.id).call()];
|
|
245
|
-
});
|
|
148
|
+
getOptionsDepositSpent() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
return Order.contract.methods.getOptionsDepositSpent(this.id).call();
|
|
246
151
|
});
|
|
247
|
-
}
|
|
152
|
+
}
|
|
248
153
|
/**
|
|
249
154
|
* Function for fetching order deposit spent from blockchain
|
|
250
155
|
*/
|
|
251
|
-
|
|
252
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
_a = this;
|
|
258
|
-
_b = utils_1.tupleToObject;
|
|
259
|
-
return [4 /*yield*/, Order.contract.methods.getOrderSelectedUsage(this.id).call()];
|
|
260
|
-
case 1:
|
|
261
|
-
_a.selectedUsage = _b.apply(void 0, [_f.sent(), Order_1.OrderUsageStructure]);
|
|
262
|
-
this.selectedUsage.optionsCount = this.selectedUsage.optionsCount.map(function (item) { return +item; });
|
|
263
|
-
_c = this.selectedUsage;
|
|
264
|
-
_d = utils_1.unpackSlotInfo;
|
|
265
|
-
_e = [this.selectedUsage.slotInfo];
|
|
266
|
-
return [4 /*yield*/, TeeOffers_1.default.getDenominator()];
|
|
267
|
-
case 2:
|
|
268
|
-
_c.slotInfo = _d.apply(void 0, _e.concat([_f.sent()]));
|
|
269
|
-
return [2 /*return*/, this.selectedUsage];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
156
|
+
getSelectedUsage() {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
this.selectedUsage = (0, utils_1.tupleToObject)(yield Order.contract.methods.getOrderSelectedUsage(this.id).call(), Order_1.OrderUsageStructure);
|
|
159
|
+
this.selectedUsage.optionsCount = this.selectedUsage.optionsCount.map((item) => +item);
|
|
160
|
+
this.selectedUsage.slotInfo = (0, utils_1.unpackSlotInfo)(this.selectedUsage.slotInfo, yield TeeOffers_1.default.getDenominator());
|
|
161
|
+
return this.selectedUsage;
|
|
272
162
|
});
|
|
273
|
-
}
|
|
163
|
+
}
|
|
274
164
|
/**
|
|
275
165
|
* Function for fetching hold deposits sum of the order and its suborders
|
|
276
166
|
*/
|
|
277
|
-
|
|
278
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
-
return
|
|
280
|
-
return [2 /*return*/, Order.contract.methods.calculateTotalOrderDeposit(this.id).call()];
|
|
281
|
-
});
|
|
167
|
+
calculateTotalOrderDeposit() {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
return Order.contract.methods.calculateTotalOrderDeposit(this.id).call();
|
|
282
170
|
});
|
|
283
|
-
}
|
|
171
|
+
}
|
|
284
172
|
/**
|
|
285
173
|
* Function for fetching reserve for output order
|
|
286
174
|
*/
|
|
287
|
-
|
|
288
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
289
|
-
return
|
|
290
|
-
return [2 /*return*/, Order.contract.methods.calculateOrderOutputReserve(this.id).call()];
|
|
291
|
-
});
|
|
175
|
+
calculateOrderOutputReserve() {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
return Order.contract.methods.calculateOrderOutputReserve(this.id).call();
|
|
292
178
|
});
|
|
293
|
-
}
|
|
179
|
+
}
|
|
294
180
|
/**
|
|
295
181
|
* Function for fetching spent deposits sum of the order and its suborders
|
|
296
182
|
*/
|
|
297
|
-
|
|
298
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
299
|
-
return
|
|
300
|
-
return [2 /*return*/, Order.contract.methods.calculateTotalDepositSpent(this.id).call()];
|
|
301
|
-
});
|
|
183
|
+
calculateTotalDepositSpent() {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
return Order.contract.methods.calculateTotalDepositSpent(this.id).call();
|
|
302
186
|
});
|
|
303
|
-
}
|
|
187
|
+
}
|
|
304
188
|
/**
|
|
305
189
|
* Function for fetching unspent deposits sum of the order and its suborders
|
|
306
190
|
*/
|
|
307
|
-
|
|
308
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
-
return
|
|
310
|
-
return [2 /*return*/, Order.contract.methods.calculateTotalDepositUnspent(this.id).call()];
|
|
311
|
-
});
|
|
191
|
+
calculateTotalDepositUnspent() {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
return Order.contract.methods.calculateTotalDepositUnspent(this.id).call();
|
|
312
194
|
});
|
|
313
|
-
}
|
|
195
|
+
}
|
|
314
196
|
/**
|
|
315
197
|
* Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
|
|
316
198
|
*/
|
|
317
|
-
|
|
318
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
origins = (0, utils_1.tupleToObject)(origins, Origins_1.OriginsStructure);
|
|
327
|
-
// Convert blockchain time seconds to js time milliseconds
|
|
328
|
-
origins.createdDate = +origins.createdDate * 1000;
|
|
329
|
-
origins.modifiedDate = +origins.modifiedDate * 1000;
|
|
330
|
-
return [2 /*return*/, (this.origins = origins)];
|
|
331
|
-
}
|
|
332
|
-
});
|
|
199
|
+
getOrigins() {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
let origins = yield Order.contract.methods.getOrderOrigins(this.id).call();
|
|
202
|
+
// Converts blockchain array into object
|
|
203
|
+
origins = (0, utils_1.tupleToObject)(origins, Origins_1.OriginsStructure);
|
|
204
|
+
// Convert blockchain time seconds to js time milliseconds
|
|
205
|
+
origins.createdDate = +origins.createdDate * 1000;
|
|
206
|
+
origins.modifiedDate = +origins.modifiedDate * 1000;
|
|
207
|
+
return (this.origins = origins);
|
|
333
208
|
});
|
|
334
|
-
}
|
|
209
|
+
}
|
|
335
210
|
/**
|
|
336
211
|
* Function for fetching parent order from blockchain
|
|
337
212
|
*/
|
|
338
|
-
|
|
339
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
340
|
-
return
|
|
341
|
-
return [2 /*return*/, Order.contract.methods.getAwaitingPayment(this.id).call()];
|
|
342
|
-
});
|
|
213
|
+
getAwaitingPayment() {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
return Order.contract.methods.getAwaitingPayment(this.id).call();
|
|
343
216
|
});
|
|
344
|
-
}
|
|
217
|
+
}
|
|
345
218
|
/**
|
|
346
219
|
* Function for fetching deposit of order from blockchain
|
|
347
220
|
*/
|
|
348
|
-
|
|
349
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
350
|
-
return
|
|
351
|
-
return [2 /*return*/, Order.contract.methods.getOrderDeposit(this.id).call()];
|
|
352
|
-
});
|
|
221
|
+
getDeposit() {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
return Order.contract.methods.getOrderDeposit(this.id).call();
|
|
353
224
|
});
|
|
354
|
-
}
|
|
225
|
+
}
|
|
355
226
|
/**
|
|
356
227
|
* Function for fetching start of processing date
|
|
357
228
|
*/
|
|
358
|
-
|
|
359
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
360
|
-
return
|
|
361
|
-
return [2 /*return*/, Order.contract.methods.getStartDate(this.id).call()];
|
|
362
|
-
});
|
|
229
|
+
getStartDate() {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
return Order.contract.methods.getStartDate(this.id).call();
|
|
363
232
|
});
|
|
364
|
-
}
|
|
233
|
+
}
|
|
365
234
|
/**
|
|
366
235
|
* Function for fetching parent order from blockchain
|
|
367
236
|
*/
|
|
368
|
-
|
|
369
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
374
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
375
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.setAwaitingPayment, [this.id, value], transactionOptions)];
|
|
376
|
-
case 1:
|
|
377
|
-
_a.sent();
|
|
378
|
-
return [2 /*return*/];
|
|
379
|
-
}
|
|
380
|
-
});
|
|
237
|
+
setAwaitingPayment(value, transactionOptions) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
240
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
241
|
+
yield TxManager_1.default.execute(Order.contract.methods.setAwaitingPayment, [this.id, value], transactionOptions);
|
|
381
242
|
});
|
|
382
|
-
}
|
|
243
|
+
}
|
|
383
244
|
/**
|
|
384
245
|
* Updates order price
|
|
385
246
|
*/
|
|
386
|
-
|
|
387
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
392
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
393
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.updateOrderPrice, [this.id, price], transactionOptions)];
|
|
394
|
-
case 1:
|
|
395
|
-
_a.sent();
|
|
396
|
-
return [2 /*return*/];
|
|
397
|
-
}
|
|
398
|
-
});
|
|
247
|
+
updateOrderPrice(price, transactionOptions) {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
250
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
251
|
+
yield TxManager_1.default.execute(Order.contract.methods.updateOrderPrice, [this.id, price], transactionOptions);
|
|
399
252
|
});
|
|
400
|
-
}
|
|
253
|
+
}
|
|
401
254
|
/**
|
|
402
255
|
* Sets options deposit spent
|
|
403
256
|
*/
|
|
404
|
-
|
|
405
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
410
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
411
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.setOptionsDepositSpent, [this.id, value], transactionOptions)];
|
|
412
|
-
case 1:
|
|
413
|
-
_a.sent();
|
|
414
|
-
return [2 /*return*/];
|
|
415
|
-
}
|
|
416
|
-
});
|
|
257
|
+
setOptionsDepositSpent(value, transactionOptions) {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
260
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
261
|
+
yield TxManager_1.default.execute(Order.contract.methods.setOptionsDepositSpent, [this.id, value], transactionOptions);
|
|
417
262
|
});
|
|
418
|
-
}
|
|
263
|
+
}
|
|
419
264
|
/**
|
|
420
265
|
* Function for updating status of contract
|
|
421
266
|
*/
|
|
422
|
-
|
|
423
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
case 1:
|
|
432
|
-
_a.sent();
|
|
433
|
-
_a.label = 2;
|
|
434
|
-
case 2:
|
|
435
|
-
if (this.orderInfo)
|
|
436
|
-
this.orderInfo.status = status;
|
|
437
|
-
return [2 /*return*/];
|
|
438
|
-
}
|
|
439
|
-
});
|
|
267
|
+
updateStatus(status, transactionOptions) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
270
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
271
|
+
if (status === Order_1.OrderStatus.Processing) {
|
|
272
|
+
yield TxManager_1.default.execute(Order.contract.methods.processOrder, [this.id], transactionOptions);
|
|
273
|
+
}
|
|
274
|
+
if (this.orderInfo)
|
|
275
|
+
this.orderInfo.status = status;
|
|
440
276
|
});
|
|
441
|
-
}
|
|
277
|
+
}
|
|
442
278
|
/**
|
|
443
279
|
* Function for updating status of contract
|
|
444
280
|
*/
|
|
445
|
-
|
|
446
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
451
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
452
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.cancelOrder, [this.id], transactionOptions)];
|
|
453
|
-
case 1:
|
|
454
|
-
_a.sent();
|
|
455
|
-
return [2 /*return*/];
|
|
456
|
-
}
|
|
457
|
-
});
|
|
281
|
+
cancelOrder(transactionOptions) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
284
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
285
|
+
yield TxManager_1.default.execute(Order.contract.methods.cancelOrder, [this.id], transactionOptions);
|
|
458
286
|
});
|
|
459
|
-
}
|
|
287
|
+
}
|
|
460
288
|
/**
|
|
461
289
|
* Starts suspended order
|
|
462
290
|
*/
|
|
463
|
-
|
|
464
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
469
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
470
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.startOrder, [this.id], transactionOptions)];
|
|
471
|
-
case 1:
|
|
472
|
-
_a.sent();
|
|
473
|
-
return [2 /*return*/];
|
|
474
|
-
}
|
|
475
|
-
});
|
|
291
|
+
start(transactionOptions) {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
294
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
295
|
+
yield TxManager_1.default.execute(Order.contract.methods.startOrder, [this.id], transactionOptions);
|
|
476
296
|
});
|
|
477
|
-
}
|
|
297
|
+
}
|
|
478
298
|
/**
|
|
479
299
|
* Updates order result
|
|
480
300
|
*/
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
case 0:
|
|
487
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
488
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
489
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.updateOrderResult, [this.id, encryptedResult], transactionOptions)];
|
|
490
|
-
case 1:
|
|
491
|
-
_a.sent();
|
|
492
|
-
return [2 /*return*/];
|
|
493
|
-
}
|
|
494
|
-
});
|
|
301
|
+
updateOrderResult(encryptedResult = "", transactionOptions) {
|
|
302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
304
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
305
|
+
yield TxManager_1.default.execute(Order.contract.methods.updateOrderResult, [this.id, encryptedResult], transactionOptions);
|
|
495
306
|
});
|
|
496
|
-
}
|
|
307
|
+
}
|
|
497
308
|
/**
|
|
498
309
|
* Completes order
|
|
499
310
|
*/
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
case 0:
|
|
506
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
507
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
508
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.completeOrder, [this.id, status, encryptedResult], transactionOptions)];
|
|
509
|
-
case 1:
|
|
510
|
-
_a.sent();
|
|
511
|
-
return [2 /*return*/];
|
|
512
|
-
}
|
|
513
|
-
});
|
|
311
|
+
complete(status, encryptedResult = "", transactionOptions) {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
314
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
315
|
+
yield TxManager_1.default.execute(Order.contract.methods.completeOrder, [this.id, status, encryptedResult], transactionOptions);
|
|
514
316
|
});
|
|
515
|
-
}
|
|
317
|
+
}
|
|
516
318
|
/**
|
|
517
319
|
* Unlocks profit
|
|
518
320
|
*/
|
|
519
|
-
|
|
520
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
525
|
-
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
526
|
-
return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.unlockProfit, [this.id], transactionOptions)];
|
|
527
|
-
case 1:
|
|
528
|
-
_a.sent();
|
|
529
|
-
return [2 /*return*/];
|
|
530
|
-
}
|
|
531
|
-
});
|
|
321
|
+
unlockProfit(transactionOptions) {
|
|
322
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
323
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
324
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
325
|
+
yield TxManager_1.default.execute(Order.contract.methods.unlockProfit, [this.id], transactionOptions);
|
|
532
326
|
});
|
|
533
|
-
}
|
|
327
|
+
}
|
|
534
328
|
/**
|
|
535
329
|
* Function for creating sub orders for current order
|
|
536
330
|
* @param subOrderInfo - order info for new subOrder
|
|
@@ -538,189 +332,162 @@ var Order = /** @class */ (function () {
|
|
|
538
332
|
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
539
333
|
* @returns Promise<void> - Does not return id of created sub order!
|
|
540
334
|
*/
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
deposit: deposit,
|
|
556
|
-
};
|
|
557
|
-
if (!checkTxBeforeSend) return [3 /*break*/, 2];
|
|
558
|
-
return [4 /*yield*/, TxManager_1.default.dryRun(Order.contract.methods.createSubOrder, [this.id, tupleSubOrder, params], transactionOptions)];
|
|
559
|
-
case 1:
|
|
560
|
-
_a.sent();
|
|
561
|
-
_a.label = 2;
|
|
562
|
-
case 2: return [4 /*yield*/, TxManager_1.default.execute(Order.contract.methods.createSubOrder, [this.id, tupleSubOrder, params], transactionOptions)];
|
|
563
|
-
case 3:
|
|
564
|
-
_a.sent();
|
|
565
|
-
return [2 /*return*/];
|
|
566
|
-
}
|
|
567
|
-
});
|
|
335
|
+
createSubOrder(subOrderInfo, blockParentOrder, deposit = "0", transactionOptions, checkTxBeforeSend = false) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
transactionOptions !== null && transactionOptions !== void 0 ? transactionOptions : this.checkInitOrder(transactionOptions);
|
|
338
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
339
|
+
const preparedInfo = Object.assign(Object.assign({}, subOrderInfo), { externalId: (0, utils_2.formatBytes32String)(subOrderInfo.externalId) });
|
|
340
|
+
const tupleSubOrder = (0, utils_1.objectToTuple)(preparedInfo, Order_1.OrderInfoStructure);
|
|
341
|
+
const params = {
|
|
342
|
+
blockParentOrder,
|
|
343
|
+
deposit,
|
|
344
|
+
};
|
|
345
|
+
if (checkTxBeforeSend) {
|
|
346
|
+
yield TxManager_1.default.dryRun(Order.contract.methods.createSubOrder, [this.id, tupleSubOrder, params], transactionOptions);
|
|
347
|
+
}
|
|
348
|
+
yield TxManager_1.default.execute(Order.contract.methods.createSubOrder, [this.id, tupleSubOrder, params], transactionOptions);
|
|
568
349
|
});
|
|
569
|
-
}
|
|
350
|
+
}
|
|
570
351
|
/**
|
|
571
352
|
* Function for creating pack of sub orders (wokflow) for current order
|
|
572
353
|
* @param subOrdersInfo - orders info for new subOrders
|
|
573
354
|
* @param transactionOptions - object what contains action account and web3 instance
|
|
574
355
|
* @returns {Promise<string[]>} - tx hashes
|
|
575
356
|
*/
|
|
576
|
-
|
|
577
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (err)
|
|
602
|
-
rej(err);
|
|
603
|
-
});
|
|
604
|
-
batch.add(request);
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
batch.execute();
|
|
608
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
609
|
-
case 1:
|
|
610
|
-
txs = _a.sent();
|
|
611
|
-
return [2 /*return*/, txs.reduce(function (a, b) { return a.concat(b); }, [])];
|
|
612
|
-
}
|
|
357
|
+
createSubOrders(subOrdersInfo, transactionOptions) {
|
|
358
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
+
this.checkInitOrder(transactionOptions);
|
|
360
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
361
|
+
const batch = new transactionOptions.web3.BatchRequest();
|
|
362
|
+
const promises = subOrdersInfo.map((subOrderInfo) => {
|
|
363
|
+
return new Promise((res, rej) => {
|
|
364
|
+
const preparedInfo = Object.assign(Object.assign({}, subOrderInfo), { externalId: (0, utils_2.formatBytes32String)(subOrderInfo.externalId) });
|
|
365
|
+
const tupleSubOrder = (0, utils_1.objectToTuple)(preparedInfo, Order_1.OrderInfoStructure);
|
|
366
|
+
const params = {
|
|
367
|
+
blockParentOrder: subOrderInfo.blocking,
|
|
368
|
+
deposit: subOrderInfo.deposit,
|
|
369
|
+
};
|
|
370
|
+
const request = Order.contract.methods.createSubOrder(this.id, tupleSubOrder, params).send.request({
|
|
371
|
+
from: transactionOptions.from,
|
|
372
|
+
gasPrice: store_1.default.gasPrice,
|
|
373
|
+
gas: store_1.default.gasLimit,
|
|
374
|
+
}, (err, data) => {
|
|
375
|
+
if (data)
|
|
376
|
+
res(data);
|
|
377
|
+
if (err)
|
|
378
|
+
rej(err);
|
|
379
|
+
});
|
|
380
|
+
batch.add(request);
|
|
381
|
+
});
|
|
613
382
|
});
|
|
383
|
+
batch.execute();
|
|
384
|
+
const txs = yield Promise.all(promises);
|
|
385
|
+
return txs.reduce((a, b) => a.concat(b), []);
|
|
614
386
|
});
|
|
615
|
-
}
|
|
387
|
+
}
|
|
616
388
|
/**
|
|
617
389
|
* Function for adding event listeners to contract events
|
|
618
390
|
* @param callback - function for processing each order related with event
|
|
619
391
|
* @returns unsubscribe - function unsubscribing from event
|
|
620
392
|
*/
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
var logger = this.logger.child({ method: "onOrderStatusUpdated" });
|
|
393
|
+
onStatusUpdated(callback) {
|
|
394
|
+
const logger = this.logger.child({ method: "onOrderStatusUpdated" });
|
|
624
395
|
// TODO: add ability to use this event without https provider initialization
|
|
625
|
-
|
|
626
|
-
|
|
396
|
+
const contractWss = BlockchainEventsListener_1.default.getInstance().getContract();
|
|
397
|
+
const subscription = contractWss.events
|
|
627
398
|
.OrderStatusUpdated()
|
|
628
|
-
.on("data",
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
});
|
|
638
|
-
}); })
|
|
639
|
-
.on("error", function (error, receipt) {
|
|
399
|
+
.on("data", (event) => __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
if (event.returnValues.orderId != this.id) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (this.orderInfo)
|
|
404
|
+
this.orderInfo.status = event.returnValues.status;
|
|
405
|
+
callback(event.returnValues.status);
|
|
406
|
+
}))
|
|
407
|
+
.on("error", (error, receipt) => {
|
|
640
408
|
if (receipt)
|
|
641
409
|
return; // Used to avoid logging of transaction rejected
|
|
642
410
|
logger.warn(error);
|
|
643
411
|
});
|
|
644
|
-
return
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
}());
|
|
412
|
+
return () => subscription.unsubscribe();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
__decorate([
|
|
416
|
+
(0, utils_1.incrementMethodCall)()
|
|
417
|
+
], Order.prototype, "getOrderInfo", null);
|
|
418
|
+
__decorate([
|
|
419
|
+
(0, utils_1.incrementMethodCall)()
|
|
420
|
+
], Order.prototype, "getConsumer", null);
|
|
421
|
+
__decorate([
|
|
422
|
+
(0, utils_1.incrementMethodCall)()
|
|
423
|
+
], Order.prototype, "getOrderResult", null);
|
|
424
|
+
__decorate([
|
|
425
|
+
(0, utils_1.incrementMethodCall)()
|
|
426
|
+
], Order.prototype, "getSubOrders", null);
|
|
427
|
+
__decorate([
|
|
428
|
+
(0, utils_1.incrementMethodCall)()
|
|
429
|
+
], Order.prototype, "getParentOrder", null);
|
|
430
|
+
__decorate([
|
|
431
|
+
(0, utils_1.incrementMethodCall)()
|
|
432
|
+
], Order.prototype, "getOptionsDepositSpent", null);
|
|
433
|
+
__decorate([
|
|
434
|
+
(0, utils_1.incrementMethodCall)()
|
|
435
|
+
], Order.prototype, "getSelectedUsage", null);
|
|
436
|
+
__decorate([
|
|
437
|
+
(0, utils_1.incrementMethodCall)()
|
|
438
|
+
], Order.prototype, "calculateTotalOrderDeposit", null);
|
|
439
|
+
__decorate([
|
|
440
|
+
(0, utils_1.incrementMethodCall)()
|
|
441
|
+
], Order.prototype, "calculateOrderOutputReserve", null);
|
|
442
|
+
__decorate([
|
|
443
|
+
(0, utils_1.incrementMethodCall)()
|
|
444
|
+
], Order.prototype, "calculateTotalDepositSpent", null);
|
|
445
|
+
__decorate([
|
|
446
|
+
(0, utils_1.incrementMethodCall)()
|
|
447
|
+
], Order.prototype, "calculateTotalDepositUnspent", null);
|
|
448
|
+
__decorate([
|
|
449
|
+
(0, utils_1.incrementMethodCall)()
|
|
450
|
+
], Order.prototype, "getOrigins", null);
|
|
451
|
+
__decorate([
|
|
452
|
+
(0, utils_1.incrementMethodCall)()
|
|
453
|
+
], Order.prototype, "getAwaitingPayment", null);
|
|
454
|
+
__decorate([
|
|
455
|
+
(0, utils_1.incrementMethodCall)()
|
|
456
|
+
], Order.prototype, "getDeposit", null);
|
|
457
|
+
__decorate([
|
|
458
|
+
(0, utils_1.incrementMethodCall)()
|
|
459
|
+
], Order.prototype, "getStartDate", null);
|
|
460
|
+
__decorate([
|
|
461
|
+
(0, utils_1.incrementMethodCall)()
|
|
462
|
+
], Order.prototype, "setAwaitingPayment", null);
|
|
463
|
+
__decorate([
|
|
464
|
+
(0, utils_1.incrementMethodCall)()
|
|
465
|
+
], Order.prototype, "updateOrderPrice", null);
|
|
466
|
+
__decorate([
|
|
467
|
+
(0, utils_1.incrementMethodCall)()
|
|
468
|
+
], Order.prototype, "setOptionsDepositSpent", null);
|
|
469
|
+
__decorate([
|
|
470
|
+
(0, utils_1.incrementMethodCall)()
|
|
471
|
+
], Order.prototype, "updateStatus", null);
|
|
472
|
+
__decorate([
|
|
473
|
+
(0, utils_1.incrementMethodCall)()
|
|
474
|
+
], Order.prototype, "cancelOrder", null);
|
|
475
|
+
__decorate([
|
|
476
|
+
(0, utils_1.incrementMethodCall)()
|
|
477
|
+
], Order.prototype, "start", null);
|
|
478
|
+
__decorate([
|
|
479
|
+
(0, utils_1.incrementMethodCall)()
|
|
480
|
+
], Order.prototype, "updateOrderResult", null);
|
|
481
|
+
__decorate([
|
|
482
|
+
(0, utils_1.incrementMethodCall)()
|
|
483
|
+
], Order.prototype, "complete", null);
|
|
484
|
+
__decorate([
|
|
485
|
+
(0, utils_1.incrementMethodCall)()
|
|
486
|
+
], Order.prototype, "unlockProfit", null);
|
|
487
|
+
__decorate([
|
|
488
|
+
(0, utils_1.incrementMethodCall)()
|
|
489
|
+
], Order.prototype, "createSubOrder", null);
|
|
490
|
+
__decorate([
|
|
491
|
+
(0, utils_1.incrementMethodCall)()
|
|
492
|
+
], Order.prototype, "createSubOrders", null);
|
|
726
493
|
exports.default = Order;
|