This commit is contained in:
Josh Harvey 2016-03-29 17:58:27 +01:00
parent 7be7c3f8e6
commit 591ffcf162
4 changed files with 129 additions and 54 deletions

77
bin/ssu
View file

@ -4,14 +4,42 @@
var wreck = require('wreck')
var argv = process.argv.slice(2)
var Promise = require('es6-promise')
var pgp = require('pg-promise')({
promiseLib: Promise
})
var fs = require('fs')
var cmd = argv[0]
if (!cmd) bail()
function bail () {
console.log('Command line utility for lamassu-server')
console.log('\nssu reboot <machine-fingerprint>')
console.log('This will remotely reboot your lamassu-machine.')
console.log('\nssu crypto <code> <ticker-plugin> <wallet-plugin>')
console.log('This will configure a new cryptocurrency.')
process.exit(1)
}
switch (cmd) {
case 'reboot':
reboot()
break
case 'crypto':
crypto()
break
default:
}
function reboot () {
var fingerprint = argv[1]
if (!cmd || !fingerprint) {
console.log('Command line utility for lamassu-server')
console.log('\nUsage: ssu reboot <machine-fingerprint>')
console.log('This will remotely reboot your lamassu-machine.')
if (!fingerprint) {
console.log('Fingerprint required')
process.exit(1)
}
@ -81,3 +109,44 @@ wreck.get('http://localhost:7070/pid?fingerprint=' + fingerprint, opts, function
}, 5000)
})
})
}
function crypto () {
var code = argv[1]
var tickerPlugin = argv[2]
var walletPlugin = argv[3]
if (!code || !tickerPlugin || !walletPlugin) {
console.log('\nssu crypto <code> <ticker-plugin> <wallet-plugin>')
console.log('This will configure a new cryptocurrency.')
process.exit(1)
}
code = code.toUpperCase()
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
config.exchanges.plugins.current[code] = {
ticker: tickerPlugin,
transfer: walletPlugin
}
return db.none('update user_config set data=$1 where type=$2', [config, 'exchanges'])
})
.then(function () {
console.log('success')
pgp.end()
})
.catch(function (err) {
console.log(err.stack)
pgp.end()
})
}

View file

@ -2,7 +2,10 @@
var _ = require('lodash')
var async = require('async')
var BigNumber = require('bignumber.js')
BigNumber.config({DECIMAL_PLACES: 40})
var logger = require('./logger')
var argv = require('minimist')(process.argv.slice(2))

View file

@ -1,8 +1,9 @@
require('es6-promise').polyfill()
var axios = require('axios')
var _ = require('lodash')
var BigNumber = require('bignumber.js')
BigNumber.config({DECIMAL_PLACES: 30})
BigNumber.config({DECIMAL_PLACES: 40})
exports.NAME = 'Kraken'
exports.SUPPORTED_MODULES = ['ticker']

View file

@ -35,7 +35,9 @@
"lodash": "^2.4.1",
"minimist": "0.0.8",
"node-uuid": "^1.4.2",
"pg": "~2.11.1",
"pg": "^4.5.1",
"pg-promise": "^3.4.3",
"web3": "^0.15.3",
"wreck": "5.1.0"
},
"repository": {