|
|
@ -28,8 +28,8 @@ function mapping (type, stateDefinitions, contractName) { |
|
|
|
const valueType = parseType(valueTypeName, stateDefinitions, contractName, 'storage') |
|
|
|
const valueType = parseType(valueTypeName, stateDefinitions, contractName, 'storage') |
|
|
|
|
|
|
|
|
|
|
|
var underlyingTypes = { |
|
|
|
var underlyingTypes = { |
|
|
|
'keyType': keyType, |
|
|
|
keyType: keyType, |
|
|
|
'valueType': valueType |
|
|
|
valueType: valueType |
|
|
|
} |
|
|
|
} |
|
|
|
return new MappingType(underlyingTypes, 'location', removeLocation(type)) |
|
|
|
return new MappingType(underlyingTypes, 'location', removeLocation(type)) |
|
|
|
} |
|
|
|
} |
|
|
@ -41,7 +41,7 @@ function mapping (type, stateDefinitions, contractName) { |
|
|
|
* @return {Object} returns decoded info about the current type: { storageBytes, typeName} |
|
|
|
* @return {Object} returns decoded info about the current type: { storageBytes, typeName} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function uint (type) { |
|
|
|
function uint (type) { |
|
|
|
type === 'uint' ? 'uint256' : type |
|
|
|
type = type === 'uint' ? 'uint256' : type |
|
|
|
const storageBytes = parseInt(type.replace('uint', '')) / 8 |
|
|
|
const storageBytes = parseInt(type.replace('uint', '')) / 8 |
|
|
|
return new UintType(storageBytes) |
|
|
|
return new UintType(storageBytes) |
|
|
|
} |
|
|
|
} |
|
|
@ -53,7 +53,7 @@ function uint (type) { |
|
|
|
* @return {Object} returns decoded info about the current type: { storageBytes, typeName} |
|
|
|
* @return {Object} returns decoded info about the current type: { storageBytes, typeName} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function int (type) { |
|
|
|
function int (type) { |
|
|
|
type === 'int' ? 'int256' : type |
|
|
|
type = type === 'int' ? 'int256' : type |
|
|
|
const storageBytes = parseInt(type.replace('int', '')) / 8 |
|
|
|
const storageBytes = parseInt(type.replace('int', '')) / 8 |
|
|
|
return new IntType(storageBytes) |
|
|
|
return new IntType(storageBytes) |
|
|
|
} |
|
|
|
} |
|
|
@ -139,7 +139,6 @@ function stringType (type, stateDefinitions, contractName, location) { |
|
|
|
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray} |
|
|
|
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function array (type, stateDefinitions, contractName, location) { |
|
|
|
function array (type, stateDefinitions, contractName, location) { |
|
|
|
let arraySize |
|
|
|
|
|
|
|
const match = type.match(/(.*)\[(.*?)\]( storage ref| storage pointer| memory| calldata)?$/) |
|
|
|
const match = type.match(/(.*)\[(.*?)\]( storage ref| storage pointer| memory| calldata)?$/) |
|
|
|
if (!match) { |
|
|
|
if (!match) { |
|
|
|
console.log('unable to parse type ' + type) |
|
|
|
console.log('unable to parse type ' + type) |
|
|
@ -148,7 +147,7 @@ function array (type, stateDefinitions, contractName, location) { |
|
|
|
if (!location) { |
|
|
|
if (!location) { |
|
|
|
location = match[3].trim() |
|
|
|
location = match[3].trim() |
|
|
|
} |
|
|
|
} |
|
|
|
arraySize = match[2] === '' ? 'dynamic' : parseInt(match[2]) |
|
|
|
const arraySize = match[2] === '' ? 'dynamic' : parseInt(match[2]) |
|
|
|
const underlyingType = parseType(match[1], stateDefinitions, contractName, location) |
|
|
|
const underlyingType = parseType(match[1], stateDefinitions, contractName, location) |
|
|
|
if (underlyingType === null) { |
|
|
|
if (underlyingType === null) { |
|
|
|
console.log('unable to parse type ' + type) |
|
|
|
console.log('unable to parse type ' + type) |
|
|
@ -215,7 +214,7 @@ function getEnum (type, stateDefinitions, contractName) { |
|
|
|
} |
|
|
|
} |
|
|
|
const state = stateDefinitions[contractName] |
|
|
|
const state = stateDefinitions[contractName] |
|
|
|
if (state) { |
|
|
|
if (state) { |
|
|
|
for (let dec of state.stateDefinitions) { |
|
|
|
for (const dec of state.stateDefinitions) { |
|
|
|
if (dec && dec.name && type === contractName + '.' + dec.name) { |
|
|
|
if (dec && dec.name && type === contractName + '.' + dec.name) { |
|
|
|
return dec |
|
|
|
return dec |
|
|
|
} |
|
|
|
} |
|
|
@ -242,7 +241,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) { |
|
|
|
} |
|
|
|
} |
|
|
|
const state = stateDefinitions[contractName] |
|
|
|
const state = stateDefinitions[contractName] |
|
|
|
if (state) { |
|
|
|
if (state) { |
|
|
|
for (let dec of state.stateDefinitions) { |
|
|
|
for (const dec of state.stateDefinitions) { |
|
|
|
if (dec.nodeType === 'StructDefinition' && type === contractName + '.' + dec.name) { |
|
|
|
if (dec.nodeType === 'StructDefinition' && type === contractName + '.' + dec.name) { |
|
|
|
const offsets = computeOffsets(dec.members, stateDefinitions, contractName, location) |
|
|
|
const offsets = computeOffsets(dec.members, stateDefinitions, contractName, location) |
|
|
|
if (!offsets) { |
|
|
|
if (!offsets) { |
|
|
@ -290,18 +289,18 @@ function typeClass (fullType) { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function parseType (type, stateDefinitions, contractName, location) { |
|
|
|
function parseType (type, stateDefinitions, contractName, location) { |
|
|
|
const decodeInfos = { |
|
|
|
const decodeInfos = { |
|
|
|
'contract': address, |
|
|
|
contract: address, |
|
|
|
'address': address, |
|
|
|
address: address, |
|
|
|
'array': array, |
|
|
|
array: array, |
|
|
|
'bool': bool, |
|
|
|
bool: bool, |
|
|
|
'bytes': dynamicByteArray, |
|
|
|
bytes: dynamicByteArray, |
|
|
|
'bytesX': fixedByteArray, |
|
|
|
bytesX: fixedByteArray, |
|
|
|
'enum': enumType, |
|
|
|
enum: enumType, |
|
|
|
'string': stringType, |
|
|
|
string: stringType, |
|
|
|
'struct': struct, |
|
|
|
struct: struct, |
|
|
|
'int': int, |
|
|
|
int: int, |
|
|
|
'uint': uint, |
|
|
|
uint: uint, |
|
|
|
'mapping': mapping |
|
|
|
mapping: mapping |
|
|
|
} |
|
|
|
} |
|
|
|
const currentType = typeClass(type) |
|
|
|
const currentType = typeClass(type) |
|
|
|
if (currentType === null) { |
|
|
|
if (currentType === null) { |
|
|
|