WIP
This commit is contained in:
parent
259b527214
commit
0a2d2f658e
6 changed files with 90 additions and 61 deletions
|
|
@ -27,9 +27,11 @@ if (!httpOnly) {
|
||||||
|
|
||||||
options.mock = argv.mock
|
options.mock = argv.mock
|
||||||
|
|
||||||
var server = createServer(options)
|
console.log('DEBUG23')
|
||||||
|
|
||||||
server.listen(port, function () {
|
createServer(options)
|
||||||
console.log('lamassu-server listening on port ' + port + ' ' +
|
.then(server => {
|
||||||
(httpOnly ? '(http)' : '(https)'))
|
console.log('DEBUG22')
|
||||||
|
return server.listen(port, () => console.log('lamassu-server listening on port ' +
|
||||||
|
port + ' ' + (httpOnly ? '(http)' : '(https)')))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
12
lib/app.js
12
lib/app.js
|
|
@ -24,16 +24,22 @@ module.exports = function (options) {
|
||||||
|
|
||||||
console.log('DEBUG6')
|
console.log('DEBUG6')
|
||||||
|
|
||||||
configManager.load()
|
return configManager.load()
|
||||||
.then(config => {
|
.then(config => {
|
||||||
console.log('DEBUG5: %j', config)
|
console.log('DEBUG5: %j', config)
|
||||||
|
console.log('DEBUG8 ****************')
|
||||||
|
|
||||||
plugins.configure(config)
|
plugins.configure(config)
|
||||||
|
console.log('DEBUG9.1 ****************')
|
||||||
plugins.startPolling()
|
plugins.startPolling()
|
||||||
|
console.log('DEBUG9.2 ****************')
|
||||||
plugins.startCheckingNotification()
|
plugins.startCheckingNotification()
|
||||||
})
|
console.log('DEBUG9.3 ****************')
|
||||||
|
|
||||||
app.use(bodyParser.json())
|
app.use(bodyParser.json())
|
||||||
|
|
||||||
|
console.log('DEBUG9 ****************')
|
||||||
|
|
||||||
var authMiddleware
|
var authMiddleware
|
||||||
|
|
||||||
if (options.https) {
|
if (options.https) {
|
||||||
|
|
@ -69,6 +75,7 @@ module.exports = function (options) {
|
||||||
var localServer = http.createServer(localApp)
|
var localServer = http.createServer(localApp)
|
||||||
var localPort = 7070
|
var localPort = 7070
|
||||||
|
|
||||||
|
console.log('DEBUG7 ****************')
|
||||||
routes.init({
|
routes.init({
|
||||||
app: app,
|
app: app,
|
||||||
localApp: localApp,
|
localApp: localApp,
|
||||||
|
|
@ -83,4 +90,5 @@ module.exports = function (options) {
|
||||||
})
|
})
|
||||||
|
|
||||||
return server
|
return server
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ function fallbackValue (crypto, machine, instances) {
|
||||||
const pickValue = arr => R.find(instance => matchesValue(arr[0], arr[1], instance), instances)
|
const pickValue = arr => R.find(instance => matchesValue(arr[0], arr[1], instance), instances)
|
||||||
console.log('DEBUG11: %j', permutations(crypto, machine))
|
console.log('DEBUG11: %j', permutations(crypto, machine))
|
||||||
console.log('DEBUG14: %j', R.map(pickValue, permutations(crypto, machine)))
|
console.log('DEBUG14: %j', R.map(pickValue, permutations(crypto, machine)))
|
||||||
return R.find(notNil, R.map(pickValue, permutations(crypto, machine)))
|
const fallbackRec = R.find(notNil, R.map(pickValue, permutations(crypto, machine)))
|
||||||
|
return fallbackRec && fallbackRec.fieldValue.value
|
||||||
}
|
}
|
||||||
|
|
||||||
function generalScoped (crypto, machine, config) {
|
function generalScoped (crypto, machine, config) {
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,6 @@ const TRADE_INTERVAL = T.minute
|
||||||
const TRADE_TTL = 5 * T.minutes
|
const TRADE_TTL = 5 * T.minutes
|
||||||
const LOW_BALANCE_MARGIN_DEFAULT = 1.05
|
const LOW_BALANCE_MARGIN_DEFAULT = 1.05
|
||||||
|
|
||||||
let cryptoCodes = null
|
|
||||||
|
|
||||||
const tickerPlugins = {}
|
const tickerPlugins = {}
|
||||||
const traderPlugins = {}
|
const traderPlugins = {}
|
||||||
const walletPlugins = {}
|
const walletPlugins = {}
|
||||||
|
|
@ -167,13 +165,22 @@ exports.loadOrConfigPlugin = loadOrConfigPlugin
|
||||||
|
|
||||||
// Note: this whole function gets called every time there's a config update
|
// Note: this whole function gets called every time there's a config update
|
||||||
exports.configure = function configure (config) {
|
exports.configure = function configure (config) {
|
||||||
|
console.log('DEBUG40')
|
||||||
console.log('DEBUG4: %j', config)
|
console.log('DEBUG4: %j', config)
|
||||||
|
|
||||||
cachedConfig = config
|
cachedConfig = config
|
||||||
|
|
||||||
|
console.log('DEBUG41')
|
||||||
|
|
||||||
const accounts = configManager.loadAccounts()
|
const accounts = configManager.loadAccounts()
|
||||||
|
|
||||||
|
console.log('DEBUG42')
|
||||||
deviceCurrency = config.fiat.fiatCurrency
|
deviceCurrency = config.fiat.fiatCurrency
|
||||||
cryptoCodes = config.crypto.cryptoCurrencies
|
// cryptoCodes = config.crypto.cryptoCurrencies TODO: add to admin
|
||||||
|
console.log('DEBUG43')
|
||||||
|
const cryptoCodes = getCryptoCodes()
|
||||||
|
|
||||||
|
console.log('DEBUG30')
|
||||||
|
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
const cryptoScopedConfig = config.cryptoScoped(cryptoCode, cachedConfig)
|
const cryptoScopedConfig = config.cryptoScoped(cryptoCode, cachedConfig)
|
||||||
|
|
@ -192,6 +199,8 @@ exports.configure = function configure (config) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.log('DEBUG31')
|
||||||
|
|
||||||
// Give each crypto a different derived seed so as not to allow any
|
// Give each crypto a different derived seed so as not to allow any
|
||||||
// plugin to spend another plugin's funds
|
// plugin to spend another plugin's funds
|
||||||
const cryptoSeed = hkdf.derive(cryptoCode, 32)
|
const cryptoSeed = hkdf.derive(cryptoCode, 32)
|
||||||
|
|
@ -226,6 +235,8 @@ exports.configure = function configure (config) {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log('DEBUG32')
|
||||||
|
|
||||||
const unscopedCfg = config.unscoped(cachedConfig)
|
const unscopedCfg = config.unscoped(cachedConfig)
|
||||||
|
|
||||||
// ID VERIFIER [optional] configure (or load)
|
// ID VERIFIER [optional] configure (or load)
|
||||||
|
|
@ -252,6 +263,8 @@ exports.configure = function configure (config) {
|
||||||
unscopedCfg,
|
unscopedCfg,
|
||||||
accounts
|
accounts
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.log('DEBUG33')
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getConfig = function getConfig (machineId) {
|
exports.getConfig = function getConfig (machineId) {
|
||||||
|
|
@ -418,7 +431,7 @@ exports.fiatBalance = function fiatBalance (cryptoCode) {
|
||||||
const deviceRate = exports.getDeviceRate(cryptoCode)
|
const deviceRate = exports.getDeviceRate(cryptoCode)
|
||||||
if (!deviceRate) return null
|
if (!deviceRate) return null
|
||||||
const rawRate = deviceRate.rates.ask
|
const rawRate = deviceRate.rates.ask
|
||||||
const commission = cachedConfig.commissions.cashInCommission
|
const commission = new BigNumber(cachedConfig.commissions.cashInCommission).div(100)
|
||||||
const lastBalanceRec = lastBalances[cryptoCode]
|
const lastBalanceRec = lastBalances[cryptoCode]
|
||||||
if (!lastBalanceRec) return null
|
if (!lastBalanceRec) return null
|
||||||
const lastBalance = lastBalanceRec.balance
|
const lastBalance = lastBalanceRec.balance
|
||||||
|
|
@ -493,6 +506,7 @@ function monitorUnnotified () {
|
||||||
exports.startPolling = function startPolling () {
|
exports.startPolling = function startPolling () {
|
||||||
executeTrades()
|
executeTrades()
|
||||||
|
|
||||||
|
const cryptoCodes = getCryptoCodes()
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
setInterval(async.apply(pollBalance, cryptoCode), POLLING_RATE)
|
setInterval(async.apply(pollBalance, cryptoCode), POLLING_RATE)
|
||||||
setInterval(async.apply(pollRate, cryptoCode), POLLING_RATE)
|
setInterval(async.apply(pollRate, cryptoCode), POLLING_RATE)
|
||||||
|
|
@ -686,9 +700,11 @@ exports.verifyTx = function verifyTx (data, cb) {
|
||||||
idVerifierPlugin.verifyTransaction(data, cb)
|
idVerifierPlugin.verifyTransaction(data, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getcryptoCodes = function getcryptoCodes () {
|
function getCryptoCodes () {
|
||||||
return cryptoCodes
|
console.log('DEBUG17 TODO: generalize')
|
||||||
|
return ['BTC', 'ETC']
|
||||||
}
|
}
|
||||||
|
exports.getCryptoCodes = getCryptoCodes
|
||||||
|
|
||||||
function sendMessage (rec) {
|
function sendMessage (rec) {
|
||||||
const pluginPromises = []
|
const pluginPromises = []
|
||||||
|
|
@ -760,7 +776,7 @@ function checkNotification () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBalances () {
|
function checkBalances () {
|
||||||
const cryptoCodes = exports.getcryptoCodes()
|
const cryptoCodes = exports.getCryptoCodes()
|
||||||
|
|
||||||
const balances = []
|
const balances = []
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ const pids = {}
|
||||||
const reboots = {}
|
const reboots = {}
|
||||||
|
|
||||||
function buildRates (deviceId) {
|
function buildRates (deviceId) {
|
||||||
const cryptoCodes = plugins.getcryptoCodes()
|
const cryptoCodes = plugins.getCryptoCodes()
|
||||||
const config = plugins.getConfig(deviceId)
|
const config = plugins.getConfig(deviceId)
|
||||||
|
|
||||||
const cashInCommission = config.commissions.cashInCommission
|
const cashInCommission = new BigNumber(config.commissions.cashInCommission).div(100)
|
||||||
const cashOutCommission = config.commissions.cashOutCommission
|
const cashOutCommission = new BigNumber(config.commissions.cashOutCommission).div(100)
|
||||||
|
|
||||||
const rates = {}
|
const rates = {}
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
|
|
@ -42,7 +42,7 @@ function buildRates (deviceId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildBalances () {
|
function buildBalances () {
|
||||||
const cryptoCodes = plugins.getcryptoCodes()
|
const cryptoCodes = plugins.getCryptoCodes()
|
||||||
|
|
||||||
const _balances = {}
|
const _balances = {}
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
|
|
|
||||||
4
todo.txt
4
todo.txt
|
|
@ -92,5 +92,7 @@ options: configure per machine; configure per crypto/fiat
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
- convert result to actual value, not record
|
|
||||||
- default values
|
- default values
|
||||||
|
- server side validation, including required
|
||||||
|
- need to think hard about how to do required checks for scopes
|
||||||
|
- what to do if validation fails?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue