From 81d42265264e10fc61a502bef551d4eb28ceeb3d Mon Sep 17 00:00:00 2001 From: "Nicholas J. Paterno" Date: Wed, 15 Jan 2020 16:49:09 -0500 Subject: [PATCH] Fix Incompatible EIP155-based V RPC error --- lib/statemanager.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/statemanager.js b/lib/statemanager.js index bb4d6a9420..d9407dbccd 100644 --- a/lib/statemanager.js +++ b/lib/statemanager.js @@ -15,6 +15,8 @@ var sigUtil = require("eth-sig-util"); var _ = require("lodash"); const { BlockOutOfRangeError } = require("./utils/errorhelper"); const BN = utils.BN; +const rlp = require("rlp"); +const Common = require("ethereumjs-common").default; const ZERO_BUFFER = Buffer.from([0]); @@ -287,7 +289,39 @@ StateManager.prototype.getCode = function(address, number, callback) { }; StateManager.prototype.queueRawTransaction = function(data, callback) { - const tx = new Transaction(data, Transaction.types.signed, this.blockchain.vm.opts.common); + let chainId; + if (Buffer.isBuffer(data)) { + let decodedData = rlp.decode(data); + let v = decodedData[6]; + if (v !== undefined) { + v = utils.bufferToInt(v); + let _chainId = Math.floor((v - 35) / 2); + switch (_chainId) { + case this.net_version: + chainId = this.net_version; + break; + case 1337: + chainId = _chainId; + break; + default: + break; + } + } + } + let common = !chainId + ? this.blockchain.vm.opts.common + : Common.forCustomChain( + "mainnet", // TODO needs to match chain id + { + name: "ganache", + networkId: this.options.network_id || this.forkVersion, + chainId, + comment: "Local test network", + bootstrapNodes: [] + }, + this.options.hardfork + ); + let tx = new Transaction(data, Transaction.types.signed, common); // use toLowerCase() to properly handle from addresses meant to be validated. const from = to.hex(tx.from).toLowerCase(); this._queueTransaction("eth_sendRawTransaction", tx, from, null, callback);