Commit 45d38adf authored by aniket-engg's avatar aniket-engg Committed by Aniket

solidity decoder src updated

parent 9fc2291d
'use strict' 'use strict'
const { AstWalker } = require('@remix-project/remix-astwalker') import { AstWalker } from '@remix-project/remix-astwalker'
/** /**
* return all contract definitions of the given @astList * return all contract definitions of the given @astList
...@@ -7,7 +7,7 @@ const { AstWalker } = require('@remix-project/remix-astwalker') ...@@ -7,7 +7,7 @@ const { AstWalker } = require('@remix-project/remix-astwalker')
* @param {Object} sourcesList - sources list (containing root AST node) * @param {Object} sourcesList - sources list (containing root AST node)
* @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts * @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts
*/ */
function extractContractDefinitions (sourcesList) { export function extractContractDefinitions (sourcesList) {
const ret = { const ret = {
contractsById: {}, contractsById: {},
contractsByName: {}, contractsByName: {},
...@@ -33,7 +33,7 @@ function extractContractDefinitions (sourcesList) { ...@@ -33,7 +33,7 @@ function extractContractDefinitions (sourcesList) {
* @param {Map} contracts - all contracts defined in the current context * @param {Map} contracts - all contracts defined in the current context
* @return {Array} - array of base contracts in derived to base order as AST nodes. * @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] }) return contractsById[id].linearizedBaseContracts.map(function (id) { return contractsById[id] })
} }
...@@ -46,7 +46,7 @@ function getLinearizedBaseContracts (id, contractsById) { ...@@ -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 * @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 * stateVariables - list of all the variable declaration of the @arg contractName
*/ */
function extractStateDefinitions (contractName, sourcesList, contracts) { export function extractStateDefinitions (contractName, sourcesList, contracts) {
if (!contracts) { if (!contracts) {
contracts = extractContractDefinitions(sourcesList) contracts = extractContractDefinitions(sourcesList)
} }
...@@ -78,7 +78,7 @@ function extractStateDefinitions (contractName, sourcesList, contracts) { ...@@ -78,7 +78,7 @@ function extractStateDefinitions (contractName, sourcesList, contracts) {
* @param {Object} [contracts] - map of contract definitions (contains contractsById, contractsByName) * @param {Object} [contracts] - map of contract definitions (contains contractsById, contractsByName)
* @return {Object} - returns a mapping between contract name and contract state * @return {Object} - returns a mapping between contract name and contract state
*/ */
function extractStatesDefinitions (sourcesList, contracts) { export function extractStatesDefinitions (sourcesList, contracts) {
if (!contracts) { if (!contracts) {
contracts = extractContractDefinitions(sourcesList) contracts = extractContractDefinitions(sourcesList)
} }
...@@ -94,9 +94,3 @@ function extractStatesDefinitions (sourcesList, contracts) { ...@@ -94,9 +94,3 @@ function extractStatesDefinitions (sourcesList, contracts) {
return ret return ret
} }
module.exports = {
extractStatesDefinitions: extractStatesDefinitions,
extractStateDefinitions: extractStateDefinitions,
extractContractDefinitions: extractContractDefinitions,
getLinearizedBaseContracts: getLinearizedBaseContracts
}
...@@ -368,17 +368,17 @@ function computeOffsets (types, stateDefinitions, contractName, location) { ...@@ -368,17 +368,17 @@ function computeOffsets (types, stateDefinitions, contractName, location) {
} }
} }
module.exports = { export {
parseType, parseType,
computeOffsets, computeOffsets,
Uint: uint, uint as Uint,
Address: address, address as Address,
Bool: bool, bool as Bool,
DynamicByteArray: dynamicByteArray, dynamicByteArray as DynamicByteArray,
FixedByteArray: fixedByteArray, fixedByteArray as FixedByteArray,
Int: int, int as Int,
String: stringType, stringType as String,
Array: array, array as Array,
Enum: enumType, enumType as Enum,
Struct: struct struct as Struct
} }
...@@ -3,4 +3,4 @@ const stateDecoder = require('./stateDecoder') ...@@ -3,4 +3,4 @@ const stateDecoder = require('./stateDecoder')
const localDecoder = require('./localDecoder') const localDecoder = require('./localDecoder')
const InternalCallTree = require('./internalCallTree') 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') ...@@ -14,7 +14,23 @@ const typesUtil = require('./types/util.js')
* Triggers `callTreeReady` event when tree is ready * Triggers `callTreeReady` event when tree is ready
* Triggers `callTreeBuildFailed` event when tree fails to build * 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 * constructor
* *
...@@ -375,5 +391,3 @@ function addParams (parameterList, tree, scopeId, states, contractName, sourceLo ...@@ -375,5 +391,3 @@ function addParams (parameterList, tree, scopeId, states, contractName, sourceLo
} }
return params return params
} }
module.exports = InternalCallTree
'use strict' '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) const scope = internalTreeCall.findScope(vmtraceIndex)
if (!scope) { if (!scope) {
const error = { 'message': 'Can\'t display locals. reason: compilation result might not have been provided' } const error = { 'message': 'Can\'t display locals. reason: compilation result might not have been provided' }
...@@ -34,5 +34,3 @@ function formatMemory (memory) { ...@@ -34,5 +34,3 @@ function formatMemory (memory) {
} }
return memory return memory
} }
module.exports = {solidityLocals}
...@@ -5,7 +5,14 @@ const stateDecoder = require('./stateDecoder') ...@@ -5,7 +5,14 @@ const stateDecoder = require('./stateDecoder')
const astHelper = require('./astHelper') const astHelper = require('./astHelper')
const util = remixLib.util const util = remixLib.util
class SolidityProxy { export class SolidityProxy {
cache
getCurrentCalledAddressAt
getCode
sources
contracts
constructor ({getCurrentCalledAddressAt, getCode}) { constructor ({getCurrentCalledAddressAt, getCode}) {
this.cache = new Cache() this.cache = new Cache()
this.reset({}) this.reset({})
...@@ -133,6 +140,12 @@ function contractObjectFromCode (contracts, code, address) { ...@@ -133,6 +140,12 @@ function contractObjectFromCode (contracts, code, address) {
} }
class Cache { class Cache {
contractObjectByAddress
stateVariablesByContractName
contractDeclarations
statesDefinitions
constructor () { constructor () {
this.reset() this.reset()
} }
...@@ -143,5 +156,3 @@ class Cache { ...@@ -143,5 +156,3 @@ class Cache {
this.statesDefinitions = null this.statesDefinitions = null
} }
} }
module.exports = SolidityProxy
const astHelper = require('./astHelper') import { extractStatesDefinitions } from './astHelper'
const {computeOffsets} = require('./decodeInfo') import { computeOffsets } from './decodeInfo'
/** /**
* decode the contract state storage * decode the contract state storage
...@@ -8,7 +8,7 @@ const {computeOffsets} = require('./decodeInfo') ...@@ -8,7 +8,7 @@ const {computeOffsets} = require('./decodeInfo')
* @param {Object} storageResolver - resolve storage queries * @param {Object} storageResolver - resolve storage queries
* @return {Map} - decoded state variable * @return {Map} - decoded state variable
*/ */
async function decodeState (stateVars, storageResolver) { export async function decodeState (stateVars, storageResolver) {
const ret = {} const ret = {}
for (var k in stateVars) { for (var k in stateVars) {
var stateVar = stateVars[k] var stateVar = stateVars[k]
...@@ -34,8 +34,8 @@ async function decodeState (stateVars, storageResolver) { ...@@ -34,8 +34,8 @@ async function decodeState (stateVars, storageResolver) {
* @param {Object} sourcesList - sources list * @param {Object} sourcesList - sources list
* @return {Object} - return the location of all contract variables in the storage * @return {Object} - return the location of all contract variables in the storage
*/ */
function extractStateVariables (contractName, sourcesList) { export function extractStateVariables (contractName, sourcesList) {
const states = astHelper.extractStatesDefinitions(sourcesList) const states = extractStatesDefinitions(sourcesList, null)
if (!states[contractName]) { if (!states[contractName]) {
return [] return []
} }
...@@ -55,7 +55,7 @@ function extractStateVariables (contractName, sourcesList) { ...@@ -55,7 +55,7 @@ function extractStateVariables (contractName, sourcesList) {
* @param {String} contractName - contract for which state var should be resolved * @param {String} contractName - contract for which state var should be resolved
* @return {Map} - return the state of the contract * @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) const stateVars = extractStateVariables(contractName, astList)
try { try {
return await decodeState(stateVars, storageResolver) return await decodeState(stateVars, storageResolver)
...@@ -63,5 +63,3 @@ async function solidityState (storageResolver, astList, contractName) { ...@@ -63,5 +63,3 @@ async function solidityState (storageResolver, astList, contractName) {
return '<decoding failed - ' + e.message + '>' return '<decoding failed - ' + e.message + '>'
} }
} }
module.exports = {solidityState, extractStateVariables, decodeState}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment