diff --git a/libs/remix-debug/src/solidity-decoder/types/Address.ts b/libs/remix-debug/src/solidity-decoder/types/Address.ts index 1a52f18f1a..b5a43021a4 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Address.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Address.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 diff --git a/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts b/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts index 3aed4e240b..a4672465fa 100644 --- a/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/Bool.ts b/libs/remix-debug/src/solidity-decoder/types/Bool.ts index da8c47c3fa..fec866138c 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Bool.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Bool.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts b/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts index c469e887a3..9c86fc4cbb 100644 --- a/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts +++ b/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/Enum.ts b/libs/remix-debug/src/solidity-decoder/types/Enum.ts index 5614aab2b3..10cc27e728 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Enum.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Enum.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/FixedByteArray.ts b/libs/remix-debug/src/solidity-decoder/types/FixedByteArray.ts index e0fafa5fe5..e1cc4db867 100644 --- a/libs/remix-debug/src/solidity-decoder/types/FixedByteArray.ts +++ b/libs/remix-debug/src/solidity-decoder/types/FixedByteArray.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/Int.ts b/libs/remix-debug/src/solidity-decoder/types/Int.ts index 8bea14f120..ad4eee2fe8 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Int.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Int.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/Mapping.ts b/libs/remix-debug/src/solidity-decoder/types/Mapping.ts index 4d07517ad0..0334e9b2a5 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Mapping.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Mapping.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/RefType.ts b/libs/remix-debug/src/solidity-decoder/types/RefType.ts index f4ca0a16f2..bf4a6b91a2 100644 --- a/libs/remix-debug/src/solidity-decoder/types/RefType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/RefType.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/StringType.ts b/libs/remix-debug/src/solidity-decoder/types/StringType.ts index 92fc7c2460..9963fd0b3c 100644 --- a/libs/remix-debug/src/solidity-decoder/types/StringType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/StringType.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/Struct.ts b/libs/remix-debug/src/solidity-decoder/types/Struct.ts index e01a7659c6..c54f778744 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Struct.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Struct.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/Uint.ts b/libs/remix-debug/src/solidity-decoder/types/Uint.ts index 9b1fdc2652..beabd9aa4f 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Uint.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Uint.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/ValueType.ts b/libs/remix-debug/src/solidity-decoder/types/ValueType.ts index 18624c9783..eb3d4f526d 100644 --- a/libs/remix-debug/src/solidity-decoder/types/ValueType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/ValueType.ts @@ -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 diff --git a/libs/remix-debug/src/solidity-decoder/types/util.ts b/libs/remix-debug/src/solidity-decoder/types/util.ts index cef96f21a4..a66b5e99ec 100644 --- a/libs/remix-debug/src/solidity-decoder/types/util.ts +++ b/libs/remix-debug/src/solidity-decoder/types/util.ts @@ -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} \ No newline at end of file