clean recorder instanciation

pull/1/head
yann300 6 years ago
parent 718077200e
commit 0f2c407054
  1. 18
      src/app/tabs/run-tab.js
  2. 22
      src/recorder.js

@ -198,15 +198,8 @@ function updateAccountBalances (container, self) {
RECORDER RECORDER
------------------------------------------------ */ ------------------------------------------------ */
function makeRecorder (registry, runTabEvent, self) { function makeRecorder (registry, runTabEvent, self) {
var recorder = new Recorder(self._deps.compiler, self._deps.udapp, var recorder = new Recorder(self._deps.compiler, self._deps.udapp, (msg) => {
(msg) => {
self._deps.editorPanel.logMessage(msg) self._deps.editorPanel.logMessage(msg)
}, {
events: {
udapp: self._deps.udapp.event,
executioncontext: executionContext.event,
runtab: runTabEvent
}
}) })
recorder.event.register('newTxRecorded', (count) => { recorder.event.register('newTxRecorded', (count) => {
@ -217,6 +210,15 @@ function makeRecorder (registry, runTabEvent, self) {
self.data.count = 0 self.data.count = 0
self._view.recorderCount.innerText = 0 self._view.recorderCount.innerText = 0
}) })
executionContext.event.register('contextChanged', () => {
recorder.clearAll()
})
runTabEvent.register('clearInstance', () => {
recorder.clearAll()
})
var css2 = csjs` var css2 = csjs`
.container {} .container {}
.runTxs {} .runTxs {}

@ -13,19 +13,13 @@ var modal = require('./app/ui/modal-dialog-custom')
* *
*/ */
class Recorder { class Recorder {
constructor (compiler, udapp, logMessageCallback, opts = {}) { constructor (compiler, udapp, msgCallBack) {
var self = this var self = this
self.logMessageCallback = logMessageCallback self.msgCallBack = msgCallBack
self.event = new EventManager() self.event = new EventManager()
self.data = { _listen: true, _replay: false, journal: [], _createdContracts: {}, _createdContractsReverse: {}, _usedAccounts: {}, _abis: {}, _contractABIReferences: {}, _linkReferences: {} } self.data = { _listen: true, _replay: false, journal: [], _createdContracts: {}, _createdContractsReverse: {}, _usedAccounts: {}, _abis: {}, _contractABIReferences: {}, _linkReferences: {} }
opts.events.executioncontext.register('contextChanged', () => {
self.clearAll()
})
opts.events.runtab.register('clearInstance', () => {
self.clearAll()
})
opts.events.udapp.register('initiatingTransaction', (timestamp, tx, payLoad) => { udapp.event.register('initiatingTransaction', (timestamp, tx, payLoad) => {
if (tx.useCall) return if (tx.useCall) return
var { from, to, value } = tx var { from, to, value } = tx
@ -70,7 +64,7 @@ class Recorder {
} }
}) })
opts.events.udapp.register('transactionExecuted', (error, from, to, data, call, txResult, timestamp) => { udapp.event.register('transactionExecuted', (error, from, to, data, call, txResult, timestamp) => {
if (error) return console.log(error) if (error) return console.log(error)
if (call) return if (call) return
@ -184,7 +178,7 @@ class Recorder {
run (records, accounts, options, abis, linkReferences, udapp, newContractFn) { run (records, accounts, options, abis, linkReferences, udapp, newContractFn) {
var self = this var self = this
self.setListen(false) self.setListen(false)
self.logMessageCallback(`Running ${records.length} transaction(s) ...`) self.msgCallBack(`Running ${records.length} transaction(s) ...`)
async.eachOfSeries(records, function (tx, index, cb) { async.eachOfSeries(records, function (tx, index, cb) {
var record = self.resolveAddress(tx.record, accounts, options) var record = self.resolveAddress(tx.record, accounts, options)
var abi = abis[tx.record.abi] var abi = abis[tx.record.abi]
@ -241,14 +235,14 @@ class Recorder {
cb(data.error) cb(data.error)
return return
} else { } else {
self.logMessageCallback(`(${index}) ${JSON.stringify(record, null, '\t')}`) self.msgCallBack(`(${index}) ${JSON.stringify(record, null, '\t')}`)
self.logMessageCallback(`(${index}) data: ${data.data}`) self.msgCallBack(`(${index}) data: ${data.data}`)
record.data = { dataHex: data.data, funArgs: tx.record.parameters, funAbi: fnABI, contractBytecode: tx.record.bytecode, contractName: tx.record.contractName } record.data = { dataHex: data.data, funArgs: tx.record.parameters, funAbi: fnABI, contractBytecode: tx.record.bytecode, contractName: tx.record.contractName }
} }
udapp.runTx(record, function (err, txResult) { udapp.runTx(record, function (err, txResult) {
if (err) { if (err) {
console.error(err) console.error(err)
self.logMessageCallback(err + '. Execution failed at ' + index) self.msgCallBack(err + '. Execution failed at ' + index)
} else { } else {
var address = executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress var address = executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress
if (address) { if (address) {

Loading…
Cancel
Save