lint, build & test working for remix-simulator

pull/5/head
aniket-engg 4 years ago
parent 6c1c567790
commit a1f50eb141
  1. 15
      libs/remix-simulator/.eslintrc
  2. 4
      libs/remix-simulator/package.json
  3. 218
      libs/remix-simulator/src/methods/blocks.js
  4. 94
      libs/remix-simulator/src/methods/filters.js
  5. 413
      libs/remix-simulator/src/methods/transactions.js
  6. 2
      libs/remix-simulator/src/methods/txProcess.js
  7. 100
      libs/remix-simulator/src/provider.js
  8. 18
      libs/remix-simulator/tsconfig.lib.json
  9. 1022
      package-lock.json
  10. 6
      package.json
  11. 25
      workspace.json

@ -0,0 +1,15 @@
{
"extends": "../../.eslintrc",
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off"
},
"env": {
"browser": true,
"amd": true,
"node": true,
"es6": true
},
"ignorePatterns": ["!**/*"]
}

@ -25,7 +25,7 @@
"express": "^4.16.3",
"express-ws": "^4.0.0",
"merge": "^1.2.0",
"remix-lib": "0.4.29",
"@remix-project/remix-lib": "0.4.29",
"standard": "^10.0.3",
"time-stamp": "^2.0.0",
"web3": "^1.2.4"
@ -44,7 +44,7 @@
},
"scripts": {
"lint": "standard",
"test": "standard && mocha test/"
"test": "./../../node_modules/.bin/mocha --require tsconfig-paths/register test/"
},
"bin": {
"ethsim": "./bin/ethsim",

@ -1,138 +1,140 @@
const Blocks = function (executionContext, _options) {
this.executionContext = executionContext
const options = _options || {}
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000'
this.blockNumber = 0
}
Blocks.prototype.methods = function () {
return {
eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this),
eth_gasPrice: this.eth_gasPrice.bind(this),
eth_coinbase: this.eth_coinbase.bind(this),
eth_blockNumber: this.eth_blockNumber.bind(this),
eth_getBlockByHash: this.eth_getBlockByHash.bind(this),
eth_getBlockTransactionCountByHash: this.eth_getBlockTransactionCountByHash.bind(this),
eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this),
eth_getUncleCountByBlockHash: this.eth_getUncleCountByBlockHash.bind(this),
eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this),
eth_getStorageAt: this.eth_getStorageAt.bind(this)
class Blocks {
constructor (executionContext, _options) {
this.executionContext = executionContext
const options = _options || {}
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000'
this.blockNumber = 0
}
}
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
let blockIndex = payload.params[0]
if (blockIndex === 'latest') {
blockIndex = this.executionContext.latestBlockNumber
methods () {
return {
eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this),
eth_gasPrice: this.eth_gasPrice.bind(this),
eth_coinbase: this.eth_coinbase.bind(this),
eth_blockNumber: this.eth_blockNumber.bind(this),
eth_getBlockByHash: this.eth_getBlockByHash.bind(this),
eth_getBlockTransactionCountByHash: this.eth_getBlockTransactionCountByHash.bind(this),
eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this),
eth_getUncleCountByBlockHash: this.eth_getUncleCountByBlockHash.bind(this),
eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this),
eth_getStorageAt: this.eth_getStorageAt.bind(this)
}
}
const block = this.executionContext.blocks[blockIndex]
eth_getBlockByNumber (payload, cb) {
let blockIndex = payload.params[0]
if (blockIndex === 'latest') {
blockIndex = this.executionContext.latestBlockNumber
}
if (!block) {
return cb(new Error('block not found'))
}
const block = this.executionContext.blocks[blockIndex]
let b = {
'number': toHex(block.header.number),
'hash': toHex(block.hash()),
'parentHash': toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': []
}
if (!block) {
return cb(new Error('block not found'))
}
cb(null, b)
let b = {
'number': this.toHex(block.header.number),
'hash': this.toHex(block.hash()),
'parentHash': this.toHex(block.header.parentHash),
'nonce': this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': this.toHex(block.header.gasLimit),
'gasUsed': this.toHex(block.header.gasUsed),
'timestamp': this.toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': []
}
cb(null, b)
}
function toHex (value) {
toHex (value) {
if (!value) return '0x0'
let v = value.toString('hex')
return ((v === '0x' || v === '') ? '0x0' : ('0x' + v))
}
Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
let b = {
'number': toHex(block.header.number),
'hash': toHex(block.hash()),
'parentHash': toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': []
}
cb(null, b)
}
eth_getBlockByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
let b = {
'number': this.toHex(block.header.number),
'hash': this.toHex(block.hash()),
'parentHash': this.toHex(block.header.parentHash),
'nonce': this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': this.toHex(block.header.gasLimit),
'gasUsed': this.toHex(block.header.gasUsed),
'timestamp': this.toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': []
}
Blocks.prototype.eth_gasPrice = function (payload, cb) {
cb(null, 1)
}
cb(null, b)
}
Blocks.prototype.eth_coinbase = function (payload, cb) {
cb(null, this.coinbase)
}
eth_gasPrice (payload, cb) {
cb(null, 1)
}
Blocks.prototype.eth_blockNumber = function (payload, cb) {
cb(null, this.blockNumber)
}
eth_coinbase (payload, cb) {
cb(null, this.coinbase)
}
Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
eth_blockNumber (payload, cb) {
cb(null, this.blockNumber)
}
cb(null, block.transactions.length)
}
eth_getBlockTransactionCountByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
Blocks.prototype.eth_getBlockTransactionCountByNumber = function (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
cb(null, block.transactions.length)
}
cb(null, block.transactions.length)
}
eth_getBlockTransactionCountByNumber (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
Blocks.prototype.eth_getUncleCountByBlockHash = function (payload, cb) {
cb(null, 0)
}
cb(null, block.transactions.length)
}
Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) {
cb(null, 0)
}
eth_getUncleCountByBlockHash (payload, cb) {
cb(null, 0)
}
Blocks.prototype.eth_getStorageAt = function (payload, cb) {
const [address, position, blockNumber] = payload.params
eth_getUncleCountByBlockNumber (payload, cb) {
cb(null, 0)
}
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => {
if (err || (result.storage && Object.values(result.storage).length === 0)) {
return cb(err, '')
}
eth_getStorageAt (payload, cb) {
const [address, position, blockNumber] = payload.params
let value = Object.values(result.storage)[0].value
cb(err, value)
})
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => {
if (err || (result.storage && Object.values(result.storage).length === 0)) {
return cb(err, '')
}
let value = Object.values(result.storage)[0].value
cb(err, value)
})
}
}
module.exports = Blocks

