make sure contract creation are handled properly (address from the receipt)

pull/1/head
yann300 5 years ago
parent 105118530b
commit 1ca80d1212
  1. 11
      src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js
  2. 6
      src/app/tabs/debugger-tab.js
  3. 11
      src/app/tabs/debugger/debuggerUI.js

@ -17,7 +17,6 @@ export default class FetchAndCompile extends Plugin {
constructor () { constructor () {
super(profile) super(profile)
this.unresolvedAddresses = [] this.unresolvedAddresses = []
this.firstResolvedAddress = null
this.sourceVerifierNetWork = ['Main', 'Rinkeby', 'Ropsten', 'Goerli'] this.sourceVerifierNetWork = ['Main', 'Rinkeby', 'Ropsten', 'Goerli']
} }
@ -26,15 +25,12 @@ export default class FetchAndCompile extends Plugin {
* Put the artifacts in the file explorer * Put the artifacts in the file explorer
* Compile the code using Solidity compiler * Compile the code using Solidity compiler
* Returns compilation data * Returns compilation data
* if no contract address are passed, we default to the first resolved address.
* *
* @param {string} contractAddress - Address of the contrac to resolve * @param {string} contractAddress - Address of the contrac to resolve
* @param {string} compilersartefacts - Object containing a mapping of compilation results (byContractAddress and __last) * @param {string} compilersartefacts - Object containing a mapping of compilation results (byContractAddress and __last)
* @return {CompilerAbstract} - compilation data targeting the given @arg contractAddress * @return {CompilerAbstract} - compilation data targeting the given @arg contractAddress
*/ */
async resolve (contractAddress, targetPath, web3) { async resolve (contractAddress, targetPath, web3) {
contractAddress = contractAddress || this.firstResolvedAddress
const compilersartefacts = globalRegistry.get('compilersartefacts').api const compilersartefacts = globalRegistry.get('compilersartefacts').api
const localCompilation = () => compilersartefacts.get('__last') ? compilersartefacts.get('__last') : null const localCompilation = () => compilersartefacts.get('__last') ? compilersartefacts.get('__last') : null
@ -42,9 +38,8 @@ export default class FetchAndCompile extends Plugin {
const resolved = compilersartefacts.get(contractAddress) const resolved = compilersartefacts.get(contractAddress)
if (resolved) return resolved if (resolved) return resolved
if (this.unresolvedAddresses.includes(contractAddress)) return localCompilation() if (this.unresolvedAddresses.includes(contractAddress)) return localCompilation()
if (this.firstResolvedAddress) return compilersartefacts.get(this.firstResolvedAddress)
// ^ for the moment we don't add compilation result for each adddress, but just for the root addres ^ . We can add this later. // sometimes when doing an internal call, the only available artifact is the Solidity interface.
// usecase is: sometimes when doing an internal call, the only available artifact is the Solidity interface.
// resolving addresses of internal call would allow to step over the source code, even if the declaration was made using an Interface. // resolving addresses of internal call would allow to step over the source code, even if the declaration was made using an Interface.
let network let network
@ -67,7 +62,6 @@ export default class FetchAndCompile extends Plugin {
}) })
if (found) { if (found) {
compilersartefacts.addResolvedContract(contractAddress, compilation) compilersartefacts.addResolvedContract(contractAddress, compilation)
this.firstResolvedAddress = contractAddress
setTimeout(_ => this.emit('usingLocalCompilation', contractAddress), 0) setTimeout(_ => this.emit('usingLocalCompilation', contractAddress), 0)
return compilation return compilation
} }
@ -119,7 +113,6 @@ export default class FetchAndCompile extends Plugin {
setTimeout(_ => this.emit('compiling', settings), 0) setTimeout(_ => this.emit('compiling', settings), 0)
const compData = await compile(compilationTargets, settings) const compData = await compile(compilationTargets, settings)
compilersartefacts.addResolvedContract(contractAddress, compData) compilersartefacts.addResolvedContract(contractAddress, compData)
this.firstResolvedAddress = contractAddress
return compData return compData
} catch (e) { } catch (e) {
this.unresolvedAddresses.push(contractAddress) this.unresolvedAddresses.push(contractAddress)

@ -1,4 +1,5 @@
const yo = require('yo-yo') const yo = require('yo-yo')
const remixLib = require('remix-lib')
const css = require('./styles/debugger-tab-styles') const css = require('./styles/debugger-tab-styles')
import toaster from '../ui/tooltip' import toaster from '../ui/tooltip'
const DebuggerUI = require('./debugger/debuggerUI') const DebuggerUI = require('./debugger/debuggerUI')
@ -57,7 +58,10 @@ class DebuggerTab extends ViewPlugin {
this.debuggerUI = new DebuggerUI( this.debuggerUI = new DebuggerUI(
this.el.querySelector('#debugger'), this.el.querySelector('#debugger'),
this.blockchain, this.blockchain,
adddress => this.call('fetchAndCompile', 'resolve', adddress, '.debug', this.blockchain.web3())) (address, receipt) => {
const target = (address && remixLib.helpers.trace.isContractCreation(address)) ? receipt.contractAddress : address
return this.call('fetchAndCompile', 'resolve', target || receipt.contractAddress || receipt.to, '.debug', this.blockchain.web3())
})
this.call('manager', 'activatePlugin', 'source-verification') this.call('manager', 'activatePlugin', 'source-verification')
// this.call('manager', 'activatePlugin', 'udapp') // this.call('manager', 'activatePlugin', 'udapp')

@ -44,6 +44,7 @@ class DebuggerUI {
this.stepManager = null this.stepManager = null
this.statusMessage = '' this.statusMessage = ''
this.currentReceipt
this.view this.view
@ -79,7 +80,9 @@ class DebuggerUI {
}) })
this.debugger.event.register('newSourceLocation', async function (lineColumnPos, rawLocation) { this.debugger.event.register('newSourceLocation', async function (lineColumnPos, rawLocation) {
const contracts = await self.fetchContractAndCompile() const contracts = await self.fetchContractAndCompile(
self.currentReceipt.contractAddress || self.currentReceipt.to,
self.currentReceipt)
if (contracts) { if (contracts) {
const path = contracts.getSourceName(rawLocation.file) const path = contracts.getSourceName(rawLocation.file)
if (path) self.sourceHighlighter.currentSourceLocationFromfileName(lineColumnPos, path) if (path) self.sourceHighlighter.currentSourceLocationFromfileName(lineColumnPos, path)
@ -128,12 +131,13 @@ class DebuggerUI {
if (this.debugger) this.unLoad() if (this.debugger) this.unLoad()
let web3 = await this.getDebugWeb3() let web3 = await this.getDebugWeb3()
this.currentReceipt = await web3.eth.getTransactionReceipt(txNumber)
this.debugger = new Debugger({ this.debugger = new Debugger({
web3, web3,
offsetToLineColumnConverter: this.registry.get('offsettolinecolumnconverter').api, offsetToLineColumnConverter: this.registry.get('offsettolinecolumnconverter').api,
compilationResult: async (address) => { compilationResult: async (address) => {
try { try {
return await this.fetchContractAndCompile(address) return await this.fetchContractAndCompile(address, this.currentReceipt)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
@ -157,12 +161,13 @@ class DebuggerUI {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const web3 = await this.getDebugWeb3() const web3 = await this.getDebugWeb3()
this.currentReceipt = await web3.eth.getTransactionReceipt(hash)
const debug = new Debugger({ const debug = new Debugger({
web3, web3,
offsetToLineColumnConverter: this.registry.get('offsettolinecolumnconverter').api, offsetToLineColumnConverter: this.registry.get('offsettolinecolumnconverter').api,
compilationResult: async (address) => { compilationResult: async (address) => {
try { try {
return await this.fetchContractAndCompile(address) return await this.fetchContractAndCompile(address, this.currentReceipt)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }

Loading…
Cancel
Save