finally conflicts resolved

pull/5370/head
aniket-engg 5 years ago
parent e0e4acea68
commit 98db35e81f
  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. 37
      libs/remix-simulator/src/methods/accounts.js
  5. 95
      libs/remix-simulator/src/methods/blocks.js
  6. 45
      libs/remix-simulator/src/methods/filters.js
  7. 49
      libs/remix-simulator/src/methods/transactions.js
  8. 26
      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, 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 { AstWalker } from '@remix-project/remix-astwalker'
import { FunctionDefinitionAstNode, ParameterListAstNode, ModifierDefinitionAstNode, ContractHLAst, VariableDeclarationAstNode, import { FunctionDefinitionAstNode, ParameterListAstNode, ModifierDefinitionAstNode, ContractHLAst, VariableDeclarationAstNode,
FunctionHLAst, ReportObj, ReportFunction, VisitFunction, ModifierHLAst, CompilationResult } from '../../types' FunctionHLAst, ReportObj, ReportFunction, VisitFunction, ModifierHLAst, CompilationResult } from '../../types'

@ -3,7 +3,7 @@
import { FunctionDefinitionAstNode, ModifierDefinitionAstNode, ParameterListAstNode, ForStatementAstNode, import { FunctionDefinitionAstNode, ModifierDefinitionAstNode, ParameterListAstNode, ForStatementAstNode,
WhileStatementAstNode, VariableDeclarationAstNode, ContractDefinitionAstNode, InheritanceSpecifierAstNode, WhileStatementAstNode, VariableDeclarationAstNode, ContractDefinitionAstNode, InheritanceSpecifierAstNode,
MemberAccessAstNode, BinaryOperationAstNode, FunctionCallAstNode, ExpressionStatementAstNode, UnaryOperationAstNode, 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' import { util } from '@remix-project/remix-lib'
type SpecialObjDetail = { type SpecialObjDetail = {

@ -3,7 +3,9 @@ const { BN, privateToAddress, isValidPrivate } = require('ethereumjs-util')
const Web3 = require('web3') const Web3 = require('web3')
const crypto = require('crypto') const crypto = require('crypto')
const Accounts = function (executionContext) { class Accounts{
constructor(executionContext) {
this.web3 = new Web3() this.web3 = new Web3()
this.executionContext = executionContext this.executionContext = executionContext
// TODO: make it random and/or use remix-libs // TODO: make it random and/or use remix-libs
@ -23,9 +25,9 @@ const Accounts = function (executionContext) {
this.accountsKeys = {} this.accountsKeys = {}
this.executionContext.init({get: () => { return true }}) this.executionContext.init({get: () => { return true }})
} }
Accounts.prototype.init = async function () { async init () {
let setBalance = (account) => { let setBalance = (account) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.accountsKeys[ethJSUtil.toChecksumAddress(account.address)] = account.privateKey this.accountsKeys[ethJSUtil.toChecksumAddress(account.address)] = account.privateKey
@ -45,9 +47,9 @@ Accounts.prototype.init = async function () {
for (let _account of this.accountsList) { for (let _account of this.accountsList) {
await setBalance(_account) await setBalance(_account)
} }
} }
Accounts.prototype.resetAccounts = function () { resetAccounts () {
// TODO: setting this to {} breaks the app currently, unclear why still // TODO: setting this to {} breaks the app currently, unclear why still
// this.accounts = {} // this.accounts = {}
// this.accountsKeys = {} // this.accountsKeys = {}
@ -56,9 +58,9 @@ Accounts.prototype.resetAccounts = function () {
this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', '0x56BC75E2D63100000') this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', '0x56BC75E2D63100000')
this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea', '0x56BC75E2D63100000') this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea', '0x56BC75E2D63100000')
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce', '0x56BC75E2D63100000') this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce', '0x56BC75E2D63100000')
} }
Accounts.prototype._addAccount = function (privateKey, balance) { _addAccount (privateKey, balance) {
privateKey = Buffer.from(privateKey, 'hex') privateKey = Buffer.from(privateKey, 'hex')
const address = ethJSUtil.privateToAddress(privateKey) const address = ethJSUtil.privateToAddress(privateKey)
@ -74,30 +76,30 @@ Accounts.prototype._addAccount = function (privateKey, balance) {
this.accounts[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 } this.accounts[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 }
this.accountsKeys[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex') this.accountsKeys[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex')
} }
Accounts.prototype.newAccount = function (cb) { newAccount (cb) {
let privateKey let privateKey
do { do {
privateKey = crypto.randomBytes(32) privateKey = crypto.randomBytes(32)
} while (!isValidPrivate(privateKey)) } while (!isValidPrivate(privateKey))
this._addAccount(privateKey, '0x56BC75E2D63100000') this._addAccount(privateKey, '0x56BC75E2D63100000')
return cb(null, '0x' + privateToAddress(privateKey).toString('hex')) return cb(null, '0x' + privateToAddress(privateKey).toString('hex'))
} }
Accounts.prototype.methods = function () { methods () {
return { return {
eth_accounts: this.eth_accounts.bind(this), eth_accounts: this.eth_accounts.bind(this),
eth_getBalance: this.eth_getBalance.bind(this), eth_getBalance: this.eth_getBalance.bind(this),
eth_sign: this.eth_sign.bind(this) eth_sign: this.eth_sign.bind(this)
} }
} }
Accounts.prototype.eth_accounts = function (_payload, cb) { eth_accounts (_payload, cb) {
return cb(null, Object.keys(this.accounts)) return cb(null, Object.keys(this.accounts))
} }
Accounts.prototype.eth_getBalance = function (payload, cb) { eth_getBalance (payload, cb) {
let address = payload.params[0] let address = payload.params[0]
address = ethJSUtil.stripHexPrefix(address) address = ethJSUtil.stripHexPrefix(address)
@ -107,9 +109,9 @@ Accounts.prototype.eth_getBalance = function (payload, cb) {
} }
cb(null, new BN(account.balance).toString(10)) cb(null, new BN(account.balance).toString(10))
}) })
} }
Accounts.prototype.eth_sign = function (payload, cb) { eth_sign (payload, cb) {
const address = payload.params[0] const address = payload.params[0]
const message = payload.params[1] const message = payload.params[1]
@ -122,6 +124,7 @@ Accounts.prototype.eth_sign = function (payload, cb) {
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,12 +1,12 @@
class Blocks {
const Blocks = function (executionContext, _options) { constructor (executionContext, _options) {
this.executionContext = executionContext this.executionContext = executionContext
const options = _options || {} const options = _options || {}
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000'
this.blockNumber = 0 this.blockNumber = 0
} }
Blocks.prototype.methods = function () { methods () {
return { return {
eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this), eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this),
eth_gasPrice: this.eth_gasPrice.bind(this), eth_gasPrice: this.eth_gasPrice.bind(this),
@ -19,9 +19,9 @@ Blocks.prototype.methods = function () {
eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this), eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this),
eth_getStorageAt: this.eth_getStorageAt.bind(this) eth_getStorageAt: this.eth_getStorageAt.bind(this)
} }
} }
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { eth_getBlockByNumber (payload, cb) {
let blockIndex = payload.params[0] let blockIndex = payload.params[0]
if (blockIndex === 'latest') { if (blockIndex === 'latest') {
blockIndex = this.executionContext.latestBlockNumber blockIndex = this.executionContext.latestBlockNumber
@ -34,22 +34,22 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
} }
let b = { let b = {
'number': toHex(block.header.number), 'number': this.toHex(block.header.number),
'hash': toHex(block.hash()), 'hash': this.toHex(block.hash()),
'parentHash': toHex(block.header.parentHash), 'parentHash': this.toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce), 'nonce': this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', 'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': toHex(block.header.stateRoot), 'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase, 'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty), 'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty), 'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData), 'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591 'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit), 'gasLimit': this.toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed), 'gasUsed': this.toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp), 'timestamp': this.toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), 'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': [] 'uncles': []
} }
@ -57,72 +57,72 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
cb(null, b) 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) { eth_getBlockByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]] var block = this.executionContext.blocks[payload.params[0]]
let b = { let b = {
'number': toHex(block.header.number), 'number': this.toHex(block.header.number),
'hash': toHex(block.hash()), 'hash': this.toHex(block.hash()),
'parentHash': toHex(block.header.parentHash), 'parentHash': this.toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce), 'nonce': this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', 'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': toHex(block.header.stateRoot), 'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase, 'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty), 'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty), 'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData), 'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591 'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit), 'gasLimit': this.toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed), 'gasUsed': this.toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp), 'timestamp': this.toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), 'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': [] 'uncles': []
} }
cb(null, b) cb(null, b)
} }
Blocks.prototype.eth_gasPrice = function (payload, cb) { eth_gasPrice (payload, cb) {
cb(null, 1) cb(null, 1)
} }
Blocks.prototype.eth_coinbase = function (payload, cb) { eth_coinbase (payload, cb) {
cb(null, this.coinbase) cb(null, this.coinbase)
} }
Blocks.prototype.eth_blockNumber = function (payload, cb) { eth_blockNumber (payload, cb) {
cb(null, this.blockNumber) cb(null, this.blockNumber)
} }
Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) { eth_getBlockTransactionCountByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]] var block = this.executionContext.blocks[payload.params[0]]
cb(null, block.transactions.length) cb(null, block.transactions.length)
} }
Blocks.prototype.eth_getBlockTransactionCountByNumber = function (payload, cb) { eth_getBlockTransactionCountByNumber (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]] var block = this.executionContext.blocks[payload.params[0]]
cb(null, block.transactions.length) cb(null, block.transactions.length)
} }
Blocks.prototype.eth_getUncleCountByBlockHash = function (payload, cb) { eth_getUncleCountByBlockHash (payload, cb) {
cb(null, 0) cb(null, 0)
} }
Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) { eth_getUncleCountByBlockNumber (payload, cb) {
cb(null, 0) cb(null, 0)
} }
Blocks.prototype.eth_getStorageAt = function (payload, cb) { eth_getStorageAt (payload, cb) {
const [address, position, blockNumber] = payload.params const [address, position, blockNumber] = payload.params
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => { this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => {
@ -133,6 +133,7 @@ Blocks.prototype.eth_getStorageAt = function (payload, cb) {
let value = Object.values(result.storage)[0].value let value = Object.values(result.storage)[0].value
cb(err, value) cb(err, value)
}) })
}
} }
module.exports = Blocks module.exports = Blocks

