@oasisprotocol/sapphire-hardhat
Version:
A Hardhat plugin for developing on the Sapphire ParaTime.
51 lines • 2.45 kB
JavaScript
;
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.sapphireMainnet = exports.sapphireTestnet = exports.sapphireLocalnet = void 0;
const sapphire_paratime_1 = require("@oasisprotocol/sapphire-paratime");
const config_1 = require("hardhat/config");
const LOCALNET_POLL_INTERVAL = 100; // in milliseconds
exports.sapphireLocalnet = {
url: sapphire_paratime_1.NETWORKS.localnet.defaultGateway,
chainId: sapphire_paratime_1.NETWORKS.localnet.chainId,
};
exports.sapphireTestnet = {
url: sapphire_paratime_1.NETWORKS.testnet.defaultGateway,
chainId: sapphire_paratime_1.NETWORKS.testnet.chainId,
};
exports.sapphireMainnet = {
url: sapphire_paratime_1.NETWORKS.mainnet.defaultGateway,
chainId: sapphire_paratime_1.NETWORKS.mainnet.chainId,
};
(0, config_1.extendEnvironment)((hre) => {
const { chainId } = hre.network.config;
const rpcUrl = 'url' in hre.network.config ? hre.network.config.url : '';
if (chainId) {
if (!sapphire_paratime_1.NETWORKS[chainId])
return;
}
else {
if (!/sapphire/i.test(rpcUrl))
return;
console.warn('The Hardhat config for the network with `url`', rpcUrl, 'did not specify `chainId`.', 'The RPC URL looks like it may be Sapphire, so `@oasisprotocol/sapphire-hardhat` has been activated.', 'You can prevent this from happening by setting a non-Sapphire `chainId`.');
}
// A hack to reduce polling interval on Sapphire Localnet.
// Must be applied before wrapEthereumProvider so Sapphire captures the patched upstream.
if (chainId == sapphire_paratime_1.NETWORKS.localnet.chainId) {
const origRequest = hre.network.provider.request.bind(hre.network.provider);
hre.network.provider.request = async ({ method, params }) => {
if (method !== 'eth_getTransactionByHash') {
return origRequest({ method, params });
}
for (let i = 0; i < 30; i++) {
const result = await origRequest({ method, params });
if (result !== null)
return result;
await new Promise((r) => setTimeout(r, LOCALNET_POLL_INTERVAL));
}
return origRequest({ method, params });
};
}
hre.network.provider = (0, sapphire_paratime_1.wrapEthereumProvider)(hre.network.provider);
});
//# sourceMappingURL=index.js.map