Commit 0757c48a authored by yann300's avatar yann300 Committed by Liana Husikyan

fix decode orphan struct definition

parent 50e46e43
...@@ -27,6 +27,27 @@ export function extractContractDefinitions (sourcesList) { ...@@ -27,6 +27,27 @@ export function extractContractDefinitions (sourcesList) {
} }
/** /**
* return nodes from an ast @arg sourcesList that are declared outside of a ContractDefinition @astList
*
* @param {Object} sourcesList - sources list (containing root AST node)
* @return {Object} - returns a list of node
*/
export function extractOrphanDefinitions (sourcesList) {
const ret = []
for (const k in sourcesList) {
const ast = sourcesList[k].ast
if (ast.nodes && ast.nodes.length) {
for (const node of ast.nodes) {
if (node.nodeType !== 'ContractDefinition') {
ret.push(node)
}
}
}
}
return ret
}
/**
* returns the linearized base contracts of the contract @arg id * returns the linearized base contracts of the contract @arg id
* *
* @param {Int} id - contract id to resolve * @param {Int} id - contract id to resolve
...@@ -54,7 +75,7 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) { ...@@ -54,7 +75,7 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) {
if (!node) { if (!node) {
return null return null
} }
const stateItems = [] const stateItems = extractOrphanDefinitions(sourcesList)
const stateVar = [] const stateVar = []
const baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById) const baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById)
baseContracts.reverse() baseContracts.reverse()
......
...@@ -233,11 +233,11 @@ function getEnum (type, stateDefinitions, contractName) { ...@@ -233,11 +233,11 @@ function getEnum (type, stateDefinitions, contractName) {
* @return {Array} containing all members of the current struct type * @return {Array} containing all members of the current struct type
*/ */
function getStructMembers (type, stateDefinitions, contractName, location) { function getStructMembers (type, stateDefinitions, contractName, location) {
const split = type.split('.') if (type.indexOf('.') === -1) {
if (!split.length) {
type = contractName + '.' + type type = contractName + '.' + type
} else { }
contractName = split[0] if (!contractName) {
contractName = type.split('.')[0]
} }
const state = stateDefinitions[contractName] const state = stateDefinitions[contractName]
if (state) { if (state) {
......
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