1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
|
7 | const errors_1 = require("../errors");
|
8 | const managers_1 = require("../managers");
|
9 | const fee_1 = require("../managers/fee");
|
10 | const validation_1 = require("../validation");
|
11 | const types_1 = require("./types");
|
12 | class TransactionRegistry {
|
13 | constructor() {
|
14 | this.coreTypes = new Map();
|
15 | this.customTypes = new Map();
|
16 | types_1.TransactionTypeFactory.initialize(this.coreTypes, this.customTypes);
|
17 | this.registerCoreType(types_1.TransferTransaction);
|
18 | this.registerCoreType(types_1.SecondSignatureRegistrationTransaction);
|
19 | this.registerCoreType(types_1.DelegateRegistrationTransaction);
|
20 | this.registerCoreType(types_1.VoteTransaction);
|
21 | this.registerCoreType(types_1.MultiSignatureRegistrationTransaction);
|
22 | this.registerCoreType(types_1.IpfsTransaction);
|
23 | this.registerCoreType(types_1.TimelockTransferTransaction);
|
24 | this.registerCoreType(types_1.MultiPaymentTransaction);
|
25 | this.registerCoreType(types_1.DelegateResignationTransaction);
|
26 | }
|
27 | registerCustomType(constructor) {
|
28 | const { type } = constructor;
|
29 | if (this.customTypes.has(type)) {
|
30 | throw new errors_1.TransactionAlreadyRegisteredError(constructor.name);
|
31 | }
|
32 | if (type < 100) {
|
33 | throw new errors_1.TransactionTypeInvalidRangeError(type);
|
34 | }
|
35 | this.customTypes.set(type, constructor);
|
36 | this.updateSchemas(constructor);
|
37 | this.updateStaticFees();
|
38 | }
|
39 | deregisterCustomType(type) {
|
40 | if (this.customTypes.has(type)) {
|
41 | const schema = this.customTypes.get(type);
|
42 | this.updateSchemas(schema, true);
|
43 | this.customTypes.delete(type);
|
44 | }
|
45 | }
|
46 | updateStaticFees(height) {
|
47 | const customConstructors = Array.from(this.customTypes.values());
|
48 | const milestone = managers_1.configManager.getMilestone(height);
|
49 | const { staticFees } = milestone.fees;
|
50 | for (const constructor of customConstructors) {
|
51 | const { type, name } = constructor;
|
52 | if (milestone.fees && milestone.fees.staticFees) {
|
53 | const value = staticFees[lodash_camelcase_1.default(name.replace("Transaction", ""))];
|
54 | if (!value) {
|
55 | throw new errors_1.MissingMilestoneFeeError(name);
|
56 | }
|
57 | fee_1.feeManager.set(type, value);
|
58 | }
|
59 | }
|
60 | }
|
61 | registerCoreType(constructor) {
|
62 | const { type } = constructor;
|
63 | if (this.coreTypes.has(type)) {
|
64 | throw new errors_1.TransactionAlreadyRegisteredError(constructor.name);
|
65 | }
|
66 | this.coreTypes.set(type, constructor);
|
67 | this.updateSchemas(constructor);
|
68 | }
|
69 | updateSchemas(transaction, remove) {
|
70 | validation_1.validator.extendTransaction(transaction.getSchema(), remove);
|
71 | }
|
72 | }
|
73 | exports.transactionRegistry = new TransactionRegistry();
|
74 |
|
\ | No newline at end of file |