Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Fix bug with library linking for Solidity >=0.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Dec 21, 2020
1 parent e627d26 commit 1f4b159
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/metacoin/truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('dotenv').config()
module.exports = {
compilers: {
solc: {
version: '0.7.0',
version: '0.8.0',
settings: {
optimizer: {
enabled: true,
Expand Down
33 changes: 30 additions & 3 deletions verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const verifyContract = async (artifact, options) => {
const sendVerifyRequest = async (artifact, options) => {
const compilerVersion = extractCompilerVersion(artifact)
const encodedConstructorArgs = await fetchConstructorValues(artifact, options)
const inputJSON = await fetchInputJSON(artifact, options)
const inputJSON = getInputJSON(artifact, options)

const postQueries = {
apikey: options.apiKey,
Expand Down Expand Up @@ -187,17 +187,19 @@ const fetchConstructorValues = async (artifact, options) => {
}
}

const fetchInputJSON = async (artifact, options) => {
const getInputJSON = (artifact, options) => {
const metadata = JSON.parse(artifact.metadata)

const libraries = getLibraries(artifact, options)

const inputJSON = {
language: metadata.language,
sources: metadata.sources,
settings: {
remappings: metadata.settings.remappings,
optimizer: metadata.settings.optimizer,
evmVersion: metadata.settings.evmVersion,
libraries: { '': artifact.networks[`${options.networkId}`].links || {} }
libraries
}
}

Expand All @@ -212,6 +214,31 @@ const fetchInputJSON = async (artifact, options) => {
return inputJSON
}

const getLibraries = (artifact, options) => {
const libraries = {
// Example data structure of libraries object in Standard Input JSON
// 'ConvertLib.sol': {
// 'ConvertLib': '0x...',
// 'OtherLibInSameSourceFile': '0x...'
// }
}

const links = artifact.networks[`${options.networkId}`].links || {}

for (const libraryName in links) {
// Retrieve the source path for this library
const libraryArtifact = getArtifact(libraryName, options)
const librarySourceFile = libraryArtifact.ast.absolutePath

// Add the library to the object of libraries for this source path
const librariesForSourceFile = libraries[librarySourceFile] || {}
librariesForSourceFile[libraryName] = links[libraryName]
libraries[librarySourceFile] = librariesForSourceFile
}

return libraries
}

const verificationStatus = async (guid, options) => {
logger.debug(`Checking status of verification request ${guid}`)
// Retry API call every second until status is no longer pending
Expand Down

0 comments on commit 1f4b159

Please sign in to comment.