diff --git a/remix-simulator/README.md b/remix-simulator/README.md index 6aebce1c55..8a346ae999 100644 --- a/remix-simulator/README.md +++ b/remix-simulator/README.md @@ -17,12 +17,12 @@ Implemented: * [X] eth_blockNumber * [X] eth_getBalance * [_] eth_getStorageAt -* [X] eth_getTransactionCount +* [~] eth_getTransactionCount * [_] eth_getBlockTransactionCountByHash * [_] eth_getBlockTransactionCountByNumber * [_] eth_getUncleCountByBlockHash * [_] eth_getUncleCountByBlockNumber -* [~] eth_getCode +* [X] eth_getCode * [~] eth_sign * [X] eth_sendTransaction * [_] eth_sendRawTransaction diff --git a/remix-simulator/src/methods/transactions.js b/remix-simulator/src/methods/transactions.js index 6dcfd066fa..6b0f573ddf 100644 --- a/remix-simulator/src/methods/transactions.js +++ b/remix-simulator/src/methods/transactions.js @@ -2,10 +2,23 @@ var RemixLib = require('remix-lib') var executionContext = RemixLib.execution.executionContext var processTx = require('./txProcess.js') +function hexConvert(ints) { + var ret = '0x' + for (var i = 0; i < ints.length; i++) { + var h = ints[i] + if (h) { + ret += (h <= 0xf ? '0' : '') + h.toString(16) + } else { + ret += '00' + } + } + return ret +} + var Transactions = function (accounts) { this.accounts = accounts // TODO: fix me; this is a temporary and very hackish thing just to get the getCode working for now - this.deployedContracts = {} + //this.deployedContracts = {} } Transactions.prototype.methods = function () { @@ -29,7 +42,7 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { if (error) { return cb(error) } - self.deployedContracts[receipt.contractAddress] = receipt.data + //self.deployedContracts[receipt.contractAddress] = receipt.data var r = { 'transactionHash': receipt.hash, @@ -54,7 +67,11 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) { Transactions.prototype.eth_getCode = function (payload, cb) { let address = payload.params[0] - cb(null, this.deployedContracts[address] || '0x') + const account = ethJSUtil.toBuffer(address) + executionContext.vm().stateManager.getContractCode(account, (error, result) => { + cb(error, hexConvert(result)) + }) + //cb(null, this.deployedContracts[address] || '0x') } Transactions.prototype.eth_call = function (payload, cb) {