WIP
This commit is contained in:
parent
f62e65fe93
commit
bd3441adfb
4 changed files with 43 additions and 21 deletions
|
|
@ -46,7 +46,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"code": "crypto-services",
|
||||
"code": "cryptoServices",
|
||||
"display": "Crypto services",
|
||||
"cryptoScope": "specific",
|
||||
"machineScope": "both",
|
||||
|
|
|
|||
|
|
@ -9,19 +9,31 @@ exports.connect = connect
|
|||
|
||||
function load () {
|
||||
var db = connect()
|
||||
return db.one('select data from user_config where type=$1', 'exchanges')
|
||||
return db.one('select data from user_config where type=$1', 'config')
|
||||
.then(function (data) {
|
||||
pgp.end()
|
||||
return data.data
|
||||
})
|
||||
}
|
||||
|
||||
function loadAccounts () {
|
||||
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
|
||||
const toPairs = r => [r.code, toFields(r.fields)]
|
||||
var db = connect()
|
||||
return db.one('select data from user_config where type=$1', 'accounts')
|
||||
.then(function (data) {
|
||||
pgp.end()
|
||||
return R.fromPairs(R.map(toPairs, data.data.accounts))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
load,
|
||||
unscoped,
|
||||
cryptoScoped,
|
||||
machineScoped,
|
||||
scoped
|
||||
scoped,
|
||||
loadAccounts
|
||||
}
|
||||
|
||||
function matchesValue (crypto, machine, instance) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ const tickerPlugins = {}
|
|||
const traderPlugins = {}
|
||||
const walletPlugins = {}
|
||||
let idVerifierPlugin = null
|
||||
let infoPlugin = null
|
||||
let emailPlugin = null
|
||||
let smsPlugin = null
|
||||
let hkdf = null
|
||||
|
|
@ -133,11 +132,9 @@ function loadPlugin (name, config) {
|
|||
return plugin
|
||||
}
|
||||
|
||||
function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, options,
|
||||
function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, cfg, accounts, options,
|
||||
onChangeCallback) {
|
||||
const currentName = cryptoCode
|
||||
? cachedConfig.exchanges.plugins.current[cryptoCode][pluginType]
|
||||
: cachedConfig.exchanges.plugins.current[pluginType]
|
||||
const currentName = cfg.cryptoServices[pluginType]
|
||||
|
||||
currentlyUsedPlugins[cryptoCode] = currentlyUsedPlugins[cryptoCode] || {}
|
||||
|
||||
|
|
@ -145,7 +142,7 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, options,
|
|||
|
||||
if (!currentName) pluginHandle = null
|
||||
else { // some plugins may be disabled
|
||||
const pluginConfig = cachedConfig.exchanges.plugins.settings[currentName] || {}
|
||||
const pluginConfig = accounts[currentName]
|
||||
|
||||
const mergedConfig = R.merge(pluginConfig, options)
|
||||
|
||||
|
|
@ -169,23 +166,26 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, options,
|
|||
exports.loadOrConfigPlugin = loadOrConfigPlugin
|
||||
|
||||
// Note: this whole function gets called every time there's a config update
|
||||
exports.configure = function configure (config) {
|
||||
exports.configure = function configure (cfg) {
|
||||
if (config.exchanges.settings.lowBalanceMargin < 1) {
|
||||
throw new Error('\'settings.lowBalanceMargin\' has to be >= 1')
|
||||
}
|
||||
|
||||
cachedConfig = config
|
||||
cachedConfig = cfg
|
||||
const accounts = config.loadAccounts()
|
||||
deviceCurrency = config.fiat.fiatCurrency
|
||||
cryptoCodes = config.crypto.cryptoCurrencies
|
||||
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
cryptoScopedConfig = config.cryptoScoped(cryptoCode, cachedConfig)
|
||||
const cryptoScopedConfig = config.cryptoScoped(cryptoCode, cachedConfig)
|
||||
|
||||
// TICKER [required] configure (or load)
|
||||
loadOrConfigPlugin(
|
||||
tickerPlugins[cryptoCode],
|
||||
'ticker',
|
||||
cryptoCode,
|
||||
cryptoScopedConfig,
|
||||
accounts,
|
||||
{currency: deviceCurrency},
|
||||
function onTickerChange (newTicker) {
|
||||
tickerPlugins[cryptoCode] = newTicker
|
||||
|
|
@ -201,6 +201,8 @@ exports.configure = function configure (config) {
|
|||
walletPlugins[cryptoCode],
|
||||
'transfer',
|
||||
cryptoCode,
|
||||
cryptoScopedConfig,
|
||||
accounts,
|
||||
{masterSeed: cryptoSeed},
|
||||
function onWalletChange (newWallet) {
|
||||
walletPlugins[cryptoCode] = newWallet
|
||||
|
|
@ -214,6 +216,8 @@ exports.configure = function configure (config) {
|
|||
traderPlugins[cryptoCode],
|
||||
'trader',
|
||||
cryptoCode,
|
||||
cryptoScopedConfig,
|
||||
accounts,
|
||||
null,
|
||||
function onTraderChange (newTrader) {
|
||||
traderPlugins[cryptoCode] = newTrader
|
||||
|
|
@ -223,25 +227,31 @@ exports.configure = function configure (config) {
|
|||
)
|
||||
})
|
||||
|
||||
const unscopedCfg = config.unscoped(cachedConfig)
|
||||
|
||||
// ID VERIFIER [optional] configure (or load)
|
||||
idVerifierPlugin = loadOrConfigPlugin(
|
||||
idVerifierPlugin,
|
||||
'idVerifier'
|
||||
)
|
||||
|
||||
infoPlugin = loadOrConfigPlugin(
|
||||
infoPlugin,
|
||||
'info'
|
||||
'idVerifier',
|
||||
null,
|
||||
unscopedCfg,
|
||||
accounts
|
||||
)
|
||||
|
||||
emailPlugin = loadOrConfigPlugin(
|
||||
emailPlugin,
|
||||
'email'
|
||||
'email',
|
||||
null,
|
||||
unscopedCfg,
|
||||
accounts
|
||||
)
|
||||
|
||||
smsPlugin = loadOrConfigPlugin(
|
||||
smsPlugin,
|
||||
'sms'
|
||||
'sms',
|
||||
null,
|
||||
unscopedCfg,
|
||||
accounts
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
2
todo.txt
2
todo.txt
|
|
@ -38,7 +38,7 @@ v update migrate-config to match lamassu.json schema
|
|||
- look into how each plugin is used
|
||||
- info plugin not used
|
||||
|
||||
- need either transitive closure of all cryptos accross machines,
|
||||
- need either transitive closure of all cryptos across machines,
|
||||
or add new plugin when needed
|
||||
- currently we're looking at all cryptos, so this is probably easier
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue