poll address summary until balance non-zero or timeout
This commit is contained in:
parent
70d423f596
commit
9a921ad181
2 changed files with 17 additions and 2 deletions
test/integration
|
@ -5,6 +5,7 @@ var bitcoin = require('../../')
|
||||||
var blockchain = new (require('cb-insight'))('https://test-insight.bitpay.com')
|
var blockchain = new (require('cb-insight'))('https://test-insight.bitpay.com')
|
||||||
var faucetWithdraw = require('./utils').faucetWithdraw
|
var faucetWithdraw = require('./utils').faucetWithdraw
|
||||||
var pollUnspent = require('./utils').pollUnspent
|
var pollUnspent = require('./utils').pollUnspent
|
||||||
|
var pollSummary = require('./utils').pollSummary
|
||||||
|
|
||||||
describe('bitcoinjs-lib (multisig)', function () {
|
describe('bitcoinjs-lib (multisig)', function () {
|
||||||
it('can create a 2-of-3 multisig P2SH address', function () {
|
it('can create a 2-of-3 multisig P2SH address', function () {
|
||||||
|
@ -72,7 +73,7 @@ describe('bitcoinjs-lib (multisig)', function () {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
// check that the funds (1e4 Satoshis) indeed arrived at the intended address
|
// check that the funds (1e4 Satoshis) indeed arrived at the intended address
|
||||||
blockchain.addresses.summary(targetAddress, function (err, result) {
|
pollSummary(blockchain, targetAddress, function (err, result) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
assert.strictEqual(result.balance, 1e4)
|
assert.strictEqual(result.balance, 1e4)
|
||||||
|
|
|
@ -19,10 +19,24 @@ function pollUnspent(blockchain, address, done) {
|
||||||
|
|
||||||
done(null, unspents)
|
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 = {
|
module.exports = {
|
||||||
faucetWithdraw: faucetWithdraw,
|
faucetWithdraw: faucetWithdraw,
|
||||||
pollUnspent: pollUnspent
|
pollUnspent: pollUnspent,
|
||||||
|
pollSummary: pollSummary
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue