add blockcypher [WIP]
This commit is contained in:
parent
b28c99aabb
commit
23458b6b56
10 changed files with 133 additions and 17 deletions
28
lib/plugins/zero-conf/blockcypher/blockcypher.js
Normal file
28
lib/plugins/zero-conf/blockcypher/blockcypher.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
const qs = require('querystring')
|
||||
const axios = require('axios')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
module.exports = {authorize}
|
||||
|
||||
function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
|
||||
const query = qs.stringify({
|
||||
token: account.token,
|
||||
includeConfidence: true,
|
||||
confidence: account.confidence
|
||||
})
|
||||
|
||||
const url = `https://api.blockcypher.com/v1/btc/main/addrs/${toAddress}?${query}`
|
||||
|
||||
return axios.get(url)
|
||||
.then(r => {
|
||||
const data = r.data
|
||||
const authorizedValue = _.sumBy('value', data.txrefs)
|
||||
|
||||
return cryptoAtoms.lte(authorizedValue)
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue