Commit d5b890fb authored by yann300's avatar yann300

refactor calldata decoding & fix nested array decoding

parent f8be36a5
......@@ -52,6 +52,13 @@ export class RefType {
offset = parseInt(offset, 16)
return this.decodeFromMemoryInternal(offset, memory, cursor)
} else if (this.isInCallData()) {
return this._decodeFromCallData(variableDetails, calldata)
} else {
return { error: '<decoding failed - no decoder for ' + this.location + '>', type: this.typeName }
}
}
_decodeFromCallData (variableDetails, calldata) {
calldata = calldata.length > 0 ? calldata[0] : '0x'
const ethersAbi = new ethers.utils.Interface(variableDetails.abi)
const fnSign = calldata.substr(0, 10)
......@@ -59,20 +66,31 @@ export class RefType {
let decodedValue = decodedData[variableDetails.name]
const isArray = Array.isArray(decodedValue)
if (isArray) {
decodedValue = decodedValue.map((el) => {
return {
value: el.toString(),
type: this.underlyingType.typeName
}
})
return this._decodeCallDataArray(decodedValue, this)
}
return {
length: Array.isArray(decodedValue) ? '0x' + decodedValue.length.toString(16) : undefined,
length: isArray ? '0x' + decodedValue.length.toString(16) : undefined,
value: decodedValue,
type: this.typeName
}
}
_decodeCallDataArray (value, type) {
const isArray = Array.isArray(value)
if (isArray) {
value = value.map((el) => {
return this._decodeCallDataArray(el, this.underlyingType)
})
return {
length: value.length.toString(16),
value: value,
type: type.typeName
}
} else {
return { error: '<decoding failed - no decoder for ' + this.location + '>', type: this.typeName }
return {
value: value.toString(),
type: type.underlyingType.typeName
}
}
}
......
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