@solarity/hardhat-gobind
Version:
Generation of smart contract bindings for Golang
51 lines • 2.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Generator = require("./abigen/generator");
const config_1 = require("hardhat/config");
const plugins_1 = require("hardhat/plugins");
const task_names_1 = require("hardhat/builtin-tasks/task-names");
require("./type-extensions");
const config_2 = require("./config");
const constants_1 = require("./constants");
(0, config_1.extendConfig)(config_2.getDefaultGoBindConfig);
const gobind = async ({ outdir, deployable, noCompile, v2, _abigenPath }, hre) => {
hre.config.gobind.outdir = outdir === undefined ? hre.config.gobind.outdir : outdir;
hre.config.gobind.deployable = !deployable ? hre.config.gobind.deployable : deployable;
hre.config.gobind.abigenVersion = !v2 ? hre.config.gobind.abigenVersion : "v2";
if (!noCompile) {
await hre.run(task_names_1.TASK_COMPILE, { generateBind: false, v2: v2, _abigenPath: _abigenPath });
}
try {
const contracts = await new Generator(hre, _abigenPath).generate();
console.log(`\nGenerated bindings for ${contracts.length} contracts`);
}
catch (e) {
throw new plugins_1.NomicLabsHardhatPluginError(constants_1.pluginName, e.message);
}
};
(0, config_1.task)(constants_1.TASK_GOBIND, "Generate Go bindings for compiled contracts")
.addOptionalParam("outdir", "Output directory for generated bindings (Go package name is derived from it as well)", undefined, config_1.types.string)
.addFlag("deployable", "Generate bindings with the bytecode in order to deploy the contracts within Go")
.addFlag("noCompile", "Do not compile smart contracts before the generation")
.addFlag("v2", "Use abigen version 2")
.setAction(gobind);
(0, config_1.task)(task_names_1.TASK_COMPILE)
.addFlag("generateBindings", "Generate bindings after compilation")
.addFlag("v2", "Use abigen version 2 for binding generation")
.setAction(async ({ generateBindings, v2, _abigenPath }, { config, run }, runSuper) => {
await runSuper();
if (config.gobind.runOnCompile || generateBindings) {
await run(constants_1.TASK_GOBIND, { noCompile: true, v2: v2, _abigenPath: _abigenPath });
}
});
(0, config_1.task)(task_names_1.TASK_CLEAN, "Clears the cache and deletes all artifacts").setAction(async ({ global }, hre, runSuper) => {
if (!global)
try {
await new Generator(hre).clean();
}
catch (e) {
throw new plugins_1.NomicLabsHardhatPluginError(constants_1.pluginName, e.message);
}
await runSuper();
});
//# sourceMappingURL=index.js.map