fix linting issues

pull/3094/head
Iuri Matias 7 years ago
parent 1bc72a1f80
commit 6ba89e9bd1
  1. 6
      remix-simulator/src/methods/accounts.js
  2. 4
      remix-simulator/src/methods/blocks.js
  3. 5
      remix-simulator/src/methods/misc.js
  4. 20
      remix-simulator/src/methods/transactions.js
  5. 7
      remix-simulator/src/methods/whisper.js
  6. 20
      remix-simulator/src/provider.js

@ -1,6 +1,6 @@
var Web3 = require('web3') var Web3 = require('web3')
var Accounts = function(web3) { var Accounts = function () {
this.web3 = new Web3() this.web3 = new Web3()
// TODO: make it random and/or use remix-libs // TODO: make it random and/or use remix-libs
this.accounts = [this.web3.eth.accounts.create(['abcd'])] this.accounts = [this.web3.eth.accounts.create(['abcd'])]
@ -15,8 +15,8 @@ Accounts.prototype.methods = function () {
} }
} }
Accounts.prototype.eth_accounts = function(payload, cb) { Accounts.prototype.eth_accounts = function (payload, cb) {
return cb(null, this.accounts.map((x) => x.address)) return cb(null, this.accounts.map((x) => x.address))
} }
module.exports = Accounts; module.exports = Accounts

@ -1,5 +1,5 @@
var Blocks = function() { var Blocks = function () {
} }
Blocks.prototype.methods = function () { Blocks.prototype.methods = function () {
@ -39,4 +39,4 @@ Blocks.prototype.eth_gasPrice = function (payload, cb) {
cb(null, 1) cb(null, 1)
} }
module.exports = Blocks; module.exports = Blocks

@ -1,6 +1,6 @@
var version = require('../../package.json').version var version = require('../../package.json').version
var Misc = function() { var Misc = function () {
} }
Misc.prototype.methods = function () { Misc.prototype.methods = function () {
@ -13,5 +13,4 @@ Misc.prototype.web3_clientVersion = function (payload, cb) {
cb(null, 'Remix Simulator/' + version) cb(null, 'Remix Simulator/' + version)
} }
module.exports = Misc
module.exports = Misc;

@ -2,8 +2,8 @@ var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext var executionContext = RemixLib.execution.executionContext
var processTx = require('./txProcess.js') var processTx = require('./txProcess.js')
var Transactions = function(accounts) { var Transactions = function (accounts) {
this.accounts = accounts; this.accounts = accounts
// TODO: fix me; this is a temporary and very hackish thing just to get the getCode working for now // TODO: fix me; this is a temporary and very hackish thing just to get the getCode working for now
this.deployedContracts = {} this.deployedContracts = {}
} }
@ -18,12 +18,12 @@ Transactions.prototype.methods = function () {
} }
} }
Transactions.prototype.eth_sendTransaction = function(payload, cb) { Transactions.prototype.eth_sendTransaction = function (payload, cb) {
processTx(this.accounts, payload, false, cb); processTx(this.accounts, payload, false, cb)
} }
Transactions.prototype.eth_getTransactionReceipt = function(payload, cb) { Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
const self = this; const self = this
executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => { executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => {
if (error) { if (error) {
return cb(error) return cb(error)
@ -46,18 +46,18 @@ Transactions.prototype.eth_getTransactionReceipt = function(payload, cb) {
}) })
} }
Transactions.prototype.eth_estimateGas = function(payload, cb) { Transactions.prototype.eth_estimateGas = function (payload, cb) {
cb(null, 3000000) cb(null, 3000000)
} }
Transactions.prototype.eth_getCode = function(payload, cb) { Transactions.prototype.eth_getCode = function (payload, cb) {
let address = payload.params[0] let address = payload.params[0]
cb(null, this.deployedContracts[address] || '0x') cb(null, this.deployedContracts[address] || '0x')
} }
Transactions.prototype.eth_call = function(payload, cb) { Transactions.prototype.eth_call = function (payload, cb) {
processTx(this.accounts, payload, true, cb) processTx(this.accounts, payload, true, cb)
} }
module.exports = Transactions; module.exports = Transactions

@ -1,16 +1,15 @@
var Whisper = function() { var Whisper = function () {
} }
Whisper.prototype.methods = function() { Whisper.prototype.methods = function () {
return { return {
shh_version: this.shh_version.bind(this) shh_version: this.shh_version.bind(this)
} }
} }
Whisper.prototype.shh_version = function(payload, cb) { Whisper.prototype.shh_version = function (payload, cb) {
cb(null, 5) cb(null, 5)
} }
module.exports = Whisper module.exports = Whisper

@ -1,18 +1,14 @@
var RemixLib = require('remix-lib')
const log = require('fancy-log') const log = require('fancy-log')
const merge = require('merge')
const Accounts = require('./methods/accounts.js') const Accounts = require('./methods/accounts.js')
const Blocks = require('./methods/blocks.js') const Blocks = require('./methods/blocks.js')
const Misc = require('./methods/misc.js') const Misc = require('./methods/misc.js')
const Transactions = require('./methods/transactions.js') const Transactions = require('./methods/transactions.js')
const Whisper = require('./methods/whisper.js') const Whisper = require('./methods/whisper.js')
const merge = require('merge')
function jsonRPCResponse (id, result) {
return {'id': id, 'jsonrpc': '2.0', 'result': result}
}
var Provider = function () { var Provider = function () {
this.Accounts = new Accounts(); this.Accounts = new Accounts()
this.methods = {} this.methods = {}
this.methods = merge(this.methods, this.Accounts.methods()) this.methods = merge(this.methods, this.Accounts.methods())
@ -24,19 +20,19 @@ var Provider = function () {
} }
Provider.prototype.sendAsync = function (payload, callback) { Provider.prototype.sendAsync = function (payload, callback) {
const self = this
log.info('payload method is ', payload.method) log.info('payload method is ', payload.method)
let method = this.methods[payload.method] let method = this.methods[payload.method]
if (method) { if (method) {
return method.call(method, payload, (err, result) => { return method.call(method, payload, (err, result) => {
if (err) { if (err) {
return callback({error: err}) return callback(err)
} }
callback(null, jsonRPCResponse(payload.id, result)) let response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result}
}); callback(null, response)
})
} }
callback("unknown method " + payload.method); callback(new Error('unknown method ' + payload.method))
} }
Provider.prototype.isConnected = function () { Provider.prototype.isConnected = function () {

Loading…
Cancel
Save