@@ -5005,13 +5005,53 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
5005
5005
url += apiKey ;
5006
5006
return Provider . fetchJSON ( url , null , getResult ) ;
5007
5007
5008
+ case 'getEtherPrice' :
5009
+ if ( this . name !== 'homestead' ) { return Promise . resolve ( 0.0 ) ; }
5010
+ url += '/api?module=stats&action=ethprice' ;
5011
+ url += apiKey ;
5012
+ return Provider . fetchJSON ( url , null , getResult ) . then ( function ( result ) {
5013
+ return parseFloat ( result . ethusd ) ;
5014
+ } ) ;
5015
+
5008
5016
default :
5009
5017
break ;
5010
5018
}
5011
5019
5012
5020
return Promise . reject ( new Error ( 'not implemented - ' + method ) ) ;
5013
5021
} ) ;
5014
5022
5023
+ utils . defineProperty ( EtherscanProvider . prototype , 'getHistory' , function ( addressOrName , startBlock , endBlock ) {
5024
+
5025
+ var url = this . baseUrl ;
5026
+
5027
+ var apiKey = '' ;
5028
+ if ( this . apiKey ) { apiKey += '&apikey=' + this . apiKey ; }
5029
+
5030
+ if ( startBlock == null ) { startBlock = 0 ; }
5031
+ if ( endBlock == null ) { endBlock = 99999999 ; }
5032
+
5033
+ return this . resolveName ( addressOrName ) . then ( function ( address ) {
5034
+ url += '/api?module=account&action=txlist&address=' + address ;
5035
+ url += '&fromBlock=' + startBlock ;
5036
+ url += '&endBlock=' + endBlock ;
5037
+ url += '&sort=asc' ;
5038
+
5039
+ return Provider . fetchJSON ( url , null , getResult ) . then ( function ( result ) {
5040
+ var output = [ ] ;
5041
+ result . forEach ( function ( tx ) {
5042
+ [ 'contractAddress' , 'to' ] . forEach ( function ( key ) {
5043
+ if ( tx [ key ] == '' ) { delete tx [ key ] ; }
5044
+ } ) ;
5045
+ if ( tx . creates == null && tx . contractAddress != null ) {
5046
+ tx . creates = tx . contractAddress ;
5047
+ }
5048
+ output . push ( Provider . _formatters . checkTransactionResponse ( tx ) ) ;
5049
+ } ) ;
5050
+ return output ;
5051
+ } ) ;
5052
+ } ) ;
5053
+ } ) ;
5054
+
5015
5055
module . exports = EtherscanProvider ; ;
5016
5056
5017
5057
} , { "./provider.js" :24 , "ethers-utils/convert.js" :6 , "ethers-utils/properties.js" :9 } ] , 19 :[ function ( require , module , exports ) {
@@ -5160,6 +5200,13 @@ function InfuraProvider(network, apiAccessToken) {
5160
5200
}
5161
5201
JsonRpcProvider . inherits ( InfuraProvider ) ;
5162
5202
5203
+ utils . defineProperty ( InfuraProvider . prototype , '_startPending' , function ( ) {
5204
+ console . log ( 'WARNING: INFURA does not support pending filters' ) ;
5205
+ } ) ;
5206
+
5207
+ utils . defineProperty ( InfuraProvider . prototype , '_stopPending' , function ( ) {
5208
+ } ) ;
5209
+
5163
5210
module . exports = InfuraProvider ;
5164
5211
5165
5212
} , { "./json-rpc-provider" :22 , "./provider" :24 , "ethers-utils/properties.js" :9 } ] , 22 :[ function ( require , module , exports ) {
@@ -5179,6 +5226,15 @@ var utils = (function() {
5179
5226
}
5180
5227
} ) ( ) ;
5181
5228
5229
+ // @TODO : Move this to utils
5230
+ function timer ( timeout ) {
5231
+ return new Promise ( function ( resolve ) {
5232
+ setTimeout ( function ( ) {
5233
+ resolve ( ) ;
5234
+ } , timeout ) ;
5235
+ } ) ;
5236
+ }
5237
+
5182
5238
function getResult ( payload ) {
5183
5239
if ( payload . error ) {
5184
5240
var error = new Error ( payload . error . message ) ;
@@ -5322,6 +5378,48 @@ utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, para
5322
5378
return Promise . reject ( new Error ( 'not implemented - ' + method ) ) ;
5323
5379
} ) ;
5324
5380
5381
+ utils . defineProperty ( JsonRpcProvider . prototype , '_startPending' , function ( ) {
5382
+ if ( this . _pendingFilter != null ) { return ; }
5383
+ var self = this ;
5384
+
5385
+ var pendingFilter = this . send ( 'eth_newPendingTransactionFilter' , [ ] ) ;
5386
+ this . _pendingFilter = pendingFilter ;
5387
+
5388
+ pendingFilter . then ( function ( filterId ) {
5389
+ function poll ( ) {
5390
+ self . send ( 'eth_getFilterChanges' , [ filterId ] ) . then ( function ( hashes ) {
5391
+ if ( self . _pendingFilter != pendingFilter ) { return ; }
5392
+
5393
+ var seq = Promise . resolve ( ) ;
5394
+ hashes . forEach ( function ( hash ) {
5395
+ seq = seq . then ( function ( ) {
5396
+ return self . getTransaction ( hash ) . then ( function ( tx ) {
5397
+ self . emit ( 'pending' , tx ) ;
5398
+ } ) ;
5399
+ } ) ;
5400
+ } ) ;
5401
+
5402
+ return seq . then ( function ( ) {
5403
+ return timer ( 1000 ) ;
5404
+ } ) ;
5405
+ } ) . then ( function ( ) {
5406
+ if ( self . _pendingFilter != pendingFilter ) {
5407
+ self . send ( 'eth_uninstallFilter' , [ filterIf ] ) ;
5408
+ return ;
5409
+ }
5410
+ setTimeout ( function ( ) { poll ( ) ; } , 0 ) ;
5411
+ } ) ;
5412
+ }
5413
+ poll ( ) ;
5414
+
5415
+ return filterId ;
5416
+ } ) ;
5417
+ } ) ;
5418
+
5419
+ utils . defineProperty ( JsonRpcProvider . prototype , '_stopPending' , function ( ) {
5420
+ this . _pendingFilter = null ;
5421
+ } ) ;
5422
+
5325
5423
module . exports = JsonRpcProvider ;
5326
5424
5327
5425
} , { "./provider.js" :24 , "ethers-utils/convert" :6 , "ethers-utils/properties" :9 } ] , 23 :[ function ( require , module , exports ) {
@@ -5586,7 +5684,6 @@ function checkTransaction(transaction) {
5586
5684
}
5587
5685
5588
5686
if ( ! transaction . raw ) {
5589
-
5590
5687
// Very loose providers (e.g. TestRPC) don't provide a signature or raw
5591
5688
if ( transaction . v && transaction . r && transaction . s ) {
5592
5689
var raw = [
@@ -6089,7 +6186,7 @@ utils.defineProperty(Provider.prototype, 'sendTransaction', function(signedTrans
6089
6186
6090
6187
utils . defineProperty ( Provider . prototype , 'call' , function ( transaction ) {
6091
6188
var self = this ;
6092
- return this . _resolveNames ( transaction , [ 'to' , 'from' ] ) . then ( function ( transaction ) {
6189
+ return this . _resolveNames ( transaction , [ 'to' , 'from' ] ) . then ( function ( transaction ) {
6093
6190
var params = { transaction : checkTransactionRequest ( transaction ) } ;
6094
6191
return self . perform ( 'call' , params ) . then ( function ( result ) {
6095
6192
return utils . hexlify ( result ) ;
@@ -6099,7 +6196,7 @@ utils.defineProperty(Provider.prototype, 'call', function(transaction) {
6099
6196
6100
6197
utils . defineProperty ( Provider . prototype , 'estimateGas' , function ( transaction ) {
6101
6198
var self = this ;
6102
- return this . _resolveNames ( transaction , [ 'to' , 'from' ] ) . then ( function ( transaction ) {
6199
+ return this . _resolveNames ( transaction , [ 'to' , 'from' ] ) . then ( function ( transaction ) {
6103
6200
var params = { transaction : checkTransactionRequest ( transaction ) } ;
6104
6201
return self . perform ( 'estimateGas' , params ) . then ( function ( result ) {
6105
6202
return utils . bigNumberify ( result ) ;
@@ -6305,6 +6402,9 @@ function getEventString(object) {
6305
6402
if ( object === 'block' ) {
6306
6403
return 'block' ;
6307
6404
6405
+ } else if ( object === 'pending' ) {
6406
+ return 'pending' ;
6407
+
6308
6408
} else if ( utils . isHexString ( object ) ) {
6309
6409
if ( object . length === 66 ) {
6310
6410
return 'tx:' + object ;
@@ -6332,6 +6432,9 @@ function parseEventString(string) {
6332
6432
} else if ( string === 'block' ) {
6333
6433
return { type : 'block' } ;
6334
6434
6435
+ } else if ( string === 'pending' ) {
6436
+ return { type : 'pending' } ;
6437
+
6335
6438
} else if ( string . substring ( 0 , 8 ) === 'address:' ) {
6336
6439
return { type : 'address' , address : string . substring ( 8 ) } ;
6337
6440
@@ -6351,17 +6454,26 @@ function parseEventString(string) {
6351
6454
throw new Error ( 'invalid event string' ) ;
6352
6455
}
6353
6456
6457
+ utils . defineProperty ( Provider . prototype , '_startPending' , function ( ) {
6458
+ console . log ( 'WARNING: this provider does not support pending events' ) ;
6459
+ } ) ;
6460
+
6461
+ utils . defineProperty ( Provider . prototype , '_stopPending' , function ( ) {
6462
+ } ) ;
6463
+
6354
6464
utils . defineProperty ( Provider . prototype , 'on' , function ( eventName , listener ) {
6355
6465
var key = getEventString ( eventName ) ;
6356
6466
if ( ! this . _events [ key ] ) { this . _events [ key ] = [ ] ; }
6357
6467
this . _events [ key ] . push ( { eventName : eventName , listener : listener , type : 'on' } ) ;
6468
+ if ( key === 'pending' ) { this . _startPending ( ) ; }
6358
6469
this . polling = true ;
6359
6470
} ) ;
6360
6471
6361
6472
utils . defineProperty ( Provider . prototype , 'once' , function ( eventName , listener ) {
6362
6473
var key = getEventString ( eventName ) ;
6363
6474
if ( ! this . _events [ key ] ) { this . _events [ key ] = [ ] ; }
6364
6475
this . _events [ key ] . push ( { eventName : eventName , listener : listener , type : 'once' } ) ;
6476
+ if ( key === 'pending' ) { this . _startPending ( ) ; }
6365
6477
this . polling = true ;
6366
6478
} ) ;
6367
6479
@@ -6386,7 +6498,11 @@ utils.defineProperty(Provider.prototype, 'emit', function(eventName) {
6386
6498
}
6387
6499
}
6388
6500
6389
- if ( listeners . length === 0 ) { delete this . _events [ key ] ; }
6501
+ if ( listeners . length === 0 ) {
6502
+ delete this . _events [ key ] ;
6503
+ if ( key === 'pending' ) { this . _stopPending ( ) ; }
6504
+ }
6505
+
6390
6506
if ( this . listenerCount ( ) === 0 ) { this . polling = false ; }
6391
6507
} ) ;
6392
6508
@@ -6431,6 +6547,10 @@ utils.defineProperty(Provider.prototype, 'removeListener', function(eventName, l
6431
6547
if ( this . listenerCount ( ) === 0 ) { this . polling = false ; }
6432
6548
} ) ;
6433
6549
6550
+ utils . defineProperty ( Provider , '_formatters' , {
6551
+ checkTransactionResponse : checkTransaction
6552
+ } ) ;
6553
+
6434
6554
module . exports = Provider ;
6435
6555
6436
6556
} , { "./networks.json" :23 , "ethers-utils/address" :3 , "ethers-utils/bignumber" :4 , "ethers-utils/contract-address" :5 , "ethers-utils/convert" :6 , "ethers-utils/namehash" :8 , "ethers-utils/properties" :9 , "ethers-utils/rlp" :10 , "ethers-utils/utf8" :13 , "inherits" :14 , "xmlhttprequest" :17 } ] } , { } , [ 20 ] ) ;
0 commit comments