@ -1,61 +1,63 @@
const Filters = function (executionContext) {
this.executionContext = executionContext
}
class Filters {
constructor(executionContext) {
this.executionContext = executionContext
}
Filters.prototype.methods = function () {
return {
eth_getLogs: this.eth_getLogs.bind(this),
eth_subscribe: this.eth_subscribe.bind(this),
eth_unsubscribe: this.eth_unsubscribe.bind(this)
methods () {
return {
eth_getLogs: this.eth_getLogs.bind(this),
eth_subscribe: this.eth_subscribe.bind(this),
eth_unsubscribe: this.eth_unsubscribe.bind(this)
}
}
}
Filters.prototype.eth_getLogs = function (payload, cb) {
let results = this.executionContext.logsManager.getLogsFor(payload.params[0])
cb(null, results)
}
eth_getLogs (payload, cb) {
let results = this.executionContext.logsManager.getLogsFor(payload.params[0])
cb(null, results)
}
Filters.prototype.eth_subscribe = function (payload, cb) {
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params)
cb(null, subscriptionId)
}
eth_subscribe (payload, cb) {
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params)
cb(null, subscriptionId)
}
Filters.prototype.eth_unsubscribe = function (payload, cb) {
this.executionContext.logsManager.unsubscribe(payload.params[0])
cb(null, true)
}
eth_unsubscribe (payload, cb) {
this.executionContext.logsManager.unsubscribe(payload.params[0])
cb(null, true)
}
Filters.prototype.eth_newFilter = function (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('filter', payload.params[0])
cb(null, filterId)
}
eth_newFilter (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('filter', payload.params[0])
cb(null, filterId)
}
Filters.prototype.eth_newBlockFilter = function (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('block')
cb(null, filterId)
}
eth_newBlockFilter (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('block')
cb(null, filterId)
}
Filters.prototype.eth_newPendingTransactionFilter = function (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('pendingTransactions')
cb(null, filterId)
}
eth_newPendingTransactionFilter (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('pendingTransactions')
cb(null, filterId)
}
Filters.prototype.eth_uninstallfilter = function (payload, cb) {
const result = this.executionContext.logsManager.uninstallFilter(payload.params[0])
cb(null, result)
}
eth_uninstallfilter (payload, cb) {
const result = this.executionContext.logsManager.uninstallFilter(payload.params[0])
cb(null, result)
}
Filters.prototype.eth_getFilterChanges = function (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId)
cb(null, results)
}
eth_getFilterChanges (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId)
cb(null, results)
}
Filters.prototype.eth_getFilterLogs = function (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true)
cb(null, results)
eth_getFilterLogs (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true)
cb(null, results)
}
}
module.exports = Filters

@ -3,233 +3,236 @@ const ethJSUtil = require('ethereumjs-util')
const processTx = require('./txProcess.js')
const BN = ethJSUtil.BN
const Transactions = function (executionContext) {
this.executionContext = executionContext
}
Transactions.prototype.init = function (accounts) {
this.accounts = accounts
}
Transactions.prototype.methods = function () {
return {
eth_sendTransaction: this.eth_sendTransaction.bind(this),
eth_getTransactionReceipt: this.eth_getTransactionReceipt.bind(this),
eth_getCode: this.eth_getCode.bind(this),
eth_call: this.eth_call.bind(this),
eth_estimateGas: this.eth_estimateGas.bind(this),
eth_getTransactionCount: this.eth_getTransactionCount.bind(this),
eth_getTransactionByHash: this.eth_getTransactionByHash.bind(this),
eth_getTransactionByBlockHashAndIndex: this.eth_getTransactionByBlockHashAndIndex.bind(this),
eth_getTransactionByBlockNumberAndIndex: this.eth_getTransactionByBlockNumberAndIndex.bind(this)
class Transactions{
constructor(executionContext) {
this.executionContext = executionContext
}
}
Transactions.prototype.eth_sendTransaction = function (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)
init (accounts) {
this.accounts = accounts
}
processTx(this.executionContext, this.accounts, payload, false, cb)
}
Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
this.executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => {
if (error) {
return cb(error)
}
const txBlock = this.executionContext.txs[receipt.hash]
const r = {
'transactionHash': receipt.hash,
'transactionIndex': '0x00',
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'gasUsed': Web3.utils.toHex(receipt.gas),
'cumulativeGasUsed': Web3.utils.toHex(receipt.gas),
'contractAddress': receipt.contractAddress,
'logs': receipt.logs,
'status': receipt.status
}
if (r.blockNumber === '0x') {
r.blockNumber = '0x0'
}
cb(null, r)
})
}
Transactions.prototype.eth_estimateGas = function (payload, cb) {
cb(null, 3000000)
}
Transactions.prototype.eth_getCode = function (payload, cb) {
let address = payload.params[0]
this.executionContext.web3().eth.getCode(address, (error, result) => {
if (error) {
console.dir('error getting code')
console.dir(error)
methods () {
return {
eth_sendTransaction: this.eth_sendTransaction.bind(this),
eth_getTransactionReceipt: this.eth_getTransactionReceipt.bind(this),
eth_getCode: this.eth_getCode.bind(this),
eth_call: this.eth_call.bind(this),
eth_estimateGas: this.eth_estimateGas.bind(this),
eth_getTransactionCount: this.eth_getTransactionCount.bind(this),
eth_getTransactionByHash: this.eth_getTransactionByHash.bind(this),
eth_getTransactionByBlockHashAndIndex: this.eth_getTransactionByBlockHashAndIndex.bind(this),
eth_getTransactionByBlockNumberAndIndex: this.eth_getTransactionByBlockNumberAndIndex.bind(this)
}
cb(error, result)
})
}
Transactions.prototype.eth_call = function (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)
}
if (payload.params && payload.params.length > 0 && payload.params[0].to) {
payload.params[0].to = ethJSUtil.toChecksumAddress(payload.params[0].to)
}
payload.params[0].value = undefined
processTx(this.executionContext, this.accounts, payload, true, cb)
}
Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
let address = payload.params[0]
this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
if (err) {
return cb(err)
}
let nonce = new BN(account.nonce).toString(10)
cb(null, nonce)
})
}
Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
const address = payload.params[0]
this.executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => {
if (error) {
return cb(error)
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)
}
processTx(this.executionContext, this.accounts, payload, false, cb)
}
const txBlock = this.executionContext.txs[receipt.transactionHash]
// TODO: params to add later
const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}
if (receipt.to) {
r.to = receipt.to
}
if (r.value === '0x') {
r.value = '0x0'
}
if (r.blockNumber === '0x') {
r.blockNumber = '0x0'
}
cb(null, r)
})
}
Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) {
const txIndex = payload.params[1]
eth_getTransactionReceipt (payload, cb) {
this.executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => {
if (error) {
return cb(error)
}
const txBlock = this.executionContext.txs[receipt.hash]
const r = {
'transactionHash': receipt.hash,
'transactionIndex': '0x00',
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'gasUsed': Web3.utils.toHex(receipt.gas),
'cumulativeGasUsed': Web3.utils.toHex(receipt.gas),
'contractAddress': receipt.contractAddress,
'logs': receipt.logs,
'status': receipt.status
}
if (r.blockNumber === '0x') {
r.blockNumber = '0x0'
}
cb(null, r)
})
}
const txBlock = this.executionContext.blocks[payload.params[0]]
const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
eth_estimateGas (payload, cb) {
cb(null, 3000000)
}
this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
if (error) {
return cb(error)
}
eth_getCode (payload, cb) {
let address = payload.params[0]
// TODO: params to add later
let r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}
this.executionContext.web3().eth.getCode(address, (error, result) => {
if (error) {
console.dir('error getting code')
console.dir(error)
}
cb(error, result)
})
}
if (receipt.to) {
r.to = receipt.to
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)
}
if (r.value === '0x') {
r.value = '0x0'
if (payload.params && payload.params.length > 0 && payload.params[0].to) {
payload.params[0].to = ethJSUtil.toChecksumAddress(payload.params[0].to)
}
cb(null, r)
})
}
payload.params[0].value = undefined
Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) {
const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]]
const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
processTx(this.executionContext, this.accounts, payload, true, cb)
}
this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
if (error) {
return cb(error)
}
eth_getTransactionCount (payload, cb) {
let address = payload.params[0]
// TODO: params to add later
const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}
this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
if (err) {
return cb(err)
}
let nonce = new BN(account.nonce).toString(10)
cb(null, nonce)
})
}
if (receipt.to) {
r.to = receipt.to
}
eth_getTransactionByHash (payload, cb) {
const address = payload.params[0]
this.executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => {
if (error) {
return cb(error)
}
const txBlock = this.executionContext.txs[receipt.transactionHash]
// TODO: params to add later
const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}
if (receipt.to) {
r.to = receipt.to
}
if (r.value === '0x') {
r.value = '0x0'
}
if (r.blockNumber === '0x') {
r.blockNumber = '0x0'
}
cb(null, r)
})
}
if (r.value === '0x') {
r.value = '0x0'
}
eth_getTransactionByBlockHashAndIndex (payload, cb) {
const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]]
const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
if (error) {
return cb(error)
}
// TODO: params to add later
let r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}
if (receipt.to) {
r.to = receipt.to
}
if (r.value === '0x') {
r.value = '0x0'
}
cb(null, r)
})
}
cb(null, r)
})
eth_getTransactionByBlockNumberAndIndex (payload, cb) {
const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]]
const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
if (error) {
return cb(error)
}
// TODO: params to add later
const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}
if (receipt.to) {
r.to = receipt.to
}
if (r.value === '0x') {
r.value = '0x0'
}
cb(null, r)
})
}
}
module.exports = Transactions

@ -1,4 +1,4 @@
const RemixLib = require('remix-lib')
const RemixLib = require('@remix-project/remix-lib')
const TxExecution = RemixLib.execution.txExecution
const TxRunner = RemixLib.execution.txRunner

@ -1,4 +1,4 @@
const RemixLib = require('remix-lib')
const RemixLib = require('@remix-project/remix-lib')
const executionContext = RemixLib.execution.executionContext
const log = require('./utils/logs.js')
@ -13,63 +13,65 @@ const Transactions = require('./methods/transactions.js')
const generateBlock = require('./genesis.js')
var Provider = function (options) {
this.options = options || {}
// TODO: init executionContext here
this.executionContext = executionContext
this.Accounts = new Accounts(this.executionContext)
this.Transactions = new Transactions(this.executionContext)
class Provider {
constructor(options) {
this.options = options || {}
// TODO: init executionContext here
this.executionContext = executionContext
this.Accounts = new Accounts(this.executionContext)
this.Transactions = new Transactions(this.executionContext)
this.methods = {}
this.methods = merge(this.methods, this.Accounts.methods())
this.methods = merge(this.methods, (new Blocks(this.executionContext, options)).methods())
this.methods = merge(this.methods, (new Misc()).methods())
this.methods = merge(this.methods, (new Filters(this.executionContext)).methods())
this.methods = merge(this.methods, (new Net()).methods())
this.methods = merge(this.methods, this.Transactions.methods())
this.methods = {}
this.methods = merge(this.methods, this.Accounts.methods())
this.methods = merge(this.methods, (new Blocks(this.executionContext, options)).methods())
this.methods = merge(this.methods, (new Misc()).methods())
this.methods = merge(this.methods, (new Filters(this.executionContext)).methods())
this.methods = merge(this.methods, (new Net()).methods())
this.methods = merge(this.methods, this.Transactions.methods())
generateBlock(this.executionContext)
this.init()
}
generateBlock(this.executionContext)
this.init()
}
Provider.prototype.init = async function () {
await this.Accounts.init()
this.Transactions.init(this.Accounts.accounts)
}
async init () {
await this.Accounts.init()
this.Transactions.init(this.Accounts.accounts)
}
Provider.prototype.sendAsync = function (payload, callback) {
log.info('payload method is ', payload.method)
sendAsync (payload, callback) {
log.info('payload method is ', payload.method)
const method = this.methods[payload.method]
if (this.options.logDetails) {
log.info(payload)
}
if (method) {
return method.call(method, payload, (err, result) => {
if (this.options.logDetails) {
log.info(err)
log.info(result)
}
if (err) {
return callback(err)
}
const response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result}
callback(null, response)
})
const method = this.methods[payload.method]
if (this.options.logDetails) {
log.info(payload)
}
if (method) {
return method.call(method, payload, (err, result) => {
if (this.options.logDetails) {
log.info(err)
log.info(result)
}
if (err) {
return callback(err)
}
const response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result}
callback(null, response)
})
}
callback(new Error('unknown method ' + payload.method))
}
callback(new Error('unknown method ' + payload.method))
}
Provider.prototype.send = function (payload, callback) {
this.sendAsync(payload, callback || function () {})
}
send (payload, callback) {
this.sendAsync(payload, callback || function () {})
}
Provider.prototype.isConnected = function () {
return true
}
isConnected () {
return true
}
Provider.prototype.on = function (type, cb) {
this.executionContext.logsManager.addListener(type, cb)
on (type, cb) {
this.executionContext.logsManager.addListener(type, cb)
}
}
module.exports = Provider

@ -0,0 +1,18 @@
{
"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/"
]
}

1022
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -132,11 +132,14 @@
"dependencies": {
"@remixproject/engine": "^0.2.3",
"@types/tape": "^4.2.33",
"ansi-gray": "^0.1.1",
"color-support": "^1.1.3",
"ethereumjs-block": "^2.2.2",
"ethereumjs-tx": "^2.1.2",
"ethereumjs-vm": "4.1.3",
"http-server": "^0.11.1",
"npm-install-version": "^6.0.2"
"npm-install-version": "^6.0.2",
"time-stamp": "^2.2.0"
},
"devDependencies": {
"@babel/core": "^7.4.5",
@ -200,6 +203,7 @@
"js-beautify": "1.6.14",
"minixhr": "^3.2.2",
"mkdirp": "^0.5.1",
"mocha": "^8.0.1",
"nanohtml": "^1.6.3",
"nightwatch": "^1.3.5",
"notify-error": "^1.2.0",

@ -234,29 +234,36 @@
"schematics": {},
"architect": {
"lint": {
"builder": "@nrwl/workspace:run-commands",
"builder": "@nrwl/linter:lint",
"options": {
"commands": [
{
"command": "./../../node_modules/.bin/npm-run-all lint"
}
"linter": "eslint",
"config": "libs/remix-simulator/.eslintrc",
"files": [
"libs/remix-simulator/**/*.js"
],
"cwd": "libs/remix-simulator"
"exclude": ["**/node_modules/**", "libs/remix-simulator/test/**/*"]
}
},
"test": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "rm -rf ../../dist"
},
{
"command": "./../../node_modules/.bin/npm-run-all test"
}
],
"cwd": "libs/remix-simulator"
}
},
"build": {
"builder": "@nrwl/node:package",
"options": {
"outputPath": "dist/libs/remix-simulator",
"tsConfig": "libs/remix-simulator/tsconfig.lib.json",
"packageJson": "libs/remix-simulator/package.json",
"main": "libs/remix-simulator/index.js",
"assets": ["libs/remix-simulator/*.md"]
}
}
}
},

Loading…
Cancel
Save