This commit is contained in:
Josh Harvey 2016-11-27 16:54:08 +02:00
parent 4184e99273
commit 493e669e6d
5 changed files with 198 additions and 196 deletions

View file

@ -1,12 +1,11 @@
const mem = require('mem')
const settingsLoader = require('./settings-loader')
const configManager = require('./config-manager')
const FETCH_INTERVAL = 5000
function fetchWallet (cryptoCode) {
return settingsLoader.settings()
.then(settings => {
function fetchWallet (settings, cryptoCode) {
return Promise.resolve()
.then(() => {
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).cryptoServices.wallet
const account = settings.accounts.plugin
const wallet = require('lamassu-' + plugin)
@ -15,8 +14,8 @@ function fetchWallet (cryptoCode) {
})
}
function balance (cryptoCode) {
return fetchWallet(cryptoCode)
function balance (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.balance(r.account))
.then(balance => ({balance, timestamp: Date.now()}))
}
@ -32,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 (toAdress, cryptoAtoms, cryptoCode) {
return fetchWallet(cryptoCode)
function getStatus (settings, toAdress, cryptoAtoms, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.getStatus(r.account, toAdress, cryptoAtoms, cryptoCode))
}