add coin activation and hot-loading
This commit is contained in:
parent
b440993159
commit
fefeedb086
2 changed files with 48 additions and 7 deletions
52
bin/ssu
52
bin/ssu
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
var chalk = require('chalk')
|
||||||
var wreck = require('wreck')
|
var wreck = require('wreck')
|
||||||
var argv = process.argv.slice(2)
|
var argv = process.argv.slice(2)
|
||||||
var Promise = require('es6-promise')
|
var Promise = require('es6-promise')
|
||||||
|
|
@ -9,19 +10,22 @@ var pgp = require('pg-promise')({
|
||||||
promiseLib: Promise
|
promiseLib: Promise
|
||||||
})
|
})
|
||||||
var inquirer = require('inquirer')
|
var inquirer = require('inquirer')
|
||||||
|
var R = require('ramda')
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
|
||||||
var cmd = argv[0]
|
var cmd = argv[0]
|
||||||
|
|
||||||
if (!cmd) bail()
|
if (!cmd) bail()
|
||||||
|
|
||||||
function bail () {
|
function bail (error) {
|
||||||
console.log('Command line utility for lamassu-server')
|
error = error || 'Command line utility for lamassu-server'
|
||||||
|
console.log(chalk.bold(error))
|
||||||
console.log('\nssu reboot <machine-fingerprint>')
|
console.log('\nssu reboot <machine-fingerprint>')
|
||||||
console.log('This will remotely reboot your lamassu-machine.')
|
console.log('This will remotely reboot your lamassu-machine.')
|
||||||
console.log('\nssu crypto <code> <ticker-plugin> <wallet-plugin> [<trader-plugin>]')
|
console.log('\nssu crypto <code> <ticker-plugin> <wallet-plugin> [<trader-plugin>]')
|
||||||
console.log('This will configure a new cryptocurrency.')
|
console.log('This will configure a new cryptocurrency.')
|
||||||
|
console.log('\nssu crypto <code> [on|off]')
|
||||||
|
console.log('This will activate or deactivate a cryptocurrency.')
|
||||||
console.log('\nssu config <plugin> <key>')
|
console.log('\nssu config <plugin> <key>')
|
||||||
console.log('Configure a plugin setting.')
|
console.log('Configure a plugin setting.')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
|
@ -38,7 +42,8 @@ switch (cmd) {
|
||||||
configure()
|
configure()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
bail('No such command: ' + cmd)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
function reboot () {
|
function reboot () {
|
||||||
|
|
@ -117,12 +122,45 @@ function reboot () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cryptoActivate (code, on) {
|
||||||
|
var psqlUrl
|
||||||
|
try {
|
||||||
|
psqlUrl = process.env.DATABASE_URL || JSON.parse(fs.readFileSync('/etc/lamassu.json')).postgresql
|
||||||
|
} catch (ex) {
|
||||||
|
psqlUrl = 'psql://lamassu:lamassu@localhost/lamassu'
|
||||||
|
}
|
||||||
|
var db = pgp(psqlUrl)
|
||||||
|
|
||||||
|
return db.one('select data from user_config where type=$1', 'exchanges')
|
||||||
|
.then(function (data) {
|
||||||
|
var config = data.data
|
||||||
|
if (on) {
|
||||||
|
config.exchanges.settings.coins = R.append(code, config.exchanges.settings.coins)
|
||||||
|
} else {
|
||||||
|
config.exchanges.settings.coins = R.without([code], config.exchanges.settings.coins)
|
||||||
|
}
|
||||||
|
db.none('update user_config set data=$1 where type=$2', [config, 'exchanges'])
|
||||||
|
db.none('notify "config_update"')
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
console.log('success')
|
||||||
|
pgp.end()
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
console.log(err.stack)
|
||||||
|
pgp.end()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function crypto () {
|
function crypto () {
|
||||||
var code = argv[1]
|
var code = argv[1]
|
||||||
var tickerPlugin = argv[2]
|
var tickerPlugin = argv[2]
|
||||||
var walletPlugin = argv[3]
|
var walletPlugin = argv[3]
|
||||||
var traderPlugin = argv[4]
|
var traderPlugin = argv[4]
|
||||||
|
|
||||||
|
if (code && tickerPlugin === 'on') return cryptoActivate(code, true)
|
||||||
|
if (code && tickerPlugin === 'off') return cryptoActivate(code, false)
|
||||||
|
|
||||||
if (!code || !tickerPlugin || !walletPlugin) {
|
if (!code || !tickerPlugin || !walletPlugin) {
|
||||||
console.log('\nssu crypto <code> <ticker-plugin> <wallet-plugin> [<trader-plugin>]')
|
console.log('\nssu crypto <code> <ticker-plugin> <wallet-plugin> [<trader-plugin>]')
|
||||||
console.log('This will configure a new cryptocurrency.')
|
console.log('This will configure a new cryptocurrency.')
|
||||||
|
|
@ -148,7 +186,8 @@ function crypto () {
|
||||||
trader: traderPlugin
|
trader: traderPlugin
|
||||||
}
|
}
|
||||||
config.exchanges.settings.coins = ['BTC', code]
|
config.exchanges.settings.coins = ['BTC', code]
|
||||||
return db.none('update user_config set data=$1 where type=$2', [config, 'exchanges'])
|
db.none('update user_config set data=$1 where type=$2', [config, 'exchanges'])
|
||||||
|
db.none('notify "config_update"')
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
console.log('success')
|
console.log('success')
|
||||||
|
|
@ -195,7 +234,8 @@ function configure () {
|
||||||
var config = data.data
|
var config = data.data
|
||||||
config.exchanges.plugins.settings[plugin] = config.exchanges.plugins.settings[plugin] || {}
|
config.exchanges.plugins.settings[plugin] = config.exchanges.plugins.settings[plugin] || {}
|
||||||
config.exchanges.plugins.settings[plugin][key] = value
|
config.exchanges.plugins.settings[plugin][key] = value
|
||||||
return db.none('update user_config set data=$1 where type=$2', [config, 'exchanges'])
|
db.none('update user_config set data=$1 where type=$2', [config, 'exchanges'])
|
||||||
|
db.none('notify "config_update"')
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
console.log('success')
|
console.log('success')
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
"axios": "^0.9.1",
|
"axios": "^0.9.1",
|
||||||
"bignumber.js": "^2.3.0",
|
"bignumber.js": "^2.3.0",
|
||||||
"bluebird": "^3.3.4",
|
"bluebird": "^3.3.4",
|
||||||
|
"chalk": "^1.1.3",
|
||||||
"es6-promise": "^3.1.2",
|
"es6-promise": "^3.1.2",
|
||||||
"ethereumjs-wallet": "^0.5.1",
|
"ethereumjs-wallet": "^0.5.1",
|
||||||
"express": "~3.4.7",
|
"express": "~3.4.7",
|
||||||
|
|
@ -39,10 +40,10 @@
|
||||||
"pg-promise": "^3.4.3",
|
"pg-promise": "^3.4.3",
|
||||||
"prompt": "^1.0.0",
|
"prompt": "^1.0.0",
|
||||||
"promptly": "^1.1.0",
|
"promptly": "^1.1.0",
|
||||||
"web3": "^0.15.3",
|
|
||||||
"ramda": "^0.19.1",
|
"ramda": "^0.19.1",
|
||||||
"smtp-connection": "^2.2.1",
|
"smtp-connection": "^2.2.1",
|
||||||
"twilio": "^3.3.0-edge",
|
"twilio": "^3.3.0-edge",
|
||||||
|
"web3": "^0.15.3",
|
||||||
"wreck": "5.1.0"
|
"wreck": "5.1.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue