move sha3 function outside of solidity code

pull/7/head
yann300 8 years ago
parent 668daa8674
commit c2113932e5
  1. 16
      src/helpers/util.js
  2. 3
      src/solidity/types/ArrayType.js
  3. 3
      src/solidity/types/DynamicByteArray.js
  4. 7
      src/solidity/types/util.js

@ -1,4 +1,6 @@
'use strict' 'use strict'
var ethutil = require('ethereumjs-util')
module.exports = { module.exports = {
/* /*
ints: IntArray ints: IntArray
@ -115,7 +117,19 @@ module.exports = {
*/ */
findCall: findCall, findCall: findCall,
buildCallPath: buildCallPath buildCallPath: buildCallPath,
/**
* sha3 the given @arg value
*
* @param {String} value - value to sha3
* @return {Object} - return sha3ied value
*/
sha3: function (value) {
var ret = ethutil.bufferToHex(ethutil.setLengthLeft(value, 32))
ret = ethutil.sha3(ret)
return ethutil.bufferToHex(ret)
}
} }
/** /**

@ -1,5 +1,6 @@
'use strict' 'use strict'
var util = require('./util') var util = require('./util')
var helper = require('../../helpers/util')
var BN = require('ethereumjs-util').BN var BN = require('ethereumjs-util').BN
var RefType = require('./RefType') var RefType = require('./RefType')
@ -33,7 +34,7 @@ class ArrayType extends RefType {
} }
if (this.arraySize === 'dynamic') { if (this.arraySize === 'dynamic') {
size = util.toBN('0x' + slotValue) size = util.toBN('0x' + slotValue)
currentLocation.slot = util.sha3(location.slot) currentLocation.slot = helper.sha3(location.slot)
} else { } else {
size = new BN(this.arraySize) size = new BN(this.arraySize)
} }

@ -1,5 +1,6 @@
'use strict' 'use strict'
var util = require('./util') var util = require('./util')
var helper = require('../../helpers/util')
var BN = require('ethereumjs-util').BN var BN = require('ethereumjs-util').BN
var RefType = require('./RefType') var RefType = require('./RefType')
@ -13,7 +14,7 @@ class DynamicByteArray extends RefType {
var bn = new BN(value, 16) var bn = new BN(value, 16)
if (bn.testn(0)) { if (bn.testn(0)) {
var length = bn.div(new BN(2)) var length = bn.div(new BN(2))
var dataPos = new BN(util.sha3(location.slot).replace('0x', ''), 16) var dataPos = new BN(helper.sha3(location.slot).replace('0x', ''), 16)
var ret = '' var ret = ''
var currentSlot = await util.readFromStorage(dataPos, storageContent) var currentSlot = await util.readFromStorage(dataPos, storageContent)
while (length.gt(ret.length) && ret.length < 32000) { while (length.gt(ret.length) && ret.length < 32000) {

@ -7,7 +7,6 @@ module.exports = {
decodeIntFromHex: decodeIntFromHex, decodeIntFromHex: decodeIntFromHex,
extractHexValue: extractHexValue, extractHexValue: extractHexValue,
extractHexByteSlice: extractHexByteSlice, extractHexByteSlice: extractHexByteSlice,
sha3: sha3,
toBN: toBN, toBN: toBN,
add: add, add: add,
extractLocation: extractLocation, extractLocation: extractLocation,
@ -67,12 +66,6 @@ async function extractHexValue (location, storageContent, byteLength) {
return extractHexByteSlice(slotvalue, byteLength, location.offset) return extractHexByteSlice(slotvalue, byteLength, location.offset)
} }
function sha3 (slot) {
var remoteSlot = ethutil.bufferToHex(ethutil.setLengthLeft(slot, 32))
var key = ethutil.sha3(remoteSlot)
return ethutil.bufferToHex(key)
}
function toBN (value) { function toBN (value) {
if (value instanceof BN) { if (value instanceof BN) {
return value return value

Loading…
Cancel
Save