@mainsail/transactions 0.0.1-evm.2 → 0.0.1-evm.4
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/distribution/handlers/handler-provider.d.ts +0 -1
- package/distribution/handlers/handler-provider.d.ts.map +1 -1
- package/distribution/handlers/handler-provider.js +0 -9
- package/distribution/handlers/handler-provider.js.map +1 -1
- package/distribution/handlers/transaction.d.ts +5 -14
- package/distribution/handlers/transaction.d.ts.map +1 -1
- package/distribution/handlers/transaction.js +14 -103
- package/distribution/handlers/transaction.js.map +1 -1
- package/distribution/transaction-validator.d.ts +1 -4
- package/distribution/transaction-validator.d.ts.map +1 -1
- package/distribution/transaction-validator.js +5 -45
- package/distribution/transaction-validator.js.map +1 -1
- package/package.json +7 -7
@@ -1,7 +1,6 @@
|
|
1
1
|
import { Contracts } from "@mainsail/contracts";
|
2
2
|
export declare class TransactionHandlerProvider implements Contracts.Transactions.TransactionHandlerProvider {
|
3
3
|
#private;
|
4
|
-
private readonly attributeRepository;
|
5
4
|
private readonly handlerConstructors;
|
6
5
|
private readonly transactionRegistry;
|
7
6
|
isRegistrationRequired(): boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"handler-provider.d.ts","sourceRoot":"","sources":["../../source/handlers/handler-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA2B,MAAM,qBAAqB,CAAC;AAMzE,qBACa,0BAA2B,YAAW,SAAS,CAAC,YAAY,CAAC,0BAA0B;;IAEnG,OAAO,CAAC,QAAQ,CAAC,mBAAmB,
|
1
|
+
{"version":3,"file":"handler-provider.d.ts","sourceRoot":"","sources":["../../source/handlers/handler-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA2B,MAAM,qBAAqB,CAAC;AAMzE,qBACa,0BAA2B,YAAW,SAAS,CAAC,YAAY,CAAC,0BAA0B;;IAEnG,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAmC;IAGvE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAwC;IAKrE,sBAAsB,IAAI,OAAO;IAIjC,gBAAgB,IAAI,IAAI;CA4E/B"}
|
@@ -57,11 +57,6 @@ _TransactionHandlerProvider_registerHandler = function _TransactionHandlerProvid
|
|
57
57
|
throw new Exceptions.UnsatisfiedDependencyError(internalType);
|
58
58
|
}
|
59
59
|
}
|
60
|
-
for (const attribute of handler.walletAttributes()) {
|
61
|
-
if (!this.attributeRepository.has(attribute.name)) {
|
62
|
-
this.attributeRepository.set(attribute.name, attribute.type);
|
63
|
-
}
|
64
|
-
}
|
65
60
|
if (transactionConstructor.typeGroup !== Contracts.Crypto.TransactionTypeGroup.Core) {
|
66
61
|
this.transactionRegistry.registerTransactionType(transactionConstructor);
|
67
62
|
}
|
@@ -88,10 +83,6 @@ _TransactionHandlerProvider_hasOtherHandler = function _TransactionHandlerProvid
|
|
88
83
|
handler.typeGroup === dependency.typeGroup &&
|
89
84
|
handler.version === dependency.version);
|
90
85
|
};
|
91
|
-
__decorate([
|
92
|
-
inject(Identifiers.State.Wallet.Attributes),
|
93
|
-
__metadata("design:type", Object)
|
94
|
-
], TransactionHandlerProvider.prototype, "attributeRepository", void 0);
|
95
86
|
__decorate([
|
96
87
|
inject(Identifiers.Transaction.Handler.Constructors),
|
97
88
|
__metadata("design:type", Array)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"handler-provider.js","sourceRoot":"","sources":["../../source/handlers/handler-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAA0B,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAKlC,IAAM,0BAA0B,GAAh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YAAY,IAAI,2BAA2B,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YAC3F,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;mGAEgB,qBAAoD;IACpE,MAAM,UAAU,GAAG,IAAI,qBAAqB,EAAE,CAAC,cAAc,EAAE,CAAC;IAEhE,OAAO,CAAC,GAAG,uBAAA,IAAI,2DAAyB,CAAC,CAAC,IAAI,CAC7C,CAAC,OAAO,EAAE,EAAE,CACX,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI;QAChC,OAAO,CAAC,SAAS,KAAK,UAAU,CAAC,SAAS;QAC1C,OAAO,CAAC,OAAO,KAAK,UAAU,CAAC,OAAO,CACvC,CAAC;AACH,CAAC;AAvFgB;IADhB,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC;;uEACkB;AAGtD;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC;;uEACsB;AALhE,0BAA0B;IADtC,UAAU,EAAE;GACA,0BAA0B,CA0FtC"}
|
@@ -1,27 +1,18 @@
|
|
1
1
|
import { Contracts } from "@mainsail/contracts";
|
2
2
|
export declare abstract class TransactionHandler implements Contracts.Transactions.TransactionHandler {
|
3
|
-
#private;
|
4
3
|
protected readonly app: Contracts.Kernel.Application;
|
4
|
+
protected readonly gasFeeCalculator: Contracts.Evm.GasFeeCalculator;
|
5
5
|
protected readonly logger: Contracts.Kernel.Logger;
|
6
6
|
protected readonly configuration: Contracts.Crypto.Configuration;
|
7
7
|
protected readonly verifier: Contracts.Crypto.TransactionVerifier;
|
8
8
|
protected readonly gasLimits: Contracts.Evm.GasLimits;
|
9
9
|
protected readonly eventDispatcher: Contracts.Kernel.EventDispatcher;
|
10
|
-
verify(
|
11
|
-
throwIfCannotBeApplied(
|
12
|
-
apply(context: Contracts.Transactions.TransactionHandlerContext, transaction: Contracts.Crypto.Transaction): Promise<Contracts.Transactions.TransactionApplyResult>;
|
13
|
-
applyToSender(context: Contracts.Transactions.TransactionHandlerContext, transaction: Contracts.Crypto.Transaction): Promise<Contracts.Transactions.TransactionApplyResult>;
|
14
|
-
applyToRecipient(context: Contracts.Transactions.TransactionHandlerContext, transaction: Contracts.Crypto.Transaction): Promise<Contracts.Transactions.TransactionApplyResult>;
|
10
|
+
verify(transaction: Contracts.Crypto.Transaction): Promise<boolean>;
|
11
|
+
throwIfCannotBeApplied(transaction: Contracts.Crypto.Transaction, sender: Contracts.State.Wallet): Promise<void>;
|
15
12
|
emitEvents(transaction: Contracts.Crypto.Transaction): void;
|
16
|
-
|
17
|
-
name: string;
|
18
|
-
type: Contracts.State.AttributeType;
|
19
|
-
}>;
|
20
|
-
throwIfCannotEnterPool(context: Contracts.Transactions.TransactionHandlerContext, transaction: Contracts.Crypto.Transaction): Promise<void>;
|
21
|
-
verifySignatures(wallet: Contracts.State.Wallet, transaction: Contracts.Crypto.TransactionData, multiSignature?: Contracts.Crypto.MultiSignatureAsset): Promise<boolean>;
|
13
|
+
verifySignatures(wallet: Contracts.State.Wallet, transaction: Contracts.Crypto.TransactionData, multiSignature: Contracts.Crypto.MultiSignatureAsset): Promise<boolean>;
|
22
14
|
protected allTransactions(transactions: Contracts.Crypto.Transaction[]): Contracts.Crypto.TransactionData[];
|
23
|
-
|
24
|
-
protected applyFeeToSender(transaction: Contracts.Crypto.Transaction, sender: Contracts.State.Wallet): void;
|
15
|
+
abstract apply(context: Contracts.Transactions.TransactionHandlerContext, transaction: Contracts.Crypto.Transaction): Promise<Contracts.Evm.TransactionReceipt>;
|
25
16
|
abstract getConstructor(): Contracts.Crypto.TransactionConstructor;
|
26
17
|
abstract dependencies(): ReadonlyArray<TransactionHandlerConstructor>;
|
27
18
|
abstract isActivated(): Promise<boolean>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../source/handlers/transaction.ts"],"names":[],"mapp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AC,eAAe,EAC7C,cAAc,EAAE,SAAS,CAAC,MAAM,CAAC,mBAAmB,GAClD,OAAO,CAAC,OAAO,CAAC;IAInB,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,eAAe,EAAE;aAS3F,KAAK,CACpB,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC,yBAAyB,EACzD,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,GACvC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC;aAE5B,cAAc,IAAI,SAAS,CAAC,MAAM,CAAC,sBAAsB;aAEzD,YAAY,IAAI,aAAa,CAAC,6BAA6B,CAAC;aAE5D,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAC/C;AAED,MAAM,MAAM,6BAA6B,GAAG,UAAU,kBAAkB,CAAC"}
|
@@ -7,134 +7,45 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
9
|
};
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
14
|
-
};
|
15
|
-
var _TransactionHandler_instances, _TransactionHandler_verifyTransactionNonceApply;
|
16
10
|
import { inject, injectable } from "@mainsail/container";
|
17
11
|
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
|
18
12
|
import { Utils as AppUtils } from "@mainsail/kernel";
|
19
|
-
import { BigNumber } from "@mainsail/utils";
|
20
13
|
let TransactionHandler = class TransactionHandler {
|
21
|
-
|
22
|
-
_TransactionHandler_instances.add(this);
|
23
|
-
}
|
24
|
-
async verify({ walletRepository }, transaction) {
|
14
|
+
async verify(transaction) {
|
25
15
|
AppUtils.assert.defined(transaction.data.senderPublicKey);
|
26
|
-
const senderWallet = await walletRepository.findByPublicKey(transaction.data.senderPublicKey);
|
27
|
-
if (senderWallet.hasMultiSignature()) {
|
28
|
-
return this.verifySignatures(senderWallet, transaction.data);
|
29
|
-
}
|
30
16
|
return this.verifier.verifyHash(transaction.data);
|
31
17
|
}
|
32
|
-
async throwIfCannotBeApplied(
|
33
|
-
|
34
|
-
|
35
|
-
AppUtils.assert.defined(sender.getPublicKey());
|
36
|
-
if (!walletRepository.hasByPublicKey(sender.getPublicKey()) && senderWallet.getBalance().isZero()) {
|
37
|
-
throw new Exceptions.ColdWalletError();
|
18
|
+
async throwIfCannotBeApplied(transaction, sender) {
|
19
|
+
if (!sender.getNonce().isEqualTo(transaction.data.nonce)) {
|
20
|
+
throw new Exceptions.UnexpectedNonceError(transaction.data.nonce, sender);
|
38
21
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
22
|
+
if (sender
|
23
|
+
.getBalance()
|
24
|
+
.minus(transaction.data.amount)
|
25
|
+
.minus(this.gasFeeCalculator.calculate(transaction))
|
26
|
+
.isNegative() &&
|
43
27
|
this.configuration.getHeight() > 0) {
|
44
28
|
throw new Exceptions.InsufficientBalanceError();
|
45
29
|
}
|
46
|
-
if (transaction.data.senderPublicKey !== sender.getPublicKey()) {
|
47
|
-
throw new Exceptions.SenderWalletMismatchError();
|
48
|
-
}
|
49
|
-
// Prevent legacy multi signatures from being used
|
50
|
-
const isMultiSignatureRegistration = transaction.type === Contracts.Crypto.TransactionType.MultiSignature &&
|
51
|
-
transaction.typeGroup === Contracts.Crypto.TransactionTypeGroup.Core;
|
52
|
-
if (sender.hasMultiSignature()) {
|
53
|
-
AppUtils.assert.defined(transaction.data.senderPublicKey);
|
54
|
-
// Ensure the database wallet already has a multi signature, in case we checked a pool wallet.
|
55
|
-
const databaseSender = await walletRepository.findByPublicKey(transaction.data.senderPublicKey);
|
56
|
-
if (!databaseSender.hasMultiSignature()) {
|
57
|
-
throw new Exceptions.MissingMultiSignatureOnSenderError();
|
58
|
-
}
|
59
|
-
if (databaseSender.hasAttribute("multiSignature.legacy")) {
|
60
|
-
throw new Exceptions.LegacyMultiSignatureError();
|
61
|
-
}
|
62
|
-
if (!(await this.verifySignatures(databaseSender, transaction.data, databaseSender.getAttribute("multiSignature")))) {
|
63
|
-
throw new Exceptions.InvalidMultiSignaturesError();
|
64
|
-
}
|
65
|
-
}
|
66
|
-
else if (transaction.data.signatures && !isMultiSignatureRegistration) {
|
67
|
-
throw new Exceptions.UnsupportedMultiSignatureRegistrationTransactionError();
|
68
|
-
}
|
69
|
-
}
|
70
|
-
async apply(context, transaction) {
|
71
|
-
const senderResult = await this.applyToSender(context, transaction);
|
72
|
-
const recipientResult = await this.applyToRecipient(context, transaction);
|
73
|
-
// Merge results; effectively only one is ever set depending on the transaction type.
|
74
|
-
return {
|
75
|
-
gasUsed: senderResult.gasUsed + recipientResult.gasUsed,
|
76
|
-
receipt: recipientResult.receipt,
|
77
|
-
};
|
78
|
-
}
|
79
|
-
async applyToSender(context, transaction) {
|
80
|
-
AppUtils.assert.defined(transaction.data.senderPublicKey);
|
81
|
-
const sender = await context.walletRepository.findByPublicKey(transaction.data.senderPublicKey);
|
82
|
-
const data = transaction.data;
|
83
|
-
await this.throwIfCannotBeApplied(context, transaction, sender);
|
84
|
-
__classPrivateFieldGet(this, _TransactionHandler_instances, "m", _TransactionHandler_verifyTransactionNonceApply).call(this, sender, transaction);
|
85
|
-
AppUtils.assert.defined(data.nonce);
|
86
|
-
sender.setNonce(data.nonce);
|
87
|
-
// Subtract fee
|
88
|
-
this.applyFeeToSender(transaction, sender);
|
89
|
-
// Native gas usage
|
90
|
-
let gasUsed = 0;
|
91
|
-
const isEvmCall = transaction.type === Contracts.Crypto.TransactionType.EvmCall &&
|
92
|
-
transaction.typeGroup === Contracts.Crypto.TransactionTypeGroup.Core;
|
93
|
-
if (!isEvmCall) {
|
94
|
-
// TODO: calculate accurate amount (follow-up)
|
95
|
-
gasUsed = this.gasLimits.of(transaction);
|
96
|
-
}
|
97
|
-
return { gasUsed };
|
98
|
-
}
|
99
|
-
async applyToRecipient(context, transaction) {
|
100
|
-
return { gasUsed: 0 };
|
101
30
|
}
|
102
31
|
emitEvents(transaction) { }
|
103
|
-
walletAttributes() {
|
104
|
-
return [];
|
105
|
-
}
|
106
|
-
async throwIfCannotEnterPool(context, transaction) { }
|
107
32
|
async verifySignatures(wallet, transaction, multiSignature) {
|
108
|
-
return this.verifier.verifySignatures(transaction, multiSignature
|
33
|
+
return this.verifier.verifySignatures(transaction, multiSignature);
|
109
34
|
}
|
110
35
|
allTransactions(transactions) {
|
111
36
|
return transactions
|
112
37
|
.filter(({ data }) => data.type === this.getConstructor().type && data.typeGroup === this.getConstructor().typeGroup)
|
113
38
|
.map(({ data }) => data);
|
114
39
|
}
|
115
|
-
verifyTransactionFee({ walletRepository }, transaction, sender) {
|
116
|
-
if (sender.getBalance().minus(transaction.data.amount).minus(transaction.data.fee).isNegative() &&
|
117
|
-
this.configuration.getHeight() > 0) {
|
118
|
-
throw new Exceptions.InsufficientBalanceError();
|
119
|
-
}
|
120
|
-
}
|
121
|
-
applyFeeToSender(transaction, sender) {
|
122
|
-
const data = transaction.data;
|
123
|
-
const newBalance = sender.getBalance().minus(data.fee);
|
124
|
-
sender.setBalance(newBalance);
|
125
|
-
}
|
126
|
-
};
|
127
|
-
_TransactionHandler_instances = new WeakSet();
|
128
|
-
_TransactionHandler_verifyTransactionNonceApply = function _TransactionHandler_verifyTransactionNonceApply(wallet, transaction) {
|
129
|
-
const nonce = transaction.data.nonce || BigNumber.ZERO;
|
130
|
-
if (!wallet.getNonce().plus(1).isEqualTo(nonce)) {
|
131
|
-
throw new Exceptions.UnexpectedNonceError(nonce, wallet, false);
|
132
|
-
}
|
133
40
|
};
|
134
41
|
__decorate([
|
135
42
|
inject(Identifiers.Application.Instance),
|
136
43
|
__metadata("design:type", Object)
|
137
44
|
], TransactionHandler.prototype, "app", void 0);
|
45
|
+
__decorate([
|
46
|
+
inject(Identifiers.Evm.Gas.FeeCalculator),
|
47
|
+
__metadata("design:type", Object)
|
48
|
+
], TransactionHandler.prototype, "gasFeeCalculator", void 0);
|
138
49
|
__decorate([
|
139
50
|
inject(Identifiers.Services.Log.Service),
|
140
51
|
__metadata("design:type", Object)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../source/handlers/transaction.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../source/handlers/transaction.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG9C,IAAe,kBAAkB,GAAjC,MAAe,kBAAkB;IAsBhC,KAAK,CAAC,MAAM,CAAC,WAAyC;QAC5D,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAS,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,sBAAsB,CAClC,WAAyC,EACzC,MAA8B;QAE9B,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,UAAU,CAAC,oBAAoB,CAAC,WAAW,CAAC,IAAI,CAA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AC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC;;oDACa;AAGhD;IADlB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;;qDACoB;AAGpC;IADlB,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC;;2DACiB;AApBjD,kBAAkB;IADvC,UAAU,EAAE;GACS,kBAAkB,CA4EvC"}
|
@@ -1,12 +1,9 @@
|
|
1
1
|
import { Contracts } from "@mainsail/contracts";
|
2
2
|
export declare class TransactionValidator implements Contracts.Transactions.TransactionValidator {
|
3
|
-
#private;
|
4
3
|
private readonly evm;
|
5
4
|
private readonly handlerRegistry;
|
6
|
-
private readonly stateService;
|
7
5
|
private readonly transactionFactory;
|
8
|
-
initialize(): void;
|
9
6
|
getEvm(): Contracts.Evm.Instance;
|
10
|
-
validate(context: Contracts.Transactions.TransactionValidatorContext, transaction: Contracts.Crypto.Transaction): Promise<Contracts.
|
7
|
+
validate(context: Contracts.Transactions.TransactionValidatorContext, transaction: Contracts.Crypto.Transaction): Promise<Contracts.Evm.TransactionReceipt>;
|
11
8
|
}
|
12
9
|
//# sourceMappingURL=transaction-validator.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transaction-validator.d.ts","sourceRoot":"","sources":["../source/transaction-validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAI7D,qBACa,oBAAqB,YAAW,SAAS,CAAC,YAAY,CAAC,oBAAoB
|
1
|
+
{"version":3,"file":"transaction-validator.d.ts","sourceRoot":"","sources":["../source/transaction-validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAI7D,qBACa,oBAAqB,YAAW,SAAS,CAAC,YAAY,CAAC,oBAAoB;IAGvF,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0B;IAG9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqD;IAGrF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAEnE,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,QAAQ;IAI1B,QAAQ,CACpB,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC,2BAA2B,EAC3D,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,GACvC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC;CA4B5C"}
|
@@ -7,64 +7,34 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
9
|
};
|
10
|
-
|
11
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
12
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
13
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
14
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
15
|
-
};
|
16
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
17
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
18
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
19
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
20
|
-
};
|
21
|
-
var _TransactionValidator_instances, _TransactionValidator_walletRepository, _TransactionValidator_updateEvmAccountInfoHost;
|
22
|
-
import { inject, injectable, postConstruct, tagged } from "@mainsail/container";
|
10
|
+
import { inject, injectable, tagged } from "@mainsail/container";
|
23
11
|
import { Contracts, Identifiers } from "@mainsail/contracts";
|
24
12
|
import { Utils as AppUtils } from "@mainsail/kernel";
|
25
13
|
import { strictEqual } from "assert";
|
26
14
|
let TransactionValidator = class TransactionValidator {
|
27
|
-
constructor() {
|
28
|
-
_TransactionValidator_instances.add(this);
|
29
|
-
_TransactionValidator_walletRepository.set(this, void 0);
|
30
|
-
}
|
31
|
-
initialize() {
|
32
|
-
__classPrivateFieldSet(this, _TransactionValidator_walletRepository, this.stateService.createStoreClone().walletRepository, "f");
|
33
|
-
}
|
34
15
|
getEvm() {
|
35
16
|
return this.evm;
|
36
17
|
}
|
37
18
|
async validate(context, transaction) {
|
38
19
|
const deserialized = await this.transactionFactory.fromBytes(transaction.serialized);
|
39
20
|
strictEqual(transaction.id, deserialized.id);
|
40
|
-
const { commitKey, gasLimit, timestamp,
|
21
|
+
const { commitKey, gasLimit, timestamp, generatorAddress } = context;
|
41
22
|
const handler = await this.handlerRegistry.getActivatedHandlerForData(transaction.data);
|
42
|
-
const
|
23
|
+
const receipt = await handler.apply({
|
43
24
|
evm: {
|
44
25
|
blockContext: {
|
45
26
|
commitKey,
|
46
27
|
gasLimit: BigInt(gasLimit),
|
47
28
|
timestamp: BigInt(timestamp),
|
48
|
-
validatorAddress:
|
29
|
+
validatorAddress: generatorAddress,
|
49
30
|
},
|
50
31
|
instance: this.evm,
|
51
32
|
},
|
52
|
-
walletRepository: __classPrivateFieldGet(this, _TransactionValidator_walletRepository, "f"),
|
53
33
|
}, transaction);
|
54
34
|
AppUtils.assert.defined(transaction.data.senderPublicKey);
|
55
|
-
|
56
|
-
return { gasUsed: result.gasUsed };
|
35
|
+
return receipt;
|
57
36
|
}
|
58
37
|
};
|
59
|
-
_TransactionValidator_walletRepository = new WeakMap();
|
60
|
-
_TransactionValidator_instances = new WeakSet();
|
61
|
-
_TransactionValidator_updateEvmAccountInfoHost = async function _TransactionValidator_updateEvmAccountInfoHost(commitKey, sender) {
|
62
|
-
await this.evm.updateAccountInfo({
|
63
|
-
account: sender.getAddress(),
|
64
|
-
commitKey,
|
65
|
-
nonce: sender.getNonce().toBigInt(),
|
66
|
-
});
|
67
|
-
};
|
68
38
|
__decorate([
|
69
39
|
inject(Identifiers.Evm.Instance),
|
70
40
|
tagged("instance", "ephemeral"),
|
@@ -74,20 +44,10 @@ __decorate([
|
|
74
44
|
inject(Identifiers.Transaction.Handler.Registry),
|
75
45
|
__metadata("design:type", Object)
|
76
46
|
], TransactionValidator.prototype, "handlerRegistry", void 0);
|
77
|
-
__decorate([
|
78
|
-
inject(Identifiers.State.Service),
|
79
|
-
__metadata("design:type", Object)
|
80
|
-
], TransactionValidator.prototype, "stateService", void 0);
|
81
47
|
__decorate([
|
82
48
|
inject(Identifiers.Cryptography.Transaction.Factory),
|
83
49
|
__metadata("design:type", Object)
|
84
50
|
], TransactionValidator.prototype, "transactionFactory", void 0);
|
85
|
-
__decorate([
|
86
|
-
postConstruct(),
|
87
|
-
__metadata("design:type", Function),
|
88
|
-
__metadata("design:paramtypes", []),
|
89
|
-
__metadata("design:returntype", void 0)
|
90
|
-
], TransactionValidator.prototype, "initialize", null);
|
91
51
|
TransactionValidator = __decorate([
|
92
52
|
injectable()
|
93
53
|
], TransactionValidator);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transaction-validator.js","sourceRoot":"","sources":["../source/transaction-validator.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"transaction-validator.js","sourceRoot":"","sources":["../source/transaction-validator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAG9B,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAWzB,MAAM;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC;IACjB,C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|
{
|
2
2
|
"name": "@mainsail/transactions",
|
3
|
-
"version": "0.0.1-evm.
|
3
|
+
"version": "0.0.1-evm.4",
|
4
4
|
"description": "Transaction Services for Mainsail blockchain",
|
5
5
|
"license": "GPL-3.0-only",
|
6
6
|
"contributors": [],
|
@@ -11,16 +11,16 @@
|
|
11
11
|
"/distribution"
|
12
12
|
],
|
13
13
|
"dependencies": {
|
14
|
-
"@mainsail/container": "0.0.1-evm.
|
15
|
-
"@mainsail/contracts": "0.0.1-evm.
|
16
|
-
"@mainsail/crypto-transaction": "0.0.1-evm.
|
17
|
-
"@mainsail/
|
18
|
-
"@mainsail/kernel": "0.0.1-evm.2"
|
14
|
+
"@mainsail/container": "0.0.1-evm.4",
|
15
|
+
"@mainsail/contracts": "0.0.1-evm.4",
|
16
|
+
"@mainsail/crypto-transaction": "0.0.1-evm.4",
|
17
|
+
"@mainsail/kernel": "0.0.1-evm.4"
|
19
18
|
},
|
20
19
|
"devDependencies": {
|
21
20
|
"dayjs": "1.11.10",
|
22
21
|
"uvu": "^0.5.6",
|
23
|
-
"@mainsail/
|
22
|
+
"@mainsail/utils": "0.0.1-evm.4",
|
23
|
+
"@mainsail/crypto-config": "0.0.1-evm.4"
|
24
24
|
},
|
25
25
|
"engines": {
|
26
26
|
"node": ">=20.x"
|