format for latest standard

This commit is contained in:
Josh Harvey 2018-03-10 18:59:40 +00:00
parent 4108efd9c7
commit c2af183911
77 changed files with 1697 additions and 1693 deletions

View file

@ -7,7 +7,7 @@ var db = pgp(psqlUrl)
db.manyOrNone(`select * from transactions where incoming=false db.manyOrNone(`select * from transactions where incoming=false
and stage='final_request' and authority='machine'`) and stage='final_request' and authority='machine'`)
.then(rs => .then(rs =>
db.tx(t => db.tx(t =>
t.batch(rs.map(r => db.none(`insert into cash_in_txs (session_id, t.batch(rs.map(r => db.none(`insert into cash_in_txs (session_id,
device_fingerprint, to_address, crypto_atoms, crypto_code, fiat, device_fingerprint, to_address, crypto_atoms, crypto_code, fiat,
@ -17,10 +17,10 @@ db.manyOrNone(`select * from transactions where incoming=false
r.tx_hash, r.error, r.created])) r.tx_hash, r.error, r.created]))
) )
) )
) )
.then(() => db.manyOrNone(`select * from transactions where incoming=true .then(() => db.manyOrNone(`select * from transactions where incoming=true
and stage='initial_request' and authority='pending'`)) and stage='initial_request' and authority='pending'`))
.then(rs => .then(rs =>
db.tx(t => db.tx(t =>
t.batch(rs.map(r => db.none(`insert into cash_out_txs (session_id, t.batch(rs.map(r => db.none(`insert into cash_out_txs (session_id,
device_fingerprint, to_address, crypto_atoms, crypto_code, fiat, device_fingerprint, to_address, crypto_atoms, crypto_code, fiat,
@ -30,10 +30,10 @@ db.manyOrNone(`select * from transactions where incoming=false
r.tx_hash, r.phone, r.error, r.created])) r.tx_hash, r.phone, r.error, r.created]))
) )
) )
) )
.then(() => db.manyOrNone(`select * from transactions where incoming=true .then(() => db.manyOrNone(`select * from transactions where incoming=true
and stage='dispense' and authority='authorized'`)) and stage='dispense' and authority='authorized'`))
.then(rs => .then(rs =>
db.tx(t => db.tx(t =>
t.batch(rs.map(r => t.batch(rs.map(r =>
db.none(`update cash_out_txs set dispensed=true where session_id=$1`, [r.session_id]) db.none(`update cash_out_txs set dispensed=true where session_id=$1`, [r.session_id])
@ -41,10 +41,10 @@ db.manyOrNone(`select * from transactions where incoming=false
created) values ($1, $2, $3)`, [r.session_id, 'dispensed', r.created])) created) values ($1, $2, $3)`, [r.session_id, 'dispensed', r.created]))
)) ))
) )
) )
.then(() => pgp.end()) .then(() => pgp.end())
.then(() => console.log('Success.')) .then(() => console.log('Success.'))
.catch(e => { .catch(e => {
console.log(e) console.log(e)
pgp.end() pgp.end()
}) })

View file

@ -2,11 +2,11 @@ const settingsLoader = require('../lib/settings-loader')
const pp = require('../lib/pp') const pp = require('../lib/pp')
settingsLoader.loadLatest() settingsLoader.loadLatest()
.then(r => { .then(r => {
pp('config')(r) pp('config')(r)
process.exit(0) process.exit(0)
}) })
.catch(e => { .catch(e => {
console.log(e.stack) console.log(e.stack)
process.exit(1) process.exit(1)
}) })

View file

@ -8,7 +8,7 @@ const psqlUrl = require('../lib/options').postgresql
const db = pgp(psqlUrl) const db = pgp(psqlUrl)
db.many('select data from user_config', 'exchanges') db.many('select data from user_config', 'exchanges')
.then(rows => { .then(rows => {
const config = rows.filter(r => r.type === 'exchanges')[0].data const config = rows.filter(r => r.type === 'exchanges')[0].data
const brain = rows.filter(r => r.type === 'unit')[0].data const brain = rows.filter(r => r.type === 'unit')[0].data
const settings = config.exchanges.settings const settings = config.exchanges.settings
@ -42,4 +42,4 @@ db.many('select data from user_config', 'exchanges')
console.error('Error: %s', err) console.error('Error: %s', err)
process.exit(1) process.exit(1)
}) })
}) })

View file

@ -13,7 +13,7 @@ const headers = {
const body = JSON.stringify({tx: tx}) const body = JSON.stringify({tx: tx})
got('http://localhost:3000/dispense', {body: body, json: true, headers: headers}) got('http://localhost:3000/dispense', {body: body, json: true, headers: headers})
.then(res => { .then(res => {
console.log(res.body) console.log(res.body)
}) })
.catch(console.log) .catch(console.log)

View file

@ -15,7 +15,7 @@ db.init(psqlUrl)
notifier.init(db, getBalances, {lowBalanceThreshold: 10}) notifier.init(db, getBalances, {lowBalanceThreshold: 10})
console.log('DEBUG0') console.log('DEBUG0')
notifier.checkStatus() notifier.checkStatus()
.then(function (alertRec) { .then(function (alertRec) {
console.log('DEBUG1') console.log('DEBUG1')
console.log('%j', alertRec) console.log('%j', alertRec)
var subject = notifier.alertSubject(alertRec) var subject = notifier.alertSubject(alertRec)
@ -24,8 +24,8 @@ notifier.checkStatus()
console.log(body) console.log(body)
console.log(notifier.alertFingerprint(alertRec)) console.log(notifier.alertFingerprint(alertRec))
process.exit(0) process.exit(0)
}) })
.catch(function (err) { .catch(function (err) {
console.log(err.stack) console.log(err.stack)
process.exit(1) process.exit(1)
}) })

View file

@ -17,7 +17,7 @@ var rec = {
var db = config.connection var db = config.connection
config.loadConfig(db) config.loadConfig(db)
.then(function (config) { .then(function (config) {
plugins.configure(config) plugins.configure(config)
plugins.sendMessage(rec) plugins.sendMessage(rec)
.then(function () { .then(function () {
@ -26,4 +26,4 @@ config.loadConfig(db)
.catch(function (err) { .catch(function (err) {
console.log(err.stack) console.log(err.stack)
}) })
}) })

View file

@ -9,7 +9,6 @@ const schemas = ph.loadSchemas()
function fetchAccounts () { function fetchAccounts () {
return db.oneOrNone('select data from user_config where type=$1', ['accounts']) return db.oneOrNone('select data from user_config where type=$1', ['accounts'])
.then(row => { .then(row => {
// Hard code this for now // Hard code this for now
const accounts = [{ const accounts = [{
code: 'blockcypher', code: 'blockcypher',

View file

@ -65,7 +65,7 @@ function getField (schema, group, fieldCode) {
} }
const fetchMachines = () => machineLoader.getMachines() const fetchMachines = () => machineLoader.getMachines()
.then(machineList => machineList.map(r => r.deviceId)) .then(machineList => machineList.map(r => r.deviceId))
function validateCurrentConfig () { function validateCurrentConfig () {
return fetchConfig() return fetchConfig()

View file

@ -114,4 +114,3 @@ function run () {
inquirer.prompt(questions) inquirer.prompt(questions)
.then(answers => processCryptos(answers.crypto)) .then(answers => processCryptos(answers.crypto))
} }

View file

@ -16,4 +16,3 @@ function run () {
}) })
}) })
} }

View file

@ -505,13 +505,23 @@ function plugins (settings, deviceId) {
: null : null
const cassette1Alert = cashOutEnabled && device.cassette1 < config.cashOutCassette1AlertThreshold const cassette1Alert = cashOutEnabled && device.cassette1 < config.cashOutCassette1AlertThreshold
? {code: 'LOW_CASH_OUT', cassette: 1, machineName, deviceId: device.deviceId, ? {code: 'LOW_CASH_OUT',
notes: device.cassette1, denomination: denomination1, fiatCode} cassette: 1,
machineName,
deviceId: device.deviceId,
notes: device.cassette1,
denomination: denomination1,
fiatCode}
: null : null
const cassette2Alert = cashOutEnabled && device.cassette2 < config.cashOutCassette2AlertThreshold const cassette2Alert = cashOutEnabled && device.cassette2 < config.cashOutCassette2AlertThreshold
? {code: 'LOW_CASH_OUT', cassette: 2, machineName, deviceId: device.deviceId, ? {code: 'LOW_CASH_OUT',
notes: device.cassette2, denomination: denomination2, fiatCode} cassette: 2,
machineName,
deviceId: device.deviceId,
notes: device.cassette2,
denomination: denomination2,
fiatCode}
: null : null
return _.compact([cashInAlert, cassette1Alert, cassette2Alert]) return _.compact([cashInAlert, cassette1Alert, cassette2Alert])

View file

@ -2,7 +2,6 @@ const axios = require('axios')
const BN = require('../../../bn') const BN = require('../../../bn')
function ticker (account, fiatCode, cryptoCode) { function ticker (account, fiatCode, cryptoCode) {
return axios.get('https://bitpay.com/api/rates/' + cryptoCode + '/' + fiatCode) return axios.get('https://bitpay.com/api/rates/' + cryptoCode + '/' + fiatCode)
.then(r => { .then(r => {
const data = r.data const data = r.data

View file

@ -52,4 +52,3 @@ function ticker (account, fiatCode, cryptoCode) {
module.exports = { module.exports = {
ticker ticker
} }

View file

@ -35,4 +35,3 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
}) })
}) })
} }

View file

@ -182,7 +182,7 @@ function updateCustomer (req, res, next) {
const patch = req.body const patch = req.body
customers.getById(id) customers.getById(id)
.then(customer => { .then(customer => {
if (!customer) { throw httpError('Not Found', 404)} if (!customer) { throw httpError('Not Found', 404) }
return customers.update(id, patch) return customers.update(id, patch)
}) })
.then(customer => respond(req, res, {customer})) .then(customer => respond(req, res, {customer}))

View file

@ -6,7 +6,7 @@ const rawCountries = require('../raw-countries.json')
const topCodes = ['US', 'GB', 'CA', 'AU'] const topCodes = ['US', 'GB', 'CA', 'AU']
const countries = rawCountries const countries = rawCountries
.map(r => ({code: r.cca2, display: r.name.common})) .map(r => ({code: r.cca2, display: r.name.common}))
const topCountries = topCodes.map(c => countries.find(_.matchesProperty('code', c))) const topCountries = topCodes.map(c => countries.find(_.matchesProperty('code', c)))
const final = _.uniqBy(_.get('code'), _.concat(topCountries, countries)) const final = _.uniqBy(_.get('code'), _.concat(topCountries, countries))

View file

@ -5,7 +5,7 @@ const fields = [
] ]
settingsLoader.modifyConfig(fields) settingsLoader.modifyConfig(fields)
.then(() => { .then(() => {
console.log('success.') console.log('success.')
process.exit(0) process.exit(0)
}) })

View file

@ -15,11 +15,11 @@ function dbFetchConfig () {
} }
dbFetchConfig() dbFetchConfig()
.then(config => { .then(config => {
pp(config) pp(config)
process.exit(0) process.exit(0)
}) })
.catch(e => { .catch(e => {
console.log(e) console.log(e)
process.exit(1) process.exit(1)
}) })