always return value when reading from storage

pull/7/head
yann300 8 years ago
parent e24d28c8c3
commit db46587840
  1. 16
      src/solidity/types/util.js

@ -4,15 +4,12 @@ var BN = require('ethereumjs-util').BN
module.exports = { module.exports = {
extractHexByteSlice: extractHexByteSlice, extractHexByteSlice: extractHexByteSlice,
extractSlotValue: extractSlotValue, readFromStorage: readFromStorage,
decodeInt: decodeInt decodeInt: decodeInt
} }
function decodeInt (location, storageContent, byteLength, signed) { function decodeInt (location, storageContent, byteLength, signed) {
var slotvalue = extractSlotValue(location.slot, storageContent) var slotvalue = readFromStorage(location.slot, storageContent)
if (slotvalue === null) {
return '0'
}
var value = extractHexByteSlice(slotvalue, byteLength, location.offset) var value = extractHexByteSlice(slotvalue, byteLength, location.offset)
var bigNumber = new BN(value, 16) var bigNumber = new BN(value, 16)
if (signed) { if (signed) {
@ -21,24 +18,21 @@ function decodeInt (location, storageContent, byteLength, signed) {
return bigNumber.toString(10) return bigNumber.toString(10)
} }
function extractSlotValue (slot, storageContent) { function readFromStorage (slot, storageContent) {
var hexSlot = ethutil.bufferToHex(slot) var hexSlot = ethutil.bufferToHex(slot)
if (storageContent[hexSlot] !== undefined) { if (storageContent[hexSlot] !== undefined) {
return storageContent[hexSlot] return storageContent[hexSlot]
} else { } else {
hexSlot = ethutil.bufferToHex(ethutil.setLengthLeft(slot, 32)) hexSlot = ethutil.bufferToHex(ethutil.setLengthLeft(slot, 32))
if (storageContent[hexSlot]) { if (storageContent[hexSlot] !== undefined) {
return storageContent[hexSlot] return storageContent[hexSlot]
} else { } else {
return null return '0x0'
} }
} }
} }
function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) { function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
if (slotValue === undefined) {
slotValue = '0'
}
slotValue = slotValue.replace('0x', '') slotValue = slotValue.replace('0x', '')
if (slotValue.length < 64) { if (slotValue.length < 64) {
slotValue = (new Array(64 - slotValue.length + 1).join('0')) + slotValue slotValue = (new Array(64 - slotValue.length + 1).join('0')) + slotValue

Loading…
Cancel
Save