Merge pull request #673 from ethereum/txLogger

TxLogger
pull/1/head
yann300 7 years ago committed by GitHub
commit cb160c4377
  1. 48
      src/app.js
  2. 5
      src/app/execution/txListener.js
  3. 35
      src/app/execution/txLogger.js
  4. 2
      src/app/tabs/run-tab.js
  5. 7
      src/universal-dapp.js

@ -32,6 +32,7 @@ var RighthandPanel = require('./app/panels/righthand-panel')
var examples = require('./app/editor/example-contracts') var examples = require('./app/editor/example-contracts')
var modalDialogCustom = require('./app/ui/modal-dialog-custom') var modalDialogCustom = require('./app/ui/modal-dialog-custom')
var Txlistener = require('./app/execution/txListener') var Txlistener = require('./app/execution/txListener')
var txLogger = require('./app/execution/txLogger')
var EventsDecoder = require('./app/execution/eventsDecoder') var EventsDecoder = require('./app/execution/eventsDecoder')
var Web3VMProvider = remix.web3.web3VMProvider var Web3VMProvider = remix.web3.web3VMProvider
@ -812,33 +813,28 @@ function run () {
txlistener.startListening() txlistener.startListening()
txlistener.event.register('newTransaction', (tx) => { txLogger({
var resolvedTransaction = txlistener.resolvedTransaction(tx.hash) api: {
var address = null /**
if (resolvedTransaction) { * log the given transaction.
var resolvedContract *
address = resolvedTransaction.contractAddress ? resolvedTransaction.contractAddress : tx.to * @param {Object} tx - DOM element representing the transaction
resolvedContract = txlistener.resolvedContract(address) */
if (resolvedContract) { log: function (tx) {
eventsDecoder.parseLogs(tx, resolvedContract, compiledContracts(), (error, log) => { // terminal.log(tx)
console.log({ },
tx: tx, resolvedTransaction: function (hash) {
resolvedTransaction: resolvedTransaction, return txlistener.resolvedTransaction(hash)
resolvedContract: resolvedContract, },
resolvedEvents: (!error ? log : error) parseLogs: function (tx, contractName, contracts, cb) {
}) eventsDecoder.parseLogs(tx, contractName, contracts, cb)
}) },
} else { compiledContracts: function () {
console.log({ return compiledContracts()
tx: tx,
resolvedTransaction: resolvedTransaction
})
} }
} else { },
// contract unknown - just displaying raw tx. events: {
console.log({ txListener: txlistener.event
tx: tx
})
} }
}) })

@ -25,7 +25,7 @@ class TxListener {
this.startListening(context) this.startListening(context)
} }
}) })
opt.event.udapp.register('transactionExecuted', (to, data, lookupOnly, txResult) => { opt.event.udapp.register('transactionExecuted', (to, data, txResult) => {
if (this.loopId && this._api.isVM()) { if (this.loopId && this._api.isVM()) {
this._api.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => { this._api.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => {
if (error) return console.log(error) if (error) return console.log(error)
@ -186,6 +186,7 @@ class TxListener {
for (var fn in compiledContracts[contractName].functionHashes) { for (var fn in compiledContracts[contractName].functionHashes) {
if (compiledContracts[contractName].functionHashes[fn] === inputData.substring(0, 8)) { if (compiledContracts[contractName].functionHashes[fn] === inputData.substring(0, 8)) {
this._resolvedTransactions[tx.hash] = { this._resolvedTransactions[tx.hash] = {
contractName: contractName,
to: tx.to, to: tx.to,
fn: fn, fn: fn,
params: this._decodeInputParams(inputData.substring(8), getFunction(abi, fn)) params: this._decodeInputParams(inputData.substring(8), getFunction(abi, fn))
@ -195,6 +196,7 @@ class TxListener {
} }
// fallback function // fallback function
this._resolvedTransactions[tx.hash] = { this._resolvedTransactions[tx.hash] = {
contractName: contractName,
to: tx.to, to: tx.to,
fn: '(fallback)', fn: '(fallback)',
params: null params: null
@ -206,6 +208,7 @@ class TxListener {
params = this._decodeInputParams(inputData.substring(bytecode.length), getConstructorInterface(abi)) params = this._decodeInputParams(inputData.substring(bytecode.length), getConstructorInterface(abi))
} }
this._resolvedTransactions[tx.hash] = { this._resolvedTransactions[tx.hash] = {
contractName: contractName,
to: null, to: null,
fn: '(constructor)', fn: '(constructor)',
params: params params: params

@ -0,0 +1,35 @@
'use strict'
/**
* This just export a function that register to `newTransaction` and forward them to the logger.
*
*/
module.exports = (opts = {}) => {
opts.events.txListener.register('newTransaction', (tx) => {
log(tx, opts.api)
})
}
function log (tx, api) {
var resolvedTransaction = api.resolvedTransaction(tx.hash)
if (resolvedTransaction) {
api.parseLogs(tx, resolvedTransaction.contractName, api.compiledContracts(), (error, logs) => {
if (!error) {
api.log(renderResolvedTransaction(tx, resolvedTransaction, logs))
}
})
} else {
// contract unknown - just displaying raw tx.
api.log(renderTransaction(tx))
}
}
function renderResolvedTransaction (tx, resolvedTransaction, logs) {
console.log([tx, resolvedTransaction])
return JSON.stringify([tx, resolvedTransaction])
}
function renderTransaction (tx) {
console.log(tx)
return JSON.stringify(tx)
}

@ -257,8 +257,6 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
txFormat.buildData(contract, contracts, true, constructor, args, appAPI.udapp(), appAPI.executionContext(), (error, data) => { txFormat.buildData(contract, contracts, true, constructor, args, appAPI.udapp(), appAPI.executionContext(), (error, data) => {
if (!error) { if (!error) {
txExecution.createContract(data, appAPI.udapp(), (error, txResult) => { txExecution.createContract(data, appAPI.udapp(), (error, txResult) => {
// TODO here should send the result to the dom-console
console.log('Contract creation', error, txResult)
var address = appAPI.executionContext().isVM() ? txResult.result.createdAddress : txResult.result.contractAddress var address = appAPI.executionContext().isVM() ? txResult.result.createdAddress : txResult.result.contractAddress
if (!init) { if (!init) {
instanceContainer.innerHTML = '' instanceContainer.innerHTML = ''

@ -473,7 +473,12 @@ UniversalDApp.prototype.runTx = function (args, cb) {
}, },
// run transaction // run transaction
function (callback) { function (callback) {
self.txRunner.rawRun(tx, function (error, result) { callback(error, result) }) self.txRunner.rawRun(tx, function (error, result) {
if (!args.useCall) {
self.event.trigger('transactionExecuted', [args.to, args.data, result])
}
callback(error, result)
})
} }
], cb) ], cb)
} }

Loading…
Cancel
Save