UNPKG

1.75 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const client_common_1 = require("@neo-one/client-common");
4const InvocationResultBase_1 = require("./InvocationResultBase");
5const MAX_SIZE = 1024;
6class InvocationResultError extends InvocationResultBase_1.InvocationResultBase {
7 constructor({ gasConsumed, gasCost, stack, message }) {
8 super({ state: client_common_1.VMState.Fault, gasConsumed, gasCost, stack });
9 this.message = message;
10 this.sizeExclusive = client_common_1.utils.lazy(() => client_common_1.IOHelper.sizeOfVarString(this.message));
11 }
12 static deserializeWireBase(options) {
13 const { reader } = options;
14 const { state, gasConsumed, gasCost, stack } = super.deserializeInvocationResultWireBase(options);
15 if (state !== client_common_1.VMState.Fault) {
16 throw new client_common_1.InvalidFormatError(`Expected VMState to be: ${client_common_1.VMState.Fault}. Received: ${state}`);
17 }
18 const message = reader.readVarString(MAX_SIZE);
19 return new this({ gasConsumed, gasCost, stack, message });
20 }
21 serializeWireBase(writer) {
22 super.serializeWireBase(writer);
23 writer.writeVarString(this.message, MAX_SIZE);
24 }
25 serializeJSON(context) {
26 return {
27 state: client_common_1.VMState.Fault,
28 gas_consumed: client_common_1.JSONHelper.writeFixed8(this.gasConsumed),
29 gas_cost: client_common_1.JSONHelper.writeFixed8(this.gasCost),
30 stack: this.stack.map((value) => value.serializeJSON(context)),
31 message: this.message,
32 };
33 }
34}
35exports.InvocationResultError = InvocationResultError;
36
37//# sourceMappingURL=InvocationResultError.js.map