refactor storageRange

pull/5370/head
Iuri Matias 4 years ago committed by aniket-engg
parent b59fec1507
commit 503da36dd0
  1. 16
      libs/remix-debug/src/debugger/VmDebugger.js
  2. 10
      libs/remix-debug/src/storage/storageViewer.js
  3. 6
      libs/remix-debug/test/debugger.js

@ -102,13 +102,13 @@ class VmDebuggerLogic {
var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager) var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager)
storageViewer.storageRange((error, storage) => { storageViewer.storageRange().then((storage) => {
if (error) { if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerStorageUpdate', [{}])
} else if (this.stepManager.currentStepIndex === index) {
var header = storageViewer.isComplete(address) ? '[Completely Loaded]' : '[Partially Loaded]' var header = storageViewer.isComplete(address) ? '[Completely Loaded]' : '[Partially Loaded]'
this.event.trigger('traceManagerStorageUpdate', [storage, header]) this.event.trigger('traceManagerStorageUpdate', [storage, header])
} }
}).catch((_error) => {
this.event.trigger('traceManagerStorageUpdate', [{}])
}) })
} catch (error) { } catch (error) {
} }
@ -185,11 +185,9 @@ class VmDebuggerLogic {
for (var k in this.addresses) { for (var k in this.addresses) {
var address = this.addresses[k] var address = this.addresses[k]
var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager) var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager)
storageViewer.storageRange((error, result) => { storageViewer.storageRange().then((result) => {
if (!error) { storageJSON[address] = result
storageJSON[address] = result this.event.trigger('traceStorageUpdate', [storageJSON])
this.event.trigger('traceStorageUpdate', [storageJSON])
}
}) })
} }
}) })

@ -30,10 +30,12 @@ class StorageViewer {
* *
* @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} * @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value}
*/ */
storageRange (callback) { storageRange () {
this.storageResolver.storageRange(this.context.tx, this.context.stepIndex, this.context.address).then((storage) => { return new Promise((resolve, reject) => {
callback(null, Object.assign({}, storage, this.storageChanges)) this.storageResolver.storageRange(this.context.tx, this.context.stepIndex, this.context.address).then((storage) => {
}).catch(callback) resolve(Object.assign({}, storage, this.storageChanges))
}).catch(reject)
})
} }
/** /**

@ -224,9 +224,11 @@ function testDebugging (debugManager) {
const address = debugManager.traceManager.getCurrentCalledAddressAt(38) const address = debugManager.traceManager.getCurrentCalledAddressAt(38)
console.log(address) console.log(address)
var storageView = debugManager.storageViewAt(196, address) var storageView = debugManager.storageViewAt(196, address)
storageView.storageRange((error, storage) => {
if (error) return t.end(error) storageView.storageRange().then((storage) => {
t.equal(JSON.stringify(storage), JSON.stringify({ '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563': { key: '0x0000000000000000000000000000000000000000000000000000000000000000', value: '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db' } })) t.equal(JSON.stringify(storage), JSON.stringify({ '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563': { key: '0x0000000000000000000000000000000000000000000000000000000000000000', value: '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db' } }))
}).catch((error) => {
if (error) return t.end(error)
}) })
} catch (error) { } catch (error) {
return t.end(error) return t.end(error)

Loading…
Cancel
Save