correclt convert address

pull/3094/head
yann300 7 years ago
parent 32ad128aa5
commit 389b7ea507
  1. 20
      src/recorder.js

@ -53,11 +53,10 @@ class Recorder {
opts.events.udapp.register('transactionExecuted', (error, from, to, data, call, txResult, timestamp) => { opts.events.udapp.register('transactionExecuted', (error, from, to, data, call, txResult, timestamp) => {
if (error) return console.log(error) if (error) return console.log(error)
if (call) return if (call) return
var tx = this.data._pendingTxs[timestamp]
var address = executionContext.isVM() ? txResult.result.createdAddress : tx.result.contractAddress var address = executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress
if (!address) return // not a contract creation if (!address) return // not a contract creation
address = '0x' + address.toString('hex') address = addressToString(address)
// save back created addresses for the convertion from tokens to real adresses // save back created addresses for the convertion from tokens to real adresses
this.data._createdContracts[address] = timestamp this.data._createdContracts[address] = timestamp
this.data._createdContractsReverse[timestamp] = address this.data._createdContractsReverse[timestamp] = address
@ -154,9 +153,9 @@ class Recorder {
if (err) { if (err) {
console.error(err) console.error(err)
} else { } else {
var address = executionContext.isVM() ? txResult.result.createdAddress : tx.result.contractAddress var address = executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress
if (!address) return // not a contract creation if (!address) return // not a contract creation
address = '0x' + address.toString('hex') address = addressToString(address)
// save back created addresses for the convertion from tokens to real adresses // save back created addresses for the convertion from tokens to real adresses
self.data._createdContracts[address] = tx.timestamp self.data._createdContracts[address] = tx.timestamp
self.data._createdContractsReverse[tx.timestamp] = address self.data._createdContractsReverse[tx.timestamp] = address
@ -171,4 +170,15 @@ class Recorder {
} }
} }
function addressToString (address) {
if (!address) return null
if (typeof address !== 'string') {
address = address.toString('hex')
}
if (address.indexOf('0x') === -1) {
address = '0x' + address
}
return address
}
module.exports = Recorder module.exports = Recorder

Loading…
Cancel
Save