-
Notifications
You must be signed in to change notification settings - Fork 215
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
Showing
21 changed files
with
110 additions
and
81 deletions.
There are no files selected for viewing
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
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { LOCAL_CONFIG_KEY, fetchNetworkConfig } from './network-config.js'; | ||
|
||
/** | ||
* @import {MinimalNetworkConfig} from './network-config.js'; | ||
*/ | ||
|
||
/** | ||
* Fetch the network config for the AGORIC_NET environment variable. | ||
* | ||
* If none is set or it's 'local', return a local chain config. | ||
* | ||
* @param {{ env: typeof process.env, fetch: typeof fetch }} io | ||
* @returns {Promise<MinimalNetworkConfig>} | ||
*/ | ||
|
||
export const fetchEnvNetworkConfig = async ({ env, fetch }) => { | ||
const net = env.AGORIC_NET || LOCAL_CONFIG_KEY; | ||
|
||
return fetchNetworkConfig(net, { fetch }); | ||
}; |
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,42 @@ | ||
/** | ||
* @typedef {{ rpcAddrs: string[], chainName: string }} MinimalNetworkConfig | ||
*/ | ||
|
||
export const toNetworkConfigUrl = agoricNetSubdomain => | ||
`https://${agoricNetSubdomain}.agoric.net/network-config`; | ||
|
||
export const toRpcUrl = agoricNetSubdomain => | ||
`https://${agoricNetSubdomain}.rpc.agoric.net:443`; | ||
|
||
/** @satisfies {MinimalNetworkConfig} */ | ||
export const LOCAL_CONFIG = { | ||
rpcAddrs: ['http://0.0.0.0:26657'], | ||
chainName: 'agoriclocal', | ||
}; | ||
|
||
export const LOCAL_CONFIG_KEY = 'local'; | ||
|
||
/** | ||
* Fetches the network config for the given network specifier. | ||
* | ||
* @param {string} spec | ||
* @param {{ fetch: typeof fetch }} io | ||
* @returns {Promise<MinimalNetworkConfig>} | ||
*/ | ||
export const fetchNetworkConfig = async (spec, { fetch }) => { | ||
const [netName, chainName] = spec.split(','); | ||
|
||
if (netName === LOCAL_CONFIG_KEY) { | ||
return LOCAL_CONFIG; | ||
} | ||
|
||
if (chainName) { | ||
return { chainName, rpcAddrs: [toRpcUrl(netName)] }; | ||
} | ||
|
||
return fetch(toNetworkConfigUrl(netName)) | ||
.then(res => res.json()) | ||
.catch(err => { | ||
throw Error(`cannot get network config (${spec}): ${err.message}`); | ||
}); | ||
}; |
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
Oops, something went wrong.