'use strict'

function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory) {
  var scope = internalTreeCall.findScope(vmtraceIndex)
  if (!scope) {
    return { 'error': 'Can\'t display locals. reason: compilation result might not have been provided' }
  }
  var locals = {}
  for (var local in scope.locals) {
    let variable = scope.locals[local]
    if (variable.type.decodeLocals) {
      locals[variable.name] = variable.type.decodeLocals(variable.stackHeight, stack, memory)
    } else {
      locals[variable.name] = ''
    }
  }
  return locals
}

module.exports = {
  solidityLocals: solidityLocals
}

@@ -279,16 +279,48 @@
 ls = %7B%7D%0A
+  memory = formatMemory(memory)%0A
   for (v
@@ -593,16 +593,153 @@
 cals%0A%7D%0A%0A
+function formatMemory (memory) %7B%0A  if (memory instanceof Array) %7B%0A    memory = memory.join('').replace(/0x/g, '')%0A  %7D%0A  return memory%0A%7D%0A%0A
 module.e

format memory before decoding