@eth-optimism/ethereumjs-vm
Version:
An Ethereum VM implementation
77 lines • 3.34 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var BN = require("bn.js");
var buffer_utils_1 = require("../ovm/utils/buffer-utils");
var Message = /** @class */ (function () {
function Message(opts) {
this.to = opts.to;
this.value = opts.value ? new BN(opts.value) : new BN(0);
this.caller = opts.caller;
this.gasLimit = opts.gasLimit;
this.data = opts.data || Buffer.alloc(0);
this.depth = opts.depth || 0;
this.code = opts.code;
this._codeAddress = opts.codeAddress;
this.isStatic = opts.isStatic || false;
this.isCompiled = opts.isCompiled || false; // For CALLCODE, TODO: Move from here
this.salt = opts.salt; // For CREATE2, TODO: Move from here
this.selfdestruct = opts.selfdestruct; // TODO: Move from here
this.delegatecall = opts.delegatecall || false;
// Custom variables
this.originalTargetAddress = opts.originalTargetAddress;
}
Object.defineProperty(Message.prototype, "codeAddress", {
get: function () {
return this._codeAddress ? this._codeAddress : this.to;
},
enumerable: false,
configurable: true
});
Message.prototype.isTargetMessage = function () {
return ((!this.to && !this.originalTargetAddress) ||
(this.to && this.originalTargetAddress && this.to.equals(this.originalTargetAddress)));
};
Message.prototype.toOvmMessage = function (vm, block) {
if (!vm.contracts.OVM_ExecutionManager.address) {
throw new Error('Cannot create a message because the ExecutionManager does not exist.');
}
var notTooBigGasLimit = new BN(vm.emGasLimit);
var calldata = vm.contracts.OVM_ExecutionManager.iface.encodeFunctionData('run', [
{
timestamp: new BN(block.header.timestamp).toNumber(),
blockNumber: new BN(block.header.number).toNumber(),
l1QueueOrigin: 0,
l1TxOrigin: buffer_utils_1.toHexString(this.caller),
entrypoint: buffer_utils_1.toHexString(this.caller),
gasLimit: buffer_utils_1.toHexString(notTooBigGasLimit.toBuffer()),
data: vm.contracts.mockOVM_ECDSAContractAccount.iface.encodeFunctionData('execute', [
buffer_utils_1.toHexString(this.data),
0,
0,
'0x' + '00'.repeat(32),
'0x' + '00'.repeat(32),
]),
},
vm.contracts.OVM_StateManager.addressHex,
]);
return new Message(__assign(__assign({}, this), {
to: vm.contracts.OVM_ExecutionManager.address,
data: buffer_utils_1.fromHexString(calldata),
originalTargetAddress: this.to,
}));
};
return Message;
}());
exports.default = Message;
//# sourceMappingURL=message.js.map