<commit_before>var style = require('./styles/basicStyles')
var util = require('../helpers/global')
var EventManager = require('../lib/eventManager')
var traceHelper = require('../helpers/traceHelper')
var yo = require('yo-yo')
var ui = require('../helpers/ui')
var init = require('../helpers/init')
var DropdownPanel = require('./DropdownPanel')

function TxBrowser (_parent) {
  this.event = new EventManager()

  this.blockNumber
  this.txNumber
  this.view
  this.displayConnectionSetting = true
  this.basicPanel = new DropdownPanel('Transaction')
  this.basicPanel.data = {}
  var self = this
  _parent.event.register('providerChanged', this, function (provider) {
    self.displayConnectionSetting = provider === 'INTERNAL'
    self.setDefaultValues()
    if (self.view) {
      yo.update(self.view, self.render())
    }
  })
}

// creation 0xa9619e1d0a35b2c1d686f5b661b3abd87f998d2844e8e9cc905edb57fc9ce349
// invokation 0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4 0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff
// test:
// creation: 0x72908de76f99fca476f9e3a3b5d352f350a98cd77d09cebfc59ffe32a6ecaa0b
// invokation: 0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51

TxBrowser.prototype.setDefaultValues = function () {
  this.blockNumber = null
  this.connectInfo = ''
  this.basicPanel.data = {}
  this.basicPanel.update()
  this.basicPanel.hide()
  this.updateWeb3Url(util.web3.currentProvider.host)
}

TxBrowser.prototype.submit = function () {
  if (!this.txNumber) {
    return
  }
  this.event.trigger('newTxLoading', [this.blockNumber, this.txNumber])
  try {
    var self = this
    if (this.txNumber.indexOf('0x') !== -1) {
      util.web3.eth.getTransaction(this.txNumber, function (error, result) {
        self.update(error, result)
      })
    } else {
      util.web3.eth.getTransactionFromBlock(this.blockNumber, this.txNumber, function (error, result) {
        self.update(error, result)
      })
    }
  } catch (e) {
    self.update(e.message)
  }
}

TxBrowser.prototype.update = function (error, tx) {
  var info = {}
  if (error) {
    console.log(error)
    info[''] = error
  } else {
    if (tx) {
      if (!tx.to) {
        tx.to = traceHelper.contractCreationToken('0')
      }
      info.from = tx.from
      info.to = tx.to
      info.hash = tx.hash
      this.event.trigger('newTraceRequested', [this.blockNumber, this.txNumber, tx])
    } else {
      var mes = '<not found>'
      info.from = mes
      info.to = mes
      info.hash = mes
      console.log('cannot find ' + this.blockNumber + ' ' + this.txNumber)
    }
  }
  this.basicPanel.data = info
  this.basicPanel.update()
  if (error) {
    this.basicPanel.show()
  }
}

TxBrowser.prototype.updateWeb3Url = function (newhost) {
  init.setProvider(util.web3, newhost)
  var self = this
  this.checkWeb3(function (error, block) {
    if (!error) {
      self.connectInfo = 'Connected to ' + util.web3.currentProvider.host + '. Current block number: ' + block
    } else {
      self.connectInfo = 'Unable to connect to ' + util.web3.currentProvider.host + '. ' + error.message
    }
    yo.update(self.view, self.render())
  })
}<commit_msg>display msg if tx not found<commit_after>var style = require('./styles/basicStyles')
var util = require('../helpers/global')
var EventManager = require('../lib/eventManager')
var traceHelper = require('../helpers/traceHelper')
var yo = require('yo-yo')
var ui = require('../helpers/ui')
var init = require('../helpers/init')
var DropdownPanel = require('./DropdownPanel')

function TxBrowser (_parent) {
  this.event = new EventManager()

  this.blockNumber
  this.txNumber
  this.view
  this.displayConnectionSetting = true
  this.basicPanel = new DropdownPanel('Transaction')
  this.basicPanel.data = {}
  var self = this
  _parent.event.register('providerChanged', this, function (provider) {
    self.displayConnectionSetting = provider === 'INTERNAL'
    self.setDefaultValues()
    if (self.view) {
      yo.update(self.view, self.render())
    }
  })
}

// creation 0xa9619e1d0a35b2c1d686f5b661b3abd87f998d2844e8e9cc905edb57fc9ce349
// invokation 0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4 0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff
// test:
// creation: 0x72908de76f99fca476f9e3a3b5d352f350a98cd77d09cebfc59ffe32a6ecaa0b
// invokation: 0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51

TxBrowser.prototype.setDefaultValues = function () {
  this.blockNumber = null
  this.connectInfo = ''
  this.basicPanel.data = {}
  this.basicPanel.update()
  this.basicPanel.hide()
  this.updateWeb3Url(util.web3.currentProvider.host)
}

TxBrowser.prototype.submit = function () {
  if (!this.txNumber) {
    return
  }
  this.event.trigger('newTxLoading', [this.blockNumber, this.txNumber])
  try {
    var self = this
    if (this.txNumber.indexOf('0x') !== -1) {
      util.web3.eth.getTransaction(this.txNumber, function (error, result) {
        self.update(error, result)
      })
    } else {
      util.web3.eth.getTransactionFromBlock(this.blockNumber, this.txNumber, function (error, result) {
        self.update(error, result)
      })
    }
  } catch (e) {
    self.update(e.message)
  }
}

TxBrowser.prototype.update = function (error, tx) {
  var info = {}
  if (error) {
    console.log(error)
    info[''] = error
  } else {
    if (tx) {
      if (!tx.to) {
        tx.to = traceHelper.contractCreationToken('0')
      }
      info.from = tx.from
      info.to = tx.to
      info.hash = tx.hash
      this.event.trigger('newTraceRequested', [this.blockNumber, this.txNumber, tx])
    } else {
      var mes = '<not found>'
      info.from = mes
      info.to = mes
      info.hash = mes
      console.log('cannot find ' + this.blockNumber + ' ' + this.txNumber)
    }
  }
  this.basicPanel.data = info
  this.basicPanel.update()
}

TxBrowser.prototype.updateWeb3Url = function (newhost) {
  init.setProvider(util.web3, newhost)
  var self = this
  this.checkWeb3(function (error, block) {
    if (!error) {
      self.connectInfo = 'Connected to ' + util.web3.currentProvider.host + '. Current block number: ' + block
    } else {
      self.connectInfo = 'Unable to connect to ' + util.web3.currentProvider.host + '. ' + error.message
    }
    yo.update(self.view, self.render())
  })
}
{'fraction_non_alphanumeric': 0.1332076657241596, 'fraction_numerical': 0.06628966383914546, 'mean_word_length': 3.4493361285814115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1262428', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2269, 'n_words': 372}