finally conflicts resolved

pull/10/head
aniket-engg 4 years ago
parent 98cf38f6e7
commit bb6d16b1bb
  1. 40
      .gitignore
  2. 3
      libs/remix-analyzer/src/solidity-analyzer/modules/abstractAstView.ts
  3. 2
      libs/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
  4. 207
      libs/remix-simulator/src/methods/accounts.js
  5. 221
      libs/remix-simulator/src/methods/blocks.js
  6. 97
      libs/remix-simulator/src/methods/filters.js
  7. 415
      libs/remix-simulator/src/methods/transactions.js
  8. 102
      libs/remix-simulator/src/provider.js

40
.gitignore vendored

@ -0,0 +1,40 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
# System Files
.DS_Store
Thumbs.db

@ -1,5 +1,6 @@
import { getStateVariableDeclarationsFromContractNode, getInheritsFromName, getContractName,
getFunctionOrModifierDefinitionParameterPart, getType, getDeclaredVariableName, getFunctionDefinitionReturnParameterPart } from './staticAnalysisCommon'
getFunctionOrModifierDefinitionParameterPart, getType, getDeclaredVariableName,
getFunctionDefinitionReturnParameterPart, getCompilerVersion } from './staticAnalysisCommon'
import { AstWalker } from '@remix-project/remix-astwalker'
import { FunctionDefinitionAstNode, ParameterListAstNode, ModifierDefinitionAstNode, ContractHLAst, VariableDeclarationAstNode,
FunctionHLAst, ReportObj, ReportFunction, VisitFunction, ModifierHLAst, CompilationResult } from '../../types'

