Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null-Checking for bytecode in solc-transpiler #66

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions packages/solc-transpiler/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,50 +79,52 @@ export const compile = (configJsonString: string, callbacks?: any): string => {
for (const [filename, fileJson] of Object.entries(res.contracts)) {
log.debug(`Transpiling file: ${filename}`)
for (const [contractName, contractJson] of Object.entries(fileJson)) {
// Library links in bytecode strings have invalid hex: they are of the form __$asdfasdf$__.
// Because __$ is not a valid hex string, we replace with a valid hex string during transpilation,
// storing the links re-substituting the __$* strings afterwards
const originalRefStrings = getOriginalLinkRefStringsAndSubstituteValidHex(
contractJson
)
log.debug(
`Transpiling contract: ${contractName} with valid hex strings for link placeholders.`
)
const output = transpileContract(
transpiler,
contractJson,
filename,
contractName
)
log.debug(`Transpiled contract ${contractName}.`)
if (!!contractJson && !!contractJson.evm && !!contractJson.evm.bytecode && !!contractJson.evm.deployedBytecode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably cleaner to replace with an if(...) continue instead of a big if statement wrapper.

// Library links in bytecode strings have invalid hex: they are of the form __$asdfasdf$__.
// Because __$ is not a valid hex string, we replace with a valid hex string during transpilation,
// storing the links re-substituting the __$* strings afterwards
const originalRefStrings = getOriginalLinkRefStringsAndSubstituteValidHex(
contractJson
)
log.debug(
`Transpiling contract: ${contractName} with valid hex strings for link placeholders.`
)
const output = transpileContract(
transpiler,
contractJson,
filename,
contractName
)
log.debug(`Transpiled contract ${contractName}.`)

res.contracts[filename][contractName].evm.bytecode.object = remove0x(
output.bytecode || ''
)
res.contracts[filename][
contractName
].evm.deployedBytecode.object = remove0x(output.deployedBytecode || '')
res.contracts[filename][contractName].evm.bytecode.object = remove0x(
output.bytecode || ''
)
res.contracts[filename][
contractName
].evm.deployedBytecode.object = remove0x(output.deployedBytecode || '')
res.contracts[filename][contractName].evm.bytecode.object = remove0x(
output.bytecode || ''
)
res.contracts[filename][
contractName
].evm.deployedBytecode.object = remove0x(output.deployedBytecode || '')
res.contracts[filename][contractName].evm.bytecode.object = remove0x(
output.bytecode || ''
)
res.contracts[filename][
contractName
].evm.deployedBytecode.object = remove0x(output.deployedBytecode || '')

log.debug(
`Updating links for all libraries by putting back original invalid hex (__$...$__) strings and updating link .start's.`
)
updateLinkRefsAndSubstituteOriginalStrings(
res.contracts[filename][contractName],
originalRefStrings
)
log.debug(
`Updating links for all libraries by putting back original invalid hex (__$...$__) strings and updating link .start's.`
)
updateLinkRefsAndSubstituteOriginalStrings(
res.contracts[filename][contractName],
originalRefStrings
)

if (!!output.errors) {
if (!res.errors) {
res.errors = []
}
if (!!output.errors) {
if (!res.errors) {
res.errors = []
}

res.errors.push(...output.errors)
res.errors.push(...output.errors)
}
}
}
}
Expand Down