diff --git a/libs/remix-simulator/index.js b/libs/remix-simulator/index.js deleted file mode 100644 index 3ce817f94e..0000000000 --- a/libs/remix-simulator/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const Provider = require('./src/provider') - -module.exports = { - Provider: Provider -} diff --git a/libs/remix-simulator/src/genesis.js b/libs/remix-simulator/src/genesis.ts similarity index 100% rename from libs/remix-simulator/src/genesis.js rename to libs/remix-simulator/src/genesis.ts diff --git a/libs/remix-simulator/src/index.ts b/libs/remix-simulator/src/index.ts new file mode 100644 index 0000000000..1645bcca00 --- /dev/null +++ b/libs/remix-simulator/src/index.ts @@ -0,0 +1,3 @@ +import {Provider} from './provider' + +export { Provider } diff --git a/libs/remix-simulator/src/methods/accounts.js b/libs/remix-simulator/src/methods/accounts.ts similarity index 85% rename from libs/remix-simulator/src/methods/accounts.js rename to libs/remix-simulator/src/methods/accounts.ts index ba019dac66..95edbb4c38 100644 --- a/libs/remix-simulator/src/methods/accounts.js +++ b/libs/remix-simulator/src/methods/accounts.ts @@ -1,9 +1,14 @@ -const ethJSUtil = require('ethereumjs-util') -const { BN, privateToAddress, isValidPrivate } = require('ethereumjs-util') -const Web3 = require('web3') -const crypto = require('crypto') +import { BN, privateToAddress, toChecksumAddress, isValidPrivate} from 'ethereumjs-util' +import { stripHexPrefix } from 'ethjs-util' +import Web3 from 'web3' +import * as crypto from 'crypto' -class Accounts{ +export class Accounts { + + web3 + accounts + accountsKeys + executionContext constructor(executionContext) { this.web3 = new Web3() @@ -39,10 +44,10 @@ class Accounts{ _addAccount (privateKey, balance) { return new Promise((resolve, reject) => { privateKey = Buffer.from(privateKey, 'hex') - const address = ethJSUtil.privateToAddress(privateKey) + const address = privateToAddress(privateKey) - this.accounts[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 } - this.accountsKeys[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex') + this.accounts[toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 } + this.accountsKeys[toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex') let stateManager = this.executionContext.vm().stateManager stateManager.getAccount(address, (error, account) => { @@ -81,7 +86,7 @@ class Accounts{ eth_getBalance (payload, cb) { let address = payload.params[0] - address = ethJSUtil.stripHexPrefix(address) + address = stripHexPrefix(address) this.executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), (err, account) => { if (err) { @@ -95,7 +100,7 @@ class Accounts{ const address = payload.params[0] const message = payload.params[1] - const privateKey = this.accountsKeys[ethJSUtil.toChecksumAddress(address)] + const privateKey = this.accountsKeys[toChecksumAddress(address)] if (!privateKey) { return cb(new Error('unknown account')) } @@ -105,6 +110,4 @@ class Accounts{ cb(null, data.signature) } -} - -module.exports = Accounts \ No newline at end of file +} \ No newline at end of file diff --git a/libs/remix-simulator/src/methods/blocks.js b/libs/remix-simulator/src/methods/blocks.ts similarity index 97% rename from libs/remix-simulator/src/methods/blocks.js rename to libs/remix-simulator/src/methods/blocks.ts index 2b8d80191c..ce137a0d5e 100644 --- a/libs/remix-simulator/src/methods/blocks.js +++ b/libs/remix-simulator/src/methods/blocks.ts @@ -1,4 +1,9 @@ -class Blocks { +export class Blocks { + + executionContext + coinbase + blockNumber + constructor (executionContext, _options) { this.executionContext = executionContext const options = _options || {} @@ -130,10 +135,8 @@ class Blocks { return cb(err, '') } - let value = Object.values(result.storage)[0].value + let value = Object.values(result.storage)[0]['value'] cb(err, value) }) } -} - -module.exports = Blocks \ No newline at end of file +} \ No newline at end of file diff --git a/libs/remix-simulator/src/methods/debug.js b/libs/remix-simulator/src/methods/debug.ts similarity index 95% rename from libs/remix-simulator/src/methods/debug.js rename to libs/remix-simulator/src/methods/debug.ts index 77946fea77..060878f921 100644 --- a/libs/remix-simulator/src/methods/debug.js +++ b/libs/remix-simulator/src/methods/debug.ts @@ -1,4 +1,7 @@ -class Debug { +export class Debug { + + executionContext + constructor (executionContext) { this.executionContext = executionContext } @@ -29,5 +32,3 @@ class Debug { cb) } } - -module.exports = Debug diff --git a/libs/remix-simulator/src/methods/filters.js b/libs/remix-simulator/src/methods/filters.ts similarity index 97% rename from libs/remix-simulator/src/methods/filters.js rename to libs/remix-simulator/src/methods/filters.ts index b9aaf73a82..dba83cd3d6 100644 --- a/libs/remix-simulator/src/methods/filters.js +++ b/libs/remix-simulator/src/methods/filters.ts @@ -1,4 +1,7 @@ -class Filters { +export class Filters { + + executionContext + constructor(executionContext) { this.executionContext = executionContext } @@ -58,5 +61,3 @@ class Filters { cb(null, results) } } - -module.exports = Filters \ No newline at end of file diff --git a/libs/remix-simulator/src/methods/misc.js b/libs/remix-simulator/src/methods/misc.ts similarity index 100% rename from libs/remix-simulator/src/methods/misc.js rename to libs/remix-simulator/src/methods/misc.ts diff --git a/libs/remix-simulator/src/methods/net.js b/libs/remix-simulator/src/methods/net.ts similarity index 100% rename from libs/remix-simulator/src/methods/net.js rename to libs/remix-simulator/src/methods/net.ts diff --git a/libs/remix-simulator/src/methods/transactions.js b/libs/remix-simulator/src/methods/transactions.ts similarity index 93% rename from libs/remix-simulator/src/methods/transactions.js rename to libs/remix-simulator/src/methods/transactions.ts index 7d0f5e46d4..176583df27 100644 --- a/libs/remix-simulator/src/methods/transactions.js +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -1,9 +1,11 @@ -const Web3 = require('web3') -const ethJSUtil = require('ethereumjs-util') -const processTx = require('./txProcess.js') -const BN = ethJSUtil.BN +import Web3 from 'web3' +import { toChecksumAddress, BN } from 'ethereumjs-util' +import { processTx } from './txProcess' class Transactions{ + + executionContext + accounts constructor(executionContext) { this.executionContext = executionContext @@ -30,7 +32,7 @@ class Transactions{ eth_sendTransaction (payload, cb) { // from might be lowercased address (web3) if (payload.params && payload.params.length > 0 && payload.params[0].from) { - payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from) + payload.params[0].from = toChecksumAddress(payload.params[0].from) } processTx(this.executionContext, this.accounts, payload, false, cb) } @@ -83,10 +85,10 @@ class Transactions{ eth_call (payload, cb) { // from might be lowercased address (web3) if (payload.params && payload.params.length > 0 && payload.params[0].from) { - payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from) + payload.params[0].from = toChecksumAddress(payload.params[0].from) } if (payload.params && payload.params.length > 0 && payload.params[0].to) { - payload.params[0].to = ethJSUtil.toChecksumAddress(payload.params[0].to) + payload.params[0].to = toChecksumAddress(payload.params[0].to) } payload.params[0].value = undefined @@ -136,7 +138,7 @@ class Transactions{ } if (receipt.to) { - r.to = receipt.to + r['to'] = receipt.to } if (r.value === '0x') { @@ -182,7 +184,7 @@ class Transactions{ } if (receipt.to) { - r.to = receipt.to + r['to'] = receipt.to } if (r.value === '0x') { @@ -224,7 +226,7 @@ class Transactions{ } if (receipt.to) { - r.to = receipt.to + r['to'] = receipt.to } if (r.value === '0x') { @@ -234,6 +236,4 @@ class Transactions{ cb(null, r) }) } -} - -module.exports = Transactions \ No newline at end of file +} \ No newline at end of file diff --git a/libs/remix-simulator/src/methods/txProcess.js b/libs/remix-simulator/src/methods/txProcess.ts similarity index 96% rename from libs/remix-simulator/src/methods/txProcess.js rename to libs/remix-simulator/src/methods/txProcess.ts index d1b177eef0..2dcb582740 100644 --- a/libs/remix-simulator/src/methods/txProcess.js +++ b/libs/remix-simulator/src/methods/txProcess.ts @@ -39,7 +39,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac let txRunnerInstance -function processTx (executionContext, accounts, payload, isCall, callback) { +export function processTx (executionContext, accounts, payload, isCall, callback) { const api = { logMessage: (msg) => { }, @@ -94,5 +94,3 @@ function processTx (executionContext, accounts, payload, isCall, callback) { createContract(payload, from, data, value, gas, txRunnerInstance, callbacks, callback) } } - -module.exports = processTx diff --git a/libs/remix-simulator/src/provider.js b/libs/remix-simulator/src/provider.ts similarity index 94% rename from libs/remix-simulator/src/provider.js rename to libs/remix-simulator/src/provider.ts index f9d1d68fba..381290d99f 100644 --- a/libs/remix-simulator/src/provider.js +++ b/libs/remix-simulator/src/provider.ts @@ -5,7 +5,7 @@ const log = require('./utils/logs.js') const merge = require('merge') const Accounts = require('./methods/accounts.js') -const Blocks = require('./methods/blocks.js') +import { Blocks } from './methods/blocks' const Filters = require('./methods/filters.js') const Misc = require('./methods/misc.js') const Net = require('./methods/net.js') @@ -14,7 +14,14 @@ const Debug = require('./methods/debug.js') const generateBlock = require('./genesis.js') -class Provider { +export class Provider { + + options + executionContext + Accounts + Transactions + methods + constructor(options = {}) { this.options = options // TODO: init executionContext here @@ -74,6 +81,4 @@ class Provider { on (type, cb) { this.executionContext.logsManager.addListener(type, cb) } -} - -module.exports = Provider \ No newline at end of file +} \ No newline at end of file diff --git a/libs/remix-simulator/src/server.js b/libs/remix-simulator/src/server.ts similarity index 100% rename from libs/remix-simulator/src/server.js rename to libs/remix-simulator/src/server.ts diff --git a/libs/remix-simulator/src/utils/logs.js b/libs/remix-simulator/src/utils/logs.ts similarity index 100% rename from libs/remix-simulator/src/utils/logs.js rename to libs/remix-simulator/src/utils/logs.ts diff --git a/libs/remix-simulator/test/accounts.js b/libs/remix-simulator/test/accounts.ts similarity index 100% rename from libs/remix-simulator/test/accounts.js rename to libs/remix-simulator/test/accounts.ts diff --git a/libs/remix-simulator/test/blocks.js b/libs/remix-simulator/test/blocks.ts similarity index 100% rename from libs/remix-simulator/test/blocks.js rename to libs/remix-simulator/test/blocks.ts diff --git a/libs/remix-simulator/test/misc.js b/libs/remix-simulator/test/misc.ts similarity index 100% rename from libs/remix-simulator/test/misc.js rename to libs/remix-simulator/test/misc.ts diff --git a/libs/remix-simulator/tsconfig.json b/libs/remix-simulator/tsconfig.json new file mode 100644 index 0000000000..4f27566be2 --- /dev/null +++ b/libs/remix-simulator/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "types": ["node"] + }, + "include": ["**/*.ts"] + } \ No newline at end of file diff --git a/libs/remix-simulator/tsconfig.lib.json b/libs/remix-simulator/tsconfig.lib.json index 35b63e23e8..463da90b45 100644 --- a/libs/remix-simulator/tsconfig.lib.json +++ b/libs/remix-simulator/tsconfig.lib.json @@ -1,18 +1,14 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "module": "commonjs", - "outDir": "../../dist/out-tsc", - "allowJs": true, - "declaration": true, - "rootDir": "./", - "types": ["node"] - }, - "exclude": ["**/*.spec.js"], - "include": [ - "src/**/*.js", - "./index.js", - "bin/" - ] - } - \ No newline at end of file + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "rootDir": "./src", + "types": ["node"] + }, + "exclude": [ + "**/*.spec.ts" + ], + "include": ["**/*.ts"] +}