move storageStore memoryStore to function class

pull/7/head
yann300 8 years ago
parent f346b2b1a9
commit 4c09db3707
  1. 24
      src/solidity/types/RefType.js
  2. 10
      src/solidity/types/util.js

@ -1,5 +1,4 @@
'use strict' 'use strict'
var util = require('./util')
class RefType { class RefType {
constructor (storageSlots, storageBytes, typeName, location) { constructor (storageSlots, storageBytes, typeName, location) {
@ -39,15 +38,34 @@ class RefType {
offset = parseInt(offset, 16) offset = parseInt(offset, 16)
return decodeInternal(this, offset, memory, storage) return decodeInternal(this, offset, memory, storage)
} }
/**
* current type defined in storage
*
* @return {Bool} - return true if the type is defined in the storage
*/
storageStore () {
return this.location.indexOf('storage') === 0
}
/**
* current type defined in memory
*
* @return {Bool} - return true if the type is defined in the memory
*/
memoryStore () {
return this.location.indexOf('memory') === 0
}
} }
function decodeInternal (self, offset, memory, storage) { function decodeInternal (self, offset, memory, storage) {
if (!storage) { if (!storage) {
storage = {} // TODO this is a fallback, should manage properly locals store in storage storage = {} // TODO this is a fallback, should manage properly locals store in storage
} }
if (util.storageStore(self)) { if (self.storageStore()) {
return self.decodeFromStorage({ offset: 0, slot: offset }, storage) return self.decodeFromStorage({ offset: 0, slot: offset }, storage)
} else if (util.memoryStore(self)) { } else if (self.memoryStore()) {
return self.decodeFromMemory(offset, memory) return self.decodeFromMemory(offset, memory)
} else { } else {
return { error: '<decoding failed - no decoder for ' + self.location + '>' } return { error: '<decoding failed - no decoder for ' + self.location + '>' }

@ -11,8 +11,6 @@ module.exports = {
sha3: sha3, sha3: sha3,
toBN: toBN, toBN: toBN,
add: add, add: add,
storageStore: storageStore,
memoryStore: memoryStore,
extractLocation: extractLocation extractLocation: extractLocation
} }
@ -103,11 +101,3 @@ function extractLocation (type) {
return null return null
} }
} }
function storageStore (type) {
return type.location.indexOf('storage') === 0
}
function memoryStore (type) {
return type.location.indexOf('memory') === 0
}

Loading…
Cancel
Save