当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript solc.compile函数代码示例

本文整理汇总了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);
    }
}
开发者ID:finhaus,项目名称:vscode-solidity,代码行数:7,代码来源:compiler.ts

示例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!');
    }
}
开发者ID:finhaus,项目名称:vscode-solidity,代码行数:91,代码来源:compiler.ts


注:本文中的solc.compile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。