本文整理汇总了TypeScript中solc.compile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript compile函数的具体用法?TypeScript compile怎么用?TypeScript compile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compile函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: compileAndHighlightErrors
export function compileAndHighlightErrors(contracts: any, diagnosticCollection: vscode.DiagnosticCollection) {
let output = solc.compile({ sources: contracts }, 1);
diagnosticCollection.clear();
if (output.errors) {
outputErrorsToDiagnostics(diagnosticCollection, output.errors);
}
}
示例2: compile
export function compile(contracts: any,
diagnosticCollection: vscode.DiagnosticCollection,
buildDir: string, sourceDir: string, excludePath?: string, singleContractFilePath?: string) {
// Did we find any sol files after all?
if (Object.keys(contracts).length === 0) {
vscode.window.showWarningMessage('No solidity files (*.sol) found');
return;
}
let outputChannel = vscode.window.createOutputChannel('solidity compilation');
outputChannel.clear();
let output = solc.compile({ sources: contracts }, 1);
if (Object.keys(output).length === 0) {
vscode.window.showWarningMessage('No output by the compiler');
return;
}
diagnosticCollection.clear();
if (output.errors) {
const errorWarningCounts = outputErrorsToDiagnostics(diagnosticCollection, output.errors);
outputErrorsToChannel(outputChannel, output.errors);
if (errorWarningCounts.errors > 0) {
vscode.window.showErrorMessage(`Compilation failed with ${errorWarningCounts.errors} errors`);
}
else if (errorWarningCounts.warnings > 0) {
vscode.window.showWarningMessage(`Compilation had ${errorWarningCounts.warnings} warnings`);
}
} else {
let binPath = path.join(vscode.workspace.rootPath, buildDir);
if (!fs.existsSync(binPath)) {
fs.mkdirSync(binPath);
}
// iterate through all the sources, find contracts and output them into the same folder structure to avoid collisions, named as the contract
for (let source in output.sources) {
// TODO: ALL this validation to a method
// Output only single contract compilation or all
if (!singleContractFilePath || source === singleContractFilePath) {
if (!excludePath || !source.startsWith(excludePath)) {
// Output only source directory compilation or all (this will exclude external references)
if (!sourceDir || source.startsWith(sourceDir)) {
output.sources[source].AST.children.forEach(child => {
if (child.name === 'Contract') {
let contractName = child.attributes.name;
let relativePath = path.relative(vscode.workspace.rootPath, source);
let dirName = path.dirname(path.join(binPath, relativePath));
if (!fs.existsSync(dirName)) {
fsex.mkdirsSync(dirName);
}
let contractAbiPath = path.join(dirName, contractName + '.abi');
let contractBinPath = path.join(dirName, contractName + '.bin');
if (fs.existsSync(contractAbiPath)) {
fs.unlinkSync(contractAbiPath);
}
if (fs.existsSync(contractBinPath)) {
fs.unlinkSync(contractBinPath);
}
fs.writeFileSync(contractBinPath, output.contracts[contractName].bytecode);
fs.writeFileSync(contractAbiPath, output.contracts[contractName].interface);
}
});
}
}
}
}
outputChannel.hide();
vscode.window.showInformationMessage('Compilation completed succesfully!');
}
}