@kadena/hardhat-chainweb
Version:
Hardhat plugin for Kadena's Chainweb network
82 lines • 4.13 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runRPCNode = runRPCNode;
const server_js_1 = require("./server.js");
const fs_1 = __importDefault(require("fs"));
const watch_1 = require("hardhat/builtin-tasks/utils/watch");
const util_js_1 = require("hardhat/internal/core/providers/util.js");
const picocolors_1 = __importDefault(require("picocolors"));
const ethereumjs_util_1 = require("@nomicfoundation/ethereumjs-util");
const utils_1 = require("./utils");
const pure_utils_js_1 = require("../pure-utils.js");
async function runRPCNode(taskArgs, hre) {
const { hostname: hostnameParam, port } = taskArgs;
let hostname;
if (hostnameParam !== undefined) {
hostname = hostnameParam;
}
else {
const insideDocker = fs_1.default.existsSync('/.dockerenv');
if (insideDocker) {
hostname = '0.0.0.0';
}
else {
hostname = '127.0.0.1';
}
}
const chainweb = hre.config.chainweb[hre.config.defaultChainweb];
if (chainweb) {
const providers = await Promise.all((await hre.chainweb.getChainIds()).map(async (cid) => [cid, await hre.chainweb.getProvider(cid)]));
const server = new server_js_1.ChainwebJsonRpcServer({
port,
hostname,
providers,
});
await server.listen();
const watchers = providers.map(([, provider]) => {
return (0, watch_1.watchCompilerOutput)(provider, hre.config.paths).catch((error) => {
console.warn("There was a problem watching the compiler output, changes in the contracts won't be reflected in the Hardhat Network. Run Hardhat with --verbose to learn more.");
console.log("Compilation output can't be watched. Please report this to help us improve Hardhat.\n", error);
});
});
console.log(`Started HTTP and WebSocket ${picocolors_1.default.greenBright(`JSON-RPC`)} server at ${picocolors_1.default.greenBright(port)}\n`);
providers.forEach(([cid]) => {
console.log(picocolors_1.default.greenBright(`chain ${cid}: `), picocolors_1.default.underline(picocolors_1.default.greenBright(`http://${hostname}:${port}${(0, utils_1.mapChainIdToRoute)(cid)}`)));
});
providers.map(async ([cid]) => {
const networkName = `${(0, pure_utils_js_1.getNetworkStem)(hre.config.defaultChainweb)}${cid}`;
const networkConfig = hre.config.networks[networkName];
console.log(`\nChain #${cid} Accounts`);
console.log('=================');
logHardhatNetworkAccounts(networkConfig);
});
await server.waitUntilClosed();
await Promise.all(watchers.map((w) => w.then((w) => w === null || w === void 0 ? void 0 : w.close())));
}
}
function logHardhatNetworkAccounts(networkConfig) {
const warning = [
'',
'WARNING: These accounts, and their private keys, are publicly known',
'Any funds sent to them on Mainnet or any other live network WILL BE LOST.',
'',
]
.map((t) => picocolors_1.default.bold(t))
.join('\n');
console.log(warning);
const accounts = (0, util_js_1.normalizeHardhatNetworkAccountsConfig)(networkConfig.accounts);
for (const [index, account] of accounts.entries()) {
const address = (0, ethereumjs_util_1.toChecksumAddress)((0, ethereumjs_util_1.bytesToHex)((0, ethereumjs_util_1.privateToAddress)((0, ethereumjs_util_1.toBytes)(account.privateKey))));
const balance = (BigInt(account.balance) /
BigInt(10) ** BigInt(18)).toString(10);
const privateKey = (0, ethereumjs_util_1.bytesToHex)((0, ethereumjs_util_1.toBytes)(account.privateKey));
const entry = `Account #${index}: ${address} (${balance} ETH)\nPrivate Key: ${privateKey}`;
console.log(entry);
console.log();
}
console.log(warning);
}
//# sourceMappingURL=runRPCNode.js.map