fix blockcypher bug
This commit is contained in:
parent
86955da2ad
commit
18a702dbf8
3 changed files with 7 additions and 11 deletions
|
|
@ -1,5 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.addressReceived = function addressReceived(address, confirmations, cb) {
|
||||
cb();
|
||||
};
|
||||
|
|
@ -4,8 +4,10 @@ const _ = require('lodash/fp')
|
|||
|
||||
module.exports = {authorize}
|
||||
|
||||
function isHighConfidence (confidence, txref) {
|
||||
return txref.confirmations > 0 || txref.confidence * 100 >= confidence ? txref.value : 0
|
||||
function highConfidence (confidence, txref) {
|
||||
if (txref.double_spend) return 0
|
||||
if (txref.confirmations > 0 || txref.confidence * 100 >= confidence) return txref.value
|
||||
return 0
|
||||
}
|
||||
|
||||
function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
|
|
@ -18,15 +20,14 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
|||
includeConfidence: true
|
||||
})
|
||||
|
||||
const confidence = account.confidence
|
||||
const confidence = account.confidenceFactor
|
||||
|
||||
const url = `https://api.blockcypher.com/v1/btc/main/addrs/${toAddress}?${query}`
|
||||
|
||||
console.log(url)
|
||||
return axios.get(url)
|
||||
.then(r => {
|
||||
const data = r.data
|
||||
const sumTxRefs = txrefs => _.sumBy(txref => isHighConfidence(confidence, txref), txrefs)
|
||||
const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs)
|
||||
|
||||
const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs)
|
||||
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ function errorHandler (err, req, res, next) {
|
|||
|
||||
const json = {error: err.message}
|
||||
|
||||
logger.error(err)
|
||||
if (statusCode >= 400) logger.error(err)
|
||||
|
||||
return res.status(statusCode).json(json)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue