From a4a004800bc2e484a04266be5429e5764b253d2c Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 19 Jan 2017 10:29:46 +0100 Subject: [PATCH] make struct / array label more specific --- src/solidity/decodeInfo.js | 2 +- src/solidity/types/ArrayType.js | 2 +- src/solidity/types/Struct.js | 4 ++-- src/ui/SolidityTypeFormatter.js | 18 +++++++++++++----- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/solidity/decodeInfo.js b/src/solidity/decodeInfo.js index b78f9e6287..082c1e3b4b 100644 --- a/src/solidity/decodeInfo.js +++ b/src/solidity/decodeInfo.js @@ -181,7 +181,7 @@ function struct (type, stateDefinitions, contractName, location) { } var memberDetails = getStructMembers(match[1], stateDefinitions, contractName, location) // type is used to extract the ast struct definition if (!memberDetails) return null - return new StructType(memberDetails, location) + return new StructType(memberDetails, location, match[1]) } else { return null } diff --git a/src/solidity/types/ArrayType.js b/src/solidity/types/ArrayType.js index d1dcc84728..c40c57dbf7 100644 --- a/src/solidity/types/ArrayType.js +++ b/src/solidity/types/ArrayType.js @@ -17,7 +17,7 @@ class ArrayType extends RefType { storageSlots = arraySize * underlyingType.storageSlots } } - super(storageSlots, 32, 'array', location) + super(storageSlots, 32, underlyingType.typeName + '[' + arraySize + ']', location) this.underlyingType = underlyingType this.arraySize = arraySize } diff --git a/src/solidity/types/Struct.js b/src/solidity/types/Struct.js index 03b6b7a13a..721b45a605 100644 --- a/src/solidity/types/Struct.js +++ b/src/solidity/types/Struct.js @@ -3,8 +3,8 @@ var util = require('./util') var RefType = require('./RefType') class Struct extends RefType { - constructor (memberDetails, location) { - super(memberDetails.storageSlots, 32, 'struct', location) + constructor (memberDetails, location, fullType) { + super(memberDetails.storageSlots, 32, 'struct ' + fullType, location) this.members = memberDetails.members } diff --git a/src/ui/SolidityTypeFormatter.js b/src/ui/SolidityTypeFormatter.js index bf48f5e47c..9f34f43edb 100644 --- a/src/ui/SolidityTypeFormatter.js +++ b/src/ui/SolidityTypeFormatter.js @@ -9,7 +9,7 @@ module.exports = { function formatData (key, data) { var style = fontColor(data) var type = '' - if (data.type !== 'array' && data.type !== 'struct') { + if (!isArray(data.type) && !isStruct(data.type)) { type = data.type } return yo`` @@ -17,10 +17,10 @@ function formatData (key, data) { function extractData (item, key) { var ret = {} - if (item.type === 'array') { + if (isArray(item.type)) { ret.children = item.value || [] - ret.self = 'Array' + '[' + ret.children.length + ']' - } else if (item.type === 'struct') { + ret.self = item.type + } else if (isStruct(item.type)) { ret.children = item.value || [] ret.self = 'Struct' + '{' + Object.keys(ret.children).length + '}' } else { @@ -33,7 +33,7 @@ function extractData (item, key) { function fontColor (data) { var color = '#124B46' - if (data.type === 'array' || data.type === 'struct') { + if (isArray(data.type) || isStruct(data.type)) { color = '#847979' } else if (data.type.indexOf('uint') === 0 || data.type.indexOf('int') === 0 || @@ -45,3 +45,11 @@ function fontColor (data) { } return 'color:' + color } + +function isArray (type) { + return type.lastIndexOf(']') === type.length - 1 +} + +function isStruct (type) { + return type.indexOf('struct') === 0 +}