Daniel Cousens
10 years ago
6 changed files with 41 additions and 71 deletions
@ -0,0 +1,23 @@ |
|||
var Blockchain = require('cb-http-client') |
|||
var httpify = require('httpify') |
|||
|
|||
var BLOCKTRAIL_API_KEY = process.env.BLOCKTRAIL_API_KEY || 'c0bd8155c66e3fb148bb1664adc1e4dacd872548' |
|||
|
|||
var mainnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/BTC', { api_key: BLOCKTRAIL_API_KEY }) |
|||
var testnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/tBTC', { api_key: BLOCKTRAIL_API_KEY }) |
|||
testnet.faucet = function faucet (address, amount, callback) { |
|||
httpify({ |
|||
method: 'POST', |
|||
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY, |
|||
headers: { 'Content-Type': 'application/json' }, |
|||
body: JSON.stringify({ |
|||
address: address, |
|||
amount: amount |
|||
}) |
|||
}, callback) |
|||
} |
|||
|
|||
module.exports = { |
|||
m: mainnet, |
|||
t: testnet |
|||
} |
@ -1,49 +0,0 @@ |
|||
var httpify = require('httpify') |
|||
|
|||
var BLOCKTRAIL_API_KEY = process.env.BLOCKTRAIL_API_KEY || 'c0bd8155c66e3fb148bb1664adc1e4dacd872548' |
|||
|
|||
function faucetWithdraw (address, amount, callback) { |
|||
httpify({ |
|||
method: 'POST', |
|||
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY, |
|||
headers: { 'Content-Type': 'application/json' }, |
|||
body: JSON.stringify({ |
|||
address: address, |
|||
amount: amount |
|||
}) |
|||
}, callback) |
|||
} |
|||
|
|||
function pollUnspent (blockchain, address, done) { |
|||
blockchain.addresses.unspents(address, function (err, unspents) { |
|||
if (err) return done(err) |
|||
|
|||
if (!unspents || unspents.length === 0) { |
|||
return setTimeout(function () { |
|||
pollUnspent(blockchain, address, done) |
|||
}, 200) |
|||
} |
|||
|
|||
done(null, unspents) |
|||
}) |
|||
} |
|||
|
|||
function pollSummary (blockchain, address, done) { |
|||
blockchain.addresses.summary(address, function (err, result) { |
|||
if (err) return done(err) |
|||
|
|||
if (result.balance === 0) { |
|||
return setTimeout(function () { |
|||
pollSummary(blockchain, address, done) |
|||
}, 200) |
|||
} |
|||
|
|||
done(null, result) |
|||
}) |
|||
} |
|||
|
|||
module.exports = { |
|||
faucetWithdraw: faucetWithdraw, |
|||
pollUnspent: pollUnspent, |
|||
pollSummary: pollSummary |
|||
} |
Loading…
Reference in new issue