solidity decoder src updated

pull/697/head
aniket-engg 4 years ago committed by Aniket
parent 9fc2291d65
commit 45d38adf48
  1. 16
      libs/remix-debug/src/solidity-decoder/astHelper.ts
  2. 22
      libs/remix-debug/src/solidity-decoder/decodeInfo.ts
  3. 2
      libs/remix-debug/src/solidity-decoder/index.ts
  4. 20
      libs/remix-debug/src/solidity-decoder/internalCallTree.ts
  5. 4
      libs/remix-debug/src/solidity-decoder/localDecoder.ts
  6. 17
      libs/remix-debug/src/solidity-decoder/solidityProxy.ts
  7. 14
      libs/remix-debug/src/solidity-decoder/stateDecoder.ts

@ -1,5 +1,5 @@
'use strict'
const { AstWalker } = require('@remix-project/remix-astwalker')
import { AstWalker } from '@remix-project/remix-astwalker'
/**
* return all contract definitions of the given @astList
@ -7,7 +7,7 @@ const { AstWalker } = require('@remix-project/remix-astwalker')
* @param {Object} sourcesList - sources list (containing root AST node)
* @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts
*/
function extractContractDefinitions (sourcesList) {
export function extractContractDefinitions (sourcesList) {
const ret = {
contractsById: {},
contractsByName: {},
@ -33,7 +33,7 @@ function extractContractDefinitions (sourcesList) {
* @param {Map} contracts - all contracts defined in the current context
* @return {Array} - array of base contracts in derived to base order as AST nodes.
*/
function getLinearizedBaseContracts (id, contractsById) {
export function getLinearizedBaseContracts (id, contractsById) {
return contractsById[id].linearizedBaseContracts.map(function (id) { return contractsById[id] })
}
@ -46,7 +46,7 @@ function getLinearizedBaseContracts (id, contractsById) {
* @return {Object} - return an object containing: stateItems - list of all the children node of the @arg contractName
* stateVariables - list of all the variable declaration of the @arg contractName
*/
function extractStateDefinitions (contractName, sourcesList, contracts) {
export function extractStateDefinitions (contractName, sourcesList, contracts) {
if (!contracts) {
contracts = extractContractDefinitions(sourcesList)
}
@ -78,7 +78,7 @@ function extractStateDefinitions (contractName, sourcesList, contracts) {
* @param {Object} [contracts] - map of contract definitions (contains contractsById, contractsByName)
* @return {Object} - returns a mapping between contract name and contract state
*/
function extractStatesDefinitions (sourcesList, contracts) {
export function extractStatesDefinitions (sourcesList, contracts) {
if (!contracts) {
contracts = extractContractDefinitions(sourcesList)
}
@ -94,9 +94,3 @@ function extractStatesDefinitions (sourcesList, contracts) {
return ret
}
module.exports = {
extractStatesDefinitions: extractStatesDefinitions,
extractStateDefinitions: extractStateDefinitions,
extractContractDefinitions: extractContractDefinitions,
getLinearizedBaseContracts: getLinearizedBaseContracts
}

@ -368,17 +368,17 @@ function computeOffsets (types, stateDefinitions, contractName, location) {
}
}
module.exports = {
export {
parseType,
computeOffsets,
Uint: uint,
Address: address,
Bool: bool,
DynamicByteArray: dynamicByteArray,
FixedByteArray: fixedByteArray,
Int: int,
String: stringType,
Array: array,
Enum: enumType,
Struct: struct
uint as Uint,
address as Address,
bool as Bool,
dynamicByteArray as DynamicByteArray,
fixedByteArray as FixedByteArray,
int as Int,
stringType as String,
array as Array,
enumType as Enum,
struct as Struct
}

@ -3,4 +3,4 @@ const stateDecoder = require('./stateDecoder')
const localDecoder = require('./localDecoder')
const InternalCallTree = require('./internalCallTree')
module.exports = {SolidityProxy, stateDecoder, localDecoder, InternalCallTree}
export { SolidityProxy, stateDecoder, localDecoder, InternalCallTree }

@ -14,7 +14,23 @@ const typesUtil = require('./types/util.js')
* Triggers `callTreeReady` event when tree is ready
* Triggers `callTreeBuildFailed` event when tree fails to build
*/
class InternalCallTree {
export class InternalCallTree {
includeLocalVariables
debugWithGeneratedSources
event
solidityProxy
traceManager
sourceLocationTracker
scopes
scopeStarts
functionCallStack
functionDefinitionsByScope
variableDeclarationByFile
functionDefinitionByFile
astWalker
reducedTrace
/**
* constructor
*
@ -375,5 +391,3 @@ function addParams (parameterList, tree, scopeId, states, contractName, sourceLo
}
return params
}
module.exports = InternalCallTree

@ -1,6 +1,6 @@
'use strict'
async function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, storageResolver, currentSourceLocation, cursor) {
export async function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, storageResolver, currentSourceLocation, cursor) {
const scope = internalTreeCall.findScope(vmtraceIndex)
if (!scope) {
const error = { 'message': 'Can\'t display locals. reason: compilation result might not have been provided' }
@ -34,5 +34,3 @@ function formatMemory (memory) {
}
return memory
}
module.exports = {solidityLocals}

@ -5,7 +5,14 @@ const stateDecoder = require('./stateDecoder')
const astHelper = require('./astHelper')
const util = remixLib.util
class SolidityProxy {
export class SolidityProxy {
cache
getCurrentCalledAddressAt
getCode
sources
contracts
constructor ({getCurrentCalledAddressAt, getCode}) {
this.cache = new Cache()
this.reset({})
@ -133,6 +140,12 @@ function contractObjectFromCode (contracts, code, address) {
}
class Cache {
contractObjectByAddress
stateVariablesByContractName
contractDeclarations
statesDefinitions
constructor () {
this.reset()
}
@ -143,5 +156,3 @@ class Cache {
this.statesDefinitions = null
}
}
module.exports = SolidityProxy

@ -1,5 +1,5 @@
const astHelper = require('./astHelper')
const {computeOffsets} = require('./decodeInfo')
import { extractStatesDefinitions } from './astHelper'
import { computeOffsets } from './decodeInfo'
/**
* decode the contract state storage
@ -8,7 +8,7 @@ const {computeOffsets} = require('./decodeInfo')
* @param {Object} storageResolver - resolve storage queries
* @return {Map} - decoded state variable
*/
async function decodeState (stateVars, storageResolver) {
export async function decodeState (stateVars, storageResolver) {
const ret = {}
for (var k in stateVars) {
var stateVar = stateVars[k]
@ -34,8 +34,8 @@ async function decodeState (stateVars, storageResolver) {
* @param {Object} sourcesList - sources list
* @return {Object} - return the location of all contract variables in the storage
*/
function extractStateVariables (contractName, sourcesList) {
const states = astHelper.extractStatesDefinitions(sourcesList)
export function extractStateVariables (contractName, sourcesList) {
const states = extractStatesDefinitions(sourcesList, null)
if (!states[contractName]) {
return []
}
@ -55,7 +55,7 @@ function extractStateVariables (contractName, sourcesList) {
* @param {String} contractName - contract for which state var should be resolved
* @return {Map} - return the state of the contract
*/
async function solidityState (storageResolver, astList, contractName) {
export async function solidityState (storageResolver, astList, contractName) {
const stateVars = extractStateVariables(contractName, astList)
try {
return await decodeState(stateVars, storageResolver)
@ -63,5 +63,3 @@ async function solidityState (storageResolver, astList, contractName) {
return '<decoding failed - ' + e.message + '>'
}
}
module.exports = {solidityState, extractStateVariables, decodeState}

Loading…
Cancel
Save