move eventDecoder to root folder && fix devent decoding

pull/1/head
yann300 7 years ago
parent 3cce2a17b1
commit 5d8fe54668
  1. 30
      src/app.js
  2. 15
      src/app/eventsDecoder.js
  3. 2
      src/app/txListener.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 -----------------

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

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

Loading…
Cancel
Save