poll address unspent until non-empty or timeout

This commit is contained in:
Wei Lu 2015-05-30 19:17:42 +08:00
parent a2b4558a0b
commit 713f038583
3 changed files with 22 additions and 4 deletions
test/integration

View file

@ -7,6 +7,22 @@ function faucetWithdraw(address, amount, done) {
}).on('error', done)
}
module.exports = {
faucetWithdraw: faucetWithdraw
function pollUnspent(blockchain, address, done) {
blockchain.addresses.unspents(address, function (err, unspents) {
if (err) return done(err)
if(unspents == null || unspents.length === 0) {
return setTimeout(function() {
pollUnspent(blockchain, address, done)
}, 200)
}
done(null, unspents)
})
}
module.exports = {
faucetWithdraw: faucetWithdraw,
pollUnspent: pollUnspent
}