-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba2115a
commit 7beaf44
Showing
12 changed files
with
121 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const storage = require('../internal/storage') | ||
const { | ||
createProvider, | ||
} = require('hardhat/internal/core/providers/construction') | ||
const { | ||
HardhatEthersProvider, | ||
} = require('@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider') | ||
const debug = require('common/src/debug') | ||
|
||
async function setActiveNetwork(hre) { | ||
debug.log('Setting active network', 'network') | ||
const networks = storage.readNetworks() | ||
await setNetwork(networks.activeNetwork, hre) | ||
} | ||
|
||
async function setNetwork(alias, hre) { | ||
debug.log(`Setting network ${alias}`, 'network') | ||
const networks = storage.readNetworks() | ||
|
||
let network | ||
if (alias !== 'localhost') { | ||
network = networks[alias] | ||
injectNetworkInConfig(alias, network, hre.config) | ||
} else { | ||
network = hre.config.networks[alias] | ||
} | ||
|
||
const provider = await createProvider(hre.config, alias) | ||
|
||
hre.ethers.provider = new HardhatEthersProvider(provider, alias) | ||
} | ||
|
||
function injectNetworkInConfig(alias, network, config) { | ||
if (config.networks[alias]) return | ||
|
||
config.networks[alias] = { | ||
accounts: 'remote', | ||
gas: 'auto', | ||
gasPrice: 'auto', | ||
gasMultiplier: 1, | ||
httpHeaders: {}, | ||
timeout: 40000, | ||
url: network.url, | ||
} | ||
} | ||
|
||
module.exports = { | ||
setActiveNetwork, | ||
setNetwork, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const output = require('common/src/output') | ||
const storage = require('../internal/storage') | ||
|
||
require('../scopes/net') | ||
.task('active', 'Prints the active network') | ||
.setAction(async () => { | ||
try { | ||
const networks = storage.readNetworks() | ||
output.resultBox(`Active network is ${networks.activeNetwork}`) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { types } = require('hardhat/config') | ||
const output = require('common/src/output') | ||
const autocompleteAlias = require('./autocomplete/alias') | ||
const storage = require('../internal/storage') | ||
const { setNetwork } = require('../internal/set-network') | ||
|
||
const set = require('../scopes/net') | ||
.task('set', 'Activates a network on the cli') | ||
.addOptionalParam( | ||
'alias', | ||
'How the network is referenced in the cli', | ||
undefined, | ||
types.string, | ||
) | ||
.setAction(async ({ alias }, hre) => { | ||
try { | ||
const networks = storage.readNetworks() | ||
|
||
if (!(alias in networks)) { | ||
throw new Error(`The network alias ${alias} does not exist`) | ||
} | ||
|
||
await setNetwork(alias, hre) | ||
|
||
networks.activeNetwork = alias | ||
storage.storeNetworks(networks) | ||
|
||
output.resultBox(`The active network is now "${alias}"`) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) | ||
|
||
set.paramDefinitions.alias.autocomplete = autocompleteAlias |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters