@solarity/hardhat-gobind
Version:
Generation of smart contract bindings for Golang
74 lines • 2.94 kB
JavaScript
import { isAbsolute } from "path";
import { validateUserConfigZodType } from "@nomicfoundation/hardhat-zod-utils";
import { z } from "zod";
export default async () => ({
validateUserConfig,
resolveUserConfig,
});
const userConfigType = z.object({
gobind: z
.object({
outdir: z.string().optional(),
deployable: z.boolean().optional(),
runOnCompile: z.boolean().optional(),
abigenVersion: z.enum(["v1", "v2"]).optional(),
abigenPath: z.string().optional(),
verbose: z.boolean().optional(),
onlyFiles: z.array(z.string().refine((p) => !isAbsolute(p), "Expected a relative path")).optional(),
skipFiles: z.array(z.string().refine((p) => !isAbsolute(p), "Expected a relative path")).optional(),
})
.optional(),
});
export async function validateUserConfig(userConfig) {
return validateUserConfigZodType(userConfig, userConfigType);
}
export async function resolveUserConfig(userConfig, resolveConfigurationVariable, next) {
const resolvedConfig = await next(userConfig, resolveConfigurationVariable);
const gobind = await resolveGobindConfig(userConfig.gobind, resolveConfigurationVariable);
return {
...resolvedConfig,
gobind,
};
}
async function resolveGobindConfig(gobindConfig, resolveConfigurationVariable) {
const defaultConfig = {
outdir: "./generated-types/bindings",
deployable: false,
runOnCompile: false,
abigenVersion: "v1",
verbose: false,
onlyFiles: [],
skipFiles: [],
abigenPath: "./node_modules/abigenjs/bin/abigen.wasm",
};
if (gobindConfig === undefined) {
return defaultConfig;
}
const resolved = { ...defaultConfig };
if (typeof gobindConfig.outdir === "string") {
resolved.outdir = await resolveConfigurationVariable(gobindConfig.outdir).get();
}
if (typeof gobindConfig.deployable === "boolean") {
resolved.deployable = gobindConfig.deployable;
}
if (typeof gobindConfig.runOnCompile === "boolean") {
resolved.runOnCompile = gobindConfig.runOnCompile;
}
if (typeof gobindConfig.abigenVersion === "string") {
resolved.abigenVersion = gobindConfig.abigenVersion;
}
if (typeof gobindConfig.verbose === "boolean") {
resolved.verbose = gobindConfig.verbose;
}
if (typeof gobindConfig.abigenPath === "string") {
resolved.abigenPath = await resolveConfigurationVariable(gobindConfig.abigenPath).get();
}
if (Array.isArray(gobindConfig.onlyFiles)) {
resolved.onlyFiles = await Promise.all(gobindConfig.onlyFiles.map((p) => resolveConfigurationVariable(p).get()));
}
if (Array.isArray(gobindConfig.skipFiles)) {
resolved.skipFiles = await Promise.all(gobindConfig.skipFiles.map((p) => resolveConfigurationVariable(p).get()));
}
return resolved;
}
//# sourceMappingURL=config.js.map