UPDATE acount placeholder counter to use address array index

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

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

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

@ -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 }
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 }
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) {

Loading…
Cancel
Save