diff --git a/src/solidity/types/util.js b/src/solidity/types/util.js index cf4330959f..3bf63f03d6 100644 --- a/src/solidity/types/util.js +++ b/src/solidity/types/util.js @@ -22,7 +22,7 @@ function decodeIntFromHex (value, byteLength, signed) { } function readFromStorage (slot, storageResolver) { - var hexSlot = ethutil.bufferToHex(slot) + var hexSlot = '0x' + normalizeHex(ethutil.bufferToHex(slot)) return new Promise((resolve, reject) => { storageResolver.storageSlot(hexSlot, (error, slot) => { if (error) { @@ -34,11 +34,7 @@ function readFromStorage (slot, storageResolver) { value: '' } } - slot.value = slot.value.replace('0x', '') - if (slot.value.length < 64) { - slot.value = (new Array(64 - slot.value.length + 1).join('0')) + slot.value - } - return resolve(slot.value) + return resolve(normalizeHex(slot.value)) } }) }) @@ -102,3 +98,11 @@ function extractLocation (type) { return null } } + +function normalizeHex (hex) { + hex = hex.replace('0x', '') + if (hex.length < 64) { + return (new Array(64 - hex.length + 1).join('0')) + hex + } + return hex +}