lamassu-server/packages/server/migrations/1617742522808-zeroConfLimit-migrate.js
siiky e10493abc6 Merge branch 'dev' into feat/lam-1291/stress-testing
* dev: (85 commits)
  chore: console.log debug leftovers
  fix: third level navigation links
  fix: show subheader on refresh
  fix: machines/:id routing
  fix: customer route
  chore: update wallet nodes
  feat: shorten long addresses in funding page
  feat: shorten long addresses
  refactor: support copied text different from presented text
  chore: udpate react, downshift and routing
  refactor: use Wizard component on first route
  fix: autocomplete component rendering
  feat: skip2fa option on .env
  fix: drop contraint before dropping index
  chore: stop using alias imports
  fix: re-instate urlResolver
  chore: server code formatting
  chore: reformat code
  chore: adding eslint and prettier config
  chore: typo
  ...
2025-05-20 11:59:44 +01:00

50 lines
1.6 KiB
JavaScript

const _ = require('lodash/fp')
var db = require('../lib/db')
const settingsLoader = require('../lib/new-settings-loader')
const configManager = require('../lib/new-config-manager')
exports.up = function (next) {
return db
.tx(async t => {
const settingsPromise = settingsLoader.loadLatestConfig()
const machinesPromise = t.any('SELECT device_id FROM devices')
const [config, machines] = await Promise.all([
settingsPromise,
machinesPromise,
])
const cryptoCodes = configManager.getCryptosFromWalletNamespace(config)
const deviceIds = _.map(_.get('device_id'))(machines)
const getZeroConfLimit = _.compose(_.get('zeroConfLimit'), it =>
configManager.getCashOut(it, config),
)
const zeroConfLimits = _.map(getZeroConfLimit)(deviceIds)
const configMin = _.min(zeroConfLimits)
const smallerZeroConf = _.isFinite(configMin) ? Number(configMin) : 0
_.forEach(cryptoCode => {
const walletConfig = configManager.getWalletSettings(cryptoCode, config)
const zeroConfLimit = _.get('zeroConfLimit', walletConfig)
if (_.isNil(zeroConfLimit)) {
config[`wallets_${cryptoCode}_zeroConfLimit`] = smallerZeroConf
}
}, cryptoCodes)
_.forEach(deviceId => {
const key = `cashOut_${deviceId}_zeroConfLimit`
if (_.has(key, config)) {
config[key] = null
}
})(deviceIds)
return settingsLoader.migrationSaveConfig(config)
})
.then(() => next())
.catch(err => next(err))
}
exports.down = function (next) {
next()
}