hardhat/builtin-tasks/task-names#TASK_COMPILE_SOLIDITY_RUN_SOLCJS TypeScript Examples

The following examples show how to use hardhat/builtin-tasks/task-names#TASK_COMPILE_SOLIDITY_RUN_SOLCJS. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From plugins with MIT License 5 votes vote down vote up
subtask(
  TASK_COMPILE_SOLIDITY_RUN_SOLC,
  async (args: { input: any; solcPath: string }, hre, runSuper) => {
    const ignoreRxList = hre.network.config.ignoreRxList || [];
    const ignore = (filename: string) => ignoreRxList.reduce((ignored: boolean, rx: string | RegExp) => ignored || new RegExp(rx).test(filename), false);
    if (hre.network.ovm !== true) {
        // Separate the EVM and OVM inputs.
        for (const file of Object.keys(args.input.sources)) {
          // Ignore any contract that has this tag or in ignore list
          if (args.input.sources[file].content.includes('// @unsupported: evm') || ignore(file)) {
              delete args.input.sources[file];
          }
          else {
              //console.log(file + ' included');
          }
        }
        return runSuper(args)
    }

    // Just some silly sanity checks, make sure we have a solc version to download. Our format is
    // `X.Y.Z` (for now).
    let ovmSolcVersion = DEFAULT_OVM_SOLC_VERSION
    if (hre.config?.ovm?.solcVersion) {
      ovmSolcVersion = hre.config.ovm.solcVersion
    }

    // Get a path to a soljson file.
    const ovmSolcPath = await getOvmSolcPath(ovmSolcVersion)

    // These objects get fed into the compiler. We're creating two of these because we need to
    // throw one into the OVM compiler and another into the EVM compiler. Users are able to prevent
    // certain files from being compiled by the OVM compiler by adding "// @unsupported: ovm"
    // somewhere near the top of their file.
    const ovmInput = {
      language: 'Solidity',
      sources: {},
      settings: args.input.settings,
    }

    // Separate the EVM and OVM inputs.
    for (const file of Object.keys(args.input.sources)) {
      // Ignore any contract that has this tag or in ignore list
      if (!args.input.sources[file].content.includes('// @unsupported: ovm') && !ignore(file)) {
        ovmInput.sources[file] = args.input.sources[file]
      }
    }

    // Build both inputs separately.
    const ovmOutput = await hre.run(TASK_COMPILE_SOLIDITY_RUN_SOLCJS, {
      input: ovmInput,
      solcJsPath: ovmSolcPath,
    })

    // Just doing this to add some extra useful information to any errors in the OVM compiler output.
    ovmOutput.errors = (ovmOutput.errors || []).map((error: any) => {
      if (error.severity === 'error') {
        error.formattedMessage = `OVM Compiler Error (insert "// @unsupported: ovm" if you don't want this file to be compiled for the OVM):\n ${error.formattedMessage}`
      }

      return error
    })

    return ovmOutput
  }
)