added addressToString to helper

pull/698/head
LianaHus 4 years ago committed by yann300
parent 9c8687f336
commit 0e80908f30
  1. 6
      apps/remix-ide/src/app/compiler/compiler-artefacts.js
  2. 26
      apps/remix-ide/src/app/tabs/runTab/contractDropdown.js
  3. 20
      apps/remix-ide/src/app/tabs/runTab/model/recorder.js
  4. 11
      apps/remix-ide/src/lib/helper.js

@ -15,7 +15,6 @@ module.exports = class CompilerArtefacts extends Plugin {
super(profile)
this.compilersArtefacts = {}
this.compilersArtefactsPerFile = {}
this.addressToCompilationResults = {}
}
clear () {
@ -68,6 +67,11 @@ module.exports = class CompilerArtefacts extends Plugin {
return contractsData
}
getCompilerAbstract(file) {
return this.compilersArtefactsPerFile[file]
}
// compilerData is a CompilerAbstract object
addResolvedContract (address, compilerData) {
this.compilersArtefacts[address] = compilerData
}

@ -1,13 +1,14 @@
import publishToStorage from '../../../publishToStorage'
var yo = require('yo-yo')
var css = require('../styles/run-tab-styles')
var modalDialogCustom = require('../../ui/modal-dialog-custom')
var remixLib = require('@remix-project/remix-lib')
var EventManager = remixLib.EventManager
var confirmDialog = require('../../ui/confirmDialog')
var modalDialog = require('../../ui/modaldialog')
var MultiParamManager = require('../../ui/multiParamManager')
const yo = require('yo-yo')
const css = require('../styles/run-tab-styles')
const modalDialogCustom = require('../../ui/modal-dialog-custom')
const remixLib = require('@remix-project/remix-lib')
const EventManager = remixLib.EventManager
const confirmDialog = require('../../ui/confirmDialog')
const modalDialog = require('../../ui/modaldialog')
const MultiParamManager = require('../../ui/multiParamManager')
const helper = require('../../../lib/helper')
class ContractDropdownUI {
constructor (blockchain, dropdownLogic, logCallback, runView) {
@ -31,11 +32,7 @@ class ContractDropdownUI {
this.selectContractNames.innerHTML = ''
if (success) {
this.dropdownLogic.getCompiledContracts(compiler, compilerFullName).forEach((contract) => {
console.log('file = ', file)
console.log('contrtact.file = ', contract.file)
this.selectContractNames.appendChild(yo`<option value="${contract.name}" compiler="${compilerFullName}">${contract.name} - ${contract.file}</option>`)
this.runView.compilersArtefacts.addressToCompilationResults[contract.name + '-' + contract.file] = data
console.log("runView.compilersArtefacts.addressToCompilationResults ", this.runView.compilersArtefacts.addressToCompilationResults)
})
}
this.enableAtAddress(success)
@ -303,9 +300,8 @@ class ContractDropdownUI {
self.event.trigger('newContractInstanceAdded', [contractObject, address, contractObject.name])
const data = self.runView.compilersArtefacts.addressToCompilationResults[contractObject.name + '-' + contractObject.file]
self.runView.compilersArtefacts.addResolvedContract(address, data)
console.log("this.runView.compilersArtefacts.addressToCompilationResults[contractObject.name + '-' + contractObject.file]", data)
const data = self.runView.compilersArtefacts.getCompilerAbstract(contractObject.contract.file)
self.runView.compilersArtefacts.addResolvedContract(helper.addressToString(address), data)
if (self.ipfsCheckedState) {
publishToStorage('ipfs', self.runView.fileProvider, self.runView.fileManager, selectedContract)
}

@ -4,11 +4,10 @@ var remixLib = require('@remix-project/remix-lib')
var EventManager = remixLib.EventManager
var format = remixLib.execution.txFormat
var txHelper = remixLib.execution.txHelper
const helper = require('../../../../lib/helper')
/**
* Record transaction as long as the user create them.
*
*
*/
class Recorder {
constructor (blockchain) {
@ -69,8 +68,7 @@ class Recorder {
if (call) return
if (!rawAddress) return // not a contract creation
const stringAddress = this.addressToString(rawAddress)
const address = ethutil.toChecksumAddress(stringAddress)
const address = helper.addressToString(rawAddress)
// save back created addresses for the convertion from tokens to real adresses
this.data._createdContracts[address] = timestamp
this.data._createdContractsReverse[timestamp] = address
@ -252,8 +250,7 @@ class Recorder {
return logCallBack(err + '. Execution failed at ' + index)
}
if (rawAddress) {
const stringAddress = self.addressToString(rawAddress)
const address = ethutil.toChecksumAddress(stringAddress)
const address = helper.addressToString(rawAddress)
// save back created addresses for the convertion from tokens to real adresses
self.data._createdContracts[address] = tx.timestamp
self.data._createdContractsReverse[tx.timestamp] = address
@ -265,17 +262,6 @@ class Recorder {
}, () => { self.setListen(true); self.clearAll() })
}
addressToString (address) {
if (!address) return null
if (typeof address !== 'string') {
address = address.toString('hex')
}
if (address.indexOf('0x') === -1) {
address = '0x' + address
}
return address
}
runScenario (json, continueCb, promptCb, alertCb, confirmationCb, logCallBack, cb) {
if (!json) {
return cb('a json content must be provided')

@ -1,10 +1,21 @@
var async = require('async')
const ethJSUtil = require('ethereumjs-util')
module.exports = {
shortenAddress: function (address, etherBalance) {
var len = address.length
return address.slice(0, 5) + '...' + address.slice(len - 5, len) + (etherBalance ? ' (' + etherBalance.toString() + ' ether)' : '')
},
addressToString: function (address) {
if (!address) return null
if (typeof address !== 'string') {
address = address.toString('hex')
}
if (address.indexOf('0x') === -1) {
address = '0x' + address
}
return ethJSUtil.toChecksumAddress(address)
},
shortenHexData: function (data) {
if (!data) return ''
if (data.length < 5) return data

Loading…
Cancel
Save