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) {
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;

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

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

Loading…
Cancel
Save