@@ -434,8 +434,15 @@ Bitcoin.prototype._resetCaches = function() {
434
434
this . blockOverviewCache . reset ( ) ;
435
435
} ;
436
436
437
- Bitcoin . prototype . _tryAll = function ( func , callback ) {
438
- async . retry ( { times : this . nodes . length , interval : this . tryAllInterval || 1000 } , func , callback ) ;
437
+ Bitcoin . prototype . _tryAllClients = function ( func , callback ) {
438
+ var self = this ;
439
+ var nodesIndex = this . nodesIndex ;
440
+ var retry = function ( done ) {
441
+ var client = self . nodes [ nodesIndex ] . client ;
442
+ nodesIndex = ( nodesIndex + 1 ) % self . nodes . length ;
443
+ func ( client , done ) ;
444
+ } ;
445
+ async . retry ( { times : this . nodes . length , interval : this . tryAllInterval || 1000 } , retry , callback ) ;
439
446
} ;
440
447
441
448
Bitcoin . prototype . _wrapRPCError = function ( errObj ) {
@@ -1544,8 +1551,8 @@ Bitcoin.prototype.getAddressSummary = function(addressArg, options, callback) {
1544
1551
Bitcoin . prototype . _maybeGetBlockHash = function ( blockArg , callback ) {
1545
1552
var self = this ;
1546
1553
if ( _ . isNumber ( blockArg ) || ( blockArg . length < 40 && / ^ [ 0 - 9 ] + $ / . test ( blockArg ) ) ) {
1547
- self . _tryAll ( function ( done ) {
1548
- self . client . getBlockHash ( blockArg , function ( err , response ) {
1554
+ self . _tryAllClients ( function ( client , done ) {
1555
+ client . getBlockHash ( blockArg , function ( err , response ) {
1549
1556
if ( err ) {
1550
1557
return done ( self . _wrapRPCError ( err ) ) ;
1551
1558
}
@@ -1570,7 +1577,7 @@ Bitcoin.prototype.getRawBlock = function(blockArg, callback) {
1570
1577
if ( err ) {
1571
1578
return callback ( err ) ;
1572
1579
}
1573
- self . _tryAll ( function ( done ) {
1580
+ self . _tryAllClients ( function ( client , done ) {
1574
1581
self . client . getBlock ( blockhash , false , function ( err , response ) {
1575
1582
if ( err ) {
1576
1583
return done ( self . _wrapRPCError ( err ) ) ;
@@ -1610,8 +1617,8 @@ Bitcoin.prototype.getBlockOverview = function(blockArg, callback) {
1610
1617
callback ( null , cachedBlock ) ;
1611
1618
} ) ;
1612
1619
} else {
1613
- self . _tryAll ( function ( done ) {
1614
- self . client . getBlock ( blockhash , true , function ( err , response ) {
1620
+ self . _tryAllClients ( function ( client , done ) {
1621
+ client . getBlock ( blockhash , true , function ( err , response ) {
1615
1622
if ( err ) {
1616
1623
return done ( self . _wrapRPCError ( err ) ) ;
1617
1624
}
@@ -1661,8 +1668,8 @@ Bitcoin.prototype.getBlock = function(blockArg, callback) {
1661
1668
callback ( null , cachedBlock ) ;
1662
1669
} ) ;
1663
1670
} else {
1664
- self . _tryAll ( function ( done ) {
1665
- self . client . getBlock ( blockhash , false , function ( err , response ) {
1671
+ self . _tryAllClients ( function ( client , done ) {
1672
+ client . getBlock ( blockhash , false , function ( err , response ) {
1666
1673
if ( err ) {
1667
1674
return done ( self . _wrapRPCError ( err ) ) ;
1668
1675
}
@@ -1720,8 +1727,8 @@ Bitcoin.prototype.getBlockHeader = function(blockArg, callback) {
1720
1727
if ( err ) {
1721
1728
return callback ( err ) ;
1722
1729
}
1723
- self . _tryAll ( function ( done ) {
1724
- self . client . getBlockHeader ( blockhash , function ( err , response ) {
1730
+ self . _tryAllClients ( function ( client , done ) {
1731
+ client . getBlockHeader ( blockhash , function ( err , response ) {
1725
1732
if ( err ) {
1726
1733
return done ( self . _wrapRPCError ( err ) ) ;
1727
1734
}
@@ -1802,8 +1809,8 @@ Bitcoin.prototype.getRawTransaction = function(txid, callback) {
1802
1809
callback ( null , tx ) ;
1803
1810
} ) ;
1804
1811
} else {
1805
- self . _tryAll ( function ( done ) {
1806
- self . client . getRawTransaction ( txid , function ( err , response ) {
1812
+ self . _tryAllClients ( function ( client , done ) {
1813
+ client . getRawTransaction ( txid , function ( err , response ) {
1807
1814
if ( err ) {
1808
1815
return done ( self . _wrapRPCError ( err ) ) ;
1809
1816
}
@@ -1829,8 +1836,8 @@ Bitcoin.prototype.getTransaction = function(txid, callback) {
1829
1836
callback ( null , tx ) ;
1830
1837
} ) ;
1831
1838
} else {
1832
- self . _tryAll ( function ( done ) {
1833
- self . client . getRawTransaction ( txid , function ( err , response ) {
1839
+ self . _tryAllClients ( function ( client , done ) {
1840
+ client . getRawTransaction ( txid , function ( err , response ) {
1834
1841
if ( err ) {
1835
1842
return done ( self . _wrapRPCError ( err ) ) ;
1836
1843
}
@@ -1944,8 +1951,8 @@ Bitcoin.prototype.getDetailedTransaction = function(txid, callback) {
1944
1951
callback ( null , tx ) ;
1945
1952
} ) ;
1946
1953
} else {
1947
- self . _tryAll ( function ( done ) {
1948
- self . client . getRawTransaction ( txid , 1 , function ( err , response ) {
1954
+ self . _tryAllClients ( function ( client , done ) {
1955
+ client . getRawTransaction ( txid , 1 , function ( err , response ) {
1949
1956
if ( err ) {
1950
1957
return done ( self . _wrapRPCError ( err ) ) ;
1951
1958
}
0 commit comments