UPDATE acount placeholder counter to use address array index

pull/1/head
serapath 7 years ago committed by yann300
parent 4cb317fd4b
commit 042199393e
  1. 13
      src/app/tabs/run-tab.js
  2. 17
      src/recorder.js
  3. 12
      src/universal-dapp.js

@ -246,10 +246,15 @@ function updateAccountBalances (container, appAPI) {
------------------------------------------------ */ ------------------------------------------------ */
function makeRecorder (appAPI, appEvents) { function makeRecorder (appAPI, appEvents) {
var udapp = appAPI.udapp() var udapp = appAPI.udapp()
var recorder = new Recorder({ events: { var recorder = new Recorder({
udapp: appEvents.udapp, events: {
executioncontext: executionContext.event udapp: appEvents.udapp,
}}) executioncontext: executionContext.event
},
api: {
getAccounts (cb) { udapp.getAccounts(cb) }
}
})
var css = csjs` var css = csjs`
.container { .container {
margin-top: 10px; margin-top: 10px;

@ -11,14 +11,23 @@ class Recorder {
self.clearAll() self.clearAll()
}) })
var counter = 0 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 = {} self._addressCache = {}
opts.events.udapp.register('initiatingTransaction', (timestamp, tx) => { opts.events.udapp.register('initiatingTransaction', (timestamp, tx) => {
var { from, to, value, gas, data } = tx var { from, to, value, gas, data } = tx
var record = { value, gas, data } var record = { value, gas, data }
record.from = self._addressCache[from] || (self._addressCache[from] = `<account -${(++counter)}>`) self._api.getAccounts(function (err, accounts = []) {
if (to === null) self.data._pendingCreation[timestamp] = record if (err) console.error(err)
else record.to = self._addressCache[to] || (self._addressCache[to] = `<account -${(++counter)}>`) record.from = self._addressCache[from] || (self._addressCache[from] = `<account - ${getIndex(accounts, from)}>`)
self.append(timestamp, record) if (to === null) self.data._pendingCreation[timestamp] = record
else record.to = self._addressCache[to] || (self._addressCache[to] = `<account - ${getIndex(accounts, to)}>`)
self.append(timestamp, record)
})
}) })
opts.events.udapp.register('transactionExecuted', (...args) => { opts.events.udapp.register('transactionExecuted', (...args) => {
var err = args[0] var err = args[0]

@ -469,10 +469,14 @@ function execute (pipeline, env, callback) {
UniversalDApp.prototype.replayTx = function (args, cb) { UniversalDApp.prototype.replayTx = function (args, cb) {
var self = this var self = this
var tx = { to: args.to, data: args.data, useCall: args.useCall } self.getAccounts(function (err, accounts = []) {
var pipeline = [runTransaction] if (err) console.error(err)
var env = { self, args, tx } if (args.to[0] === '<') args.to = accounts[args.to.split('>')[0].slice(11)]
execute(pipeline, env, cb) 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) { UniversalDApp.prototype.runTx = function (args, cb) {

Loading…
Cancel
Save