@ -3,7 +3,7 @@
import { FunctionDefinitionAstNode, ModifierDefinitionAstNode, ParameterListAstNode, ForStatementAstNode,
WhileStatementAstNode, VariableDeclarationAstNode, ContractDefinitionAstNode, InheritanceSpecifierAstNode,
MemberAccessAstNode, BinaryOperationAstNode, FunctionCallAstNode, ExpressionStatementAstNode, UnaryOperationAstNode,
IdentifierAstNode, IndexAccessAstNode, BlockAstNode, AssignmentAstNode, InlineAssemblyAstNode, IfStatementAstNode, CompiledContractObj, ABIParameter } from "../../types"
IdentifierAstNode, IndexAccessAstNode, BlockAstNode, AssignmentAstNode, InlineAssemblyAstNode, IfStatementAstNode, CompiledContractObj, ABIParameter, CompiledContract } from "../../types"
import { util } from '@remix-project/remix-lib'
type SpecialObjDetail = {

@ -3,125 +3,128 @@ const { BN, privateToAddress, isValidPrivate } = require('ethereumjs-util')
const Web3 = require('web3')
const crypto = require('crypto')
const Accounts = function (executionContext) {
this.web3 = new Web3()
this.executionContext = executionContext
// TODO: make it random and/or use remix-libs
this.accountsList = [
this.web3.eth.accounts.create(['abcd']),
this.web3.eth.accounts.create(['ef12']),
this.web3.eth.accounts.create(['ef34']),
this.web3.eth.accounts.create(['ab12']),
this.web3.eth.accounts.create(['ab34']),
this.web3.eth.accounts.create(['cd12']),
this.web3.eth.accounts.create(['cd34']),
this.web3.eth.accounts.create(['bcde']),
this.web3.eth.accounts.create(['cdef']),
this.web3.eth.accounts.create(['1234'])
]
this.accounts = {}
this.accountsKeys = {}
this.executionContext.init({get: () => { return true }})
}
class Accounts{
constructor(executionContext) {
this.web3 = new Web3()
this.executionContext = executionContext
// TODO: make it random and/or use remix-libs
this.accountsList = [
this.web3.eth.accounts.create(['abcd']),
this.web3.eth.accounts.create(['ef12']),
this.web3.eth.accounts.create(['ef34']),
this.web3.eth.accounts.create(['ab12']),
this.web3.eth.accounts.create(['ab34']),
this.web3.eth.accounts.create(['cd12']),
this.web3.eth.accounts.create(['cd34']),
this.web3.eth.accounts.create(['bcde']),
this.web3.eth.accounts.create(['cdef']),
this.web3.eth.accounts.create(['1234'])
]
this.accounts = {}
this.accountsKeys = {}
this.executionContext.init({get: () => { return true }})
}
Accounts.prototype.init = async function () {
let setBalance = (account) => {
return new Promise((resolve, reject) => {
this.accountsKeys[ethJSUtil.toChecksumAddress(account.address)] = account.privateKey
this.accounts[ethJSUtil.toChecksumAddress(account.address)] = { privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'), nonce: 0 }
this.executionContext.vm().stateManager.getAccount(Buffer.from(account.address.replace('0x', ''), 'hex'), (err, account) => {
if (err) {
throw new Error(err)
}
const balance = '0x56BC75E2D63100000'
account.balance = balance || '0xf00000000000000001'
resolve()
async init () {
let setBalance = (account) => {
return new Promise((resolve, reject) => {
this.accountsKeys[ethJSUtil.toChecksumAddress(account.address)] = account.privateKey
this.accounts[ethJSUtil.toChecksumAddress(account.address)] = { privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'), nonce: 0 }
this.executionContext.vm().stateManager.getAccount(Buffer.from(account.address.replace('0x', ''), 'hex'), (err, account) => {
if (err) {
throw new Error(err)
}
const balance = '0x56BC75E2D63100000'
account.balance = balance || '0xf00000000000000001'
resolve()
})
})
})
}
}
for (let _account of this.accountsList) {
await setBalance(_account)
for (let _account of this.accountsList) {
await setBalance(_account)
}
}
}
Accounts.prototype.resetAccounts = function () {
// TODO: setting this to {} breaks the app currently, unclear why still
// this.accounts = {}
// this.accountsKeys = {}
this._addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511', '0x56BC75E2D63100000')
this._addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c', '0x56BC75E2D63100000')
this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', '0x56BC75E2D63100000')
this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea', '0x56BC75E2D63100000')
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce', '0x56BC75E2D63100000')
}
resetAccounts () {
// TODO: setting this to {} breaks the app currently, unclear why still
// this.accounts = {}
// this.accountsKeys = {}
this._addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511', '0x56BC75E2D63100000')
this._addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c', '0x56BC75E2D63100000')
this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', '0x56BC75E2D63100000')
this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea', '0x56BC75E2D63100000')
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce', '0x56BC75E2D63100000')
}
Accounts.prototype._addAccount = function (privateKey, balance) {
privateKey = Buffer.from(privateKey, 'hex')
const address = ethJSUtil.privateToAddress(privateKey)
// FIXME: we don't care about the callback, but we should still make this proper
let stateManager = this.executionContext.vm().stateManager
stateManager.getAccount(address, (error, account) => {
if (error) return console.log(error)
account.balance = balance || '0xf00000000000000001'
stateManager.putAccount(address, account, (error) => {
if (error) console.log(error)
_addAccount (privateKey, balance) {
privateKey = Buffer.from(privateKey, 'hex')
const address = ethJSUtil.privateToAddress(privateKey)
// FIXME: we don't care about the callback, but we should still make this proper
let stateManager = this.executionContext.vm().stateManager
stateManager.getAccount(address, (error, account) => {
if (error) return console.log(error)
account.balance = balance || '0xf00000000000000001'
stateManager.putAccount(address, account, (error) => {
if (error) console.log(error)
})
})
})
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[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 }
this.accountsKeys[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex')
}
Accounts.prototype.newAccount = function (cb) {
let privateKey
do {
privateKey = crypto.randomBytes(32)
} while (!isValidPrivate(privateKey))
this._addAccount(privateKey, '0x56BC75E2D63100000')
return cb(null, '0x' + privateToAddress(privateKey).toString('hex'))
}
newAccount (cb) {
let privateKey
do {
privateKey = crypto.randomBytes(32)
} while (!isValidPrivate(privateKey))
this._addAccount(privateKey, '0x56BC75E2D63100000')
return cb(null, '0x' + privateToAddress(privateKey).toString('hex'))
}
Accounts.prototype.methods = function () {
return {
eth_accounts: this.eth_accounts.bind(this),
eth_getBalance: this.eth_getBalance.bind(this),
eth_sign: this.eth_sign.bind(this)
methods () {
return {
eth_accounts: this.eth_accounts.bind(this),
eth_getBalance: this.eth_getBalance.bind(this),
eth_sign: this.eth_sign.bind(this)
}
}
}
Accounts.prototype.eth_accounts = function (_payload, cb) {
return cb(null, Object.keys(this.accounts))
}
eth_accounts (_payload, cb) {
return cb(null, Object.keys(this.accounts))
}
Accounts.prototype.eth_getBalance = function (payload, cb) {
let address = payload.params[0]
address = ethJSUtil.stripHexPrefix(address)
eth_getBalance (payload, cb) {
let address = payload.params[0]
address = ethJSUtil.stripHexPrefix(address)
this.executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), (err, account) => {
if (err) {
return cb(err)
}
cb(null, new BN(account.balance).toString(10))
})
}
this.executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), (err, account) => {
if (err) {
return cb(err)
}
cb(null, new BN(account.balance).toString(10))
})
}
Accounts.prototype.eth_sign = function (payload, cb) {
const address = payload.params[0]
const message = payload.params[1]
eth_sign (payload, cb) {
const address = payload.params[0]
const message = payload.params[1]
const privateKey = this.accountsKeys[ethJSUtil.toChecksumAddress(address)]
if (!privateKey) {
return cb(new Error('unknown account'))
}
const account = this.web3.eth.accounts.privateKeyToAccount(privateKey)
const privateKey = this.accountsKeys[ethJSUtil.toChecksumAddress(address)]
if (!privateKey) {
return cb(new Error('unknown account'))
}
const account = this.web3.eth.accounts.privateKeyToAccount(privateKey)
const data = account.sign(message)
const data = account.sign(message)
cb(null, data.signature)
cb(null, data.signature)
}
}
module.exports = Accounts
module.exports = Accounts

@ -1,138 +1,139 @@
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
module.exports = Blocks

@ -1,61 +1,62 @@
class Filters {
constructor(executionContext) {
this.executionContext = executionContext
}
const Filters = function (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
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
module.exports = Transactions

@ -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
module.exports = Provider
Loading…
Cancel
Save