WIP
This commit is contained in:
parent
896bec93cb
commit
35cbb46688
6 changed files with 62 additions and 23 deletions
|
|
@ -1,8 +1,8 @@
|
|||
'use strict'
|
||||
|
||||
var fs = require('fs')
|
||||
var R = require('ramda')
|
||||
var async = require('async')
|
||||
|
||||
var BigNumber = require('bignumber.js')
|
||||
BigNumber.config({CRYPTO: true})
|
||||
|
||||
|
|
@ -34,6 +34,7 @@ var idVerifierPlugin = null
|
|||
var infoPlugin = null
|
||||
var emailPlugin = null
|
||||
var smsPlugin = null
|
||||
var masterSeed = null
|
||||
|
||||
var currentlyUsedPlugins = {}
|
||||
|
||||
|
|
@ -54,12 +55,8 @@ var alertFingerprint = null
|
|||
var lastAlertTime = null
|
||||
|
||||
// that's basically a constructor
|
||||
exports.init = function init (databaseHandle) {
|
||||
if (!databaseHandle) {
|
||||
throw new Error('\'db\' is required')
|
||||
}
|
||||
|
||||
db = databaseHandle
|
||||
exports.init = function init () {
|
||||
fs.readFileSync('seeds/seed.txt')
|
||||
}
|
||||
|
||||
function loadPlugin (name, config) {
|
||||
|
|
@ -121,7 +118,7 @@ function loadPlugin (name, config) {
|
|||
return plugin
|
||||
}
|
||||
|
||||
function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, currency,
|
||||
function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, options,
|
||||
onChangeCallback) {
|
||||
cryptoCode = cryptoCode || 'BTC'
|
||||
|
||||
|
|
@ -137,11 +134,11 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, currency,
|
|||
else { // some plugins may be disabled
|
||||
var pluginConfig = cachedConfig.exchanges.plugins.settings[currentName] || {}
|
||||
|
||||
if (currency) pluginConfig.currency = currency
|
||||
const mergedConfig = R.merge(pluginConfig, options)
|
||||
|
||||
if (pluginHandle && !pluginChanged) pluginHandle.config(pluginConfig)
|
||||
if (pluginHandle && !pluginChanged) pluginHandle.config(mergedConfig)
|
||||
else {
|
||||
pluginHandle = loadPlugin(currentName, pluginConfig)
|
||||
pluginHandle = loadPlugin(currentName, mergedConfig)
|
||||
currentlyUsedPlugins[cryptoCode] = currentlyUsedPlugins[cryptoCode] || {}
|
||||
currentlyUsedPlugins[cryptoCode][pluginType] = currentName
|
||||
logger.debug('[%s] plugin(%s) loaded: %s', cryptoCode, pluginType, pluginHandle.NAME ||
|
||||
|
|
@ -149,7 +146,7 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, currency,
|
|||
}
|
||||
}
|
||||
|
||||
if (typeof onChangeCallback === 'function') onChangeCallback(pluginHandle, currency)
|
||||
if (typeof onChangeCallback === 'function') onChangeCallback(pluginHandle)
|
||||
|
||||
return pluginHandle
|
||||
}
|
||||
|
|
@ -171,7 +168,7 @@ exports.configure = function configure (config) {
|
|||
tickerPlugins[cryptoCode],
|
||||
'ticker',
|
||||
cryptoCode,
|
||||
deviceCurrency, // device currency
|
||||
{currency: deviceCurrency},
|
||||
function onTickerChange (newTicker) {
|
||||
tickerPlugins[cryptoCode] = newTicker
|
||||
pollRate(cryptoCode)
|
||||
|
|
@ -183,7 +180,10 @@ exports.configure = function configure (config) {
|
|||
walletPlugins[cryptoCode],
|
||||
'transfer',
|
||||
cryptoCode,
|
||||
null,
|
||||
{
|
||||
nextCashOutSerialHD: db.nextCashOutSerialHD(cryptoCode),
|
||||
masterSeed: masterSeed
|
||||
},
|
||||
function onWalletChange (newWallet) {
|
||||
walletPlugins[cryptoCode] = newWallet
|
||||
pollBalance(cryptoCode)
|
||||
|
|
@ -360,8 +360,12 @@ exports.cashOut = function cashOut (session, tx) {
|
|||
walletPlugin.newAddress(tmpInfo, function (err, address) {
|
||||
if (err) return reject(err)
|
||||
|
||||
const newTx = R.assoc('toAddress', address, tx)
|
||||
return db.addInitialIncoming(session, newTx)
|
||||
const addressRec = R.is(String, address)
|
||||
? {address: address}
|
||||
: address
|
||||
|
||||
const newTx = R.assoc('toAddress', addressRec.address, tx)
|
||||
return db.addInitialIncoming(session, newTx, addressRec)
|
||||
.then(() => resolve(address))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue