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 modalDialogCustom = require('./app/ui/modal-dialog-custom')
var Txlistener = require('./app/execution/txListener')
var txLogger = require('./app/execution/txLogger')
var EventsDecoder = require('./app/execution/eventsDecoder')
var Web3VMProvider = remix.web3.web3VMProvider
@ -812,33 +813,28 @@ function run () {
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(), (error, log) => {
console.log({
tx: tx,
resolvedTransaction: resolvedTransaction,
resolvedContract: resolvedContract,
resolvedEvents: (!error ? log : error)
})
})
} else {
console.log({
tx: tx,
resolvedTransaction: resolvedTransaction
})
txLogger({
api: {
/**
* log the given transaction.
*
* @param {Object} tx - DOM element representing the transaction
*/
log: function (tx) {
// terminal.log(tx)
},
resolvedTransaction: function (hash) {
return txlistener.resolvedTransaction(hash)
},
parseLogs: function (tx, contractName, contracts, cb) {
eventsDecoder.parseLogs(tx, contractName, contracts, cb)
},
compiledContracts: function () {
return compiledContracts()
}
} else {
// contract unknown - just displaying raw tx.
console.log({
tx: tx
})
},
events: {
txListener: txlistener.event
}
})

@ -25,7 +25,7 @@ class TxListener {
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()) {
this._api.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => {
if (error) return console.log(error)
@ -186,6 +186,7 @@ class TxListener {
for (var fn in compiledContracts[contractName].functionHashes) {
if (compiledContracts[contractName].functionHashes[fn] === inputData.substring(0, 8)) {
this._resolvedTransactions[tx.hash] = {
contractName: contractName,
to: tx.to,
fn: fn,
params: this._decodeInputParams(inputData.substring(8), getFunction(abi, fn))
@ -195,6 +196,7 @@ class TxListener {
}
// fallback function
this._resolvedTransactions[tx.hash] = {
contractName: contractName,
to: tx.to,
fn: '(fallback)',
params: null
@ -206,6 +208,7 @@ class TxListener {
params = this._decodeInputParams(inputData.substring(bytecode.length), getConstructorInterface(abi))
}
this._resolvedTransactions[tx.hash] = {
contractName: contractName,
to: null,
fn: '(constructor)',
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) => {
if (!error) {
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
if (!init) {
instanceContainer.innerHTML = ''

@ -473,7 +473,12 @@ UniversalDApp.prototype.runTx = function (args, cb) {
},
// run transaction
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)
}

Loading…
Cancel
Save