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) {
|
||||
const pp = require('./pp')
|
||||
pp('DEBUG98')(machineTx)
|
||||
|
||||
return db.tx(atomic(machineTx, pi))
|
||||
.then(txVector => {
|
||||
const [, updatedTx] = txVector
|
||||
|
||||
return postProcess(txVector, pi)
|
||||
.then(_.tap(pp('DEBUG99')))
|
||||
.then(changes => update(updatedTx, changes))
|
||||
.then(tx => _.set('bills', machineTx.bills, tx))
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const pify = require('pify')
|
|||
const pgp = require('pg-promise')()
|
||||
const db = require('./db')
|
||||
const configValidate = require('./config-validate')
|
||||
const schema = require('../lamassu-schema.json')
|
||||
|
||||
let settingsCache
|
||||
|
||||
|
|
@ -167,21 +168,39 @@ function configDeleteField (scope, fieldCode) {
|
|||
}
|
||||
}
|
||||
|
||||
function cryptoCodeDefaults (cryptoCode) {
|
||||
const scope = {crypto: cryptoCode, machine: 'global'}
|
||||
const fieldCode = 'exchange'
|
||||
const fieldType = 'account'
|
||||
const fieldClass = 'exchange'
|
||||
const value = 'no-exchange'
|
||||
function populateScopes (schema) {
|
||||
const scopeLookup = {}
|
||||
_.forEach(r => {
|
||||
const scope = {
|
||||
cryptoScope: r.cryptoScope,
|
||||
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) {
|
||||
const cryptoCodeEntries = _.filter(v => v.fieldLocator.code === 'cryptoCurrencies', newFields)
|
||||
const cryptoCodes = _.map(v => v.fieldValue.value, cryptoCodeEntries)
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ function getWalletStatus (settings, tx) {
|
|||
}
|
||||
|
||||
function authorizeZeroConf (settings, tx, machineId) {
|
||||
console.log('DEBUG330: %j', machineId)
|
||||
const cryptoConfig = configManager.cryptoScoped(tx.cryptoCode, settings.config)
|
||||
const machineConfig = configManager.machineScoped(machineId, settings.config)
|
||||
const plugin = cryptoConfig.zeroConf
|
||||
|
|
@ -108,7 +107,6 @@ function getStatus (settings, tx, machineId) {
|
|||
|
||||
return Promise.all(promises)
|
||||
.then(([statusRec, isAuthorized, publishAge]) => {
|
||||
console.log('DEBUG301: %j', [statusRec, isAuthorized])
|
||||
if (statusRec.status === 'authorized') {
|
||||
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
|
||||
? 'published'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue