fix up crypto services

This commit is contained in:
Josh Harvey 2016-12-09 00:10:18 +02:00
parent e24da06a1b
commit 1b89ed5c76
9 changed files with 82 additions and 46 deletions

View file

@ -1,13 +1,11 @@
const mem = require('mem')
const configManager = require('./config-manager')
const settingsLoader = require('./settings-loader')
const FETCH_INTERVAL = 5000
function fetchWallet (cryptoCode) {
function fetchWallet (settings, cryptoCode) {
return Promise.resolve()
.then(() => {
const settings = settingsLoader.settings()
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).wallet
const account = settings.accounts[plugin]
const wallet = require('lamassu-' + plugin)
@ -16,14 +14,14 @@ function fetchWallet (cryptoCode) {
})
}
function balance (cryptoCode) {
return fetchWallet(cryptoCode)
function balance (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.balance(r.account, cryptoCode))
.then(balance => ({balance, timestamp: Date.now()}))
}
function sendCoins (toAddress, cryptoAtoms, cryptoCode) {
return fetchWallet(cryptoCode)
function sendCoins (settings, toAddress, cryptoAtoms, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => {
return r.wallet.sendCoins(r.account, toAddress, cryptoAtoms, cryptoCode)
.then(res => {
@ -33,13 +31,13 @@ function sendCoins (toAddress, cryptoAtoms, cryptoCode) {
})
}
function newAddress (cryptoCode, info) {
return fetchWallet(cryptoCode)
function newAddress (settings, cryptoCode, info) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.newAddress(r.account, cryptoCode, info))
}
function getStatus (toAddress, cryptoAtoms, cryptoCode) {
return fetchWallet(cryptoCode)
function getStatus (settings, toAddress, cryptoAtoms, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.getStatus(r.account, toAddress, cryptoAtoms, cryptoCode))
}