From 042199393e9430e1e83f3a028b1fa7c31921ff58 Mon Sep 17 00:00:00 2001 From: serapath Date: Fri, 13 Oct 2017 20:59:34 +0200 Subject: [PATCH] UPDATE acount placeholder counter to use address array index --- src/app/tabs/run-tab.js | 13 +++++++++---- src/recorder.js | 17 +++++++++++++---- src/universal-dapp.js | 12 ++++++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index b648323115..dbdda17f90 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -246,10 +246,15 @@ function updateAccountBalances (container, appAPI) { ------------------------------------------------ */ function makeRecorder (appAPI, appEvents) { var udapp = appAPI.udapp() - var recorder = new Recorder({ events: { - udapp: appEvents.udapp, - executioncontext: executionContext.event - }}) + var recorder = new Recorder({ + events: { + udapp: appEvents.udapp, + executioncontext: executionContext.event + }, + api: { + getAccounts (cb) { udapp.getAccounts(cb) } + } + }) var css = csjs` .container { margin-top: 10px; diff --git a/src/recorder.js b/src/recorder.js index 1be3eff71f..13bc87d5d9 100644 --- a/src/recorder.js +++ b/src/recorder.js @@ -11,14 +11,23 @@ class Recorder { self.clearAll() }) var counter = 0 + function getIndex (accounts, address) { + var index + accounts.forEach((addr, idx) => { if (address === addr) index = idx }) + if (!index) index = (++counter) + return index + } self._addressCache = {} opts.events.udapp.register('initiatingTransaction', (timestamp, tx) => { var { from, to, value, gas, data } = tx var record = { value, gas, data } - record.from = self._addressCache[from] || (self._addressCache[from] = ``) - if (to === null) self.data._pendingCreation[timestamp] = record - else record.to = self._addressCache[to] || (self._addressCache[to] = ``) - self.append(timestamp, record) + self._api.getAccounts(function (err, accounts = []) { + if (err) console.error(err) + record.from = self._addressCache[from] || (self._addressCache[from] = ``) + if (to === null) self.data._pendingCreation[timestamp] = record + else record.to = self._addressCache[to] || (self._addressCache[to] = ``) + self.append(timestamp, record) + }) }) opts.events.udapp.register('transactionExecuted', (...args) => { var err = args[0] diff --git a/src/universal-dapp.js b/src/universal-dapp.js index c20e7e0063..a00dfd1dc8 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -469,10 +469,14 @@ function execute (pipeline, env, callback) { UniversalDApp.prototype.replayTx = function (args, cb) { var self = this - var tx = { to: args.to, data: args.data, useCall: args.useCall } - var pipeline = [runTransaction] - var env = { self, args, tx } - execute(pipeline, env, cb) + self.getAccounts(function (err, accounts = []) { + if (err) console.error(err) + if (args.to[0] === '<') args.to = accounts[args.to.split('>')[0].slice(11)] + if (args.from && args.from[0] === '<') args.from = accounts[args.from.split('>')[0].slice(11)] + var pipeline = [runTransaction] + var env = { self, args, tx: { to: args.to, from: args.from, data: args.data, useCall: args.useCall } } + execute(pipeline, env, cb) + }) } UniversalDApp.prototype.runTx = function (args, cb) {