Commit 4c09db37 authored by yann300's avatar yann300

move storageStore memoryStore to function class

parent f346b2b1
'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 { ...@@ -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 = { ...@@ -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) { ...@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment