format for latest standard
This commit is contained in:
parent
4108efd9c7
commit
c2af183911
77 changed files with 1697 additions and 1693 deletions
104
lib/wallet.js
104
lib/wallet.js
|
|
@ -30,14 +30,14 @@ function computeSeed (masterSeed) {
|
|||
|
||||
function fetchWallet (settings, cryptoCode) {
|
||||
return fs.readFile(options.seedPath, 'utf8')
|
||||
.then(hex => {
|
||||
const masterSeed = Buffer.from(hex.trim(), 'hex')
|
||||
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).wallet
|
||||
const wallet = ph.load(ph.WALLET, plugin)
|
||||
const account = settings.accounts[plugin]
|
||||
.then(hex => {
|
||||
const masterSeed = Buffer.from(hex.trim(), 'hex')
|
||||
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).wallet
|
||||
const wallet = ph.load(ph.WALLET, plugin)
|
||||
const account = settings.accounts[plugin]
|
||||
|
||||
return {wallet, account: _.set('seed', computeSeed(masterSeed), account)}
|
||||
})
|
||||
return {wallet, account: _.set('seed', computeSeed(masterSeed), account)}
|
||||
})
|
||||
}
|
||||
|
||||
const lastBalance = {}
|
||||
|
|
@ -45,54 +45,54 @@ const lastBalance = {}
|
|||
function _balance (settings, cryptoCode) {
|
||||
logger.debug('Polled wallet balance')
|
||||
return fetchWallet(settings, cryptoCode)
|
||||
.then(r => r.wallet.balance(r.account, cryptoCode))
|
||||
.then(balance => ({balance, timestamp: Date.now()}))
|
||||
.then(r => {
|
||||
lastBalance[cryptoCode] = r
|
||||
return r
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
return lastBalance[cryptoCode]
|
||||
})
|
||||
.then(r => r.wallet.balance(r.account, cryptoCode))
|
||||
.then(balance => ({balance, timestamp: Date.now()}))
|
||||
.then(r => {
|
||||
lastBalance[cryptoCode] = r
|
||||
return r
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
return lastBalance[cryptoCode]
|
||||
})
|
||||
}
|
||||
|
||||
function sendCoins (settings, toAddress, cryptoAtoms, cryptoCode) {
|
||||
return fetchWallet(settings, cryptoCode)
|
||||
.then(r => {
|
||||
return r.wallet.sendCoins(r.account, toAddress, cryptoAtoms, cryptoCode)
|
||||
.then(res => {
|
||||
mem.clear(module.exports.balance)
|
||||
return res
|
||||
.then(r => {
|
||||
return r.wallet.sendCoins(r.account, toAddress, cryptoAtoms, cryptoCode)
|
||||
.then(res => {
|
||||
mem.clear(module.exports.balance)
|
||||
return res
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.name === INSUFFICIENT_FUNDS_NAME) {
|
||||
throw httpError(INSUFFICIENT_FUNDS_NAME, INSUFFICIENT_FUNDS_CODE)
|
||||
}
|
||||
.catch(err => {
|
||||
if (err.name === INSUFFICIENT_FUNDS_NAME) {
|
||||
throw httpError(INSUFFICIENT_FUNDS_NAME, INSUFFICIENT_FUNDS_CODE)
|
||||
}
|
||||
|
||||
throw err
|
||||
})
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
function newAddress (settings, info) {
|
||||
return fetchWallet(settings, info.cryptoCode)
|
||||
.then(r => r.wallet.newAddress(r.account, info))
|
||||
.then(r => r.wallet.newAddress(r.account, info))
|
||||
}
|
||||
|
||||
function newFunding (settings, cryptoCode, address) {
|
||||
return fetchWallet(settings, cryptoCode)
|
||||
.then(r => {
|
||||
const wallet = r.wallet
|
||||
const account = r.account
|
||||
.then(r => {
|
||||
const wallet = r.wallet
|
||||
const account = r.account
|
||||
|
||||
return wallet.newFunding(account, cryptoCode)
|
||||
})
|
||||
return wallet.newFunding(account, cryptoCode)
|
||||
})
|
||||
}
|
||||
|
||||
function getWalletStatus (settings, tx) {
|
||||
return fetchWallet(settings, tx.cryptoCode)
|
||||
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||
}
|
||||
|
||||
function authorizeZeroConf (settings, tx, machineId) {
|
||||
|
|
@ -115,34 +115,34 @@ function authorizeZeroConf (settings, tx, machineId) {
|
|||
|
||||
function getStatus (settings, tx, machineId) {
|
||||
return getWalletStatus(settings, tx)
|
||||
.then((statusRec) => {
|
||||
if (statusRec.status === 'authorized') {
|
||||
return authorizeZeroConf(settings, tx, machineId)
|
||||
.then(isAuthorized => {
|
||||
const publishAge = Date.now() - tx.publishedAt
|
||||
.then((statusRec) => {
|
||||
if (statusRec.status === 'authorized') {
|
||||
return authorizeZeroConf(settings, tx, machineId)
|
||||
.then(isAuthorized => {
|
||||
const publishAge = Date.now() - tx.publishedAt
|
||||
|
||||
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
|
||||
? 'published'
|
||||
: 'rejected'
|
||||
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
|
||||
? 'published'
|
||||
: 'rejected'
|
||||
|
||||
const status = isAuthorized ? 'authorized' : unauthorizedStatus
|
||||
const status = isAuthorized ? 'authorized' : unauthorizedStatus
|
||||
|
||||
return {status}
|
||||
})
|
||||
}
|
||||
return {status}
|
||||
})
|
||||
}
|
||||
|
||||
return statusRec
|
||||
})
|
||||
return statusRec
|
||||
})
|
||||
}
|
||||
|
||||
function sweep (settings, cryptoCode, hdIndex) {
|
||||
return fetchWallet(settings, cryptoCode)
|
||||
.then(r => r.wallet.sweep(r.account, cryptoCode, hdIndex))
|
||||
.then(r => r.wallet.sweep(r.account, cryptoCode, hdIndex))
|
||||
}
|
||||
|
||||
function isHd (settings, cryptoCode) {
|
||||
return fetchWallet(settings, cryptoCode)
|
||||
.then(r => r.wallet.supportsHd)
|
||||
.then(r => r.wallet.supportsHd)
|
||||
}
|
||||
|
||||
function cryptoNetwork (settings, cryptoCode) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue