diff --git a/remix-simulator/bin/ethsim b/remix-simulator/bin/ethsim new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/remix-simulator/bin/ethsim @@ -0,0 +1 @@ + diff --git a/remix-simulator/package.json b/remix-simulator/package.json index 6f4e497247..719f0f1d27 100644 --- a/remix-simulator/package.json +++ b/remix-simulator/package.json @@ -14,6 +14,8 @@ ], "main": "./index.js", "dependencies": { + "body-parser": "^1.18.2", + "express": "^4.16.3", "remix-lib": "latest", "standard": "^10.0.3", "web3": "1.0.0-beta.27" @@ -70,4 +72,3 @@ ] } } - diff --git a/remix-simulator/src/provider.js b/remix-simulator/src/provider.js index 31f3f99fee..f9939d2b2e 100644 --- a/remix-simulator/src/provider.js +++ b/remix-simulator/src/provider.js @@ -22,8 +22,11 @@ var Provider = function () { Provider.prototype.sendAsync = function (payload, callback) { const self = this + console.dir("payload method is ") + console.dir(payload.method) if (payload.method === 'eth_accounts') { + console.dir('eth_accounts'); return callback(null, jsonRPCResponse(payload.id, this.accounts.map((x) => x.address))) } if (payload.method === 'eth_estimateGas') { @@ -61,11 +64,42 @@ Provider.prototype.sendAsync = function (payload, callback) { let address = payload.params[0] // let block = payload.params[1] - callback(null, jsonRPCResponse(payload.id, self.deployedContracts[address])) + callback(null, jsonRPCResponse(payload.id, self.deployedContracts[address] || "0x")) } if (payload.method === 'eth_call') { processTx(this.accounts, payload, true, callback) } + if (payload.method === 'web3_clientVersion') { + callback(null, jsonRPCResponse(payload.id, "Remix Simulator/0.0.1")) + } + if (payload.method === 'shh_version') { + callback(null, jsonRPCResponse(payload.id, 5)) + } + if (payload.method === 'eth_getBlockByNumber') { + let b = { + "difficulty": "0x0", + "extraData": "0x", + "gasLimit": "0x7a1200", + "gasUsed": "0x0", + "hash": "0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "miner": "0x3333333333333333333333333333333333333333", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0000000000000042", + "number": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "size": "0x1f8", + "stateRoot": "0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff", + "timestamp": "0x0", + "totalDifficulty": "0x0", + "transactions": [], + "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncles": [] + } + callback(null, jsonRPCResponse(payload.id, b)) + } } Provider.prototype.isConnected = function () { diff --git a/remix-simulator/src/server.js b/remix-simulator/src/server.js new file mode 100644 index 0000000000..f833713307 --- /dev/null +++ b/remix-simulator/src/server.js @@ -0,0 +1,26 @@ +const express = require('express') +const bodyParser = require('body-parser') +const app = express() +const Provider = require('./provider') + +var provider = new Provider() + +app.use(bodyParser.urlencoded({extended: true})) +app.use(bodyParser.json()) + +app.get('/', (req, res) => { + res.send('Welcome to remix-simulator') +}); + +app.use(function(req,res) { + // url, body, params, method + console.log("request ", req.method, req.body) + provider.sendAsync(req.body, (err, jsonResponse) => { + console.dir("response is ") + console.dir(jsonResponse) + res.send(jsonResponse) + }); +}); + +app.listen(8545, () => console.log('Example app listening on port 8545!')) +