solidity decoder types updated

pull/697/head
aniket-engg 4 years ago committed by Aniket
parent 1b097bc6f9
commit 9fc2291d65
  1. 4
      libs/remix-debug/src/solidity-decoder/types/Address.ts
  2. 4
      libs/remix-debug/src/solidity-decoder/types/ArrayType.ts
  3. 4
      libs/remix-debug/src/solidity-decoder/types/Bool.ts
  4. 3
      libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts
  5. 4
      libs/remix-debug/src/solidity-decoder/types/Enum.ts
  6. 4
      libs/remix-debug/src/solidity-decoder/types/FixedByteArray.ts
  7. 4
      libs/remix-debug/src/solidity-decoder/types/Int.ts
  8. 4
      libs/remix-debug/src/solidity-decoder/types/Mapping.ts
  9. 11
      libs/remix-debug/src/solidity-decoder/types/RefType.ts
  10. 8
      libs/remix-debug/src/solidity-decoder/types/StringType.ts
  11. 4
      libs/remix-debug/src/solidity-decoder/types/Struct.ts
  12. 4
      libs/remix-debug/src/solidity-decoder/types/Uint.ts
  13. 8
      libs/remix-debug/src/solidity-decoder/types/ValueType.ts
  14. 31
      libs/remix-debug/src/solidity-decoder/types/util.ts

