@super-protocol/sdk-js 0.15.0 → 0.15.1
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.js +125 -235
- package/build/providers/storage/S3StorageProvider.js +173 -298
- package/build/providers/storage/StorageAdapter.d.ts +60 -0
- package/build/providers/storage/StorageAdapter.js +317 -0
- package/build/providers/storage/StorageContentWriter.d.ts +39 -0
- package/build/providers/storage/StorageContentWriter.js +181 -0
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +20 -0
- package/build/providers/storage/StorageKeyValueAdapter.js +152 -0
- package/build/providers/storage/StorageMetadataReader.d.ts +19 -0
- package/build/providers/storage/StorageMetadataReader.js +65 -0
- package/build/providers/storage/StorjAdapter.d.ts +19 -0
- package/build/providers/storage/StorjAdapter.js +62 -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
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
29
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
30
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -40,313 +14,227 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
40
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
15
|
});
|
|
42
16
|
};
|
|
43
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
44
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
45
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
46
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
47
|
-
function step(op) {
|
|
48
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
49
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
50
|
-
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;
|
|
51
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
52
|
-
switch (op[0]) {
|
|
53
|
-
case 0: case 1: t = op; break;
|
|
54
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
55
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
56
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
57
|
-
default:
|
|
58
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
59
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
60
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
61
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
62
|
-
if (t[2]) _.ops.pop();
|
|
63
|
-
_.trys.pop(); continue;
|
|
64
|
-
}
|
|
65
|
-
op = body.call(thisArg, _);
|
|
66
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
67
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
71
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
72
19
|
};
|
|
73
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
21
|
+
const BaseConnector_1 = require("./BaseConnector");
|
|
22
|
+
const web3_1 = __importDefault(require("web3"));
|
|
23
|
+
const web3_core_helpers_1 = require("web3-core-helpers");
|
|
24
|
+
const constants_1 = require("../constants");
|
|
25
|
+
const utils_1 = require("../utils");
|
|
26
|
+
const TxManager_1 = __importDefault(require("../utils/TxManager"));
|
|
27
|
+
const app_json_1 = __importDefault(require("../contracts/app.json"));
|
|
28
|
+
const ethers_1 = require("ethers");
|
|
29
|
+
const Jsonrpc = require("web3-core-requestmanager/src/jsonrpc");
|
|
83
30
|
// TODO: remove this dependencies
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return _super.call(this) || this;
|
|
31
|
+
const store_1 = __importDefault(require("../store"));
|
|
32
|
+
const Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
33
|
+
const SuperproToken_1 = __importDefault(require("../staticModels/SuperproToken"));
|
|
34
|
+
const Monitoring_1 = require("../utils/Monitoring");
|
|
35
|
+
class BlockchainConnector extends BaseConnector_1.BaseConnector {
|
|
36
|
+
constructor() {
|
|
37
|
+
super();
|
|
92
38
|
}
|
|
93
|
-
|
|
39
|
+
static getInstance() {
|
|
94
40
|
if (!BlockchainConnector.instance) {
|
|
95
41
|
BlockchainConnector.instance = new BlockchainConnector();
|
|
96
42
|
}
|
|
97
43
|
return BlockchainConnector.instance;
|
|
98
|
-
}
|
|
44
|
+
}
|
|
99
45
|
// TODO: remove this
|
|
100
|
-
|
|
46
|
+
getContract(transactionOptions) {
|
|
101
47
|
this.checkIfInitialized();
|
|
102
48
|
if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
|
|
103
49
|
return new transactionOptions.web3.eth.Contract(app_json_1.default.abi, Superpro_1.default.address);
|
|
104
50
|
}
|
|
105
|
-
return
|
|
106
|
-
}
|
|
51
|
+
return super.getContract();
|
|
52
|
+
}
|
|
107
53
|
/**
|
|
108
54
|
* Function for connecting to blockchain
|
|
109
55
|
* Used to setting up settings for blockchain connector
|
|
110
56
|
* Needs to run this function before using blockchain connector
|
|
111
57
|
*/
|
|
112
|
-
|
|
58
|
+
initialize(config) {
|
|
113
59
|
var _a;
|
|
114
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_b = SuperproToken_1.default;
|
|
134
|
-
return [4 /*yield*/, Superpro_1.default.getTokenAddress(this.contract)];
|
|
135
|
-
case 1:
|
|
136
|
-
_b.addressHttps = _c.sent();
|
|
137
|
-
Monitoring_1.Monitoring.getInstance().initializeLogging();
|
|
138
|
-
this.initialized = true;
|
|
139
|
-
this.logger.trace("Initialized");
|
|
140
|
-
return [2 /*return*/];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
this.logger.trace(config, "Initializing");
|
|
62
|
+
const url = (config === null || config === void 0 ? void 0 : config.blockchainUrl) || constants_1.defaultBlockchainUrl;
|
|
63
|
+
this.provider = new web3_1.default.providers.HttpProvider(url);
|
|
64
|
+
store_1.default.web3Https = new web3_1.default(this.provider);
|
|
65
|
+
store_1.default.gasPrice = (_a = config === null || config === void 0 ? void 0 : config.gasPrice) !== null && _a !== void 0 ? _a : constants_1.defaultGasPrice;
|
|
66
|
+
if (config === null || config === void 0 ? void 0 : config.gasLimit)
|
|
67
|
+
store_1.default.gasLimit = config.gasLimit;
|
|
68
|
+
if (config === null || config === void 0 ? void 0 : config.gasLimitMultiplier)
|
|
69
|
+
store_1.default.gasLimitMultiplier = config.gasLimitMultiplier;
|
|
70
|
+
if (config === null || config === void 0 ? void 0 : config.gasPriceMultiplier)
|
|
71
|
+
store_1.default.gasPriceMultiplier = config.gasPriceMultiplier;
|
|
72
|
+
Superpro_1.default.address = config.contractAddress;
|
|
73
|
+
this.contract = new store_1.default.web3Https.eth.Contract(app_json_1.default.abi, Superpro_1.default.address);
|
|
74
|
+
TxManager_1.default.init(store_1.default.web3Https);
|
|
75
|
+
SuperproToken_1.default.addressHttps = yield Superpro_1.default.getTokenAddress(this.contract);
|
|
76
|
+
Monitoring_1.Monitoring.getInstance().initializeLogging();
|
|
77
|
+
this.initialized = true;
|
|
78
|
+
this.logger.trace("Initialized");
|
|
143
79
|
});
|
|
144
|
-
}
|
|
80
|
+
}
|
|
145
81
|
/**
|
|
146
82
|
* Function for connecting provider action account
|
|
147
83
|
* Needs to run this function before using any set methods in blockchain connector
|
|
148
84
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.defaultActionAccount = actionAccount;
|
|
164
|
-
if (!manageNonce) return [3 /*break*/, 2];
|
|
165
|
-
return [4 /*yield*/, TxManager_1.default.initAccount(actionAccount)];
|
|
166
|
-
case 1:
|
|
167
|
-
_a.sent();
|
|
168
|
-
_a.label = 2;
|
|
169
|
-
case 2: return [2 /*return*/, actionAccount];
|
|
170
|
-
}
|
|
171
|
-
});
|
|
85
|
+
initializeActionAccount(actionAccountKey, manageNonce = true) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
this.checkIfInitialized();
|
|
88
|
+
const actionAccount = store_1.default.web3Https.eth.accounts.wallet.add(actionAccountKey).address;
|
|
89
|
+
if (!store_1.default.actionAccount)
|
|
90
|
+
store_1.default.actionAccount = actionAccount;
|
|
91
|
+
if (!store_1.default.keys[actionAccount])
|
|
92
|
+
store_1.default.keys[actionAccount] = actionAccountKey;
|
|
93
|
+
if (!this.defaultActionAccount)
|
|
94
|
+
this.defaultActionAccount = actionAccount;
|
|
95
|
+
if (manageNonce) {
|
|
96
|
+
yield TxManager_1.default.initAccount(actionAccount);
|
|
97
|
+
}
|
|
98
|
+
return actionAccount;
|
|
172
99
|
});
|
|
173
|
-
}
|
|
100
|
+
}
|
|
174
101
|
/**
|
|
175
102
|
* Returns balance of blockchain platform tokens in wei
|
|
176
103
|
*/
|
|
177
|
-
|
|
178
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return [2 /*return*/, store_1.default.web3Https.eth.getBalance(address)];
|
|
182
|
-
});
|
|
104
|
+
getBalance(address) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
this.checkIfInitialized();
|
|
107
|
+
return store_1.default.web3Https.eth.getBalance(address);
|
|
183
108
|
});
|
|
184
|
-
}
|
|
185
|
-
|
|
109
|
+
}
|
|
110
|
+
getTimestamp() {
|
|
186
111
|
var _a;
|
|
187
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
case 0:
|
|
192
|
-
this.checkIfInitialized();
|
|
193
|
-
return [4 /*yield*/, ((_a = store_1.default.web3Https) === null || _a === void 0 ? void 0 : _a.eth.getBlock("latest"))];
|
|
194
|
-
case 1:
|
|
195
|
-
block = _b.sent();
|
|
196
|
-
return [2 /*return*/, block.timestamp];
|
|
197
|
-
}
|
|
198
|
-
});
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
this.checkIfInitialized();
|
|
114
|
+
const block = yield ((_a = store_1.default.web3Https) === null || _a === void 0 ? void 0 : _a.eth.getBlock("latest"));
|
|
115
|
+
return block.timestamp;
|
|
199
116
|
});
|
|
200
|
-
}
|
|
117
|
+
}
|
|
201
118
|
/**
|
|
202
119
|
* Returns transactions events info
|
|
203
120
|
* @param txHash - transaction hash
|
|
204
121
|
* @returns {Promise<EventData[]>} - Transaction events info
|
|
205
122
|
*/
|
|
206
|
-
|
|
207
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
parseReceiptEvents(app_json_1.default.abi, Superpro_1.default.address, receipt); // don't remove
|
|
219
|
-
events = Object.values(tokenEvents.events || {});
|
|
220
|
-
eventData = [];
|
|
221
|
-
for (_i = 0, events_1 = events; _i < events_1.length; _i++) {
|
|
222
|
-
event = events_1[_i];
|
|
223
|
-
if (event.address === constants_1.POLYGON_MATIC_EVENT_PATH || !event.event) {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
data = event.returnValues;
|
|
227
|
-
dataValues = Object.values(data);
|
|
228
|
-
if (dataValues.length !== 0) {
|
|
229
|
-
for (i = 0; i < dataValues.length / 2; i++) {
|
|
230
|
-
delete data[i];
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
eventData.push({
|
|
234
|
-
contract: event.address,
|
|
235
|
-
name: event.event,
|
|
236
|
-
data: data,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
return [2 /*return*/, eventData];
|
|
123
|
+
getTransactionEvents(txHash) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
this.checkIfInitialized();
|
|
126
|
+
const parseReceiptEvents = require("web3-parse-receipt-events");
|
|
127
|
+
const receipt = yield store_1.default.web3Https.eth.getTransactionReceipt(txHash);
|
|
128
|
+
const tokenEvents = parseReceiptEvents(app_json_1.default.abi, SuperproToken_1.default.addressHttps, receipt);
|
|
129
|
+
parseReceiptEvents(app_json_1.default.abi, Superpro_1.default.address, receipt); // don't remove
|
|
130
|
+
const events = Object.values(tokenEvents.events || {});
|
|
131
|
+
const eventData = [];
|
|
132
|
+
for (const event of events) {
|
|
133
|
+
if (event.address === constants_1.POLYGON_MATIC_EVENT_PATH || !event.event) {
|
|
134
|
+
continue;
|
|
240
135
|
}
|
|
241
|
-
|
|
136
|
+
const data = event.returnValues;
|
|
137
|
+
const dataValues = Object.values(data);
|
|
138
|
+
if (dataValues.length !== 0) {
|
|
139
|
+
for (let i = 0; i < dataValues.length / 2; i++) {
|
|
140
|
+
delete data[i];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
eventData.push({
|
|
144
|
+
contract: event.address,
|
|
145
|
+
name: event.event,
|
|
146
|
+
data,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return eventData;
|
|
242
150
|
});
|
|
243
|
-
}
|
|
151
|
+
}
|
|
244
152
|
/**
|
|
245
153
|
* Function for adding event listeners on TEE offer created event in TEE offers factory contract
|
|
246
154
|
* @param callback - function for processing created TEE offer
|
|
247
155
|
* @returns unsubscribe - unsubscribe function from event
|
|
248
156
|
*/
|
|
249
|
-
|
|
250
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
index = _a.sent();
|
|
259
|
-
return [4 /*yield*/, store_1.default.web3Https.eth.getBlock(index)];
|
|
260
|
-
case 2:
|
|
261
|
-
hash = (_a.sent()).hash;
|
|
262
|
-
return [2 /*return*/, {
|
|
263
|
-
index: index,
|
|
264
|
-
hash: hash,
|
|
265
|
-
}];
|
|
266
|
-
}
|
|
267
|
-
});
|
|
157
|
+
getLastBlockInfo() {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
this.checkIfInitialized();
|
|
160
|
+
const index = yield store_1.default.web3Https.eth.getBlockNumber();
|
|
161
|
+
const hash = (yield store_1.default.web3Https.eth.getBlock(index)).hash;
|
|
162
|
+
return {
|
|
163
|
+
index,
|
|
164
|
+
hash,
|
|
165
|
+
};
|
|
268
166
|
});
|
|
269
|
-
}
|
|
167
|
+
}
|
|
270
168
|
/**
|
|
271
169
|
* Returns transactions reciept
|
|
272
170
|
* @param txHash - transaction hash
|
|
273
171
|
* @returns {Promise<TransactionReceipt>} - Transaction reciept
|
|
274
172
|
*/
|
|
275
|
-
|
|
276
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return [2 /*return*/, store_1.default.web3Https.eth.getTransactionReceipt(txHash)];
|
|
280
|
-
});
|
|
173
|
+
getTransactionReceipt(txHash) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
this.checkIfInitialized();
|
|
176
|
+
return store_1.default.web3Https.eth.getTransactionReceipt(txHash);
|
|
281
177
|
});
|
|
282
|
-
}
|
|
178
|
+
}
|
|
283
179
|
/**
|
|
284
180
|
* Returns balance of blockchain platform tokens in wei
|
|
285
181
|
*/
|
|
286
|
-
|
|
287
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
return [2 /*return*/, TxManager_1.default.publishTransaction(transaction, transactionOptions)];
|
|
297
|
-
});
|
|
182
|
+
transfer(to, amount, transactionOptions) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
this.checkIfInitialized();
|
|
185
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
186
|
+
const transaction = {
|
|
187
|
+
to,
|
|
188
|
+
value: amount,
|
|
189
|
+
};
|
|
190
|
+
return TxManager_1.default.publishTransaction(transaction, transactionOptions);
|
|
298
191
|
});
|
|
299
|
-
}
|
|
192
|
+
}
|
|
300
193
|
/**
|
|
301
194
|
* Returns transactions count
|
|
302
195
|
* @param address - wallet address
|
|
303
196
|
* @returns {Promise<number>} - Transactions count
|
|
304
197
|
*/
|
|
305
|
-
|
|
306
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
return [2 /*return*/];
|
|
316
|
-
});
|
|
198
|
+
getTransactionCount(address, status) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
+
this.checkIfInitialized();
|
|
201
|
+
if (status) {
|
|
202
|
+
return store_1.default.web3Https.eth.getTransactionCount(address, status);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
return store_1.default.web3Https.eth.getTransactionCount(address);
|
|
206
|
+
}
|
|
317
207
|
});
|
|
318
|
-
}
|
|
319
|
-
|
|
208
|
+
}
|
|
209
|
+
getAddressByKey(pk) {
|
|
320
210
|
return new ethers_1.Wallet(pk).address;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
324
|
-
return
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
});
|
|
346
|
-
})];
|
|
211
|
+
}
|
|
212
|
+
executeBatchAsync(batch) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
var requests = batch.requests;
|
|
216
|
+
batch.requestManager.sendBatch(requests, (error, results) => {
|
|
217
|
+
if (error)
|
|
218
|
+
return reject(error);
|
|
219
|
+
results = results || [];
|
|
220
|
+
var response = requests
|
|
221
|
+
.map((request, index) => {
|
|
222
|
+
return results[index] || {};
|
|
223
|
+
})
|
|
224
|
+
.map((result, index) => {
|
|
225
|
+
if (result && result.error) {
|
|
226
|
+
return web3_core_helpers_1.errors.ErrorResponse(result);
|
|
227
|
+
}
|
|
228
|
+
if (!Jsonrpc.isValidResponse(result)) {
|
|
229
|
+
return web3_core_helpers_1.errors.InvalidResponse(result);
|
|
230
|
+
}
|
|
231
|
+
return requests[index].format ? requests[index].format(result.result) : result.result;
|
|
232
|
+
});
|
|
233
|
+
resolve(response);
|
|
234
|
+
});
|
|
347
235
|
});
|
|
348
236
|
});
|
|
349
|
-
}
|
|
237
|
+
}
|
|
350
238
|
/**
|
|
351
239
|
* Fetch transactions for specific addresses starting with specific block until last block
|
|
352
240
|
* @param addresses - array of addresses to fetch transactions (from these addresses and to these addresses)
|
|
@@ -358,88 +246,74 @@ var BlockchainConnector = /** @class */ (function (_super) {
|
|
|
358
246
|
* lastBlock, - number of last fetched block (can be used to start fetching from this block next time)
|
|
359
247
|
* }>}
|
|
360
248
|
*/
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
validAddresses.forEach(function (address) { return (transactionsByAddress[address] = []); });
|
|
390
|
-
_a.label = 2;
|
|
391
|
-
case 2:
|
|
392
|
-
if (!(startBlock <= lastBlock)) return [3 /*break*/, 4];
|
|
393
|
-
batch = new store_1.default.web3Https.eth.BatchRequest();
|
|
394
|
-
getBlock = store_1.default.web3Https.eth.getBlock;
|
|
395
|
-
batchLastBlock = Math.min(startBlock + batchSize - 1, lastBlock);
|
|
396
|
-
for (blockNumber = startBlock; blockNumber <= batchLastBlock; blockNumber++) {
|
|
397
|
-
batch.add(getBlock.request(blockNumber, true));
|
|
398
|
-
}
|
|
399
|
-
return [4 /*yield*/, this.executeBatchAsync(batch)];
|
|
400
|
-
case 3:
|
|
401
|
-
blocks = (_a.sent());
|
|
402
|
-
blocks.forEach(function (block) {
|
|
403
|
-
if (!(block === null || block === void 0 ? void 0 : block.transactions))
|
|
404
|
-
return;
|
|
405
|
-
block.transactions.forEach(function (transaction) {
|
|
406
|
-
var address = null;
|
|
407
|
-
if (validAddresses.includes(transaction.from))
|
|
408
|
-
address = transaction.from;
|
|
409
|
-
else if (transaction.to && validAddresses.includes(transaction.to))
|
|
410
|
-
address = transaction.to;
|
|
411
|
-
if (address) {
|
|
412
|
-
transactionsByAddress[address].push(__assign(__assign({}, transaction), { timestamp: +block.timestamp * 1000, input: transaction.input }));
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
startBlock = batchLastBlock + 1;
|
|
417
|
-
return [3 /*break*/, 2];
|
|
418
|
-
case 4: return [2 /*return*/, {
|
|
419
|
-
transactionsByAddress: transactionsByAddress,
|
|
420
|
-
lastBlock: lastBlock,
|
|
421
|
-
}];
|
|
249
|
+
getTransactions(addresses, startBlock, lastBlock, batchSize = constants_1.BLOCK_SIZE_TO_FETCH_TRANSACTION) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
this.checkIfInitialized();
|
|
252
|
+
const blockchainLastBlock = yield store_1.default.web3Https.eth.getBlockNumber();
|
|
253
|
+
if (lastBlock) {
|
|
254
|
+
lastBlock = Math.min(lastBlock, blockchainLastBlock);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
lastBlock = blockchainLastBlock;
|
|
258
|
+
}
|
|
259
|
+
if (!startBlock) {
|
|
260
|
+
startBlock = Math.max(lastBlock - 1000, 0);
|
|
261
|
+
}
|
|
262
|
+
const transactionsByAddress = {};
|
|
263
|
+
const validAddresses = addresses.filter((address) => { var _a; return (_a = store_1.default.web3Https) === null || _a === void 0 ? void 0 : _a.utils.isAddress(address); });
|
|
264
|
+
if (!validAddresses.length) {
|
|
265
|
+
return {
|
|
266
|
+
transactionsByAddress,
|
|
267
|
+
lastBlock,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
validAddresses.forEach((address) => (transactionsByAddress[address] = []));
|
|
271
|
+
while (startBlock <= lastBlock) {
|
|
272
|
+
const batch = new store_1.default.web3Https.eth.BatchRequest();
|
|
273
|
+
const getBlock = store_1.default.web3Https.eth.getBlock;
|
|
274
|
+
const batchLastBlock = Math.min(startBlock + batchSize - 1, lastBlock);
|
|
275
|
+
for (let blockNumber = startBlock; blockNumber <= batchLastBlock; blockNumber++) {
|
|
276
|
+
batch.add(getBlock.request(blockNumber, true));
|
|
422
277
|
}
|
|
423
|
-
|
|
278
|
+
const blocks = (yield this.executeBatchAsync(batch));
|
|
279
|
+
blocks.forEach((block) => {
|
|
280
|
+
if (!(block === null || block === void 0 ? void 0 : block.transactions))
|
|
281
|
+
return;
|
|
282
|
+
block.transactions.forEach((transaction) => {
|
|
283
|
+
let address = null;
|
|
284
|
+
if (validAddresses.includes(transaction.from))
|
|
285
|
+
address = transaction.from;
|
|
286
|
+
else if (transaction.to && validAddresses.includes(transaction.to))
|
|
287
|
+
address = transaction.to;
|
|
288
|
+
if (address) {
|
|
289
|
+
transactionsByAddress[address].push(Object.assign(Object.assign({}, transaction), { timestamp: +block.timestamp * 1000, input: transaction.input }));
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
startBlock = batchLastBlock + 1;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
transactionsByAddress,
|
|
297
|
+
lastBlock,
|
|
298
|
+
};
|
|
424
299
|
});
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
300
|
+
}
|
|
301
|
+
shutdown() {
|
|
302
|
+
super.shutdown();
|
|
428
303
|
store_1.default.web3Https = undefined;
|
|
429
304
|
Monitoring_1.Monitoring.getInstance().shutdownLogging();
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}(BaseConnector_1.BaseConnector));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
__decorate([
|
|
308
|
+
(0, utils_1.incrementMethodCall)()
|
|
309
|
+
], BlockchainConnector.prototype, "getBalance", null);
|
|
310
|
+
__decorate([
|
|
311
|
+
(0, utils_1.incrementMethodCall)()
|
|
312
|
+
], BlockchainConnector.prototype, "getTransactionEvents", null);
|
|
313
|
+
__decorate([
|
|
314
|
+
(0, utils_1.incrementMethodCall)()
|
|
315
|
+
], BlockchainConnector.prototype, "transfer", null);
|
|
316
|
+
__decorate([
|
|
317
|
+
(0, utils_1.incrementMethodCall)()
|
|
318
|
+
], BlockchainConnector.prototype, "getTransactions", null);
|
|
445
319
|
exports.default = BlockchainConnector;
|