WIP
This commit is contained in:
parent
0a8021691a
commit
3d9814398d
4 changed files with 683 additions and 253 deletions
|
|
@ -71,7 +71,7 @@ function loadPlugin (name, config) {
|
|||
const moduleMethods = {
|
||||
ticker: ['ticker'],
|
||||
trader: ['purchase', 'sell'],
|
||||
wallet: ['balance', 'sendBitcoins', 'newAddress'],
|
||||
wallet: ['balance', 'sendCoins', 'newAddress'],
|
||||
idVerifier: ['verifyUser', 'verifyTransaction'],
|
||||
info: ['checkAddress'],
|
||||
email: ['sendMessage']
|
||||
|
|
@ -290,19 +290,8 @@ exports.pollQueries = function pollQueries (deviceId) {
|
|||
}
|
||||
|
||||
function _sendCoins (toAddress, cryptoAtoms, cryptoCode) {
|
||||
return new Promise((resolve, reject) => {
|
||||
_sendCoinsCb(toAddress, cryptoAtoms, cryptoCode, (err, txHash) => {
|
||||
if (err) return reject(err)
|
||||
return resolve(txHash)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function _sendCoinsCb (toAddress, cryptoAtoms, cryptoCode, cb) {
|
||||
const walletPlugin = walletPlugins[cryptoCode]
|
||||
const transactionFee = null
|
||||
|
||||
walletPlugin.sendBitcoins(toAddress, cryptoAtoms, cryptoCode, transactionFee, cb)
|
||||
return walletPlugin.sendCoins(toAddress, cryptoAtoms.toNumber(), cryptoCode)
|
||||
}
|
||||
|
||||
// NOTE: This will fail if we have already sent coins because there will be
|
||||
|
|
@ -379,21 +368,21 @@ exports.cashOut = function cashOut (deviceId, tx) {
|
|||
: Promise.resolve()
|
||||
|
||||
return serialPromise
|
||||
.then(serialNumber => new Promise((resolve, reject) => {
|
||||
.then(serialNumber => {
|
||||
const tmpInfo = {
|
||||
label: 'TX ' + Date.now(),
|
||||
account: 'deposit',
|
||||
serialNumber
|
||||
}
|
||||
|
||||
walletPlugin.newAddress(tmpInfo, (err, address) => {
|
||||
if (err) return reject(err)
|
||||
|
||||
return walletPlugin.newAddress(tmpInfo)
|
||||
.then(address => {
|
||||
const newTx = R.assoc('toAddress', address, tx)
|
||||
|
||||
return db.addInitialIncoming(deviceId, newTx, address)
|
||||
.then(() => resolve(address))
|
||||
.then(() => address)
|
||||
})
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
exports.dispenseAck = function (deviceId, tx) {
|
||||
|
|
@ -531,24 +520,24 @@ function stopTrader (cryptoCode) {
|
|||
tradesQueues[cryptoCode] = []
|
||||
}
|
||||
|
||||
function pollBalance (cryptoCode, cb) {
|
||||
function pollBalance (cryptoCode) {
|
||||
logger.debug('[%s] collecting balance', cryptoCode)
|
||||
|
||||
const walletPlugin = walletPlugins[cryptoCode]
|
||||
|
||||
walletPlugin.balance((err, balance) => {
|
||||
if (err) {
|
||||
logger.error('[%s] Error loading balance: %s', cryptoCode, err.message)
|
||||
return cb && cb(err)
|
||||
}
|
||||
|
||||
return walletPlugin.balance()
|
||||
.then(balance => {
|
||||
const unitScale = new BigNumber(10).pow(coins[cryptoCode].unitScale)
|
||||
const coinBalance = new BigNumber(balance[cryptoCode])
|
||||
const scaledCoinBalance = coinBalance.div(unitScale)
|
||||
logger.debug('[%s] Balance update: %s', cryptoCode, scaledCoinBalance.toString())
|
||||
lastBalances[cryptoCode] = {timestamp: Date.now(), balance: coinBalance}
|
||||
|
||||
return cb && cb(null, lastBalances)
|
||||
return lastBalances
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('[%s] Error loading balance: %s', cryptoCode, err.message)
|
||||
return lastBalances
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue