UNPKG

@nomiclabs/buidler

Version:

Buidler is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

68 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const extenders_1 = require("./core/config/extenders"); const errors_1 = require("./core/errors"); const errors_list_1 = require("./core/errors-list"); const dsl_1 = require("./core/tasks/dsl"); class BuidlerContext { constructor() { this.tasksDSL = new dsl_1.TasksDSL(); this.extendersManager = new extenders_1.ExtenderManager(); this.loadedPlugins = []; this.configExtenders = []; // NOTE: This is experimental and will be removed. Please contact our team if // you are planning to use it. this.experimentalBuidlerEVMMessageTraceHooks = []; } static isCreated() { const globalWithBuidlerContext = global; return globalWithBuidlerContext.__buidlerContext !== undefined; } static createBuidlerContext() { if (this.isCreated()) { throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_ALREADY_CREATED); } const globalWithBuidlerContext = global; const ctx = new BuidlerContext(); globalWithBuidlerContext.__buidlerContext = ctx; return ctx; } static getBuidlerContext() { const globalWithBuidlerContext = global; const ctx = globalWithBuidlerContext.__buidlerContext; if (ctx === undefined) { throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED); } return ctx; } static deleteBuidlerContext() { const globalAsAny = global; globalAsAny.__buidlerContext = undefined; } setBuidlerRuntimeEnvironment(env) { if (this.environment !== undefined) { throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_BRE_ALREADY_DEFINED); } this.environment = env; } getBuidlerRuntimeEnvironment() { if (this.environment === undefined) { throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_BRE_NOT_DEFINED); } return this.environment; } setPluginAsLoaded(pluginName) { this.loadedPlugins.push(pluginName); } setConfigPath(configPath) { this._configPath = configPath; } getConfigPath() { if (this._configPath === undefined) { throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_CONFIG_PATH_NOT_SET); } return this._configPath; } } exports.BuidlerContext = BuidlerContext; //# sourceMappingURL=context.js.map