编译器
环绕多个编译器来下载正确的版本并用共同的界面来引用编译.
安装
npm i @ethereum-sourcify/compilers
使用量
import {
SolidityOutput,
ISolidityCompiler,
JsonInput,
} from '@ethereum-sourcify/lib-sourcify';
import { useSolidityCompiler } from '@ethereum-sourcify/compilers';
class SolcLocal implements ISolidityCompiler {
constructor(
private solcRepoPath: string,
private solJsonRepoPath: string,
private timeoutMs?: number,
) {}
async compile(
version: string,
solcJsonInput: JsonInput,
forceEmscripten: boolean = false,
): Promise<SolidityOutput> {
return await useSolidityCompiler(
this.solcRepoPath,
this.solJsonRepoPath,
version,
solcJsonInput,
forceEmscripten,
this.timeoutMs,
);
}
}
这个 SolcLocal 类可以用作 solidityCompiler 参数 SolidityCheckedContract。 。 。 .
Vyper遵循同样的模式.
太阳
太阳 以与Solc相同的标准JSON输入和输出来编译固态. useSolarCompiler(solarRepoPath, version, solarJsonInput, timeoutMs?) 取一个相容的 SOLC_WRAPPER=1 solar --version 例如,指纹 0.8.38+commit.e7a91fc7.solar.0.3.0。该版本命名了“太阳”发行和建造承诺.
- 要发布, 函数下载
solar-<target>.tar.gz从 GitHub 中释放并检查二进制报告请求的承诺. - 一个不是释放物的建筑,比如
0.3.0-dev,来自 Sourcufy hosts 的拷贝,例如"创建 v1. 9.0 捆绑的太阳". 仅为 Linux x64 提供主机复制件 。 文件名是缓存名称,solar-<target>-v<solar version>+commit.<commit>。 。 。 . - 要用另一块,放进去
solarRepoPath以该名称为例solar-x86_64-unknown-linux-musl-v0.3.0-dev+commit.d9f23fbe。 。 。 .
编译超时
最后的论点是: useSolidityCompiler, (中文(简体) ), useVyperCompiler, (中文(简体) ), useSolarCompiler 财务报告和审定财务报表 useFeCompiler 是一个以毫秒计的可选的墙点超时编译。 当电话响了,它就否认一个错误 code 实值 COMPILER_TIMEOUT (以 COMPILER_TIMEOUT_CODE 从 @ethereum-sourcify/compilers-types) (中文(简体) ). 如果省略,则适用45分的默认.
它涵盖了编译器运行的所有三种方式,每种方式都需要不同的机制来阻止:
- 本地语言
solc编号 :vyper编号 :solar二进制为子进程运行, 使用SIGKILL fe build同步运行通过spawnSync,它本身执行超时- soljson (Emscripten) 的构造
solc运行在工人线程中的进程中 —— 没有要杀死的进程, 因此线程被终止