-
Notifications
You must be signed in to change notification settings - Fork 227
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
5b156d4
commit 1fdc1d3
Showing
6 changed files
with
123 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import fetch from 'node-fetch'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
import setGCIIngress from './set-gci-ingress'; | ||
|
||
const DEFAULT_CHAIN_CONFIG = 'https://testnet.agoric.com/network-config'; | ||
|
||
/** | ||
* @param {string} basedir | ||
* @param {string=} chainConfig | ||
* @param {boolean} [force=false] | ||
*/ | ||
async function addChain(basedir, chainConfig, force = false) { | ||
let actualConfig = chainConfig; | ||
const cache = path.join(basedir, 'add-chain-default.txt'); | ||
if (actualConfig === undefined) { | ||
if (fs.existsSync(cache)) { | ||
actualConfig = fs.readFileSync(cache, 'utf-8'); | ||
} else { | ||
actualConfig = DEFAULT_CHAIN_CONFIG; | ||
} | ||
} | ||
|
||
console.log('downloading netconfig from', actualConfig); | ||
const r = await fetch(actualConfig); | ||
const netconf = await r.json(); | ||
if (!netconf.gci) { | ||
throw Error(`${actualConfig} does not contain a "gci" entry`); | ||
} | ||
|
||
const connFile = path.join(basedir, 'connections.json'); | ||
const conns = JSON.parse(fs.readFileSync(connFile)); | ||
for (const conn of conns) { | ||
if (conn.GCI === netconf.gci) { | ||
if (!force) { | ||
console.log(`Already have an entry for ${conn.GCI}; not replacing`); | ||
return 0; | ||
} | ||
} | ||
} | ||
|
||
console.log('Setting chain parameters'); | ||
setGCIIngress(basedir, netconf.gci, netconf.rpcAddrs, netconf.chainName); | ||
|
||
if (chainConfig === undefined) { | ||
console.log('Writing', actualConfig, 'to', cache); | ||
fs.writeFileSync(cache, actualConfig); | ||
} | ||
return 0; | ||
} | ||
|
||
export default addChain; |
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