diff --git a/lib/blockchain_util.js b/lib/blockchain_util.js deleted file mode 100644 index 16eca5fa..00000000 --- a/lib/blockchain_util.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -exports.addressReceived = function addressReceived(address, confirmations, cb) { - cb(); -}; diff --git a/lib/plugins/zero-conf/blockcypher/blockcypher.js b/lib/plugins/zero-conf/blockcypher/blockcypher.js index adf1ce58..26b93c13 100644 --- a/lib/plugins/zero-conf/blockcypher/blockcypher.js +++ b/lib/plugins/zero-conf/blockcypher/blockcypher.js @@ -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) diff --git a/lib/routes.js b/lib/routes.js index 128d4a96..bec55979 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -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) }