decode int, uint, address

pull/7/head
yann300 8 years ago
parent 2fc63ea3df
commit fd906bc417
  1. 8
      src/solidity/types/Address.js
  2. 8
      src/solidity/types/Int.js
  3. 8
      src/solidity/types/Uint.js
  4. 6
      src/solidity/types/util.js

@ -12,4 +12,12 @@ Address.prototype.decodeFromStorage = function (location, storageContent) {
return '0x' + value.toUpperCase()
}
Address.prototype.decodeLocals = function (stackHeight, stack, memory) {
if (stack.length < stackHeight) {
return '0x0000000000000000000000000000000000000000'
} else {
return '0x' + util.extractHexByteSlice(stack[stack.length - 1 - stackHeight], this.storageBytes, 0)
}
}
module.exports = Address

@ -11,4 +11,12 @@ Int.prototype.decodeFromStorage = function (location, storageContent) {
return util.decodeInt(location, storageContent, this.storageBytes, true)
}
Int.prototype.decodeLocals = function (stackHeight, stack, memory) {
if (stack.length < stackHeight) {
return '0'
} else {
return util.decodeIntFromHex(stack[stack.length - 1 - stackHeight].replace('0x', ''), 32, true)
}
}
module.exports = Int

@ -11,4 +11,12 @@ Uint.prototype.decodeFromStorage = function (location, storageContent) {
return util.decodeInt(location, storageContent, this.storageBytes, false)
}
Uint.prototype.decodeLocals = function (stackHeight, stack, memory) {
if (stack.length < stackHeight) {
return '0'
} else {
return util.decodeIntFromHex(stack[stack.length - 1 - stackHeight].replace('0x', ''), this.storageBytes, false)
}
}
module.exports = Uint

@ -5,7 +5,9 @@ var BN = require('ethereumjs-util').BN
module.exports = {
readFromStorage: readFromStorage,
decodeInt: decodeInt,
decodeIntFromHex: decodeIntFromHex,
extractHexValue: extractHexValue,
extractHexByteSlice: extractHexByteSlice,
sha3: sha3,
toBN: toBN,
add: add
@ -14,6 +16,10 @@ module.exports = {
function decodeInt (location, storageContent, byteLength, signed) {
var slotvalue = readFromStorage(location.slot, storageContent)
var value = extractHexByteSlice(slotvalue, byteLength, location.offset)
return decodeIntFromHex(value, byteLength, signed)
}
function decodeIntFromHex (value, byteLength, signed) {
var bigNumber = new BN(value, 16)
if (signed) {
bigNumber = bigNumber.fromTwos(8 * byteLength)

Loading…
Cancel
Save