Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new BuidlerPluginError("Ganache network only works with locahost");
}
// Validate all options agains validator
try {
GanacheService.optionValidator.check(options);
} catch (e) {
throw new BuidlerPluginError(
`Ganache network config is invalid: ${e.message}`,
e
);
}
// Test for unsupported commands
if (options.accounts !== undefined) {
throw new BuidlerPluginError(
"Config: ganache.accounts unsupported for this network"
);
}
// Transform needed options to Ganache core server (not using SnakeCase lib for performance)
validatedOptions.hostname = url.hostname;
validatedOptions.port =
url.port !== undefined && url.port !== ""
? parseInt(url.port, 10)
: DEFAULT_PORT;
const optionsToInclude = [
"accountsKeyPath",
"dbPath",
"defaultBalanceEther",
log("Initializing server");
// Validate and Transform received options before initialize server
this._options = this._validateAndTransformOptions(options);
try {
// Initialize server and provider with given options
this._server = Ganache.server(this._options);
// Register server and system error handlers
this._registerSystemErrorsHandlers();
} catch (e) {
// Verify the expected error or throw it again
if (e.name === "TypeError") {
if (GanacheService.error === undefined) {
const error = new BuidlerPluginError(
`Ganache plugin config is invalid: ${e.message}`,
e
);
log("Failed to initialize GanacheService\n", error);
GanacheService.error = error;
}
} else {
throw new BuidlerPluginError(
`Failed to initialize GanacheService: ${e.message}`,
e
);
}
}
}
public _validateAndTransformOptions(options: GanacheOptions): any {
const validatedOptions: any = options;
// Validate and parse hostname and port from URL (this validation is priority)
const url = new URL(options.url);
if (url.hostname !== "locahost" && url.hostname !== "127.0.0.1") {
throw new BuidlerPluginError("Ganache network only works with locahost");
}
// Validate all options agains validator
try {
GanacheService.optionValidator.check(options);
} catch (e) {
throw new BuidlerPluginError(
`Ganache network config is invalid: ${e.message}`,
e
);
}
// Test for unsupported commands
if (options.accounts !== undefined) {
throw new BuidlerPluginError(
"Config: ganache.accounts unsupported for this network"
);
}
// Transform needed options to Ganache core server (not using SnakeCase lib for performance)
validatedOptions.hostname = url.hostname;
validatedOptions.port =
private _checkForServiceErrors() {
if (GanacheService.error !== undefined) {
if (this._server !== undefined) {
this._server.close();
}
throw new BuidlerPluginError(
`An error occurred in GanacheService: ${GanacheService.error.message}`,
GanacheService.error
);
}
}
async function getSolhintConfig(rootDirectory: string) {
let solhintConfig;
const { loadConfig, applyExtends } = await import(
"solhint/lib/config/config-file"
);
if (await hasConfigFile(rootDirectory)) {
try {
solhintConfig = await loadConfig();
} catch (err) {
throw new BuidlerPluginError(
"An error occurred when loading your solhint config.",
err
);
}
} else {
solhintConfig = getDefaultConfig();
}
try {
solhintConfig = applyExtends(solhintConfig);
} catch (err) {
throw new BuidlerPluginError(
"An error occurred when processing your solhint config.",
err
);
}
try {
solhintConfig = await loadConfig();
} catch (err) {
throw new BuidlerPluginError(
"An error occurred when loading your solhint config.",
err
);
}
} else {
solhintConfig = getDefaultConfig();
}
try {
solhintConfig = applyExtends(solhintConfig);
} catch (err) {
throw new BuidlerPluginError(
"An error occurred when processing your solhint config.",
err
);
}
return solhintConfig;
}
function getFormatter(formatterName = "stylish") {
try {
const solhintPath = require.resolve("solhint");
const formatterPath = require.resolve(
`eslint/lib/formatters/${formatterName}`,
{ paths: [solhintPath] }
);
return require(formatterPath);
} catch (ex) {
throw new BuidlerPluginError(
`An error occurred loading the solhint formatter ${formatterName}`,
ex
);
}
}