WIPP
This commit is contained in:
parent
0bf54fa1d8
commit
30071151ff
6 changed files with 107 additions and 242 deletions
|
|
@ -30,8 +30,8 @@ const coins = {
|
|||
ETH: {unitScale: 18}
|
||||
}
|
||||
|
||||
function plugins (settings) {
|
||||
function buildRates (deviceId, tickers) {
|
||||
function plugins (settings, deviceId) {
|
||||
function buildRates (tickers) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
const cryptoCodes = config.cryptoCurrencies
|
||||
const cashOut = config.cashOutEnabled
|
||||
|
|
@ -41,6 +41,7 @@ function plugins (settings) {
|
|||
|
||||
const rates = {}
|
||||
|
||||
console.log('DEBUG444: %j', tickers)
|
||||
cryptoCodes.forEach((cryptoCode, i) => {
|
||||
const rateRec = tickers[i]
|
||||
if (Date.now() - rateRec.timestamp > STALE_TICKER) return logger.warn('Stale rate for ' + cryptoCode)
|
||||
|
|
@ -54,7 +55,7 @@ function plugins (settings) {
|
|||
return rates
|
||||
}
|
||||
|
||||
function buildBalances (deviceId, balanceRecs) {
|
||||
function buildBalances (balanceRecs) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
const cryptoCodes = config.cryptoCurrencies
|
||||
|
||||
|
|
@ -97,7 +98,7 @@ function plugins (settings) {
|
|||
.then(row => row.id)
|
||||
}
|
||||
|
||||
function pollQueries (deviceTime, deviceId, deviceRec) {
|
||||
function pollQueries (deviceTime, deviceRec) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
const fiatCode = config.fiatCurrency
|
||||
const cryptoCodes = config.cryptoCurrencies
|
||||
|
|
@ -106,8 +107,8 @@ function plugins (settings) {
|
|||
const virtualCartridges = [config.virtualCashOutDenomination]
|
||||
|
||||
const tickerPromises = cryptoCodes.map(c => ticker.getRates(settings, fiatCode, c))
|
||||
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c, deviceId))
|
||||
const pingPromise = recordPing(deviceId, deviceTime, deviceRec)
|
||||
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
||||
const pingPromise = recordPing(deviceTime, deviceRec)
|
||||
const currentConfigVersionPromise = fetchCurrentConfigVersion()
|
||||
|
||||
const promises = [
|
||||
|
|
@ -125,8 +126,8 @@ function plugins (settings) {
|
|||
|
||||
return {
|
||||
cartridges: buildCartridges(cartridges, virtualCartridges, cartridgeCounts),
|
||||
rates: buildRates(deviceId, tickers),
|
||||
balances: buildBalances(deviceId, balances),
|
||||
rates: buildRates(tickers),
|
||||
balances: buildBalances(balances),
|
||||
currentConfigVersion
|
||||
}
|
||||
})
|
||||
|
|
@ -134,23 +135,12 @@ function plugins (settings) {
|
|||
|
||||
// NOTE: This will fail if we have already sent coins because there will be
|
||||
// a unique dbm record in the table already.
|
||||
function sendCoins (deviceId, tx) {
|
||||
return dbm.addOutgoingTx(deviceId, tx)
|
||||
.then(() => wallet.sendCoins(settings, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||
.then(txHash => {
|
||||
const fee = null // Need to fill this out in plugins
|
||||
const toSend = {cryptoAtoms: tx.cryptoAtoms, fiat: tx.fiat}
|
||||
|
||||
return dbm.sentCoins(tx, toSend, fee, null, txHash)
|
||||
.then(() => ({
|
||||
statusCode: 201, // Created
|
||||
txHash,
|
||||
txId: tx.id
|
||||
}))
|
||||
})
|
||||
function sendCoins (tx) {
|
||||
console.log('DEBUG50: %j', settings)
|
||||
return wallet.sendCoins(settings, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode)
|
||||
}
|
||||
|
||||
function trade (deviceId, rawTrade) {
|
||||
function trade (rawTrade) {
|
||||
// TODO: move this to dbm, too
|
||||
// add bill to trader queue (if trader is enabled)
|
||||
const cryptoCode = rawTrade.cryptoCode
|
||||
|
|
@ -174,18 +164,18 @@ function plugins (settings) {
|
|||
})
|
||||
}
|
||||
|
||||
function recordPing (deviceId, deviceTime, rec) {
|
||||
function recordPing (deviceTime, rec) {
|
||||
const event = {
|
||||
id: uuid.v4(),
|
||||
deviceId: deviceId,
|
||||
deviceId,
|
||||
eventType: 'ping',
|
||||
note: JSON.stringify({state: rec.state, isIdle: rec.idle === 'true', txId: rec.txId}),
|
||||
deviceTime: deviceTime
|
||||
deviceTime
|
||||
}
|
||||
return dbm.machineEvent(event)
|
||||
}
|
||||
|
||||
function cashOut (deviceId, tx) {
|
||||
function cashOut (tx) {
|
||||
const cryptoCode = tx.cryptoCode
|
||||
|
||||
const serialPromise = wallet.supportsHD
|
||||
|
|
@ -210,7 +200,7 @@ function plugins (settings) {
|
|||
})
|
||||
}
|
||||
|
||||
function dispenseAck (deviceId, tx) {
|
||||
function dispenseAck (tx) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
const cartridges = [ config.topCashOutDenomination,
|
||||
config.bottomCashOutDenomination ]
|
||||
|
|
@ -218,7 +208,7 @@ function plugins (settings) {
|
|||
return dbm.addDispense(deviceId, tx, cartridges)
|
||||
}
|
||||
|
||||
function fiatBalance (fiatCode, cryptoCode, deviceId) {
|
||||
function fiatBalance (fiatCode, cryptoCode) {
|
||||
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||
|
||||
return Promise.all([
|
||||
|
|
@ -404,11 +394,11 @@ function plugins (settings) {
|
|||
return Promise.all(promises)
|
||||
}
|
||||
|
||||
function checkDeviceBalances (deviceId) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
function checkDeviceBalances (_deviceId) {
|
||||
const config = configManager.machineScoped(_deviceId, settings.config)
|
||||
const cryptoCodes = config.cryptoCurrencies
|
||||
const fiatCode = config.fiatCurrency
|
||||
const fiatBalancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c, deviceId))
|
||||
const fiatBalancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
||||
|
||||
return Promise.all(fiatBalancePromises)
|
||||
.then(arr => {
|
||||
|
|
@ -416,7 +406,7 @@ function plugins (settings) {
|
|||
fiatBalance: balance,
|
||||
cryptoCode: cryptoCodes[i],
|
||||
fiatCode,
|
||||
deviceId
|
||||
_deviceId
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue