2020-12-12 23:40:48 +00:00
|
|
|
#!/usr/bin/env node
|
2020-12-21 19:47:00 +00:00
|
|
|
const process = require('process')
|
|
|
|
const fs = require('fs')
|
2020-12-12 23:40:48 +00:00
|
|
|
|
2020-12-21 19:47:00 +00:00
|
|
|
const compiler = require('./solc-js/wrapper.js')(require('./solc-js/soljson.js'))
|
2020-12-12 23:40:48 +00:00
|
|
|
|
2020-12-21 19:47:00 +00:00
|
|
|
for (const optimize of [false, true])
|
2020-12-12 23:40:48 +00:00
|
|
|
{
|
2020-12-21 19:47:00 +00:00
|
|
|
for (const filename of process.argv.slice(2))
|
2020-12-12 23:40:48 +00:00
|
|
|
{
|
|
|
|
if (filename !== undefined)
|
|
|
|
{
|
2020-12-21 19:47:00 +00:00
|
|
|
const input = {
|
2020-12-12 23:40:48 +00:00
|
|
|
language: 'Solidity',
|
2020-12-21 19:47:00 +00:00
|
|
|
sources: {
|
|
|
|
[filename]: {content: fs.readFileSync(filename).toString()}
|
|
|
|
},
|
2020-12-12 23:40:48 +00:00
|
|
|
settings: {
|
2020-12-21 19:47:00 +00:00
|
|
|
optimizer: {enabled: optimize},
|
|
|
|
outputSelection: {'*': {'*': ['evm.bytecode.object', 'metadata']}},
|
|
|
|
"modelChecker": {"engine": "none"}
|
2020-12-12 23:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-21 19:47:00 +00:00
|
|
|
|
|
|
|
const result = JSON.parse(compiler.compile(JSON.stringify(input)))
|
2020-12-22 01:08:40 +00:00
|
|
|
|
2020-12-12 23:40:48 +00:00
|
|
|
if (
|
|
|
|
!('contracts' in result) ||
|
|
|
|
Object.keys(result['contracts']).length === 0 ||
|
2020-12-22 01:08:40 +00:00
|
|
|
Object.keys(result['contracts']).every(file => Object.keys(result['contracts'][file]).length === 0)
|
2020-12-12 23:40:48 +00:00
|
|
|
)
|
|
|
|
// NOTE: do not exit here because this may be run on source which cannot be compiled
|
2020-12-22 01:10:10 +00:00
|
|
|
console.log(filename + ': <ERROR>')
|
2020-12-12 23:40:48 +00:00
|
|
|
else
|
2020-12-22 01:08:40 +00:00
|
|
|
for (const contractFile in result['contracts'])
|
|
|
|
for (const contractName in result['contracts'][contractFile])
|
|
|
|
{
|
|
|
|
const contractResults = result['contracts'][contractFile][contractName]
|
|
|
|
|
2020-12-22 01:10:10 +00:00
|
|
|
let bytecode = '<NO BYTECODE>'
|
|
|
|
let metadata = '<NO METADATA>'
|
2020-12-22 01:09:12 +00:00
|
|
|
|
2020-12-22 01:08:40 +00:00
|
|
|
if ('evm' in contractResults && 'bytecode' in contractResults['evm'] && 'object' in contractResults['evm']['bytecode'])
|
|
|
|
bytecode = contractResults.evm.bytecode.object
|
|
|
|
|
2020-12-22 01:09:12 +00:00
|
|
|
if ('metadata' in contractResults)
|
|
|
|
metadata = contractResults.metadata
|
|
|
|
|
2020-12-22 01:08:40 +00:00
|
|
|
console.log(filename + ':' + contractName + ' ' + bytecode)
|
2020-12-22 01:09:12 +00:00
|
|
|
console.log(filename + ':' + contractName + ' ' + metadata)
|
2020-12-22 01:08:40 +00:00
|
|
|
}
|
2020-12-12 23:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|