fix crypto defaults
This commit is contained in:
parent
b6fce47069
commit
6759bec826
3 changed files with 27 additions and 14 deletions
|
|
@ -41,15 +41,11 @@ function atomic (machineTx, pi) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function post (machineTx, pi) {
|
function post (machineTx, pi) {
|
||||||
const pp = require('./pp')
|
|
||||||
pp('DEBUG98')(machineTx)
|
|
||||||
|
|
||||||
return db.tx(atomic(machineTx, pi))
|
return db.tx(atomic(machineTx, pi))
|
||||||
.then(txVector => {
|
.then(txVector => {
|
||||||
const [, updatedTx] = txVector
|
const [, updatedTx] = txVector
|
||||||
|
|
||||||
return postProcess(txVector, pi)
|
return postProcess(txVector, pi)
|
||||||
.then(_.tap(pp('DEBUG99')))
|
|
||||||
.then(changes => update(updatedTx, changes))
|
.then(changes => update(updatedTx, changes))
|
||||||
.then(tx => _.set('bills', machineTx.bills, tx))
|
.then(tx => _.set('bills', machineTx.bills, tx))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const pify = require('pify')
|
||||||
const pgp = require('pg-promise')()
|
const pgp = require('pg-promise')()
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
const configValidate = require('./config-validate')
|
const configValidate = require('./config-validate')
|
||||||
|
const schema = require('../lamassu-schema.json')
|
||||||
|
|
||||||
let settingsCache
|
let settingsCache
|
||||||
|
|
||||||
|
|
@ -167,21 +168,39 @@ function configDeleteField (scope, fieldCode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cryptoCodeDefaults (cryptoCode) {
|
function populateScopes (schema) {
|
||||||
const scope = {crypto: cryptoCode, machine: 'global'}
|
const scopeLookup = {}
|
||||||
const fieldCode = 'exchange'
|
_.forEach(r => {
|
||||||
const fieldType = 'account'
|
const scope = {
|
||||||
const fieldClass = 'exchange'
|
cryptoScope: r.cryptoScope,
|
||||||
const value = 'no-exchange'
|
machineScope: r.machineScope
|
||||||
|
}
|
||||||
|
|
||||||
return configAddField(scope, fieldCode, fieldType, fieldClass, value)
|
_.forEach(field => { scopeLookup[field] = scope }, r.fields)
|
||||||
|
}, schema.groups)
|
||||||
|
|
||||||
|
return _.map(r => _.assign(scopeLookup[r.code], r), schema.fields)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cryptoCodeDefaults (schema, cryptoCode) {
|
||||||
|
const scope = {crypto: cryptoCode, machine: 'global'}
|
||||||
|
|
||||||
|
const schemaEntries = populateScopes(schema)
|
||||||
|
const hasCryptoSpecificDefault = r => r.cryptoScope === 'specific' && !_.isNil(r.default)
|
||||||
|
const cryptoSpecificFields = _.filter(hasCryptoSpecificDefault, schemaEntries)
|
||||||
|
|
||||||
|
return _.map(r => {
|
||||||
|
return configAddField(scope, r.code, r.fieldType, r.fieldClass, r.default)
|
||||||
|
}, cryptoSpecificFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCryptoDefaults (oldConfig, newFields) {
|
function addCryptoDefaults (oldConfig, newFields) {
|
||||||
const cryptoCodeEntries = _.filter(v => v.fieldLocator.code === 'cryptoCurrencies', newFields)
|
const cryptoCodeEntries = _.filter(v => v.fieldLocator.code === 'cryptoCurrencies', newFields)
|
||||||
const cryptoCodes = _.map(v => v.fieldValue.value, cryptoCodeEntries)
|
const cryptoCodes = _.map(v => v.fieldValue.value, cryptoCodeEntries)
|
||||||
const uniqueCryptoCodes = _.uniq(_.flatten(cryptoCodes))
|
const uniqueCryptoCodes = _.uniq(_.flatten(cryptoCodes))
|
||||||
const defaults = _.map(cryptoCodeDefaults, uniqueCryptoCodes)
|
|
||||||
|
const mapDefaults = cryptoCode => cryptoCodeDefaults(schema, cryptoCode)
|
||||||
|
const defaults = _.flatten(_.map(mapDefaults, uniqueCryptoCodes))
|
||||||
|
|
||||||
return mergeValues(defaults, oldConfig)
|
return mergeValues(defaults, oldConfig)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,6 @@ function getWalletStatus (settings, tx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function authorizeZeroConf (settings, tx, machineId) {
|
function authorizeZeroConf (settings, tx, machineId) {
|
||||||
console.log('DEBUG330: %j', machineId)
|
|
||||||
const cryptoConfig = configManager.cryptoScoped(tx.cryptoCode, settings.config)
|
const cryptoConfig = configManager.cryptoScoped(tx.cryptoCode, settings.config)
|
||||||
const machineConfig = configManager.machineScoped(machineId, settings.config)
|
const machineConfig = configManager.machineScoped(machineId, settings.config)
|
||||||
const plugin = cryptoConfig.zeroConf
|
const plugin = cryptoConfig.zeroConf
|
||||||
|
|
@ -108,7 +107,6 @@ function getStatus (settings, tx, machineId) {
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
.then(([statusRec, isAuthorized, publishAge]) => {
|
.then(([statusRec, isAuthorized, publishAge]) => {
|
||||||
console.log('DEBUG301: %j', [statusRec, isAuthorized])
|
|
||||||
if (statusRec.status === 'authorized') {
|
if (statusRec.status === 'authorized') {
|
||||||
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
|
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
|
||||||
? 'published'
|
? 'published'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue