simplify some code

pull/5370/head
Iuri Matias 4 years ago
parent 5885b495fe
commit 6b21d57acb
  1. 3
      libs/remix-debug/src/solidity-decoder/types/Address.js
  2. 12
      libs/remix-debug/src/solidity-decoder/types/ArrayType.js
  3. 33
      libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.js
  4. 11
      libs/remix-debug/src/solidity-decoder/types/Mapping.js
  5. 15
      libs/remix-debug/src/solidity-decoder/types/RefType.js
  6. 6
      libs/remix-debug/src/solidity-decoder/types/StringType.js
  7. 10
      libs/remix-debug/src/solidity-decoder/types/Struct.js
  8. 20
      libs/remix-debug/src/solidity-decoder/types/ValueType.js
  9. 24
      libs/remix-debug/src/solidity-decoder/types/util.js

@ -10,9 +10,8 @@ class Address extends ValueType {
decodeValue (value) {
if (!value) {
return '0x0000000000000000000000000000000000000000'
} else {
return '0x' + util.extractHexByteSlice(value, this.storageBytes, 0).toUpperCase()
}
return '0x' + util.extractHexByteSlice(value, this.storageBytes, 0).toUpperCase()
}
}

@ -69,11 +69,7 @@ class ArrayType extends RefType {
currentLocation.offset = 0
}
}
return {
value: ret,
length: '0x' + size.toString(16),
type: this.typeName
}
return {value: ret, length: '0x' + size.toString(16), type: this.typeName}
}
decodeFromMemoryInternal (offset, memory) {
@ -89,11 +85,7 @@ class ArrayType extends RefType {
ret.push(this.underlyingType.decodeFromMemory(contentOffset, memory))
offset += 32
}
return {
value: ret,
length: '0x' + length.toString(16),
type: this.typeName
}
return {value: ret, length: '0x' + length.toString(16), type: this.typeName}
}
}

@ -16,10 +16,7 @@ class DynamicByteArray extends RefType {
value = await util.extractHexValue(location, storageResolver, this.storageBytes)
} catch (e) {
console.log(e)
return {
value: '<decoding failed - ' + e.message + '>',
type: this.typeName
}
return {value: '<decoding failed - ' + e.message + '>', type: this.typeName}
}
const bn = new BN(value, 16)
if (bn.testn(0)) {
@ -31,10 +28,7 @@ class DynamicByteArray extends RefType {
currentSlot = await util.readFromStorage(dataPos, storageResolver)
} catch (e) {
console.log(e)
return {
value: '<decoding failed - ' + e.message + '>',
type: this.typeName
}
return {value: '<decoding failed - ' + e.message + '>', type: this.typeName}
}
while (length.gt(ret.length) && ret.length < 32000) {
currentSlot = currentSlot.replace('0x', '')
@ -44,24 +38,13 @@ class DynamicByteArray extends RefType {
currentSlot = await util.readFromStorage(dataPos, storageResolver)
} catch (e) {
console.log(e)
return {
value: '<decoding failed - ' + e.message + '>',
type: this.typeName
}
return {value: '<decoding failed - ' + e.message + '>', type: this.typeName}
}
}
return {
value: '0x' + ret.replace(/(00)+$/, ''),
length: '0x' + length.toString(16),
type: this.typeName
}
return {value: '0x' + ret.replace(/(00)+$/, ''), length: '0x' + length.toString(16), type: this.typeName}
} else {
var size = parseInt(value.substr(value.length - 2, 2), 16) / 2
return {
value: '0x' + value.substr(0, size * 2),
length: '0x' + size.toString(16),
type: this.typeName
}
return {value: '0x' + value.substr(0, size * 2), length: '0x' + size.toString(16), type: this.typeName}
}
}
@ -69,11 +52,7 @@ class DynamicByteArray extends RefType {
offset = 2 * offset
let length = memory.substr(offset, 64)
length = 2 * parseInt(length, 16)
return {
length: '0x' + length.toString(16),
value: '0x' + memory.substr(offset + 64, length),
type: this.typeName
}
return {length: '0x' + length.toString(16), value: '0x' + memory.substr(offset + 64, length), type: this.typeName}
}
}

@ -28,20 +28,13 @@ class Mapping extends RefType {
const mappingPreimages = await storageResolver.mappingsLocation(corrections)
let ret = await this.decodeMappingsLocation(mappingPreimages, location, storageResolver) // fetch mapping storage changes
ret = Object.assign({}, this.initialDecodedState, ret) // merge changes
return {
value: ret,
type: this.typeName
}
return {value: ret, type: this.typeName}
}
decodeFromMemoryInternal (offset, memory) {
// mappings can only exist in storage and not in memory
// so this should never be called
return {
value: '<not implemented>',
length: '0x',
type: this.typeName
}
return {value: '<not implemented>', length: '0x', type: this.typeName}
}
async decodeMappingsLocation (preimages, location, storageResolver) {

@ -21,10 +21,7 @@ class RefType {
*/
async decodeFromStack (stackDepth, stack, memory, storageResolver) {
if (stack.length - 1 < stackDepth) {
return {
error: '<decoding failed - stack underflow ' + stackDepth + '>',
type: this.typeName
}
return {error: '<decoding failed - stack underflow ' + stackDepth + '>', type: this.typeName}
}
let offset = stack[stack.length - 1 - stackDepth]
if (this.isInStorage()) {
@ -33,19 +30,13 @@ class RefType {
return await this.decodeFromStorage({ offset: 0, slot: offset }, storageResolver)
} catch (e) {
console.log(e)
return {
error: '<decoding failed - ' + e.message + '>',
type: this.typeName
}
return {error: '<decoding failed - ' + e.message + '>', type: this.typeName}
}
} else if (this.isInMemory()) {
offset = parseInt(offset, 16)
return this.decodeFromMemoryInternal(offset, memory)
} else {
return {
error: '<decoding failed - no decoder for ' + this.location + '>',
type: this.typeName
}
return {error: '<decoding failed - no decoder for ' + this.location + '>', type: this.typeName}
}
}

@ -39,11 +39,7 @@ function format (decoded) {
}
let value = decoded.value
value = value.replace('0x', '').replace(/(..)/g, '%$1')
const ret = {
length: decoded.length,
raw: decoded.value,
type: 'string'
}
const ret = {length: decoded.length, raw: decoded.value, type: 'string'}
try {
ret.value = decodeURIComponent(value)
} catch (e) {

@ -22,10 +22,7 @@ class Struct extends RefType {
ret[item.name] = '<decoding failed - ' + e.message + '>'
}
}
return {
value: ret,
type: this.typeName
}
return {value: ret, type: this.typeName}
}
decodeFromMemoryInternal (offset, memory) {
@ -36,10 +33,7 @@ class Struct extends RefType {
ret[item.name] = member
offset += 32
})
return {
value: ret,
type: this.typeName
}
return {value: ret, type: this.typeName}
}
}

@ -19,16 +19,10 @@ class ValueType {
async decodeFromStorage (location, storageResolver) {
try {
var value = await util.extractHexValue(location, storageResolver, this.storageBytes)
return {
value: this.decodeValue(value),
type: this.typeName
}
return {value: this.decodeValue(value), type: this.typeName}
} catch (e) {
console.log(e)
return {
value: '<decoding failed - ' + e.message + '>',
type: this.typeName
}
return {value: '<decoding failed - ' + e.message + '>', type: this.typeName}
}
}
@ -47,10 +41,7 @@ class ValueType {
} else {
value = this.decodeValue(stack[stack.length - 1 - stackDepth].replace('0x', ''))
}
return {
value: value,
type: this.typeName
}
return {value, type: this.typeName}
}
/**
@ -62,10 +53,7 @@ class ValueType {
*/
decodeFromMemory (offset, memory) {
let value = memory.substr(2 * offset, 64)
return {
value: this.decodeValue(value),
type: this.typeName
}
return {value: this.decodeValue(value), type: this.typeName}
}
}

@ -2,20 +2,6 @@
const ethutil = require('ethereumjs-util')
const BN = require('ethereumjs-util').BN
module.exports = {
readFromStorage: readFromStorage,
decodeIntFromHex: decodeIntFromHex,
extractHexValue: extractHexValue,
extractHexByteSlice: extractHexByteSlice,
toBN: toBN,
add: add,
sub: sub,
extractLocation: extractLocation,
removeLocation: removeLocation,
normalizeHex: normalizeHex,
extractLocationFromAstVariable: extractLocationFromAstVariable
}
function decodeIntFromHex (value, byteLength, signed) {
let bigNumber = new BN(value, 16)
if (signed) {
@ -30,15 +16,11 @@ function readFromStorage (slot, storageResolver) {
storageResolver.storageSlot(hexSlot, (error, slot) => {
if (error) {
return reject(error)
} else {
if (!slot) {
slot = {
key: slot,
value: ''
}
if (!slot) {
slot = { key: slot, value: '' }
}
return resolve(normalizeHex(slot.value))
}
})
})
}
@ -120,3 +102,5 @@ function normalizeHex (hex) {
}
return hex
}
module.exports = {readFromStorage, decodeIntFromHex, extractHexValue, extractHexByteSlice, toBN, add, sub, extractLocation, removeLocation, normalizeHex, extractLocationFromAstVariable}
Loading…
Cancel
Save