build working

revert-603-optF
aniket-engg 4 years ago committed by Aniket
parent d71e581b85
commit 63512c8312
  1. 5
      libs/remix-simulator/src/genesis.ts
  2. 100
      libs/remix-simulator/src/methods/misc.ts
  3. 36
      libs/remix-simulator/src/methods/net.ts
  4. 27
      libs/remix-simulator/src/provider.ts
  5. 25
      libs/remix-simulator/src/server.ts
  6. 118
      libs/remix-simulator/src/utils/logs.ts
  7. 3
      libs/remix-simulator/tsconfig.lib.json
  8. 26
      package-lock.json
  9. 1
      package.json
  10. 4
      workspace.json

@ -1,6 +1,5 @@
const EthJSBlock = require('ethereumjs-block') import EthJSBlock from 'ethereumjs-block'
const ethJSUtil = require('ethereumjs-util') import { BN } from 'ethereumjs-util'
const BN = ethJSUtil.BN
function generateBlock (executionContext) { function generateBlock (executionContext) {
const block = new EthJSBlock({ const block = new EthJSBlock({

@ -1,64 +1,62 @@
const version = require('../../package.json').version const version = require('../../package.json').version
const web3 = require('web3') import web3 from 'web3'
const Misc = function () { export class Misc {
}
methods () {
Misc.prototype.methods = function () { return {
return { web3_clientVersion: this.web3_clientVersion.bind(this),
web3_clientVersion: this.web3_clientVersion.bind(this), eth_protocolVersion: this.eth_protocolVersion.bind(this),
eth_protocolVersion: this.eth_protocolVersion.bind(this), eth_syncing: this.eth_syncing.bind(this),
eth_syncing: this.eth_syncing.bind(this), eth_mining: this.eth_mining.bind(this),
eth_mining: this.eth_mining.bind(this), eth_hashrate: this.eth_hashrate.bind(this),
eth_hashrate: this.eth_hashrate.bind(this), web3_sha3: this.web3_sha3.bind(this),
web3_sha3: this.web3_sha3.bind(this), eth_getCompilers: this.eth_getCompilers.bind(this),
eth_getCompilers: this.eth_getCompilers.bind(this), eth_compileSolidity: this.eth_compileSolidity.bind(this),
eth_compileSolidity: this.eth_compileSolidity.bind(this), eth_compileLLL: this.eth_compileLLL.bind(this),
eth_compileLLL: this.eth_compileLLL.bind(this), eth_compileSerpent: this.eth_compileSerpent.bind(this)
eth_compileSerpent: this.eth_compileSerpent.bind(this) }
} }
}
Misc.prototype.web3_clientVersion = function (payload, cb) { web3_clientVersion (payload, cb) {
cb(null, 'Remix Simulator/' + version) cb(null, 'Remix Simulator/' + version)
} }
Misc.prototype.eth_protocolVersion = function (payload, cb) { eth_protocolVersion (payload, cb) {
cb(null, '0x3f') cb(null, '0x3f')
} }
Misc.prototype.eth_syncing = function (payload, cb) { eth_syncing (payload, cb) {
cb(null, false) cb(null, false)
} }
Misc.prototype.eth_mining = function (payload, cb) { eth_mining (payload, cb) {
// TODO: should depend on the state // TODO: should depend on the state
cb(null, false) cb(null, false)
} }
Misc.prototype.eth_hashrate = function (payload, cb) { eth_hashrate (payload, cb) {
cb(null, '0x0') cb(null, '0x0')
} }
Misc.prototype.web3_sha3 = function (payload, cb) { web3_sha3 (payload, cb) {
const str = payload.params[0] const str = payload.params[0]
cb(null, web3.utils.sha3(str)) cb(null, web3.utils.sha3(str))
} }
Misc.prototype.eth_getCompilers = function (payload, cb) { eth_getCompilers (payload, cb) {
cb(null, []) cb(null, [])
} }
Misc.prototype.eth_compileSolidity = function (payload, cb) { eth_compileSolidity (payload, cb) {
cb(null, 'unsupported') cb(null, 'unsupported')
} }
Misc.prototype.eth_compileLLL = function (payload, cb) { eth_compileLLL (payload, cb) {
cb(null, 'unsupported') cb(null, 'unsupported')
} }
Misc.prototype.eth_compileSerpent = function (payload, cb) { eth_compileSerpent (payload, cb) {
cb(null, 'unsupported') cb(null, 'unsupported')
}
} }
module.exports = Misc

@ -1,26 +1,24 @@
const Net = function () { export class Net {
}
Net.prototype.methods = function () { methods () {
return { return {
net_version: this.net_version, net_version: this.net_version,
net_listening: this.net_listening, net_listening: this.net_listening,
net_peerCount: this.net_peerCount net_peerCount: this.net_peerCount
}
} }
}
Net.prototype.net_version = function (payload, cb) { net_version (payload, cb) {
// should be configured networkId // should be configured networkId
cb(null, 1337) cb(null, 1337)
} }
Net.prototype.net_listening = function (payload, cb) { net_listening (payload, cb) {
cb(null, true) cb(null, true)
} }
Net.prototype.net_peerCount = function (payload, cb) { net_peerCount (payload, cb) {
cb(null, 0) cb(null, 0)
}
} }
module.exports = Net

@ -1,16 +1,17 @@
import { Blocks } from './methods/blocks' import { Blocks } from './methods/blocks'
const RemixLib = require('@remix-project/remix-lib') import { execution } from '@remix-project/remix-lib'
const executionContext = RemixLib.execution.executionContext const { executionContext } = execution
const log = require('./utils/logs.js') import { Logger } from './utils/logs'
const merge = require('merge') const logger = new Logger()
import merge from 'merge'
const Accounts = require('./methods/accounts.js') import { Accounts } from './methods/accounts'
const Filters = require('./methods/filters.js') import { Filters } from './methods/filters'
const Misc = require('./methods/misc.js') import { Misc } from './methods/misc'
const Net = require('./methods/net.js') import { Net } from './methods/net.js'
const Transactions = require('./methods/transactions.js') import { Transactions } from './methods/transactions.js'
const Debug = require('./methods/debug.js') import { Debug } from './methods/debug.js'
const generateBlock = require('./genesis.js') const generateBlock = require('./genesis.js')
@ -51,13 +52,13 @@ export class Provider {
const method = this.methods[payload.method] const method = this.methods[payload.method]
if (this.options.logDetails) { if (this.options.logDetails) {
log.info(payload) logger.info(payload)
} }
if (method) { if (method) {
return method.call(method, payload, (err, result) => { return method.call(method, payload, (err, result) => {
if (this.options.logDetails) { if (this.options.logDetails) {
log.info(err) logger.info(err)
log.info(result) logger.info(result)
} }
if (err) { if (err) {
return callback(err) return callback(err)

@ -1,18 +1,23 @@
const express = require('express') import express from 'express'
const cors = require('cors') import cors from 'cors'
const bodyParser = require('body-parser') import bodyParser from 'body-parser'
const app = express() const app = express()
const expressWs = require('express-ws') import expressWs from 'express-ws'
const Provider = require('./provider') import { Provider } from './provider'
const log = require('./utils/logs.js') import { Logger } from './utils/logs'
const logger = new Logger()
class Server { class Server {
provider
rpcOnly
constructor (options) { constructor (options) {
this.provider = new Provider(options) this.provider = new Provider(options)
this.provider.init().then(() => { this.provider.init().then(() => {
log('Provider initiated') logger.log('Provider initiated')
}).catch((error) => { }).catch((error) => {
log(error) logger.log(error)
}) })
this.rpcOnly = options.rpc this.rpcOnly = options.rpc
} }
@ -55,9 +60,9 @@ class Server {
} }
app.listen(port, host, () => { app.listen(port, host, () => {
log('Remix Simulator listening on ws://' + host + ':' + port) logger.log('Remix Simulator listening on ws://' + host + ':' + port)
if (!this.rpcOnly) { if (!this.rpcOnly) {
log('http json-rpc is deprecated and disabled by default. To enable it use --rpc') logger.log('http json-rpc is deprecated and disabled by default. To enable it use --rpc')
} }
}) })
} }

@ -1,82 +1,78 @@
'use strict' 'use strict'
const gray = require('ansi-gray') import gray from 'ansi-gray'
const timestamp = require('time-stamp') import timestamp from 'time-stamp'
const supportsColor = require('color-support') import supportsColor from 'color-support'
function hasFlag (flag) { export class Logger {
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
}
function addColor (str) { private hasFlag(flag) {
if (hasFlag('no-color')) { return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
return str
} }
if (hasFlag('color')) { private addColor(str) {
return gray(str) if (this.hasFlag('no-color')) {
} return str
}
if (supportsColor()) { if (this.hasFlag('color')) {
return gray(str) return gray(str)
} }
return str if (supportsColor()) {
} return gray(str)
}
return str
}
const logger = { private stdout(arg) {
stdout: function (arg) {
if (typeof (process) === 'undefined' || !process.stdout) return if (typeof (process) === 'undefined' || !process.stdout) return
process.stdout.write(arg) process.stdout.write(arg)
}, }
stderr: function (arg) {
private stderr(arg) {
if (typeof (process) === 'undefined' || process.stderr) return if (typeof (process) === 'undefined' || process.stderr) return
process.stderr.write(arg) process.stderr.write(arg)
} }
}
function getTimestamp () { private getTimestamp() {
const coloredTimestamp = addColor(timestamp('HH:mm:ss')) const coloredTimestamp = this.addColor(timestamp('HH:mm:ss'))
return '[' + coloredTimestamp + ']' return '[' + coloredTimestamp + ']'
} }
function log () { log(...args: any[]) {
const time = getTimestamp() const time = this.getTimestamp()
logger.stdout(time + ' ') this.stdout(time + ' ')
console.log.apply(console, arguments) console.log(args)
return this return this
} }
function info () { info(...args: any[]) {
const time = getTimestamp() const time = this.getTimestamp()
logger.stdout(time + ' ') this.stdout(time + ' ')
console.info.apply(console, arguments) console.info(args)
return this return this
} }
function dir () { dir(...args: any[]) {
const time = getTimestamp() const time = this.getTimestamp()
logger.stdout(time + ' ') this.stdout(time + ' ')
console.dir.apply(console, arguments) console.dir(args)
return this return this
} }
function warn () { warn(...args: any[]) {
const time = getTimestamp() const time = this.getTimestamp()
logger.stderr(time + ' ') this.stderr(time + ' ')
console.warn.apply(console, arguments) console.warn(args)
return this return this
} }
function error () { error(...args: any[]) {
const time = getTimestamp() const time = this.getTimestamp()
logger.stderr(time + ' ') this.stderr(time + ' ')
console.error.apply(console, arguments) console.error(args)
return this return this
}
} }
module.exports = log
module.exports.info = info
module.exports.dir = dir
module.exports.warn = warn
module.exports.error = error

@ -8,7 +8,8 @@
"types": ["node"] "types": ["node"]
}, },
"exclude": [ "exclude": [
"**/*.spec.ts" "**/*.spec.ts",
"test/"
], ],
"include": ["**/*.ts"] "include": ["**/*.ts"]
} }

26
package-lock.json generated

@ -9013,8 +9013,7 @@
"async-limiter": { "async-limiter": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
"dev": true
}, },
"async-settle": { "async-settle": {
"version": "1.0.0", "version": "1.0.0",
@ -16901,6 +16900,24 @@
} }
} }
}, },
"express-ws": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/express-ws/-/express-ws-4.0.0.tgz",
"integrity": "sha512-KEyUw8AwRET2iFjFsI1EJQrJ/fHeGiJtgpYgEWG3yDv4l/To/m3a2GaYfeGyB3lsWdvbesjF5XCMx+SVBgAAYw==",
"requires": {
"ws": "^5.2.0"
},
"dependencies": {
"ws": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz",
"integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==",
"requires": {
"async-limiter": "~1.0.0"
}
}
}
},
"ext": { "ext": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz",
@ -28265,7 +28282,6 @@
}, },
"dezalgo": { "dezalgo": {
"version": "1.0.3", "version": "1.0.3",
"resolved": false,
"integrity": "sha1-f3Qt4Gb8dIvI24IFad3c5Jvw1FY=", "integrity": "sha1-f3Qt4Gb8dIvI24IFad3c5Jvw1FY=",
"requires": { "requires": {
"asap": "^2.0.0", "asap": "^2.0.0",
@ -28894,7 +28910,6 @@
}, },
"normalize-git-url": { "normalize-git-url": {
"version": "3.0.2", "version": "3.0.2",
"resolved": false,
"integrity": "sha1-jl8Uvgva7bc+ByADEKpBbCc1D8Q=" "integrity": "sha1-jl8Uvgva7bc+ByADEKpBbCc1D8Q="
}, },
"normalize-package-data": { "normalize-package-data": {
@ -28932,7 +28947,6 @@
}, },
"npm-install-checks": { "npm-install-checks": {
"version": "3.0.0", "version": "3.0.0",
"resolved": false,
"integrity": "sha1-1K7N/VGlPjcjt7L5Oy7ijjB7wNc=", "integrity": "sha1-1K7N/VGlPjcjt7L5Oy7ijjB7wNc=",
"requires": { "requires": {
"semver": "^2.3.0 || 3.x || 4 || 5" "semver": "^2.3.0 || 3.x || 4 || 5"
@ -29279,7 +29293,6 @@
}, },
"realize-package-specifier": { "realize-package-specifier": {
"version": "3.0.3", "version": "3.0.3",
"resolved": false,
"integrity": "sha1-0N74gpUrjeP2frpekRmWYScfQfQ=", "integrity": "sha1-0N74gpUrjeP2frpekRmWYScfQfQ=",
"requires": { "requires": {
"dezalgo": "^1.0.1", "dezalgo": "^1.0.1",
@ -29816,7 +29829,6 @@
"dependencies": { "dependencies": {
"unique-slug": { "unique-slug": {
"version": "2.0.0", "version": "2.0.0",
"resolved": false,
"integrity": "sha1-22Z258fMBimHj/GWCXx4hVrp9Ks=", "integrity": "sha1-22Z258fMBimHj/GWCXx4hVrp9Ks=",
"requires": { "requires": {
"imurmurhash": "^0.1.4" "imurmurhash": "^0.1.4"

@ -145,6 +145,7 @@
"ethereumjs-block": "^2.2.2", "ethereumjs-block": "^2.2.2",
"ethereumjs-tx": "^2.1.2", "ethereumjs-tx": "^2.1.2",
"ethereumjs-vm": "4.1.3", "ethereumjs-vm": "4.1.3",
"express-ws": "^4.0.0",
"fs-extra": "^3.0.1", "fs-extra": "^3.0.1",
"http-server": "^0.11.1", "http-server": "^0.11.1",
"isbinaryfile": "^3.0.2", "isbinaryfile": "^3.0.2",

@ -292,7 +292,7 @@
}, },
"remix-simulator": { "remix-simulator": {
"root": "libs/remix-simulator", "root": "libs/remix-simulator",
"sourceRoot": "libs/remix-simulator/", "sourceRoot": "libs/remix-simulator/src",
"projectType": "library", "projectType": "library",
"schematics": {}, "schematics": {},
"architect": { "architect": {
@ -322,7 +322,7 @@
"outputPath": "dist/libs/remix-simulator", "outputPath": "dist/libs/remix-simulator",
"tsConfig": "libs/remix-simulator/tsconfig.lib.json", "tsConfig": "libs/remix-simulator/tsconfig.lib.json",
"packageJson": "libs/remix-simulator/package.json", "packageJson": "libs/remix-simulator/package.json",
"main": "libs/remix-simulator/index.js", "main": "libs/remix-simulator/src/index.ts",
"assets": [ "assets": [
{ {
"glob": "ethsim", "glob": "ethsim",

Loading…
Cancel
Save