TxListener to trigger callExecuted

pull/1/head
yann300 7 years ago
parent 4ef065b30d
commit 8cd76ce241
  1. 32
      src/app/execution/txListener.js
  2. 2
      src/app/tabs/run-tab.js
  3. 4
      src/universal-dapp.js

@ -20,6 +20,7 @@ class TxListener {
this.event = new EventManager()
this._api = opt.api
this._resolvedTransactions = {}
this._resolvedCalls = {}
this._resolvedContracts = {}
this._isListening = false
this._listenOnNetwork = false
@ -31,7 +32,33 @@ class TxListener {
this.startListening()
}
})
opt.event.udapp.register('transactionExecuted', (error, to, data, lookupOnly, txResult) => {
opt.event.udapp.register('callExecuted', (error, from, to, data, lookupOnly, txResult) => {
if (error) return
// we go for that case if
// in VM mode
// in web3 mode && listen remix txs only
if (!this._isListening) return // we don't listen
if (this._loopId && executionContext.getProvider() !== 'vm') return // we seems to already listen on a "web3" network
var call = {
from: from,
to: to,
input: data,
hash: txResult.transactionHash ? txResult.transactionHash : 'call' + from + to + data,
isCall: true,
output: txResult.result,
returnValue: executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result),
envMode: executionContext.getProvider()
}
this._resolveTx(call, (error, resolvedData) => {
if (!error) {
this.event.trigger('newCall', [call])
}
})
})
opt.event.udapp.register('transactionExecuted', (error, from, to, data, lookupOnly, txResult) => {
if (error) return
if (lookupOnly) return
// we go for that case if
@ -42,7 +69,7 @@ class TxListener {
executionContext.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => {
if (error) return console.log(error)
if (txResult && txResult.result && txResult.result.vm) tx.returnValue = txResult.result.vm.return
tx.envMode = executionContext.getProvider()
this._resolve([tx], () => {
})
})
@ -174,7 +201,6 @@ class TxListener {
}
_resolveTx (tx, cb) {
console.log(tx)
var contracts = this._api.contracts()
if (!contracts) return cb()
var contractName

@ -411,7 +411,7 @@ function settings (appAPI, appEvents) {
`
// EVENTS
appEvents.udapp.register('transactionExecuted', (error, to, data, lookupOnly, txResult) => {
appEvents.udapp.register('transactionExecuted', (error, from, to, data, lookupOnly, txResult) => {
if (error) return
if (!lookupOnly) el.querySelector('#value').value = '0'
})

@ -468,7 +468,9 @@ UniversalDApp.prototype.runTx = function (args, cb) {
function (callback) {
self.txRunner.rawRun(tx, function (error, result) {
if (!args.useCall) {
self.event.trigger('transactionExecuted', [error, args.to, args.data, false, result])
self.event.trigger('transactionExecuted', [error, args.from, args.to, args.data, false, result])
} else {
self.event.trigger('callExecuted', [error, args.from, args.to, args.data, true, result])
}
if (error) {
if (typeof (error) !== 'string') {

Loading…
Cancel
Save