@ -1,61 +1,62 @@
class Filters {
const Filters = function (executionContext) { constructor(executionContext) {
this.executionContext = 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,15 +3,17 @@ 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{
constructor(executionContext) {
this.executionContext = executionContext this.executionContext = executionContext
} }
Transactions.prototype.init = function (accounts) { init (accounts) {
this.accounts = accounts this.accounts = accounts
} }
Transactions.prototype.methods = function () { methods () {
return { return {
eth_sendTransaction: this.eth_sendTransaction.bind(this), eth_sendTransaction: this.eth_sendTransaction.bind(this),
eth_getTransactionReceipt: this.eth_getTransactionReceipt.bind(this), eth_getTransactionReceipt: this.eth_getTransactionReceipt.bind(this),
@ -23,17 +25,17 @@ Transactions.prototype.methods = function () {
eth_getTransactionByBlockHashAndIndex: this.eth_getTransactionByBlockHashAndIndex.bind(this), eth_getTransactionByBlockHashAndIndex: this.eth_getTransactionByBlockHashAndIndex.bind(this),
eth_getTransactionByBlockNumberAndIndex: this.eth_getTransactionByBlockNumberAndIndex.bind(this) eth_getTransactionByBlockNumberAndIndex: this.eth_getTransactionByBlockNumberAndIndex.bind(this)
} }
} }
Transactions.prototype.eth_sendTransaction = function (payload, cb) { eth_sendTransaction (payload, cb) {
// from might be lowercased address (web3) // from might be lowercased address (web3)
if (payload.params && payload.params.length > 0 && payload.params[0].from) { if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from) payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
} }
processTx(this.executionContext, this.accounts, payload, false, cb) processTx(this.executionContext, this.accounts, payload, false, cb)
} }
Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { eth_getTransactionReceipt (payload, cb) {
this.executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => { this.executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => {
if (error) { if (error) {
return cb(error) return cb(error)
@ -59,13 +61,13 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
cb(null, r) cb(null, r)
}) })
} }
Transactions.prototype.eth_estimateGas = function (payload, cb) { eth_estimateGas (payload, cb) {
cb(null, 3000000) cb(null, 3000000)
} }
Transactions.prototype.eth_getCode = function (payload, cb) { eth_getCode (payload, cb) {
let address = payload.params[0] let address = payload.params[0]
this.executionContext.web3().eth.getCode(address, (error, result) => { this.executionContext.web3().eth.getCode(address, (error, result) => {
@ -75,9 +77,9 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
} }
cb(error, result) cb(error, result)
}) })
} }
Transactions.prototype.eth_call = function (payload, cb) { eth_call (payload, cb) {
// from might be lowercased address (web3) // from might be lowercased address (web3)
if (payload.params && payload.params.length > 0 && payload.params[0].from) { if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from) payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
@ -89,9 +91,9 @@ Transactions.prototype.eth_call = function (payload, cb) {
payload.params[0].value = undefined payload.params[0].value = undefined
processTx(this.executionContext, this.accounts, payload, true, cb) processTx(this.executionContext, this.accounts, payload, true, cb)
} }
Transactions.prototype.eth_getTransactionCount = function (payload, cb) { eth_getTransactionCount (payload, cb) {
let address = payload.params[0] let address = payload.params[0]
this.executionContext.vm().stateManager.getAccount(address, (err, account) => { this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
@ -101,9 +103,9 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
let nonce = new BN(account.nonce).toString(10) let nonce = new BN(account.nonce).toString(10)
cb(null, nonce) cb(null, nonce)
}) })
} }
Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { eth_getTransactionByHash (payload, cb) {
const address = payload.params[0] const address = payload.params[0]
this.executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => { this.executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => {
@ -146,9 +148,9 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
cb(null, r) cb(null, r)
}) })
} }
Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) { eth_getTransactionByBlockHashAndIndex (payload, cb) {
const txIndex = payload.params[1] const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]] const txBlock = this.executionContext.blocks[payload.params[0]]
@ -188,9 +190,9 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
cb(null, r) cb(null, r)
}) })
} }
Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) { eth_getTransactionByBlockNumberAndIndex (payload, cb) {
const txIndex = payload.params[1] const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]] const txBlock = this.executionContext.blocks[payload.params[0]]
@ -230,6 +232,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
cb(null, r) 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 executionContext = RemixLib.execution.executionContext
const log = require('./utils/logs.js') const log = require('./utils/logs.js')
@ -13,7 +13,8 @@ const Transactions = require('./methods/transactions.js')
const generateBlock = require('./genesis.js') const generateBlock = require('./genesis.js')
var Provider = function (options) { class Provider {
constructor(options) {
this.options = options || {} this.options = options || {}
// TODO: init executionContext here // TODO: init executionContext here
this.executionContext = executionContext this.executionContext = executionContext
@ -30,14 +31,14 @@ var Provider = function (options) {
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]
@ -58,18 +59,19 @@ Provider.prototype.sendAsync = function (payload, callback) {
}) })
} }
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
Loading…
Cancel
Save