fix blockcypher bug
This commit is contained in:
parent
86955da2ad
commit
18a702dbf8
3 changed files with 7 additions and 11 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue