@super-protocol/sdk-js 0.11.3-beta.0 → 0.11.6-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/models/EtlModel.d.ts +30 -0
- package/build/models/EtlModel.js +108 -0
- package/build/models/TCB.d.ts +2 -6
- package/build/models/TCB.js +7 -19
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +10 -0
- package/build/proto/Compression.d.ts +2 -1
- package/build/proto/Compression.js +7 -1
- package/build/staticModels/Consensus.d.ts +1 -1
- package/build/staticModels/Consensus.js +5 -4
- package/build/staticModels/ModelPackager.d.ts +19 -0
- package/build/staticModels/ModelPackager.js +116 -0
- package/build/types/Compressor.d.ts +5 -0
- package/build/types/Compressor.js +2 -0
- package/build/types/Consensus.d.ts +26 -0
- package/build/types/Consensus.js +10 -1
- package/build/types/EtlModel.d.ts +2 -0
- package/build/types/EtlModel.js +2 -0
- package/build/utils/NonceTracker.d.ts +14 -9
- package/build/utils/NonceTracker.js +84 -48
- package/build/utils/TxManager.d.ts +1 -7
- package/build/utils/TxManager.js +52 -104
- package/build/utils/compressors/GzipCompressor.d.ts +8 -0
- package/build/utils/compressors/GzipCompressor.js +65 -0
- package/build/utils/compressors/UncompressedCompressor.d.ts +8 -0
- package/build/utils/compressors/UncompressedCompressor.js +19 -0
- package/build/utils/compressors/index.d.ts +2 -0
- package/build/utils/compressors/index.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EtlModel as IEtlModel, EtlModelMetadata } from "@super-protocol/dto-js";
|
|
3
|
+
import { EtlModelType } from "@super-protocol/dto-js/build/enum/EtlModel.enum";
|
|
4
|
+
import { EtlModelSubtype } from "../types/EtlModel";
|
|
5
|
+
export declare class EtlModel {
|
|
6
|
+
private etlModel;
|
|
7
|
+
static logger: import("pino").default.Logger<{
|
|
8
|
+
level: string;
|
|
9
|
+
} & import("pino").default.ChildLoggerOptions>;
|
|
10
|
+
constructor(etlModel: IEtlModel);
|
|
11
|
+
/**
|
|
12
|
+
* Create instance of EtlModel from Buffer
|
|
13
|
+
*
|
|
14
|
+
* @param data - packed EtlModel
|
|
15
|
+
* @returns instance of EtlModel
|
|
16
|
+
*/
|
|
17
|
+
static unpack(data: Buffer): Promise<EtlModel>;
|
|
18
|
+
/**
|
|
19
|
+
* Packing EltModel
|
|
20
|
+
*
|
|
21
|
+
* @returns EltModel in binary format
|
|
22
|
+
*/
|
|
23
|
+
pack(): Promise<Buffer>;
|
|
24
|
+
getType(): EtlModelType;
|
|
25
|
+
setType(type: EtlModelType): void;
|
|
26
|
+
getSubtype(): EtlModelSubtype;
|
|
27
|
+
setSubtype(subtype: EtlModelSubtype | null): void;
|
|
28
|
+
getMetadata(): EtlModelMetadata | void;
|
|
29
|
+
setMetadata(metadata: EtlModelMetadata | undefined): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
exports.EtlModel = void 0;
|
|
43
|
+
var logger_1 = __importDefault(require("../logger"));
|
|
44
|
+
var ModelPackager_1 = require("../staticModels/ModelPackager");
|
|
45
|
+
var EtlModel = /** @class */ (function () {
|
|
46
|
+
function EtlModel(etlModel) {
|
|
47
|
+
this.etlModel = etlModel;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create instance of EtlModel from Buffer
|
|
51
|
+
*
|
|
52
|
+
* @param data - packed EtlModel
|
|
53
|
+
* @returns instance of EtlModel
|
|
54
|
+
*/
|
|
55
|
+
EtlModel.unpack = function (data) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var etlModel, error_1;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
_a.trys.push([0, 2, , 3]);
|
|
62
|
+
return [4 /*yield*/, ModelPackager_1.ModelPackager.unpack(data)];
|
|
63
|
+
case 1:
|
|
64
|
+
etlModel = _a.sent();
|
|
65
|
+
return [2 /*return*/, new EtlModel(etlModel)];
|
|
66
|
+
case 2:
|
|
67
|
+
error_1 = _a.sent();
|
|
68
|
+
EtlModel.logger.error("Unable to unpack EtlModel");
|
|
69
|
+
throw error_1;
|
|
70
|
+
case 3: return [2 /*return*/];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Packing EltModel
|
|
77
|
+
*
|
|
78
|
+
* @returns EltModel in binary format
|
|
79
|
+
*/
|
|
80
|
+
EtlModel.prototype.pack = function () {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
return [2 /*return*/, ModelPackager_1.ModelPackager.pack(this.etlModel)];
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
EtlModel.prototype.getType = function () {
|
|
88
|
+
return this.etlModel.type;
|
|
89
|
+
};
|
|
90
|
+
EtlModel.prototype.setType = function (type) {
|
|
91
|
+
this.etlModel.type = type;
|
|
92
|
+
};
|
|
93
|
+
EtlModel.prototype.getSubtype = function () {
|
|
94
|
+
return this.etlModel.subtype;
|
|
95
|
+
};
|
|
96
|
+
EtlModel.prototype.setSubtype = function (subtype) {
|
|
97
|
+
this.etlModel.subtype = subtype;
|
|
98
|
+
};
|
|
99
|
+
EtlModel.prototype.getMetadata = function () {
|
|
100
|
+
return this.etlModel.metadata;
|
|
101
|
+
};
|
|
102
|
+
EtlModel.prototype.setMetadata = function (metadata) {
|
|
103
|
+
this.etlModel.metadata = metadata;
|
|
104
|
+
};
|
|
105
|
+
EtlModel.logger = logger_1.default.child({ name: EtlModel.name });
|
|
106
|
+
return EtlModel;
|
|
107
|
+
}());
|
|
108
|
+
exports.EtlModel = EtlModel;
|
package/build/models/TCB.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransactionOptions } from "../types/Web3";
|
|
2
|
-
import { TcbStatus, PublicData, TcbEpochInfo, TcbVerifiedStatus } from "../types/Consensus";
|
|
2
|
+
import { TcbData, TcbStatus, PublicData, TcbEpochInfo, TcbVerifiedStatus } from "../types/Consensus";
|
|
3
3
|
declare class TCB {
|
|
4
4
|
tcbId: string;
|
|
5
5
|
private contract;
|
|
@@ -42,7 +42,7 @@ declare class TCB {
|
|
|
42
42
|
/**
|
|
43
43
|
* Function for fetching all TCB data
|
|
44
44
|
*/
|
|
45
|
-
get(): Promise<
|
|
45
|
+
get(): Promise<TcbData>;
|
|
46
46
|
/**
|
|
47
47
|
* Function for fetching the given marks for recruited TCBs from the Tables of Consensus
|
|
48
48
|
*/
|
|
@@ -50,10 +50,6 @@ declare class TCB {
|
|
|
50
50
|
blocksIds: string[];
|
|
51
51
|
marks: TcbVerifiedStatus[];
|
|
52
52
|
}>;
|
|
53
|
-
/**
|
|
54
|
-
* Function for fetching used TCB data
|
|
55
|
-
*/
|
|
56
|
-
getPublicData(): Promise<PublicData>;
|
|
57
53
|
/**
|
|
58
54
|
* Function for fetching TCB status
|
|
59
55
|
*/
|
package/build/models/TCB.js
CHANGED
|
@@ -199,8 +199,14 @@ var TCB = /** @class */ (function () {
|
|
|
199
199
|
*/
|
|
200
200
|
TCB.prototype.get = function () {
|
|
201
201
|
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
+
var tcb;
|
|
202
203
|
return __generator(this, function (_a) {
|
|
203
|
-
|
|
204
|
+
switch (_a.label) {
|
|
205
|
+
case 0: return [4 /*yield*/, this.contract.methods.getTcbById(this.tcbId).call()];
|
|
206
|
+
case 1:
|
|
207
|
+
tcb = _a.sent();
|
|
208
|
+
return [2 /*return*/, (0, utils_1.tupleToObject)(tcb, Consensus_1.TcbStructure)];
|
|
209
|
+
}
|
|
204
210
|
});
|
|
205
211
|
});
|
|
206
212
|
};
|
|
@@ -223,24 +229,6 @@ var TCB = /** @class */ (function () {
|
|
|
223
229
|
});
|
|
224
230
|
});
|
|
225
231
|
};
|
|
226
|
-
/**
|
|
227
|
-
* Function for fetching used TCB data
|
|
228
|
-
*/
|
|
229
|
-
TCB.prototype.getPublicData = function () {
|
|
230
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
-
var publicDataParams, publicData;
|
|
232
|
-
return __generator(this, function (_a) {
|
|
233
|
-
switch (_a.label) {
|
|
234
|
-
case 0: return [4 /*yield*/, this.contract.methods.getPublicData().call()];
|
|
235
|
-
case 1:
|
|
236
|
-
publicDataParams = _a.sent();
|
|
237
|
-
publicData = (0, utils_1.tupleToObject)(publicDataParams, Consensus_1.PublicDataStructure);
|
|
238
|
-
publicData.deviceID = Buffer.from((0, utils_2.parseBytes32String)(publicData.deviceID), "base64").toString("hex");
|
|
239
|
-
return [2 /*return*/, publicData];
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
232
|
/**
|
|
245
233
|
* Function for fetching TCB status
|
|
246
234
|
*/
|
package/build/models/TeeOffer.js
CHANGED
|
@@ -153,6 +153,16 @@ var TeeOffer = /** @class */ (function () {
|
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
};
|
|
156
|
+
TeeOffer.prototype.isTeeOfferVerifying = function () {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
return __generator(this, function (_a) {
|
|
159
|
+
switch (_a.label) {
|
|
160
|
+
case 0: return [4 /*yield*/, TeeOffer.contract.methods.isTeeOfferVerifying(this.id).call()];
|
|
161
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
156
166
|
/**
|
|
157
167
|
* Function for fetching offer provider from blockchain
|
|
158
168
|
*/
|
|
@@ -5,7 +5,8 @@ export interface Compression {
|
|
|
5
5
|
data: Uint8Array;
|
|
6
6
|
}
|
|
7
7
|
export declare enum Compression_TYPE {
|
|
8
|
-
|
|
8
|
+
Uncompressed = 0,
|
|
9
|
+
GZIP = 1
|
|
9
10
|
}
|
|
10
11
|
export declare function compression_TYPEFromJSON(object: any): Compression_TYPE;
|
|
11
12
|
export declare function compression_TYPEToJSON(object: Compression_TYPE): string;
|
|
@@ -9,11 +9,15 @@ var minimal_1 = __importDefault(require("protobufjs/minimal"));
|
|
|
9
9
|
exports.protobufPackage = "";
|
|
10
10
|
var Compression_TYPE;
|
|
11
11
|
(function (Compression_TYPE) {
|
|
12
|
-
Compression_TYPE[Compression_TYPE["
|
|
12
|
+
Compression_TYPE[Compression_TYPE["Uncompressed"] = 0] = "Uncompressed";
|
|
13
|
+
Compression_TYPE[Compression_TYPE["GZIP"] = 1] = "GZIP";
|
|
13
14
|
})(Compression_TYPE = exports.Compression_TYPE || (exports.Compression_TYPE = {}));
|
|
14
15
|
function compression_TYPEFromJSON(object) {
|
|
15
16
|
switch (object) {
|
|
16
17
|
case 0:
|
|
18
|
+
case "Uncompressed":
|
|
19
|
+
return Compression_TYPE.Uncompressed;
|
|
20
|
+
case 1:
|
|
17
21
|
case "GZIP":
|
|
18
22
|
return Compression_TYPE.GZIP;
|
|
19
23
|
default:
|
|
@@ -23,6 +27,8 @@ function compression_TYPEFromJSON(object) {
|
|
|
23
27
|
exports.compression_TYPEFromJSON = compression_TYPEFromJSON;
|
|
24
28
|
function compression_TYPEToJSON(object) {
|
|
25
29
|
switch (object) {
|
|
30
|
+
case Compression_TYPE.Uncompressed:
|
|
31
|
+
return "Uncompressed";
|
|
26
32
|
case Compression_TYPE.GZIP:
|
|
27
33
|
return "GZIP";
|
|
28
34
|
default:
|
|
@@ -10,7 +10,7 @@ declare class Consensus {
|
|
|
10
10
|
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
11
11
|
* @returns tcbId and lists of anothers' TCB for their checking
|
|
12
12
|
*/
|
|
13
|
-
static getListsForVerification(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<{
|
|
13
|
+
static getListsForVerification(teeOfferId: string, initializeTcbForce?: boolean, transactionOptions?: TransactionOptions): Promise<{
|
|
14
14
|
tcbId: string;
|
|
15
15
|
checkingTcbData: CheckingTcbData[];
|
|
16
16
|
}>;
|
|
@@ -55,7 +55,7 @@ var Consensus = /** @class */ (function () {
|
|
|
55
55
|
enumerable: false,
|
|
56
56
|
configurable: true
|
|
57
57
|
});
|
|
58
|
-
Consensus.initializeTcbAndAssignBlocks = function (teeOfferId, transactionOptions) {
|
|
58
|
+
Consensus.initializeTcbAndAssignBlocks = function (teeOfferId, initializeTcbForce, transactionOptions) {
|
|
59
59
|
return __awaiter(this, void 0, void 0, function () {
|
|
60
60
|
var tcbId, tcb, timeInitialized, isFirstOffersTcb, isCreatedMoreThenOneDayAgo, _a;
|
|
61
61
|
return __generator(this, function (_b) {
|
|
@@ -72,7 +72,7 @@ var Consensus = /** @class */ (function () {
|
|
|
72
72
|
return [4 /*yield*/, (0, utils_1.getTimestamp)()];
|
|
73
73
|
case 3:
|
|
74
74
|
isCreatedMoreThenOneDayAgo = _a < +(_b.sent());
|
|
75
|
-
if (!(isFirstOffersTcb || isCreatedMoreThenOneDayAgo)) return [3 /*break*/, 8];
|
|
75
|
+
if (!(isFirstOffersTcb || isCreatedMoreThenOneDayAgo || initializeTcbForce)) return [3 /*break*/, 8];
|
|
76
76
|
return [4 /*yield*/, this.initializeTcb(teeOfferId, transactionOptions)];
|
|
77
77
|
case 4:
|
|
78
78
|
_b.sent();
|
|
@@ -114,14 +114,15 @@ var Consensus = /** @class */ (function () {
|
|
|
114
114
|
* @param transactionOptions - object what contains alternative action account or gas limit (optional)
|
|
115
115
|
* @returns tcbId and lists of anothers' TCB for their checking
|
|
116
116
|
*/
|
|
117
|
-
Consensus.getListsForVerification = function (teeOfferId, transactionOptions) {
|
|
117
|
+
Consensus.getListsForVerification = function (teeOfferId, initializeTcbForce, transactionOptions) {
|
|
118
|
+
if (initializeTcbForce === void 0) { initializeTcbForce = false; }
|
|
118
119
|
return __awaiter(this, void 0, void 0, function () {
|
|
119
120
|
var tcb, blocksIds, checkingTcbData, blockIndex, tcb_1, tcbInfo;
|
|
120
121
|
return __generator(this, function (_a) {
|
|
121
122
|
switch (_a.label) {
|
|
122
123
|
case 0:
|
|
123
124
|
(0, utils_1.checkIfActionAccountInitialized)();
|
|
124
|
-
return [4 /*yield*/, this.initializeTcbAndAssignBlocks(teeOfferId, transactionOptions)];
|
|
125
|
+
return [4 /*yield*/, this.initializeTcbAndAssignBlocks(teeOfferId, initializeTcbForce, transactionOptions)];
|
|
125
126
|
case 1:
|
|
126
127
|
tcb = _a.sent();
|
|
127
128
|
return [4 /*yield*/, tcb.getCheckingBlocksMarks()];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class ModelPackager {
|
|
3
|
+
private static readonly logger;
|
|
4
|
+
private static compressors;
|
|
5
|
+
/**
|
|
6
|
+
* Compressing message with best algorithm
|
|
7
|
+
*
|
|
8
|
+
* @param message - message
|
|
9
|
+
* @returns Compressed message in bytes representation
|
|
10
|
+
*/
|
|
11
|
+
static pack<T = unknown>(message: T): Promise<Buffer>;
|
|
12
|
+
/**
|
|
13
|
+
* Uncompressing message
|
|
14
|
+
*
|
|
15
|
+
* @param message - message with bytes representation
|
|
16
|
+
* @returns original message
|
|
17
|
+
*/
|
|
18
|
+
static unpack<T = unknown>(message: Buffer): Promise<T>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
exports.ModelPackager = void 0;
|
|
43
|
+
var logger_1 = __importDefault(require("../logger"));
|
|
44
|
+
var Compression_1 = require("../proto/Compression");
|
|
45
|
+
var compressors_1 = require("../utils/compressors");
|
|
46
|
+
var ModelPackager = /** @class */ (function () {
|
|
47
|
+
function ModelPackager() {
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compressing message with best algorithm
|
|
51
|
+
*
|
|
52
|
+
* @param message - message
|
|
53
|
+
* @returns Compressed message in bytes representation
|
|
54
|
+
*/
|
|
55
|
+
ModelPackager.pack = function (message) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var promises, options, minimal, encoded;
|
|
58
|
+
var _this = this;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
promises = ModelPackager.compressors.map(function (Compressor) { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
var compressorInstance, data;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
compressorInstance = new Compressor();
|
|
68
|
+
return [4 /*yield*/, compressorInstance.compress(message)];
|
|
69
|
+
case 1:
|
|
70
|
+
data = _a.sent();
|
|
71
|
+
return [2 /*return*/, {
|
|
72
|
+
compressionType: Compressor.type,
|
|
73
|
+
data: data,
|
|
74
|
+
size: data.byteLength,
|
|
75
|
+
}];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}); });
|
|
79
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
80
|
+
case 1:
|
|
81
|
+
options = _a.sent();
|
|
82
|
+
options.sort(function (first, second) { return first.size - second.size; });
|
|
83
|
+
minimal = options[0];
|
|
84
|
+
encoded = Compression_1.Compression.encode({
|
|
85
|
+
type: minimal.compressionType,
|
|
86
|
+
data: minimal.data,
|
|
87
|
+
}).finish();
|
|
88
|
+
return [2 /*return*/, Buffer.from(encoded)];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Uncompressing message
|
|
95
|
+
*
|
|
96
|
+
* @param message - message with bytes representation
|
|
97
|
+
* @returns original message
|
|
98
|
+
*/
|
|
99
|
+
ModelPackager.unpack = function (message) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
var decoded, Compressor;
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
decoded = Compression_1.Compression.decode(message);
|
|
104
|
+
Compressor = ModelPackager.compressors.find(function (CompressorClass) { return CompressorClass.type === decoded.type; });
|
|
105
|
+
if (!Compressor) {
|
|
106
|
+
throw new Error("Cannot unpack message. Compressor ".concat(decoded.type, " isn't supported"));
|
|
107
|
+
}
|
|
108
|
+
return [2 /*return*/, new Compressor().decompress(Buffer.from(decoded.data))];
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
ModelPackager.logger = logger_1.default.child({ className: ModelPackager.name });
|
|
113
|
+
ModelPackager.compressors = [compressors_1.GzipCompressor, compressors_1.UncompressedCompressor];
|
|
114
|
+
return ModelPackager;
|
|
115
|
+
}());
|
|
116
|
+
exports.ModelPackager = ModelPackager;
|
|
@@ -46,6 +46,32 @@ export declare type TcbEpochInfo = {
|
|
|
46
46
|
index: number;
|
|
47
47
|
valid: boolean;
|
|
48
48
|
};
|
|
49
|
+
export declare const TcbStructure: {
|
|
50
|
+
quote: StringConstructor;
|
|
51
|
+
timeInitialized: NumberConstructor;
|
|
52
|
+
timeAdded: NumberConstructor;
|
|
53
|
+
publicData: {
|
|
54
|
+
teeOffer: StringConstructor;
|
|
55
|
+
deviceID: StringConstructor;
|
|
56
|
+
benchmark: NumberConstructor;
|
|
57
|
+
properties: StringConstructor;
|
|
58
|
+
};
|
|
59
|
+
utilData: {};
|
|
60
|
+
status: typeof TcbStatus;
|
|
61
|
+
epoch: {
|
|
62
|
+
index: NumberConstructor;
|
|
63
|
+
valid: BooleanConstructor;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export declare type TcbData = {
|
|
67
|
+
quote: string;
|
|
68
|
+
timeInitialized: number;
|
|
69
|
+
timeAdded: number;
|
|
70
|
+
publicData: PublicData;
|
|
71
|
+
utilData: any;
|
|
72
|
+
status: TcbStatus;
|
|
73
|
+
epoch: TcbEpochInfo;
|
|
74
|
+
};
|
|
49
75
|
export declare type EpochInfo = {
|
|
50
76
|
startDate: number;
|
|
51
77
|
endDate: number;
|
package/build/types/Consensus.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TcbEpochInfoStructure = exports.TcbStatus = exports.EpochStructure = exports.PublicDataStructure = exports.TcbVerifiedStatus = void 0;
|
|
3
|
+
exports.TcbStructure = exports.TcbEpochInfoStructure = exports.TcbStatus = exports.EpochStructure = exports.PublicDataStructure = exports.TcbVerifiedStatus = void 0;
|
|
4
4
|
var TcbVerifiedStatus;
|
|
5
5
|
(function (TcbVerifiedStatus) {
|
|
6
6
|
TcbVerifiedStatus["Valid"] = "0";
|
|
@@ -36,3 +36,12 @@ exports.TcbEpochInfoStructure = {
|
|
|
36
36
|
index: Number,
|
|
37
37
|
valid: Boolean,
|
|
38
38
|
};
|
|
39
|
+
exports.TcbStructure = {
|
|
40
|
+
quote: String,
|
|
41
|
+
timeInitialized: Number,
|
|
42
|
+
timeAdded: Number,
|
|
43
|
+
publicData: exports.PublicDataStructure,
|
|
44
|
+
utilData: {},
|
|
45
|
+
status: TcbStatus,
|
|
46
|
+
epoch: exports.TcbEpochInfoStructure,
|
|
47
|
+
};
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import Web3 from "web3";
|
|
2
2
|
declare class NonceTracker {
|
|
3
3
|
private web3;
|
|
4
|
-
private
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
getNonce(
|
|
12
|
-
consumeNonce(
|
|
4
|
+
private address;
|
|
5
|
+
private logger;
|
|
6
|
+
private txCount?;
|
|
7
|
+
private transactionsOnHold;
|
|
8
|
+
private countOfPendingTransactions;
|
|
9
|
+
constructor(web3: Web3, address: string);
|
|
10
|
+
initAccount(): Promise<void>;
|
|
11
|
+
getNonce(): number;
|
|
12
|
+
consumeNonce(): number;
|
|
13
|
+
onTransactionStartPublishing(): Promise<void>;
|
|
14
|
+
onTransactionPublished(): void;
|
|
15
|
+
onTransactionError(): Promise<void>;
|
|
16
|
+
private waitForPendingTransactions;
|
|
17
|
+
private sendHoldTransactions;
|
|
13
18
|
}
|
|
14
19
|
export default NonceTracker;
|
|
@@ -41,79 +41,115 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
var logger_1 = __importDefault(require("../logger"));
|
|
43
43
|
var NonceTracker = /** @class */ (function () {
|
|
44
|
-
function NonceTracker(web3) {
|
|
44
|
+
function NonceTracker(web3, address) {
|
|
45
45
|
this.web3 = web3;
|
|
46
|
-
this.
|
|
47
|
-
|
|
46
|
+
this.address = address;
|
|
47
|
+
this.countOfPendingTransactions = 0;
|
|
48
|
+
this.logger = logger_1.default.child({ className: "NonceTracker", address: address });
|
|
49
|
+
this.logger.trace("Created NonceTracker");
|
|
48
50
|
}
|
|
49
|
-
NonceTracker.prototype.initAccount = function (
|
|
51
|
+
NonceTracker.prototype.initAccount = function () {
|
|
50
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var
|
|
52
|
-
return __generator(this, function (
|
|
53
|
-
switch (
|
|
53
|
+
var _a;
|
|
54
|
+
return __generator(this, function (_b) {
|
|
55
|
+
switch (_b.label) {
|
|
54
56
|
case 0:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
return [4 /*yield*/, this.web3.eth.getTransactionCount(address)];
|
|
57
|
+
_a = this;
|
|
58
|
+
return [4 /*yield*/, this.web3.eth.getTransactionCount(this.address)];
|
|
59
59
|
case 1:
|
|
60
|
-
txCount =
|
|
61
|
-
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
}
|
|
64
|
-
NonceTracker.logger.trace("Initialized ".concat(address, " account with nonce: ").concat(txCount));
|
|
65
|
-
this.store[address] = txCount;
|
|
60
|
+
_a.txCount = _b.sent();
|
|
61
|
+
this.logger.trace("Initialized ".concat(this.address, " account with nonce: ").concat(this.txCount));
|
|
66
62
|
return [2 /*return*/];
|
|
67
63
|
}
|
|
68
64
|
});
|
|
69
65
|
});
|
|
70
66
|
};
|
|
71
|
-
NonceTracker.prototype.
|
|
72
|
-
|
|
67
|
+
NonceTracker.prototype.getNonce = function () {
|
|
68
|
+
if (this.txCount === undefined)
|
|
69
|
+
throw Error("NonceTracker for address ".concat(this.address, " is not initialized"));
|
|
70
|
+
this.logger.trace("Get nonce: ".concat(this.txCount));
|
|
71
|
+
return this.txCount;
|
|
73
72
|
};
|
|
74
|
-
NonceTracker.prototype.
|
|
73
|
+
NonceTracker.prototype.consumeNonce = function () {
|
|
74
|
+
if (this.txCount === undefined)
|
|
75
|
+
throw Error("NonceTracker for address ".concat(this.address, " is not initialized"));
|
|
76
|
+
this.logger.trace("Consume nonce: ".concat(this.txCount + 1));
|
|
77
|
+
return this.txCount++;
|
|
78
|
+
};
|
|
79
|
+
NonceTracker.prototype.onTransactionStartPublishing = function () {
|
|
75
80
|
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var _this = this;
|
|
77
81
|
return __generator(this, function (_a) {
|
|
78
82
|
switch (_a.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
switch (_a.label) {
|
|
83
|
-
case 0: return [4 /*yield*/, this.web3.eth.getTransactionCount(address)];
|
|
84
|
-
case 1:
|
|
85
|
-
txCount = _a.sent();
|
|
86
|
-
NonceTracker.logger.trace("Account ".concat(address, " has been reinitialized with nonce: ").concat(txCount));
|
|
87
|
-
this.store[address] = txCount;
|
|
88
|
-
return [2 /*return*/];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}); }))];
|
|
83
|
+
case 0:
|
|
84
|
+
if (!this.transactionsOnHold) return [3 /*break*/, 2];
|
|
85
|
+
return [4 /*yield*/, this.waitForPendingTransactions()];
|
|
92
86
|
case 1:
|
|
93
87
|
_a.sent();
|
|
94
|
-
|
|
88
|
+
_a.label = 2;
|
|
89
|
+
case 2:
|
|
90
|
+
this.countOfPendingTransactions++;
|
|
95
91
|
return [2 /*return*/];
|
|
96
92
|
}
|
|
97
93
|
});
|
|
98
94
|
});
|
|
99
95
|
};
|
|
100
|
-
NonceTracker.prototype.
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
NonceTracker.prototype.onTransactionPublished = function () {
|
|
97
|
+
this.countOfPendingTransactions--;
|
|
98
|
+
if (this.countOfPendingTransactions === 0) {
|
|
99
|
+
this.sendHoldTransactions();
|
|
103
100
|
}
|
|
104
|
-
throw Error("".concat(address, " account is not initialized. You must call initAccount before using it."));
|
|
105
101
|
};
|
|
106
|
-
NonceTracker.prototype.
|
|
107
|
-
this
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
NonceTracker.prototype.onTransactionError = function () {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
switch (_a.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
this.countOfPendingTransactions--;
|
|
108
|
+
if (!this.transactionsOnHold)
|
|
109
|
+
this.transactionsOnHold = [];
|
|
110
|
+
if (!(this.countOfPendingTransactions === 0)) return [3 /*break*/, 1];
|
|
111
|
+
this.sendHoldTransactions();
|
|
112
|
+
return [3 /*break*/, 3];
|
|
113
|
+
case 1: return [4 /*yield*/, this.waitForPendingTransactions()];
|
|
114
|
+
case 2:
|
|
115
|
+
_a.sent();
|
|
116
|
+
_a.label = 3;
|
|
117
|
+
case 3: return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
NonceTracker.prototype.waitForPendingTransactions = function () {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var _this = this;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
127
|
+
if (!_this.transactionsOnHold)
|
|
128
|
+
return resolve();
|
|
129
|
+
_this.transactionsOnHold.push(function () {
|
|
130
|
+
resolve();
|
|
131
|
+
});
|
|
132
|
+
})];
|
|
133
|
+
});
|
|
134
|
+
});
|
|
110
135
|
};
|
|
111
|
-
NonceTracker.prototype.
|
|
112
|
-
this
|
|
113
|
-
|
|
114
|
-
|
|
136
|
+
NonceTracker.prototype.sendHoldTransactions = function () {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
+
return __generator(this, function (_a) {
|
|
139
|
+
switch (_a.label) {
|
|
140
|
+
case 0:
|
|
141
|
+
if (!this.transactionsOnHold)
|
|
142
|
+
return [2 /*return*/];
|
|
143
|
+
return [4 /*yield*/, this.initAccount()];
|
|
144
|
+
case 1:
|
|
145
|
+
_a.sent();
|
|
146
|
+
this.transactionsOnHold.forEach(function (callback) { return callback(); });
|
|
147
|
+
this.transactionsOnHold = undefined;
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
115
152
|
};
|
|
116
|
-
NonceTracker.logger = logger_1.default.child({ className: "NonceTracker" });
|
|
117
153
|
return NonceTracker;
|
|
118
154
|
}());
|
|
119
155
|
exports.default = NonceTracker;
|
|
@@ -10,18 +10,12 @@ declare type MethodReturnType = ContractSendMethod & {
|
|
|
10
10
|
};
|
|
11
11
|
declare class TxManager {
|
|
12
12
|
private static web3;
|
|
13
|
-
private static nonceTracker;
|
|
14
13
|
private static logger;
|
|
15
|
-
private static
|
|
16
|
-
private static countOfPendingTransactions;
|
|
14
|
+
private static nonceTrackers;
|
|
17
15
|
static init(web3: Web3): void;
|
|
18
16
|
private static checkIfInitialized;
|
|
19
17
|
static initAccount(address: string): Promise<void>;
|
|
20
18
|
static execute(method: (...args: ArgumentsType) => MethodReturnType, args: ArgumentsType, transactionOptions?: TransactionOptions, to?: string): Promise<TransactionReceipt>;
|
|
21
19
|
static publishTransaction(txData: Record<string, any>, transactionOptions?: TransactionOptions, transactionCall?: MethodReturnType): Promise<TransactionReceipt>;
|
|
22
|
-
private static onStartPublishing;
|
|
23
|
-
private static onError;
|
|
24
|
-
private static onFinishPublishing;
|
|
25
|
-
private static waitForPendingTransactions;
|
|
26
20
|
}
|
|
27
21
|
export default TxManager;
|
package/build/utils/TxManager.js
CHANGED
|
@@ -62,7 +62,6 @@ var TxManager = /** @class */ (function () {
|
|
|
62
62
|
}
|
|
63
63
|
TxManager.init = function (web3) {
|
|
64
64
|
this.web3 = web3;
|
|
65
|
-
this.nonceTracker = new NonceTracker_1.default(web3);
|
|
66
65
|
};
|
|
67
66
|
TxManager.checkIfInitialized = function () {
|
|
68
67
|
if (!this.web3) {
|
|
@@ -72,7 +71,16 @@ var TxManager = /** @class */ (function () {
|
|
|
72
71
|
TxManager.initAccount = function (address) {
|
|
73
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
74
73
|
return __generator(this, function (_a) {
|
|
75
|
-
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
if (this.nonceTrackers[address])
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
this.nonceTrackers[address] = new NonceTracker_1.default(this.web3, address);
|
|
79
|
+
return [4 /*yield*/, this.nonceTrackers[address].initAccount()];
|
|
80
|
+
case 1:
|
|
81
|
+
_a.sent();
|
|
82
|
+
return [2 /*return*/];
|
|
83
|
+
}
|
|
76
84
|
});
|
|
77
85
|
});
|
|
78
86
|
};
|
|
@@ -92,55 +100,55 @@ var TxManager = /** @class */ (function () {
|
|
|
92
100
|
};
|
|
93
101
|
TxManager.publishTransaction = function (txData, transactionOptions, transactionCall) {
|
|
94
102
|
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
-
var web3, options, estimatedGas, e_1,
|
|
103
|
+
var web3, options, estimatedGas, e_1, nonceTracker, signingKey, transactionResultData, signed, e_2;
|
|
96
104
|
return __generator(this, function (_a) {
|
|
97
105
|
switch (_a.label) {
|
|
98
106
|
case 0:
|
|
99
107
|
this.checkIfInitialized();
|
|
100
108
|
(0, utils_1.checkIfInitialized)();
|
|
101
109
|
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
102
|
-
return [4 /*yield*/, this.onStartPublishing()];
|
|
103
|
-
case 1:
|
|
104
|
-
_a.sent();
|
|
105
110
|
web3 = (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) || this.web3;
|
|
106
111
|
return [4 /*yield*/, (0, utils_1.createTransactionOptions)(__assign({}, transactionOptions))];
|
|
107
|
-
case
|
|
112
|
+
case 1:
|
|
108
113
|
options = _a.sent();
|
|
109
114
|
if (!options.from) {
|
|
110
115
|
throw Error("From account is undefined. You should pass it to transactionOptions or init action account.");
|
|
111
116
|
}
|
|
112
117
|
txData = __assign(__assign({}, options), txData);
|
|
113
|
-
if (!transactionCall) return [3 /*break*/,
|
|
118
|
+
if (!transactionCall) return [3 /*break*/, 6];
|
|
114
119
|
estimatedGas = void 0;
|
|
115
|
-
_a.label =
|
|
116
|
-
case
|
|
117
|
-
_a.trys.push([
|
|
120
|
+
_a.label = 2;
|
|
121
|
+
case 2:
|
|
122
|
+
_a.trys.push([2, 4, , 5]);
|
|
118
123
|
return [4 /*yield*/, transactionCall.estimateGas(txData)];
|
|
119
|
-
case
|
|
124
|
+
case 3:
|
|
120
125
|
estimatedGas = _a.sent();
|
|
121
|
-
return [3 /*break*/,
|
|
122
|
-
case
|
|
126
|
+
return [3 /*break*/, 5];
|
|
127
|
+
case 4:
|
|
123
128
|
e_1 = _a.sent();
|
|
124
129
|
TxManager.logger.debug({ error: e_1 }, "Fail to calculate estimated gas");
|
|
125
130
|
estimatedGas = constants_1.defaultGasLimit;
|
|
126
|
-
return [3 /*break*/,
|
|
127
|
-
case
|
|
131
|
+
return [3 /*break*/, 5];
|
|
132
|
+
case 5:
|
|
128
133
|
txData.gas = Math.ceil(estimatedGas * store_1.default.gasLimitMultiplier);
|
|
129
|
-
_a.label =
|
|
134
|
+
_a.label = 6;
|
|
135
|
+
case 6:
|
|
136
|
+
if (!(!(0, utils_1.checkForUsingExternalTxManager)(transactionOptions) && this.nonceTrackers[options.from])) return [3 /*break*/, 8];
|
|
137
|
+
nonceTracker = this.nonceTrackers[options.from];
|
|
138
|
+
return [4 /*yield*/, nonceTracker.onTransactionStartPublishing()];
|
|
130
139
|
case 7:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (this.nonceTracker.isManaged(options.from)) {
|
|
134
|
-
txData.nonce = this.nonceTracker.consumeNonce(options.from);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
signingKey = store_1.default.keys[options.from];
|
|
140
|
+
_a.sent();
|
|
141
|
+
txData.nonce = nonceTracker.consumeNonce();
|
|
138
142
|
_a.label = 8;
|
|
139
143
|
case 8:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return [4 /*yield*/, web3.eth.accounts.signTransaction(txData, signingKey)];
|
|
144
|
+
signingKey = store_1.default.keys[options.from];
|
|
145
|
+
_a.label = 9;
|
|
143
146
|
case 9:
|
|
147
|
+
_a.trys.push([9, 15, , 18]);
|
|
148
|
+
transactionResultData = void 0;
|
|
149
|
+
if (!signingKey) return [3 /*break*/, 12];
|
|
150
|
+
return [4 /*yield*/, web3.eth.accounts.signTransaction(txData, signingKey)];
|
|
151
|
+
case 10:
|
|
144
152
|
signed = _a.sent();
|
|
145
153
|
if (!signed.rawTransaction) {
|
|
146
154
|
throw new Error("Failed to sign transaction");
|
|
@@ -150,97 +158,37 @@ var TxManager = /** @class */ (function () {
|
|
|
150
158
|
txData: lodash_1.default.omit(txData, ["data"]),
|
|
151
159
|
}, "Publishing signed transaction");
|
|
152
160
|
return [4 /*yield*/, web3.eth.sendSignedTransaction(signed.rawTransaction)];
|
|
153
|
-
case 10:
|
|
154
|
-
data = _a.sent();
|
|
155
|
-
this.onFinishPublishing();
|
|
156
|
-
return [2 /*return*/, data];
|
|
157
161
|
case 11:
|
|
162
|
+
transactionResultData = _a.sent();
|
|
163
|
+
return [3 /*break*/, 14];
|
|
164
|
+
case 12:
|
|
158
165
|
TxManager.logger.debug({
|
|
159
166
|
txData: lodash_1.default.omit(txData, ["data"]),
|
|
160
167
|
}, "Publishing unsigned transaction");
|
|
161
168
|
return [4 /*yield*/, web3.eth.sendTransaction(txData)];
|
|
162
|
-
case
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return [2 /*return*/, data];
|
|
166
|
-
case 13: return [3 /*break*/, 16];
|
|
169
|
+
case 13:
|
|
170
|
+
transactionResultData = _a.sent();
|
|
171
|
+
_a.label = 14;
|
|
167
172
|
case 14:
|
|
173
|
+
if (nonceTracker)
|
|
174
|
+
nonceTracker.onTransactionPublished();
|
|
175
|
+
return [2 /*return*/, transactionResultData];
|
|
176
|
+
case 15:
|
|
168
177
|
e_2 = _a.sent();
|
|
169
178
|
TxManager.logger.error(e_2, "Error during transaction execution");
|
|
170
|
-
return [
|
|
171
|
-
|
|
179
|
+
if (!nonceTracker) return [3 /*break*/, 17];
|
|
180
|
+
return [4 /*yield*/, nonceTracker.onTransactionError()];
|
|
181
|
+
case 16:
|
|
172
182
|
_a.sent();
|
|
173
|
-
|
|
174
|
-
case
|
|
175
|
-
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
TxManager.onStartPublishing = function () {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
-
return __generator(this, function (_a) {
|
|
182
|
-
switch (_a.label) {
|
|
183
|
-
case 0:
|
|
184
|
-
this.countOfPendingTransactions++;
|
|
185
|
-
if (!this.transactionsOnHold)
|
|
186
|
-
return [2 /*return*/];
|
|
187
|
-
return [4 /*yield*/, this.waitForPendingTransactions()];
|
|
188
|
-
case 1:
|
|
189
|
-
_a.sent();
|
|
190
|
-
return [2 /*return*/];
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
TxManager.onError = function () {
|
|
196
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
-
return __generator(this, function (_a) {
|
|
198
|
-
switch (_a.label) {
|
|
199
|
-
case 0:
|
|
200
|
-
this.countOfPendingTransactions--;
|
|
201
|
-
if (this.countOfPendingTransactions === 0)
|
|
202
|
-
return [2 /*return*/];
|
|
203
|
-
this.transactionsOnHold = [];
|
|
204
|
-
return [4 /*yield*/, this.waitForPendingTransactions()];
|
|
205
|
-
case 1:
|
|
206
|
-
_a.sent();
|
|
207
|
-
return [2 /*return*/];
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
TxManager.onFinishPublishing = function () {
|
|
213
|
-
var _this = this;
|
|
214
|
-
this.countOfPendingTransactions--;
|
|
215
|
-
if (this.countOfPendingTransactions === 0 && this.transactionsOnHold) {
|
|
216
|
-
this.nonceTracker.reinitialize().then(function () {
|
|
217
|
-
var _a;
|
|
218
|
-
(_a = _this.transactionsOnHold) === null || _a === void 0 ? void 0 : _a.forEach(function (callback) { return callback(); });
|
|
219
|
-
_this.transactionsOnHold = undefined;
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
TxManager.waitForPendingTransactions = function () {
|
|
224
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
var _this = this;
|
|
226
|
-
return __generator(this, function (_a) {
|
|
227
|
-
switch (_a.label) {
|
|
228
|
-
case 0: return [4 /*yield*/, new Promise(function (resolve) {
|
|
229
|
-
if (!_this.transactionsOnHold)
|
|
230
|
-
return resolve();
|
|
231
|
-
_this.transactionsOnHold.push(function () {
|
|
232
|
-
resolve();
|
|
233
|
-
});
|
|
234
|
-
})];
|
|
235
|
-
case 1:
|
|
236
|
-
_a.sent();
|
|
237
|
-
return [2 /*return*/];
|
|
183
|
+
_a.label = 17;
|
|
184
|
+
case 17: throw e_2;
|
|
185
|
+
case 18: return [2 /*return*/];
|
|
238
186
|
}
|
|
239
187
|
});
|
|
240
188
|
});
|
|
241
189
|
};
|
|
242
190
|
TxManager.logger = logger_1.default.child({ className: "TxManager" });
|
|
243
|
-
TxManager.
|
|
191
|
+
TxManager.nonceTrackers = {};
|
|
244
192
|
return TxManager;
|
|
245
193
|
}());
|
|
246
194
|
exports.default = TxManager;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Compression_TYPE } from "../../proto/Compression";
|
|
3
|
+
import { Compressor } from "../../types/Compressor";
|
|
4
|
+
export declare class GzipCompressor<T> implements Compressor<T> {
|
|
5
|
+
static type: Compression_TYPE;
|
|
6
|
+
compress(content: T): Promise<Buffer>;
|
|
7
|
+
decompress(bytes: Buffer): Promise<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.GzipCompressor = void 0;
|
|
40
|
+
var node_gzip_1 = require("node-gzip");
|
|
41
|
+
var Compression_1 = require("../../proto/Compression");
|
|
42
|
+
var GzipCompressor = /** @class */ (function () {
|
|
43
|
+
function GzipCompressor() {
|
|
44
|
+
}
|
|
45
|
+
GzipCompressor.prototype.compress = function (content) {
|
|
46
|
+
var stringified = JSON.stringify(content);
|
|
47
|
+
return (0, node_gzip_1.gzip)(stringified);
|
|
48
|
+
};
|
|
49
|
+
GzipCompressor.prototype.decompress = function (bytes) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
var stringified;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, (0, node_gzip_1.ungzip)(bytes)];
|
|
55
|
+
case 1:
|
|
56
|
+
stringified = _a.sent();
|
|
57
|
+
return [2 /*return*/, JSON.parse(stringified.toString())];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
GzipCompressor.type = Compression_1.Compression_TYPE.GZIP;
|
|
63
|
+
return GzipCompressor;
|
|
64
|
+
}());
|
|
65
|
+
exports.GzipCompressor = GzipCompressor;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Compression_TYPE } from "../../proto/Compression";
|
|
3
|
+
import { Compressor } from "../../types/Compressor";
|
|
4
|
+
export declare class UncompressedCompressor<T = unknown> implements Compressor<T> {
|
|
5
|
+
static type: Compression_TYPE;
|
|
6
|
+
compress(content: T): Promise<Buffer>;
|
|
7
|
+
decompress(bytes: Buffer): Promise<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UncompressedCompressor = void 0;
|
|
4
|
+
var Compression_1 = require("../../proto/Compression");
|
|
5
|
+
var UncompressedCompressor = /** @class */ (function () {
|
|
6
|
+
function UncompressedCompressor() {
|
|
7
|
+
}
|
|
8
|
+
UncompressedCompressor.prototype.compress = function (content) {
|
|
9
|
+
var stringified = JSON.stringify(content);
|
|
10
|
+
return Promise.resolve(Buffer.from(stringified));
|
|
11
|
+
};
|
|
12
|
+
UncompressedCompressor.prototype.decompress = function (bytes) {
|
|
13
|
+
var stringified = bytes.toString();
|
|
14
|
+
return Promise.resolve(JSON.parse(stringified));
|
|
15
|
+
};
|
|
16
|
+
UncompressedCompressor.type = Compression_1.Compression_TYPE.Uncompressed;
|
|
17
|
+
return UncompressedCompressor;
|
|
18
|
+
}());
|
|
19
|
+
exports.UncompressedCompressor = UncompressedCompressor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./GzipCompressor"), exports);
|
|
18
|
+
__exportStar(require("./UncompressedCompressor"), exports);
|