@ -2,7 +2,7 @@
const util = require('./util')
const ValueType = require('./ValueType')
class Address extends ValueType {
export class Address extends ValueType {
constructor () {
super(1, 20, 'address')
}
@ -14,5 +14,3 @@ class Address extends ValueType {
return '0x' + util.extractHexByteSlice(value, this.storageBytes, 0).toUpperCase()
}
}
module.exports = Address

@ -5,7 +5,7 @@ const sha3256 = remixLib.util.sha3_256
const BN = require('ethereumjs-util').BN
const RefType = require('./RefType')
class ArrayType extends RefType {
export class ArrayType extends RefType {
constructor (underlyingType, arraySize, location) {
let storageSlots = null
@ -104,5 +104,3 @@ class ArrayType extends RefType {
}
}
}
module.exports = ArrayType

@ -2,7 +2,7 @@
const ValueType = require('./ValueType')
const util = require('./util')
class Bool extends ValueType {
export class Bool extends ValueType {
constructor () {
super(1, 1, 'bool')
}
@ -15,5 +15,3 @@ class Bool extends ValueType {
return value !== '00'
}
}
module.exports = Bool

@ -5,7 +5,7 @@ const sha3256 = remixLib.util.sha3_256
const BN = require('ethereumjs-util').BN
const RefType = require('./RefType')
class DynamicByteArray extends RefType {
export class DynamicByteArray extends RefType {
constructor (location) {
super(1, 32, 'bytes', location)
}
@ -56,4 +56,3 @@ class DynamicByteArray extends RefType {
}
}
module.exports = DynamicByteArray

@ -1,7 +1,7 @@
'use strict'
const ValueType = require('./ValueType')
class Enum extends ValueType {
export class Enum extends ValueType {
constructor (enumDef) {
let storageBytes = 0
let length = enumDef.members.length
@ -24,5 +24,3 @@ class Enum extends ValueType {
return 'INVALID_ENUM<' + value + '>'
}
}
module.exports = Enum

@ -1,7 +1,7 @@
'use strict'
const ValueType = require('./ValueType')
class FixedByteArray extends ValueType {
export class FixedByteArray extends ValueType {
constructor (storageBytes) {
super(1, storageBytes, 'bytes' + storageBytes)
}
@ -10,5 +10,3 @@ class FixedByteArray extends ValueType {
return '0x' + value.substr(0, 2 * this.storageBytes).toUpperCase()
}
}
module.exports = FixedByteArray

@ -2,7 +2,7 @@
const util = require('./util')
const ValueType = require('./ValueType')
class Int extends ValueType {
export class Int extends ValueType {
constructor (storageBytes) {
super(1, storageBytes, 'int' + storageBytes * 8)
}
@ -12,5 +12,3 @@ class Int extends ValueType {
return util.decodeIntFromHex(value, this.storageBytes, true)
}
}
module.exports = Int

@ -3,7 +3,7 @@ const RefType = require('./RefType')
const util = require('./util')
const ethutil = require('ethereumjs-util')
class Mapping extends RefType {
export class Mapping extends RefType {
constructor (underlyingTypes, location, fullType) {
super(1, 32, fullType, 'storage')
this.keyType = underlyingTypes.keyType
@ -76,5 +76,3 @@ function concatTypedArrays (a, b) { // a, b TypedArray of same type
c.set(b, a.length)
return c
}
module.exports = Mapping

@ -1,7 +1,14 @@
'use strict'
const util = require('./util')
class RefType {
export class RefType {
location
storageSlots
storageBytes
typeName
basicType
constructor (storageSlots, storageBytes, typeName, location) {
this.location = location
this.storageSlots = storageSlots
@ -71,5 +78,3 @@ class RefType {
return this.location.indexOf('memory') === 0
}
}
module.exports = RefType

@ -1,7 +1,7 @@
'use strict'
const DynamicBytes = require('./DynamicByteArray')
class StringType extends DynamicBytes {
export class StringType extends DynamicBytes {
constructor (location) {
super(location)
this.typeName = 'string'
@ -41,12 +41,10 @@ function format (decoded) {
value = value.replace('0x', '').replace(/(..)/g, '%$1')
const ret = {length: decoded.length, raw: decoded.value, type: 'string'}
try {
ret.value = decodeURIComponent(value)
ret['value'] = decodeURIComponent(value)
} catch (e) {
ret.error = 'Invalid UTF8 encoding'
ret['error'] = 'Invalid UTF8 encoding'
ret.raw = decoded.value
}
return ret
}
module.exports = StringType

@ -2,7 +2,7 @@
const util = require('./util')
const RefType = require('./RefType')
class Struct extends RefType {
export class Struct extends RefType {
constructor (memberDetails, location, fullType) {
super(memberDetails.storageSlots, 32, 'struct ' + fullType, location)
this.members = memberDetails.members
@ -36,5 +36,3 @@ class Struct extends RefType {
return {value: ret, type: this.typeName}
}
}
module.exports = Struct

@ -2,7 +2,7 @@
const util = require('./util')
const ValueType = require('./ValueType')
class Uint extends ValueType {
export class Uint extends ValueType {
constructor (storageBytes) {
super(1, storageBytes, 'uint' + storageBytes * 8)
}
@ -12,5 +12,3 @@ class Uint extends ValueType {
return util.decodeIntFromHex(value, this.storageBytes, false)
}
}
module.exports = Uint

@ -1,7 +1,13 @@
'use strict'
var util = require('./util')
class ValueType {
export class ValueType {
storageSlots
storageBytes
typeName
basicType
constructor (storageSlots, storageBytes, typeName) {
this.storageSlots = storageSlots
this.storageBytes = storageBytes

@ -1,8 +1,7 @@
'use strict'
const ethutil = require('ethereumjs-util')
const BN = require('ethereumjs-util').BN
import { BN, bufferToHex, unpad } from 'ethereumjs-util'
function decodeIntFromHex (value, byteLength, signed) {
export function decodeIntFromHex (value, byteLength, signed) {
let bigNumber = new BN(value, 16)
if (signed) {
bigNumber = bigNumber.fromTwos(8 * byteLength)
@ -10,8 +9,8 @@ function decodeIntFromHex (value, byteLength, signed) {
return bigNumber.toString(10)
}
function readFromStorage(slot, storageResolver) {
const hexSlot = '0x' + normalizeHex(ethutil.bufferToHex(slot))
export function readFromStorage(slot, storageResolver) {
const hexSlot = '0x' + normalizeHex(bufferToHex(slot))
return new Promise((resolve, reject) => {
storageResolver.storageSlot(hexSlot, (error, slot) => {
if (error) {
@ -32,7 +31,7 @@ function readFromStorage(slot, storageResolver) {
* @param {Int} byteLength - Length of the byte slice to extract
* @param {Int} offsetFromLSB - byte distance from the right end slot value to the right end of the byte slice
*/
function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
export function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
const offset = slotValue.length - 2 * offsetFromLSB - 2 * byteLength
return slotValue.substr(offset, 2 * byteLength)
}
@ -44,7 +43,7 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
* @param {Object} storageResolver - storage resolver
* @param {Int} byteLength - Length of the byte slice to extract
*/
async function extractHexValue (location, storageResolver, byteLength) {
export async function extractHexValue (location, storageResolver, byteLength) {
let slotvalue
try {
slotvalue = await readFromStorage(location.slot, storageResolver)
@ -54,11 +53,11 @@ async function extractHexValue (location, storageResolver, byteLength) {
return extractHexByteSlice(slotvalue, byteLength, location.offset)
}
function toBN (value) {
export function toBN (value) {
if (value instanceof BN) {
return value
} else if (value.match && value.match(/^(0x)?([a-f0-9]*)$/)) {
value = ethutil.unpad(value.replace(/^(0x)/, ''))
value = unpad(value.replace(/^(0x)/, ''))
value = new BN(value === '' ? '0' : value, 16)
} else if (!isNaN(value)) {
value = new BN(value)
@ -66,19 +65,19 @@ function toBN (value) {
return value
}
function add (value1, value2) {
export function add (value1, value2) {
return toBN(value1).add(toBN(value2))
}
function sub (value1, value2) {
export function sub (value1, value2) {
return toBN(value1).sub(toBN(value2))
}
function removeLocation (type) {
export function removeLocation (type) {
return type.replace(/( storage ref| storage pointer| memory| calldata)/g, '')
}
function extractLocation (type) {
export function extractLocation (type) {
let match = type.match(/( storage ref| storage pointer| memory| calldata)?$/)
if (match[1] !== '') {
return match[1].trim()
@ -86,7 +85,7 @@ function extractLocation (type) {
return null
}
function extractLocationFromAstVariable (node) {
export function extractLocationFromAstVariable (node) {
if (node.storageLocation !== 'default') {
return node.storageLocation
} else if (node.stateVariable) {
@ -95,12 +94,10 @@ function extractLocationFromAstVariable (node) {
return 'default' // local variables => storage, function parameters & return values => memory, state => storage
}
function normalizeHex (hex) {
export function normalizeHex (hex) {
hex = hex.replace('0x', '')
if (hex.length < 64) {
return (new Array(64 - hex.length + 1).join('0')) + hex
}
return hex
}
module.exports = {readFromStorage, decodeIntFromHex, extractHexValue, extractHexByteSlice, toBN, add, sub, extractLocation, removeLocation, normalizeHex, extractLocationFromAstVariable}
Loading…
Cancel
Save