Skip to content

Commit

Permalink
replace init task with seed values
Browse files Browse the repository at this point in the history
This commit makes xud add seed values for pairs and currencies when a new database is created during startup. These are in addition to the seed nodes. An `initDb` config option can be set to `false` to disable initializing new databases with these seed values. This makes the `db:init` task obsolete.
  • Loading branch information
sangaman committed Aug 16, 2018
1 parent 7b7bafd commit ae10303
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 35 deletions.
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 @@ -133,6 +134,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). Default settings which can be overridden are shown below.
```toml
initDb = true # Whether to initalize a new database with default values
[rpc]
port = 8886
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: any;
public initDb: boolean;

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

// default configuration
this.instanceId = 0;
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 @@ -70,12 +71,25 @@ class DB {
]);

if (newDb) {
// populate new databases with seed nodes
// populate new databases with default data
// TODO: make seed peers configurable
await Host.bulkCreate(<db.HostAttributes[]>[
{ address: 'xud1.test.exchangeunion.com', port: 8885 },
{ address: 'xud2.test.exchangeunion.com', port: 8885 },
{ address: '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.

0 comments on commit ae10303

Please sign in to comment.