fix blockcypher plugin
This commit is contained in:
parent
8fd2c1a7d1
commit
e04ea6c796
2 changed files with 14 additions and 6 deletions
|
|
@ -4,6 +4,10 @@ const _ = require('lodash/fp')
|
||||||
|
|
||||||
module.exports = {authorize}
|
module.exports = {authorize}
|
||||||
|
|
||||||
|
function isHighConfidence (confidence, txref) {
|
||||||
|
return txref.confirmations > 0 || txref.confidence * 100 >= confidence ? txref.value : 0
|
||||||
|
}
|
||||||
|
|
||||||
function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
@ -11,18 +15,23 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
const query = qs.stringify({
|
const query = qs.stringify({
|
||||||
token: account.token,
|
token: account.token,
|
||||||
includeConfidence: true,
|
includeConfidence: true
|
||||||
confidence: account.confidence
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const confidence = account.confidence
|
||||||
|
|
||||||
const url = `https://api.blockcypher.com/v1/btc/main/addrs/${toAddress}?${query}`
|
const url = `https://api.blockcypher.com/v1/btc/main/addrs/${toAddress}?${query}`
|
||||||
|
|
||||||
|
console.log(url)
|
||||||
return axios.get(url)
|
return axios.get(url)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
const data = r.data
|
const data = r.data
|
||||||
const authorizedValue = _.sumBy('value', data.txrefs)
|
const sumTxRefs = txrefs => _.sumBy(txref => isHighConfidence(confidence, txref), txrefs)
|
||||||
|
|
||||||
|
const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs)
|
||||||
|
|
||||||
return cryptoAtoms.lte(authorizedValue)
|
return cryptoAtoms.lte(authorizedValue)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode)
|
if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||||
|
|
||||||
const authorizedValue = 1e5 * 2
|
const isAuthorized = true
|
||||||
console.log('DEBUG300: %j', cryptoAtoms.lte(authorizedValue))
|
return isAuthorized
|
||||||
return cryptoAtoms.lte(authorizedValue)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue