Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rainbow Config refactoring #344

Closed
Kouprin opened this issue Sep 11, 2020 · 1 comment · Fixed by #412
Closed

Rainbow Config refactoring #344

Kouprin opened this issue Sep 11, 2020 · 1 comment · Fixed by #412
Assignees

Comments

@Kouprin
Copy link
Contributor

Kouprin commented Sep 11, 2020

We need to revisit Rainbow Config and refactor it completely.
The basic idea is to make Config filled with all default values for each required configuration and switch between the configurations.
A perfect example is https://github.com/near/near-cli/blob/master/config.js

@Kouprin Kouprin self-assigned this Sep 11, 2020
@ilblackdragon
Copy link
Contributor

Also should replace the argument stuff with yargs.

So in general something like this:

config.js:


function getConfig(env) {
    switch (env) {
        case 'mainnet':
            return {
                networkId: 'mainnet',
                nearNodeUrl: 'https://rpc.mainnet.near.org',
                ethNodeUrl: '',
            };
        case 'testnet':
            return {
                networkId: 'default',
                nearNodeUrl: 'https://rpc.testnet.near.org',
                ethNodeUrl: '',
            };
        case 'local':
            return {
                networkId: 'local',
                nearNodeUrl: 'http://localhost:3030',
                ethNodeUrl: 'http://localhost:',
                keyPath: `${process.env.HOME}/.near/local/validator_key.json`,
                masterAccount: 'test.near',
                nearEthClientId: 'client.test.near',
                nearEthProverId: 'prover.test.near',
            };
        default:
            throw Error(`Unconfigured environment '${env}'. Can be configured in src/config.js.`);
    }
}

module.exports = getConfig;

bin/rainbow-cli.js:

let config = require('../config')(process.env.NEAR_ENV || 'local');
yargs
    .strict()
    .scriptName('rainbow-cli')
    .option('nearNodeUrl', {
        desc: 'NEAR node URL',
        type: 'string',
        default: config.nearNodeUrl
    })
    .option('ethNodeUrl', {
        desc: 'ETH node URL',
        type: 'string',
        default: config.ethNodeUrl
    })
    .option('networkId', {
        desc: 'NEAR network ID, allows using different keys based on network',
        type: 'string',
        default: config.networkId
    })
    .option('masterAccount', {
        desc: 'NEAR master account',
        type: 'string',
        default: config.masterAccount
    })
    .option('keyPath', {
        desc: 'Key path for NEAR master account',
        type: 'string',
        default: config.masterAccount
    })
    .option('nearEthClientId', {
        desc: 'Account Id Ethereum Client on NEAR',
        type: 'string',
        default: config.nearEthClientId
    })
    .option('nearEthProverId', {
        desc: 'Account Id Ethereum Prover on NEAR',
        type: 'string',
        default: config.nearEthProverId
    })
    .middleware(require('../middleware/key-store'))
    .command(setupBridge)
    .config(config)
    .wrap(null)
    .argv;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants