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

Replace init task with seed values #351

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/xud
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const Xud = require('../dist/Xud').default;

const { argv } = require('yargs')
.options({
initDb: {
describe: 'Whether to initialize the db with data',
type: 'boolean',
default: undefined,
},
xudir: {
describe: 'Data directory for xud',
type: 'string',
Expand Down
3 changes: 3 additions & 0 deletions instructions-for-devs.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Use `./xucli --help` to get up-to-date, optional command line arguments to overr
Options:
--help Show help [boolean]
--version Show version number [boolean]
--initDb Whether to initialize the db with data [boolean]
--xudir, -x Data directory for xud [string]
--db.database SQL database name [string]
--db.host Hostname for SQL database [string]
Expand Down Expand Up @@ -134,6 +135,8 @@ Examples:
This *optional* configuration file uses [TOML](https://github.com/toml-lang/toml) and by default should be saved at `~/.xud/xud.conf` on Linux or `AppData\Local\Xud\xud.conf` on Windows (run `xud` at least once for this folder to be created). All options with default values are shown below.

```toml
initDb = true # Whether to initalize a new database with default values

[rpc]
port = 8886
host = "localhost"
Expand Down
2 changes: 2 additions & 0 deletions lib/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Config {
public raiden: RaidenClientConfig;
public webproxy: { port: number, disable: boolean };
public instanceId = 0;
public initDb: boolean;

constructor(private args?: Arguments | Object) {
const platform = os.platform();
Expand All @@ -46,6 +47,7 @@ class Config {
}

// default configuration
this.initDb = true;
this.p2p = {
listen: true,
port: 8885, // X = 88, U = 85 in ASCII
Expand Down
16 changes: 15 additions & 1 deletion lib/db/DB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Bluebird from 'bluebird';

import Logger from '../Logger';
import { db } from '../types';
import { SwapProtocol } from '../types/enums';

type SequelizeConfig = {
host: string;
Expand Down Expand Up @@ -68,7 +69,8 @@ class DB {
]);

if (newDb) {
// populate new databases with seed nodes
// populate new databases with default data
// TODO: make seed peers configurable
await Node.bulkCreate(<db.NodeAttributes[]>[
{
nodePubKey: '02b66438730d1fcdf4a4ae5d3d73e847a272f160fee2938e132b52cab0a0d9cfc6',
Expand All @@ -83,6 +85,18 @@ class DB {
addresses: [{ host: 'xud3.test.exchangeunion.com', port: 8885 }],
},
]);

await Currency.bulkCreate(<db.CurrencyAttributes[]>[
{ id: 'BTC' },
{ id: 'LTC' },
{ id: 'ZRX' },
{ id: 'GNT' },
]);

await Pair.bulkCreate(<db.PairAttributes[]>[
{ baseCurrency: 'BTC', quoteCurrency: 'LTC', swapProtocol: SwapProtocol.LND },
{ baseCurrency: 'ZRX', quoteCurrency: 'GNT', swapProtocol: SwapProtocol.RAIDEN },
]);
}
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"scripts": {
"compile": "cross-os precompile && tsc && cross-os postcompile",
"compile:watch": "tsc -w",
"db:init": "gulp db.init",
"dev": "npm run compile && npm start",
"dev:watch": "concurrently --kill-others \"npm run compile:watch\" \"npm run nodemon:watch\"",
"docs": "typedoc --out typedoc --module commonjs --target es6 lib",
Expand Down
33 changes: 0 additions & 33 deletions tasks/db/init.ts

This file was deleted.