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

@ -1,138 +1,140 @@
const Blocks = function (executionContext, _options) { class Blocks {
this.executionContext = executionContext constructor (executionContext, _options) {
const options = _options || {} this.executionContext = executionContext
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' const options = _options || {}
this.blockNumber = 0 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)
} }
}
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { methods () {
let blockIndex = payload.params[0] return {
if (blockIndex === 'latest') { eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this),
blockIndex = this.executionContext.latestBlockNumber 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) { const block = this.executionContext.blocks[blockIndex]
return cb(new Error('block not found'))
}
let b = { if (!block) {
'number': toHex(block.header.number), return cb(new Error('block not found'))
'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) 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' if (!value) return '0x0'
let v = value.toString('hex') let v = value.toString('hex')
return ((v === '0x' || v === '') ? '0x0' : ('0x' + v)) 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, b)
cb(null, 1) }
}
Blocks.prototype.eth_coinbase = function (payload, cb) { eth_gasPrice (payload, cb) {
cb(null, this.coinbase) cb(null, 1)
} }
Blocks.prototype.eth_blockNumber = function (payload, cb) { eth_coinbase (payload, cb) {
cb(null, this.blockNumber) cb(null, this.coinbase)
} }
Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) { eth_blockNumber (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]] 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) { cb(null, block.transactions.length)
var block = this.executionContext.blocks[payload.params[0]] }
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, block.transactions.length)
cb(null, 0) }
}
Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) { eth_getUncleCountByBlockHash (payload, cb) {
cb(null, 0) cb(null, 0)
} }
Blocks.prototype.eth_getStorageAt = function (payload, cb) { eth_getUncleCountByBlockNumber (payload, cb) {
const [address, position, blockNumber] = payload.params cb(null, 0)
}
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => { eth_getStorageAt (payload, cb) {
if (err || (result.storage && Object.values(result.storage).length === 0)) { const [address, position, blockNumber] = payload.params
return cb(err, '')
}
let value = Object.values(result.storage)[0].value this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => {
cb(err, value) 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 module.exports = Blocks

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

@ -3,233 +3,236 @@ const ethJSUtil = require('ethereumjs-util')
const processTx = require('./txProcess.js') const processTx = require('./txProcess.js')
const BN = ethJSUtil.BN const BN = ethJSUtil.BN
const Transactions = function (executionContext) { class Transactions{
this.executionContext = executionContext
} constructor(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)
} }
}
Transactions.prototype.eth_sendTransaction = function (payload, cb) { init (accounts) {
// from might be lowercased address (web3) this.accounts = accounts
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)
}
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) { methods () {
cb(null, 3000000) return {
} eth_sendTransaction: this.eth_sendTransaction.bind(this),
eth_getTransactionReceipt: this.eth_getTransactionReceipt.bind(this),
Transactions.prototype.eth_getCode = function (payload, cb) { eth_getCode: this.eth_getCode.bind(this),
let address = payload.params[0] eth_call: this.eth_call.bind(this),
eth_estimateGas: this.eth_estimateGas.bind(this),
this.executionContext.web3().eth.getCode(address, (error, result) => { eth_getTransactionCount: this.eth_getTransactionCount.bind(this),
if (error) { eth_getTransactionByHash: this.eth_getTransactionByHash.bind(this),
console.dir('error getting code') eth_getTransactionByBlockHashAndIndex: this.eth_getTransactionByBlockHashAndIndex.bind(this),
console.dir(error) 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 eth_sendTransaction (payload, cb) {
// from might be lowercased address (web3)
processTx(this.executionContext, this.accounts, payload, true, cb) if (payload.params && payload.params.length > 0 && payload.params[0].from) {
} payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
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)
} }
processTx(this.executionContext, this.accounts, payload, false, cb)
}
const txBlock = this.executionContext.txs[receipt.transactionHash] eth_getTransactionReceipt (payload, cb) {
this.executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => {
// TODO: params to add later if (error) {
const r = { return cb(error)
'blockHash': '0x' + txBlock.hash().toString('hex'), }
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from, const txBlock = this.executionContext.txs[receipt.hash]
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123 const r = {
'gasPrice': '0x4a817c800', // 20000000000 'transactionHash': receipt.hash,
'hash': receipt.transactionHash, 'transactionIndex': '0x00',
'input': receipt.input, 'blockHash': '0x' + txBlock.hash().toString('hex'),
// "nonce": 2, // 0x15 'blockNumber': '0x' + txBlock.header.number.toString('hex'),
// "transactionIndex": 0, 'gasUsed': Web3.utils.toHex(receipt.gas),
'value': receipt.value 'cumulativeGasUsed': Web3.utils.toHex(receipt.gas),
// "value":"0xf3dbb76162000" // 4290000000000000 'contractAddress': receipt.contractAddress,
// "v": "0x25", // 37 'logs': receipt.logs,
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", 'status': receipt.status
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c" }
}
if (r.blockNumber === '0x') {
if (receipt.to) { r.blockNumber = '0x0'
r.to = receipt.to }
}
cb(null, r)
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]
const txBlock = this.executionContext.blocks[payload.params[0]] eth_estimateGas (payload, cb) {
const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex') cb(null, 3000000)
}
this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { eth_getCode (payload, cb) {
if (error) { let address = payload.params[0]
return cb(error)
}
// TODO: params to add later this.executionContext.web3().eth.getCode(address, (error, result) => {
let r = { if (error) {
'blockHash': '0x' + txBlock.hash().toString('hex'), console.dir('error getting code')
'blockNumber': '0x' + txBlock.header.number.toString('hex'), console.dir(error)
'from': receipt.from, }
'gas': Web3.utils.toHex(receipt.gas), cb(error, result)
// '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) { eth_call (payload, cb) {
r.to = receipt.to // 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) {
if (r.value === '0x') { payload.params[0].to = ethJSUtil.toChecksumAddress(payload.params[0].to)
r.value = '0x0'
} }
cb(null, r) payload.params[0].value = undefined
})
}
Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) { processTx(this.executionContext, this.accounts, payload, true, 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) => { eth_getTransactionCount (payload, cb) {
if (error) { let address = payload.params[0]
return cb(error)
}
// TODO: params to add later this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
const r = { if (err) {
'blockHash': '0x' + txBlock.hash().toString('hex'), return cb(err)
'blockNumber': '0x' + txBlock.header.number.toString('hex'), }
'from': receipt.from, let nonce = new BN(account.nonce).toString(10)
'gas': Web3.utils.toHex(receipt.gas), cb(null, nonce)
// '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) { eth_getTransactionByHash (payload, cb) {
r.to = receipt.to 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') { eth_getTransactionByBlockHashAndIndex (payload, cb) {
r.value = '0x0' 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 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 TxExecution = RemixLib.execution.txExecution
const TxRunner = RemixLib.execution.txRunner 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 executionContext = RemixLib.execution.executionContext
const log = require('./utils/logs.js') const log = require('./utils/logs.js')
@ -13,63 +13,65 @@ const Transactions = require('./methods/transactions.js')
const generateBlock = require('./genesis.js') const generateBlock = require('./genesis.js')
var Provider = function (options) { class Provider {
this.options = options || {} constructor(options) {
// TODO: init executionContext here this.options = options || {}
this.executionContext = executionContext // TODO: init executionContext here
this.Accounts = new Accounts(this.executionContext) this.executionContext = executionContext
this.Transactions = new Transactions(this.executionContext) this.Accounts = new Accounts(this.executionContext)
this.Transactions = new Transactions(this.executionContext)
this.methods = {} this.methods = {}
this.methods = merge(this.methods, this.Accounts.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 Blocks(this.executionContext, options)).methods())
this.methods = merge(this.methods, (new Misc()).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 Filters(this.executionContext)).methods())
this.methods = merge(this.methods, (new Net()).methods()) this.methods = merge(this.methods, (new Net()).methods())
this.methods = merge(this.methods, this.Transactions.methods()) this.methods = merge(this.methods, this.Transactions.methods())
generateBlock(this.executionContext) generateBlock(this.executionContext)
this.init() this.init()
} }
Provider.prototype.init = async function () { async init () {
await this.Accounts.init() await this.Accounts.init()
this.Transactions.init(this.Accounts.accounts) this.Transactions.init(this.Accounts.accounts)
} }
Provider.prototype.sendAsync = function (payload, callback) { sendAsync (payload, callback) {
log.info('payload method is ', payload.method) log.info('payload method is ', payload.method)
const method = this.methods[payload.method] const method = this.methods[payload.method]
if (this.options.logDetails) { if (this.options.logDetails) {
log.info(payload) log.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) log.info(err)
log.info(result) log.info(result)
} }
if (err) { if (err) {
return callback(err) return callback(err)
} }
const response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result} const response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result}
callback(null, response) callback(null, response)
}) })
}
callback(new Error('unknown method ' + payload.method))
} }
callback(new Error('unknown method ' + payload.method))
}
Provider.prototype.send = function (payload, callback) { send (payload, callback) {
this.sendAsync(payload, callback || function () {}) this.sendAsync(payload, callback || function () {})
} }
Provider.prototype.isConnected = function () { isConnected () {
return true return true
} }
Provider.prototype.on = function (type, cb) { on (type, cb) {
this.executionContext.logsManager.addListener(type, cb) this.executionContext.logsManager.addListener(type, cb)
}
} }
module.exports = Provider 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": { "dependencies": {
"@remixproject/engine": "^0.2.3", "@remixproject/engine": "^0.2.3",
"@types/tape": "^4.2.33", "@types/tape": "^4.2.33",
"ansi-gray": "^0.1.1",
"color-support": "^1.1.3",
"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",
"http-server": "^0.11.1", "http-server": "^0.11.1",
"npm-install-version": "^6.0.2" "npm-install-version": "^6.0.2",
"time-stamp": "^2.2.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.4.5", "@babel/core": "^7.4.5",
@ -200,6 +203,7 @@
"js-beautify": "1.6.14", "js-beautify": "1.6.14",
"minixhr": "^3.2.2", "minixhr": "^3.2.2",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"mocha": "^8.0.1",
"nanohtml": "^1.6.3", "nanohtml": "^1.6.3",
"nightwatch": "^1.3.5", "nightwatch": "^1.3.5",
"notify-error": "^1.2.0", "notify-error": "^1.2.0",

@ -234,29 +234,36 @@
"schematics": {}, "schematics": {},
"architect": { "architect": {
"lint": { "lint": {
"builder": "@nrwl/workspace:run-commands", "builder": "@nrwl/linter:lint",
"options": { "options": {
"commands": [ "linter": "eslint",
{ "config": "libs/remix-simulator/.eslintrc",
"command": "./../../node_modules/.bin/npm-run-all lint" "files": [
} "libs/remix-simulator/**/*.js"
], ],
"cwd": "libs/remix-simulator" "exclude": ["**/node_modules/**", "libs/remix-simulator/test/**/*"]
} }
}, },
"test": { "test": {
"builder": "@nrwl/workspace:run-commands", "builder": "@nrwl/workspace:run-commands",
"options": { "options": {
"commands": [ "commands": [
{
"command": "rm -rf ../../dist"
},
{ {
"command": "./../../node_modules/.bin/npm-run-all test" "command": "./../../node_modules/.bin/npm-run-all test"
} }
], ],
"cwd": "libs/remix-simulator" "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