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. 21
      libs/remix-simulator/src/methods/accounts.js
  5. 73
      libs/remix-simulator/src/methods/blocks.js
  6. 25
      libs/remix-simulator/src/methods/filters.js
  7. 27
      libs/remix-simulator/src/methods/transactions.js
  8. 16
      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,7 +3,9 @@ const { BN, privateToAddress, isValidPrivate } = require('ethereumjs-util')
const Web3 = require('web3')
const crypto = require('crypto')
const Accounts = function (executionContext) {
class Accounts{
constructor(executionContext) {
this.web3 = new Web3()
this.executionContext = executionContext
// TODO: make it random and/or use remix-libs
@ -25,7 +27,7 @@ const Accounts = function (executionContext) {
this.executionContext.init({get: () => { return true }})
}
Accounts.prototype.init = async function () {
async init () {
let setBalance = (account) => {
return new Promise((resolve, reject) => {
this.accountsKeys[ethJSUtil.toChecksumAddress(account.address)] = account.privateKey
@ -47,7 +49,7 @@ Accounts.prototype.init = async function () {
}
}
Accounts.prototype.resetAccounts = function () {
resetAccounts () {
// TODO: setting this to {} breaks the app currently, unclear why still
// this.accounts = {}
// this.accountsKeys = {}
@ -58,7 +60,7 @@ Accounts.prototype.resetAccounts = function () {
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce', '0x56BC75E2D63100000')
}
Accounts.prototype._addAccount = function (privateKey, balance) {
_addAccount (privateKey, balance) {
privateKey = Buffer.from(privateKey, 'hex')
const address = ethJSUtil.privateToAddress(privateKey)
@ -76,7 +78,7 @@ Accounts.prototype._addAccount = function (privateKey, balance) {
this.accountsKeys[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex')
}
Accounts.prototype.newAccount = function (cb) {
newAccount (cb) {
let privateKey
do {
privateKey = crypto.randomBytes(32)
@ -85,7 +87,7 @@ Accounts.prototype.newAccount = function (cb) {
return cb(null, '0x' + privateToAddress(privateKey).toString('hex'))
}
Accounts.prototype.methods = function () {
methods () {
return {
eth_accounts: this.eth_accounts.bind(this),
eth_getBalance: this.eth_getBalance.bind(this),
@ -93,11 +95,11 @@ Accounts.prototype.methods = function () {
}
}
Accounts.prototype.eth_accounts = function (_payload, cb) {
eth_accounts (_payload, cb) {
return cb(null, Object.keys(this.accounts))
}
Accounts.prototype.eth_getBalance = function (payload, cb) {
eth_getBalance (payload, cb) {
let address = payload.params[0]
address = ethJSUtil.stripHexPrefix(address)
@ -109,7 +111,7 @@ Accounts.prototype.eth_getBalance = function (payload, cb) {
})
}
Accounts.prototype.eth_sign = function (payload, cb) {
eth_sign (payload, cb) {
const address = payload.params[0]
const message = payload.params[1]
@ -123,5 +125,6 @@ Accounts.prototype.eth_sign = function (payload, cb) {
cb(null, data.signature)
}
}
module.exports = Accounts

@ -1,12 +1,12 @@
const Blocks = function (executionContext, _options) {
class Blocks {
constructor (executionContext, _options) {
this.executionContext = executionContext
const options = _options || {}
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000'
this.blockNumber = 0
}
Blocks.prototype.methods = function () {
methods () {
return {
eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this),
eth_gasPrice: this.eth_gasPrice.bind(this),
@ -21,7 +21,7 @@ Blocks.prototype.methods = function () {
}
}
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
eth_getBlockByNumber (payload, cb) {
let blockIndex = payload.params[0]
if (blockIndex === 'latest') {
blockIndex = this.executionContext.latestBlockNumber
@ -34,22 +34,22 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
}
let b = {
'number': toHex(block.header.number),
'hash': toHex(block.hash()),
'parentHash': toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce),
'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': toHex(block.header.stateRoot),
'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData),
'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp),
'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': []
}
@ -57,32 +57,32 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
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) {
eth_getBlockByHash (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),
'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': toHex(block.header.stateRoot),
'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData),
'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp),
'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': []
}
@ -90,39 +90,39 @@ Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
cb(null, b)
}
Blocks.prototype.eth_gasPrice = function (payload, cb) {
eth_gasPrice (payload, cb) {
cb(null, 1)
}
Blocks.prototype.eth_coinbase = function (payload, cb) {
eth_coinbase (payload, cb) {
cb(null, this.coinbase)
}
Blocks.prototype.eth_blockNumber = function (payload, cb) {
eth_blockNumber (payload, cb) {
cb(null, this.blockNumber)
}
Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) {
eth_getBlockTransactionCountByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
cb(null, block.transactions.length)
}
Blocks.prototype.eth_getBlockTransactionCountByNumber = function (payload, cb) {
eth_getBlockTransactionCountByNumber (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
cb(null, block.transactions.length)
}
Blocks.prototype.eth_getUncleCountByBlockHash = function (payload, cb) {
eth_getUncleCountByBlockHash (payload, cb) {
cb(null, 0)
}
Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) {
eth_getUncleCountByBlockNumber (payload, cb) {
cb(null, 0)
}
Blocks.prototype.eth_getStorageAt = function (payload, cb) {
eth_getStorageAt (payload, cb) {
const [address, position, blockNumber] = payload.params
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => {
@ -134,5 +134,6 @@ Blocks.prototype.eth_getStorageAt = function (payload, cb) {
cb(err, value)
})
}
}
module.exports = Blocks

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

@ -3,15 +3,17 @@ const ethJSUtil = require('ethereumjs-util')
const processTx = require('./txProcess.js')
const BN = ethJSUtil.BN
const Transactions = function (executionContext) {
class Transactions{
constructor(executionContext) {
this.executionContext = executionContext
}
Transactions.prototype.init = function (accounts) {
init (accounts) {
this.accounts = accounts
}
Transactions.prototype.methods = function () {
methods () {
return {
eth_sendTransaction: this.eth_sendTransaction.bind(this),
eth_getTransactionReceipt: this.eth_getTransactionReceipt.bind(this),
@ -25,7 +27,7 @@ Transactions.prototype.methods = function () {
}
}
Transactions.prototype.eth_sendTransaction = function (payload, cb) {
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)
@ -33,7 +35,7 @@ Transactions.prototype.eth_sendTransaction = function (payload, 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) => {
if (error) {
return cb(error)
@ -61,11 +63,11 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
})
}
Transactions.prototype.eth_estimateGas = function (payload, cb) {
eth_estimateGas (payload, cb) {
cb(null, 3000000)
}
Transactions.prototype.eth_getCode = function (payload, cb) {
eth_getCode (payload, cb) {
let address = payload.params[0]
this.executionContext.web3().eth.getCode(address, (error, result) => {
@ -77,7 +79,7 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
})
}
Transactions.prototype.eth_call = function (payload, cb) {
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)
@ -91,7 +93,7 @@ Transactions.prototype.eth_call = function (payload, 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]
this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
@ -103,7 +105,7 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
})
}
Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
eth_getTransactionByHash (payload, cb) {
const address = payload.params[0]
this.executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => {
@ -148,7 +150,7 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
})
}
Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) {
eth_getTransactionByBlockHashAndIndex (payload, cb) {
const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]]
@ -190,7 +192,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
})
}
Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) {
eth_getTransactionByBlockNumberAndIndex (payload, cb) {
const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]]
@ -231,5 +233,6 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
cb(null, r)
})
}
}
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,7 +13,8 @@ const Transactions = require('./methods/transactions.js')
const generateBlock = require('./genesis.js')
var Provider = function (options) {
class Provider {
constructor(options) {
this.options = options || {}
// TODO: init executionContext here
this.executionContext = executionContext
@ -32,12 +33,12 @@ var Provider = function (options) {
this.init()
}
Provider.prototype.init = async function () {
async init () {
await this.Accounts.init()
this.Transactions.init(this.Accounts.accounts)
}
Provider.prototype.sendAsync = function (payload, callback) {
sendAsync (payload, callback) {
log.info('payload method is ', payload.method)
const method = this.methods[payload.method]
@ -60,16 +61,17 @@ Provider.prototype.sendAsync = function (payload, callback) {
callback(new Error('unknown method ' + payload.method))
}
Provider.prototype.send = function (payload, callback) {
send (payload, callback) {
this.sendAsync(payload, callback || function () {})
}
Provider.prototype.isConnected = function () {
isConnected () {
return true
}
Provider.prototype.on = function (type, cb) {
on (type, cb) {
this.executionContext.logsManager.addListener(type, cb)
}
}
module.exports = Provider
Loading…
Cancel
Save