From c047b99484a3ca0c5285e87fb8f1e357083c8231 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 18 Apr 2016 21:10:27 +0100 Subject: [PATCH] Support event logs in VM mode --- assets/js/universal-dapp.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/assets/js/universal-dapp.js b/assets/js/universal-dapp.js index a7b74a0238..45d98e9a18 100644 --- a/assets/js/universal-dapp.js +++ b/assets/js/universal-dapp.js @@ -150,24 +150,33 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar }); $events = $('
'); + + var parseLogs = function(err,response) { + $event = $('
') + + var $close = $('
') + $close.click( function(){ $event.remove(); } ) + + $event.append( $('').text(response.event) ) + .append( $('').text( JSON.stringify(response.args, null, 2) ) ) + .append( $close ); + + $events.append( $event ); + } + if (self.options.vm){ self.vm.on('afterTx', function(response){ - // TODO: parse/use reponse.vm.logs + for (var i in response.vm.logs) { + // [address, topics, mem] + var log = response.vm.logs[i]; + + // FIXME: parse based on ABI (match event name + decode values) + parseLogs(null, { event: log[1][0].toString('hex'), args: '0x' + log[2].toString('hex') }); + } }); } else { var eventFilter = web3contract.at(address).allEvents(); - eventFilter.watch(function(err,response){ - $event = $('
') - - var $close = $('
') - $close.click( function(){ $event.remove(); } ) - - $event.append( $('').text(response.event) ) - .append( $('').text( JSON.stringify(response.args, null, 2) ) ) - .append( $close ); - - $events.append( $event ); - }) + eventFilter.watch(parseLogs); } $instance.append( $title );