revert-603-optF
aniket-engg 4 years ago committed by Aniket
parent c7107ce55a
commit 533e0626a5
  1. 5
      libs/remix-simulator/index.js
  2. 0
      libs/remix-simulator/src/genesis.ts
  3. 3
      libs/remix-simulator/src/index.ts
  4. 29
      libs/remix-simulator/src/methods/accounts.ts
  5. 13
      libs/remix-simulator/src/methods/blocks.ts
  6. 7
      libs/remix-simulator/src/methods/debug.ts
  7. 7
      libs/remix-simulator/src/methods/filters.ts
  8. 0
      libs/remix-simulator/src/methods/misc.ts
  9. 0
      libs/remix-simulator/src/methods/net.ts
  10. 26
      libs/remix-simulator/src/methods/transactions.ts
  11. 4
      libs/remix-simulator/src/methods/txProcess.ts
  12. 15
      libs/remix-simulator/src/provider.ts
  13. 0
      libs/remix-simulator/src/server.ts
  14. 0
      libs/remix-simulator/src/utils/logs.ts
  15. 0
      libs/remix-simulator/test/accounts.ts
  16. 0
      libs/remix-simulator/test/blocks.ts
  17. 0
      libs/remix-simulator/test/misc.ts
  18. 7
      libs/remix-simulator/tsconfig.json
  19. 30
      libs/remix-simulator/tsconfig.lib.json

@ -1,5 +0,0 @@
const Provider = require('./src/provider')
module.exports = {
Provider: Provider
}

@ -0,0 +1,3 @@
import {Provider} from './provider'
export { Provider }

@ -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
}

@ -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
}

@ -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

@ -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

@ -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
}

@ -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

@ -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
}

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["**/*.ts"]
}

@ -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/"
]
}
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"declaration": true,
"rootDir": "./src",
"types": ["node"]
},
"exclude": [
"**/*.spec.ts"
],
"include": ["**/*.ts"]
}

Loading…
Cancel
Save