diff --git a/src/solidity/decodeInfo.js b/src/solidity/decodeInfo.js index dda0dc3dfb..77b79458eb 100644 --- a/src/solidity/decodeInfo.js +++ b/src/solidity/decodeInfo.js @@ -11,6 +11,7 @@ var StructType = require('./types/Struct') var IntType = require('./types/Int') var UintType = require('./types/Uint') var MappingType = require('./types/Mapping') +var util = require('./types/util') /** * mapping decode the given @arg type @@ -73,9 +74,9 @@ function bool (type) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName} */ function dynamicByteArray (type) { - var match = type.match(/( storage ref| storage pointer| memory| calldata)?$/) - if (match.length > 1) { - return new BytesType(match[1].trim()) + var location = util.extractLocation(type) + if (location) { + return new BytesType(location) } else { return null } @@ -99,9 +100,9 @@ function fixedByteArray (type) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName} */ function stringType (type) { - var match = type.match(/( storage ref| storage pointer| memory| calldata)?$/) - if (match.length > 1) { - return new StringType(match[1].trim()) + var location = util.extractLocation(type) + if (location) { + return new StringType(location) } else { return null } diff --git a/src/solidity/types/util.js b/src/solidity/types/util.js index db752bb130..328dff7b34 100644 --- a/src/solidity/types/util.js +++ b/src/solidity/types/util.js @@ -12,7 +12,8 @@ module.exports = { toBN: toBN, add: add, storageStore: storageStore, - memoryStore: memoryStore + memoryStore: memoryStore, + extractLocation: extractLocation } function decodeInt (location, storageContent, byteLength, signed) { @@ -94,6 +95,15 @@ function add (value1, value2) { return toBN(value1).add(toBN(value2)) } +function extractLocation (type) { + var match = type.match(/( storage ref| storage pointer| memory| calldata)?$/) + if (match[1] !== '') { + return match[1].trim() + } else { + return null + } +} + function storageStore (type) { return type.location.indexOf('storage') === 0 }