From 5d8fe5466892e27bf02941b2c537b3f893215266 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 2 Aug 2017 13:09:16 +0200 Subject: [PATCH] move eventDecoder to root folder && fix devent decoding --- src/app.js | 30 ++++++++++++++----------- src/app/{listener => }/eventsDecoder.js | 15 +++++++------ src/app/txListener.js | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) rename src/app/{listener => }/eventsDecoder.js (84%) diff --git a/src/app.js b/src/app.js index d04db38a14..d37c6e1472 100644 --- a/src/app.js +++ b/src/app.js @@ -31,7 +31,7 @@ var RighthandPanel = require('./app/righthand-panel') var examples = require('./app/example-contracts') var modalDialogCustom = require('./app/modal-dialog-custom') var Txlistener = require('./app/txListener') -var EventsDecoder = require('./app/listener/eventsDecoder') +var EventsDecoder = require('./app/eventsDecoder') var css = csjs` html { box-sizing: border-box; } @@ -775,26 +775,30 @@ function run () { var eventsDecoder = new EventsDecoder({ txListener: txlistener }) - txlistener.event.register('txResolved', (tx, resolvedData) => { - if (resolvedData) { - eventsDecoder.parseLogs(tx, resolvedData, compiledContracts()) - } - }) - txlistener.startListening() txlistener.event.register('newTransaction', (tx) => { var resolvedTransaction = txlistener.resolvedTransaction(tx.hash) var address = null if (resolvedTransaction) { + var resolvedContract address = resolvedTransaction.contractAddress ? resolvedTransaction.contractAddress : tx.to + resolvedContract = txlistener.resolvedContract(address) + if (resolvedContract) { + eventsDecoder.parseLogs(tx, resolvedContract, compiledContracts(), () => { + console.log({ + tx: tx, + resolvedContract: resolvedContract, + resolvedTransaction: resolvedTransaction, + resolvedEvents: eventsDecoder.eventsOf(tx.hash) + }) + }) + } + } else { + console.log({ + tx: tx + }) } - console.log({ - tx: tx, - resolvedContract: txlistener.resolvedContract(address), - resolvedTransaction: resolvedTransaction, - resolvedEvents: eventsDecoder.eventsOf(tx.hash) - }) }) // ----------------- autoCompile ----------------- diff --git a/src/app/listener/eventsDecoder.js b/src/app/eventsDecoder.js similarity index 84% rename from src/app/listener/eventsDecoder.js rename to src/app/eventsDecoder.js index dd80ec0eb1..84a8413687 100644 --- a/src/app/listener/eventsDecoder.js +++ b/src/app/eventsDecoder.js @@ -19,10 +19,10 @@ class EventsDecoder { * @param {Object} tx - transaction object * @param {Function} cb - callback */ - parseLogs (tx, resolvedData, compiledContracts) { + parseLogs (tx, contractName, compiledContracts, cb) { this.txListener.resolveTransactionReceipt(tx, (error, receipt) => { - if (error) console.log(error) - this._decodeLogs(tx, receipt, resolvedData.contractName, compiledContracts) + if (error) cb(error) + this._decodeLogs(tx, receipt, contractName, compiledContracts, cb) }) } @@ -30,11 +30,11 @@ class EventsDecoder { return this.resolvedEvents[hash] } - _decodeLogs (tx, receipt, contract, contracts) { + _decodeLogs (tx, receipt, contract, contracts, cb) { if (!contract || !receipt.logs) { - return + return cb() } - this._decodeEvents(tx, receipt.logs, contract, contracts) + this._decodeEvents(tx, receipt.logs, contract, contracts, cb) } _eventABI (contractName, compiledContracts) { @@ -50,7 +50,7 @@ class EventsDecoder { return eventABI } - _decodeEvents (tx, logs, contractName, compiledContracts) { + _decodeEvents (tx, logs, contractName, compiledContracts, cb) { var eventABI = this._eventABI(contractName, compiledContracts) // FIXME: support indexed events for (var i in logs) { @@ -75,6 +75,7 @@ class EventsDecoder { } this.resolvedEvents[tx.hash].push({ event: event, args: decoded }) } + cb() } } diff --git a/src/app/txListener.js b/src/app/txListener.js index c018b63312..6acabff949 100644 --- a/src/app/txListener.js +++ b/src/app/txListener.js @@ -127,8 +127,8 @@ class TxListener { async.each(block.transactions, (tx, cb) => { this._resolveTx(tx, (error, resolvedData) => { if (error) cb(error) - this.event.trigger('newTransaction', [tx]) if (resolvedData) this.event.trigger('txResolved', [tx, resolvedData]) + this.event.trigger('newTransaction', [tx]) cb() }) }, () => {