2019-05-15 01:48:48 +03:00
"use strict" ;
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
2021-03-08 02:24:04 +03:00
function ( d , b ) { for ( var p in b ) if ( Object . prototype . hasOwnProperty . call ( b , p ) ) d [ p ] = b [ p ] ; } ;
2019-05-15 01:48:48 +03:00
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
2021-03-08 02:24:04 +03:00
if ( typeof b !== "function" && b !== null )
throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
2019-05-15 01:48:48 +03:00
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
2019-11-20 12:57:38 +03:00
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
var _ _generator = ( this && this . _ _generator ) || function ( thisArg , body ) {
var _ = { label : 0 , sent : function ( ) { if ( t [ 0 ] & 1 ) throw t [ 1 ] ; return t [ 1 ] ; } , trys : [ ] , ops : [ ] } , f , y , t , g ;
return g = { next : verb ( 0 ) , "throw" : verb ( 1 ) , "return" : verb ( 2 ) } , typeof Symbol === "function" && ( g [ Symbol . iterator ] = function ( ) { return this ; } ) , g ;
function verb ( n ) { return function ( v ) { return step ( [ n , v ] ) ; } ; }
function step ( op ) {
if ( f ) throw new TypeError ( "Generator is already executing." ) ;
while ( _ ) try {
if ( f = 1 , y && ( t = op [ 0 ] & 2 ? y [ "return" ] : op [ 0 ] ? y [ "throw" ] || ( ( t = y [ "return" ] ) && t . call ( y ) , 0 ) : y . next ) && ! ( t = t . call ( y , op [ 1 ] ) ) . done ) return t ;
if ( y = 0 , t ) op = [ op [ 0 ] & 2 , t . value ] ;
switch ( op [ 0 ] ) {
case 0 : case 1 : t = op ; break ;
case 4 : _ . label ++ ; return { value : op [ 1 ] , done : false } ;
case 5 : _ . label ++ ; y = op [ 1 ] ; op = [ 0 ] ; continue ;
case 7 : op = _ . ops . pop ( ) ; _ . trys . pop ( ) ; continue ;
default :
if ( ! ( t = _ . trys , t = t . length > 0 && t [ t . length - 1 ] ) && ( op [ 0 ] === 6 || op [ 0 ] === 2 ) ) { _ = 0 ; continue ; }
if ( op [ 0 ] === 3 && ( ! t || ( op [ 1 ] > t [ 0 ] && op [ 1 ] < t [ 3 ] ) ) ) { _ . label = op [ 1 ] ; break ; }
if ( op [ 0 ] === 6 && _ . label < t [ 1 ] ) { _ . label = t [ 1 ] ; t = op ; break ; }
if ( t && _ . label < t [ 2 ] ) { _ . label = t [ 2 ] ; _ . ops . push ( op ) ; break ; }
if ( t [ 2 ] ) _ . ops . pop ( ) ;
_ . trys . pop ( ) ; continue ;
}
op = body . call ( thisArg , _ ) ;
} catch ( e ) { op = [ 6 , e ] ; y = 0 ; } finally { f = t = 0 ; }
if ( op [ 0 ] & 5 ) throw op [ 1 ] ; return { value : op [ 0 ] ? op [ 1 ] : void 0 , done : true } ;
}
} ;
2019-05-15 01:48:48 +03:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2021-03-08 02:24:04 +03:00
exports . EtherscanProvider = void 0 ;
2019-05-15 01:48:48 +03:00
var bytes _1 = require ( "@ethersproject/bytes" ) ;
var properties _1 = require ( "@ethersproject/properties" ) ;
2021-04-18 05:41:09 +03:00
var transactions _1 = require ( "@ethersproject/transactions" ) ;
2019-05-15 01:48:48 +03:00
var web _1 = require ( "@ethersproject/web" ) ;
2020-07-14 09:33:30 +03:00
var formatter _1 = require ( "./formatter" ) ;
2019-08-02 09:10:58 +03:00
var logger _1 = require ( "@ethersproject/logger" ) ;
var _version _1 = require ( "./_version" ) ;
var logger = new logger _1 . Logger ( _version _1 . version ) ;
2019-05-15 01:48:48 +03:00
var base _provider _1 = require ( "./base-provider" ) ;
// The transaction has already been sanitized by the calls in Provider
2020-10-23 03:01:18 +03:00
function getTransactionPostData ( transaction ) {
var result = { } ;
2019-05-15 01:48:48 +03:00
for ( var key in transaction ) {
if ( transaction [ key ] == null ) {
continue ;
}
2021-03-30 22:22:45 +03:00
var value = transaction [ key ] ;
2020-10-23 03:01:18 +03:00
// Quantity-types require no leading zero, unless 0
2021-03-30 22:22:45 +03:00
if ( { type : true , gasLimit : true , gasPrice : true , nonce : true , value : true } [ key ] ) {
value = bytes _1 . hexValue ( bytes _1 . hexlify ( value ) ) ;
}
else if ( key === "accessList" ) {
2021-05-17 23:19:36 +03:00
value = "[" + transactions _1 . accessListify ( value ) . map ( function ( set ) {
2021-04-18 05:41:09 +03:00
return "{address:\"" + set . address + "\",storageKeys:[\"" + set . storageKeys . join ( '","' ) + "\"]}" ;
} ) . join ( "," ) + "]" ;
2021-03-30 22:22:45 +03:00
}
else {
value = bytes _1 . hexlify ( value ) ;
2019-05-15 01:48:48 +03:00
}
2020-10-23 03:01:18 +03:00
result [ key ] = value ;
2019-05-15 01:48:48 +03:00
}
2020-10-23 03:01:18 +03:00
return result ;
2019-05-15 01:48:48 +03:00
}
function getResult ( result ) {
// getLogs, getHistory have weird success responses
if ( result . status == 0 && ( result . message === "No records found" || result . message === "No transactions found" ) ) {
return result . result ;
}
if ( result . status != 1 || result . message != "OK" ) {
var error = new Error ( "invalid response" ) ;
error . result = JSON . stringify ( result ) ;
2020-07-14 09:33:30 +03:00
if ( ( result . result || "" ) . toLowerCase ( ) . indexOf ( "rate limit" ) >= 0 ) {
error . throttleRetry = true ;
}
2019-05-15 01:48:48 +03:00
throw error ;
}
return result . result ;
}
function getJsonResult ( result ) {
2020-07-14 09:33:30 +03:00
// This response indicates we are being throttled
if ( result && result . status == 0 && result . message == "NOTOK" && ( result . result || "" ) . toLowerCase ( ) . indexOf ( "rate limit" ) >= 0 ) {
var error = new Error ( "throttled response" ) ;
error . result = JSON . stringify ( result ) ;
error . throttleRetry = true ;
throw error ;
}
2019-05-15 01:48:48 +03:00
if ( result . jsonrpc != "2.0" ) {
// @TODO: not any
var error = new Error ( "invalid response" ) ;
error . result = JSON . stringify ( result ) ;
throw error ;
}
if ( result . error ) {
// @TODO: not any
var error = new Error ( result . error . message || "unknown error" ) ;
if ( result . error . code ) {
error . code = result . error . code ;
}
if ( result . error . data ) {
error . data = result . error . data ;
}
throw error ;
}
return result . result ;
}
// The blockTag was normalized as a string by the Provider pre-perform operations
function checkLogTag ( blockTag ) {
if ( blockTag === "pending" ) {
throw new Error ( "pending not supported" ) ;
}
if ( blockTag === "latest" ) {
return blockTag ;
}
return parseInt ( blockTag . substring ( 2 ) , 16 ) ;
}
2020-02-18 04:22:33 +03:00
var defaultApiKey = "9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB" ;
2020-09-16 10:08:36 +03:00
function checkError ( method , error , transaction ) {
2020-11-23 06:44:33 +03:00
// Undo the "convenience" some nodes are attempting to prevent backwards
// incompatibility; maybe for v6 consider forwarding reverts as errors
if ( method === "call" && error . code === logger _1 . Logger . errors . SERVER _ERROR ) {
var e = error . error ;
2021-06-24 09:13:06 +03:00
// Etherscan keeps changing their string
if ( e && ( e . message . match ( /reverted/i ) || e . message . match ( /VM execution error/i ) ) ) {
// Etherscan prefixes the data like "Reverted 0x1234"
var data = e . data ;
if ( data ) {
data = "0x" + data . replace ( /^.*0x/i , "" ) ;
}
if ( bytes _1 . isHexString ( data ) ) {
return data ;
}
logger . throwError ( "missing revert data in call exception" , logger _1 . Logger . errors . CALL _EXCEPTION , {
error : error ,
data : "0x"
} ) ;
2020-11-23 06:44:33 +03:00
}
}
2020-09-16 10:08:36 +03:00
// Get the message from any nested error structure
2020-09-11 09:10:58 +03:00
var message = error . message ;
2020-09-16 10:08:36 +03:00
if ( error . code === logger _1 . Logger . errors . SERVER _ERROR ) {
if ( error . error && typeof ( error . error . message ) === "string" ) {
message = error . error . message ;
}
else if ( typeof ( error . body ) === "string" ) {
message = error . body ;
}
else if ( typeof ( error . responseText ) === "string" ) {
message = error . responseText ;
}
}
message = ( message || "" ) . toLowerCase ( ) ;
// "Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 21464000000000 and got: 0"
if ( message . match ( /insufficient funds/ ) ) {
logger . throwError ( "insufficient funds for intrinsic transaction cost" , logger _1 . Logger . errors . INSUFFICIENT _FUNDS , {
error : error , method : method , transaction : transaction
} ) ;
}
// "Transaction with the same hash was already imported."
if ( message . match ( /same hash was already imported|transaction nonce is too low/ ) ) {
logger . throwError ( "nonce has already been used" , logger _1 . Logger . errors . NONCE _EXPIRED , {
error : error , method : method , transaction : transaction
} ) ;
}
// "Transaction gas price is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce."
if ( message . match ( /another transaction with same nonce/ ) ) {
logger . throwError ( "replacement fee too low" , logger _1 . Logger . errors . REPLACEMENT _UNDERPRICED , {
error : error , method : method , transaction : transaction
} ) ;
2020-09-11 09:10:58 +03:00
}
if ( message . match ( /execution failed due to an exception/ ) ) {
logger . throwError ( "cannot estimate gas; transaction may fail or may require manual gas limit" , logger _1 . Logger . errors . UNPREDICTABLE _GAS _LIMIT , {
2020-09-16 10:08:36 +03:00
error : error , method : method , transaction : transaction
2020-09-11 09:10:58 +03:00
} ) ;
}
throw error ;
}
2019-05-15 01:48:48 +03:00
var EtherscanProvider = /** @class */ ( function ( _super ) {
_ _extends ( EtherscanProvider , _super ) ;
function EtherscanProvider ( network , apiKey ) {
var _newTarget = this . constructor ;
var _this = this ;
2019-08-02 09:10:58 +03:00
logger . checkNew ( _newTarget , EtherscanProvider ) ;
2019-05-15 01:48:48 +03:00
_this = _super . call ( this , network ) || this ;
2021-05-17 23:19:36 +03:00
properties _1 . defineReadOnly ( _this , "baseUrl" , _this . getBaseUrl ( ) ) ;
properties _1 . defineReadOnly ( _this , "apiKey" , apiKey || defaultApiKey ) ;
return _this ;
}
EtherscanProvider . prototype . getBaseUrl = function ( ) {
switch ( this . network ? this . network . name : "invalid" ) {
2019-05-15 01:48:48 +03:00
case "homestead" :
2021-05-17 23:19:36 +03:00
return "https:/\/api.etherscan.io" ;
2019-05-15 01:48:48 +03:00
case "ropsten" :
2021-05-17 23:19:36 +03:00
return "https:/\/api-ropsten.etherscan.io" ;
2019-05-15 01:48:48 +03:00
case "rinkeby" :
2021-05-17 23:19:36 +03:00
return "https:/\/api-rinkeby.etherscan.io" ;
2019-05-15 01:48:48 +03:00
case "kovan" :
2021-05-17 23:19:36 +03:00
return "https:/\/api-kovan.etherscan.io" ;
2019-05-15 01:48:48 +03:00
case "goerli" :
2021-05-17 23:19:36 +03:00
return "https:/\/api-goerli.etherscan.io" ;
2019-05-15 01:48:48 +03:00
default :
}
2021-05-17 23:19:36 +03:00
return logger . throwArgumentError ( "unsupported network" , "network" , name ) ;
} ;
EtherscanProvider . prototype . getUrl = function ( module , params ) {
var query = Object . keys ( params ) . reduce ( function ( accum , key ) {
var value = params [ key ] ;
if ( value != null ) {
accum += "&" + key + "=" + value ;
}
return accum ;
} , "" ) ;
var apiKey = ( ( this . apiKey ) ? "&apikey=" + this . apiKey : "" ) ;
return this . baseUrl + "/api?module=" + module + query + apiKey ;
} ;
EtherscanProvider . prototype . getPostUrl = function ( ) {
return this . baseUrl + "/api" ;
} ;
EtherscanProvider . prototype . getPostData = function ( module , params ) {
params . module = module ;
params . apikey = this . apiKey ;
return params ;
} ;
EtherscanProvider . prototype . fetch = function ( module , params , post ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var url , payload , procFunc , connection , payloadStr , result ;
var _this = this ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 :
url = ( post ? this . getPostUrl ( ) : this . getUrl ( module , params ) ) ;
payload = ( post ? this . getPostData ( module , params ) : null ) ;
procFunc = ( module === "proxy" ) ? getJsonResult : getResult ;
this . emit ( "debug" , {
action : "request" ,
request : url ,
provider : this
} ) ;
connection = {
url : url ,
throttleSlotInterval : 1000 ,
throttleCallback : function ( attempt , url ) {
if ( _this . isCommunityResource ( ) ) {
formatter _1 . showThrottleMessage ( ) ;
}
return Promise . resolve ( true ) ;
}
} ;
payloadStr = null ;
if ( payload ) {
connection . headers = { "content-type" : "application/x-www-form-urlencoded; charset=UTF-8" } ;
payloadStr = Object . keys ( payload ) . map ( function ( key ) {
return key + "=" + payload [ key ] ;
} ) . join ( "&" ) ;
}
return [ 4 /*yield*/ , web _1 . fetchJson ( connection , payloadStr , procFunc || getJsonResult ) ] ;
case 1 :
result = _a . sent ( ) ;
this . emit ( "debug" , {
action : "response" ,
request : url ,
response : properties _1 . deepCopy ( result ) ,
provider : this
} ) ;
return [ 2 /*return*/ , result ] ;
}
} ) ;
} ) ;
} ;
2020-05-04 00:53:58 +03:00
EtherscanProvider . prototype . detectNetwork = function ( ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
return [ 2 /*return*/ , this . network ] ;
} ) ;
} ) ;
} ;
2019-05-15 01:48:48 +03:00
EtherscanProvider . prototype . perform = function ( method , params ) {
2019-11-20 12:57:38 +03:00
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
2021-05-17 23:19:36 +03:00
var _a , postData , error _1 , postData , error _2 , args , topic0 , logs , blocks , i , log , block , _b ;
2019-11-20 12:57:38 +03:00
return _ _generator ( this , function ( _c ) {
switch ( _c . label ) {
case 0 :
_a = method ;
switch ( _a ) {
case "getBlockNumber" : return [ 3 /*break*/ , 1 ] ;
case "getGasPrice" : return [ 3 /*break*/ , 2 ] ;
case "getBalance" : return [ 3 /*break*/ , 3 ] ;
case "getTransactionCount" : return [ 3 /*break*/ , 4 ] ;
case "getCode" : return [ 3 /*break*/ , 5 ] ;
case "getStorageAt" : return [ 3 /*break*/ , 6 ] ;
case "sendTransaction" : return [ 3 /*break*/ , 7 ] ;
case "getBlock" : return [ 3 /*break*/ , 8 ] ;
case "getTransaction" : return [ 3 /*break*/ , 9 ] ;
case "getTransactionReceipt" : return [ 3 /*break*/ , 10 ] ;
case "call" : return [ 3 /*break*/ , 11 ] ;
2020-09-11 09:10:58 +03:00
case "estimateGas" : return [ 3 /*break*/ , 15 ] ;
case "getLogs" : return [ 3 /*break*/ , 19 ] ;
case "getEtherPrice" : return [ 3 /*break*/ , 26 ] ;
2019-05-15 01:48:48 +03:00
}
2020-09-11 09:10:58 +03:00
return [ 3 /*break*/ , 28 ] ;
2021-05-17 23:19:36 +03:00
case 1 : return [ 2 /*return*/ , this . fetch ( "proxy" , { action : "eth_blockNumber" } ) ] ;
case 2 : return [ 2 /*return*/ , this . fetch ( "proxy" , { action : "eth_gasPrice" } ) ] ;
case 3 :
// Returns base-10 result
return [ 2 /*return*/ , this . fetch ( "account" , {
action : "balance" ,
address : params . address ,
tag : params . blockTag
} ) ] ;
case 4 : return [ 2 /*return*/ , this . fetch ( "proxy" , {
action : "eth_getTransactionCount" ,
address : params . address ,
tag : params . blockTag
} ) ] ;
case 5 : return [ 2 /*return*/ , this . fetch ( "proxy" , {
action : "eth_getCode" ,
address : params . address ,
tag : params . blockTag
} ) ] ;
case 6 : return [ 2 /*return*/ , this . fetch ( "proxy" , {
action : "eth_getStorageAt" ,
address : params . address ,
position : params . position ,
tag : params . blockTag
} ) ] ;
case 7 : return [ 2 /*return*/ , this . fetch ( "proxy" , {
2020-10-23 03:01:18 +03:00
action : "eth_sendRawTransaction" ,
2021-05-17 23:19:36 +03:00
hex : params . signedTransaction
} , true ) . catch ( function ( error ) {
2020-10-23 03:01:18 +03:00
return checkError ( "sendTransaction" , error , params . signedTransaction ) ;
} ) ] ;
2019-11-20 12:57:38 +03:00
case 8 :
if ( params . blockTag ) {
2021-05-17 23:19:36 +03:00
return [ 2 /*return*/ , this . fetch ( "proxy" , {
action : "eth_getBlockByNumber" ,
tag : params . blockTag ,
boolean : ( params . includeTransactions ? "true" : "false" )
} ) ] ;
2019-05-15 01:48:48 +03:00
}
2020-04-24 06:35:39 +03:00
throw new Error ( "getBlock by blockHash not implemented" ) ;
2021-05-17 23:19:36 +03:00
case 9 : return [ 2 /*return*/ , this . fetch ( "proxy" , {
action : "eth_getTransactionByHash" ,
txhash : params . transactionHash
} ) ] ;
case 10 : return [ 2 /*return*/ , this . fetch ( "proxy" , {
action : "eth_getTransactionReceipt" ,
txhash : params . transactionHash
} ) ] ;
2019-11-20 12:57:38 +03:00
case 11 :
2020-09-11 09:10:58 +03:00
if ( params . blockTag !== "latest" ) {
throw new Error ( "EtherscanProvider does not support blockTag for call" ) ;
2019-05-15 01:48:48 +03:00
}
2020-10-23 03:01:18 +03:00
postData = getTransactionPostData ( params . transaction ) ;
postData . module = "proxy" ;
postData . action = "eth_call" ;
2019-11-20 12:57:38 +03:00
_c . label = 12 ;
case 12 :
2020-09-11 09:10:58 +03:00
_c . trys . push ( [ 12 , 14 , , 15 ] ) ;
2021-05-17 23:19:36 +03:00
return [ 4 /*yield*/ , this . fetch ( "proxy" , postData , true ) ] ;
2020-09-11 09:10:58 +03:00
case 13 : return [ 2 /*return*/ , _c . sent ( ) ] ;
case 14 :
error _1 = _c . sent ( ) ;
2020-09-16 10:08:36 +03:00
return [ 2 /*return*/ , checkError ( "call" , error _1 , params . transaction ) ] ;
2020-09-11 09:10:58 +03:00
case 15 :
2020-10-23 03:01:18 +03:00
postData = getTransactionPostData ( params . transaction ) ;
postData . module = "proxy" ;
postData . action = "eth_estimateGas" ;
2020-09-11 09:10:58 +03:00
_c . label = 16 ;
case 16 :
_c . trys . push ( [ 16 , 18 , , 19 ] ) ;
2021-05-17 23:19:36 +03:00
return [ 4 /*yield*/ , this . fetch ( "proxy" , postData , true ) ] ;
2020-09-11 09:10:58 +03:00
case 17 : return [ 2 /*return*/ , _c . sent ( ) ] ;
case 18 :
error _2 = _c . sent ( ) ;
2020-09-16 10:08:36 +03:00
return [ 2 /*return*/ , checkError ( "estimateGas" , error _2 , params . transaction ) ] ;
2020-09-11 09:10:58 +03:00
case 19 :
2021-05-17 23:19:36 +03:00
args = { action : "getLogs" } ;
2019-11-20 12:57:38 +03:00
if ( params . filter . fromBlock ) {
2021-05-17 23:19:36 +03:00
args . fromBlock = checkLogTag ( params . filter . fromBlock ) ;
2019-11-20 12:57:38 +03:00
}
if ( params . filter . toBlock ) {
2021-05-17 23:19:36 +03:00
args . toBlock = checkLogTag ( params . filter . toBlock ) ;
2019-11-20 12:57:38 +03:00
}
if ( params . filter . address ) {
2021-05-17 23:19:36 +03:00
args . address = params . filter . address ;
2019-11-20 12:57:38 +03:00
}
// @TODO: We can handle slightly more complicated logs using the logs API
if ( params . filter . topics && params . filter . topics . length > 0 ) {
if ( params . filter . topics . length > 1 ) {
logger . throwError ( "unsupported topic count" , logger _1 . Logger . errors . UNSUPPORTED _OPERATION , { topics : params . filter . topics } ) ;
2019-05-15 01:48:48 +03:00
}
2019-11-20 12:57:38 +03:00
if ( params . filter . topics . length === 1 ) {
topic0 = params . filter . topics [ 0 ] ;
if ( typeof ( topic0 ) !== "string" || topic0 . length !== 66 ) {
logger . throwError ( "unsupported topic format" , logger _1 . Logger . errors . UNSUPPORTED _OPERATION , { topic0 : topic0 } ) ;
}
2021-05-17 23:19:36 +03:00
args . topic0 = topic0 ;
2019-05-15 01:48:48 +03:00
}
2019-11-20 12:57:38 +03:00
}
2021-05-17 23:19:36 +03:00
return [ 4 /*yield*/ , this . fetch ( "logs" , args ) ] ;
2020-09-11 09:10:58 +03:00
case 20 :
2019-11-20 12:57:38 +03:00
logs = _c . sent ( ) ;
2020-10-23 04:55:40 +03:00
blocks = { } ;
2019-11-20 12:57:38 +03:00
i = 0 ;
2020-09-11 09:10:58 +03:00
_c . label = 21 ;
case 21 :
if ( ! ( i < logs . length ) ) return [ 3 /*break*/ , 25 ] ;
2019-11-20 12:57:38 +03:00
log = logs [ i ] ;
if ( log . blockHash != null ) {
2020-09-11 09:10:58 +03:00
return [ 3 /*break*/ , 24 ] ;
2019-11-20 12:57:38 +03:00
}
2020-10-23 04:55:40 +03:00
if ( ! ( blocks [ log . blockNumber ] == null ) ) return [ 3 /*break*/ , 23 ] ;
return [ 4 /*yield*/ , this . getBlock ( log . blockNumber ) ] ;
2020-09-11 09:10:58 +03:00
case 22 :
2020-10-23 04:55:40 +03:00
block = _c . sent ( ) ;
if ( block ) {
blocks [ log . blockNumber ] = block . hash ;
2019-11-20 12:57:38 +03:00
}
2020-09-11 09:10:58 +03:00
_c . label = 23 ;
case 23 :
2020-10-23 04:55:40 +03:00
log . blockHash = blocks [ log . blockNumber ] ;
2020-09-11 09:10:58 +03:00
_c . label = 24 ;
case 24 :
2019-11-20 12:57:38 +03:00
i ++ ;
2020-09-11 09:10:58 +03:00
return [ 3 /*break*/ , 21 ] ;
case 25 : return [ 2 /*return*/ , logs ] ;
case 26 :
2019-11-20 12:57:38 +03:00
if ( this . network . name !== "homestead" ) {
return [ 2 /*return*/ , 0.0 ] ;
}
_b = parseFloat ;
2021-05-17 23:19:36 +03:00
return [ 4 /*yield*/ , this . fetch ( "stats" , { action : "ethprice" } ) ] ;
2020-09-11 09:10:58 +03:00
case 27 : return [ 2 /*return*/ , _b . apply ( void 0 , [ ( _c . sent ( ) ) . ethusd ] ) ] ;
case 28 : return [ 3 /*break*/ , 29 ] ;
case 29 : return [ 2 /*return*/ , _super . prototype . perform . call ( this , method , params ) ] ;
2019-05-15 01:48:48 +03:00
}
2019-11-20 12:57:38 +03:00
} ) ;
} ) ;
2019-05-15 01:48:48 +03:00
} ;
2021-05-17 23:19:36 +03:00
// Note: The `page` page parameter only allows pagination within the
// 10,000 window abailable without a page and offset parameter
// Error: Result window is too large, PageNo x Offset size must
// be less than or equal to 10000
2019-05-15 01:48:48 +03:00
EtherscanProvider . prototype . getHistory = function ( addressOrName , startBlock , endBlock ) {
2021-05-17 23:19:36 +03:00
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var params , result ;
var _a ;
var _this = this ;
return _ _generator ( this , function ( _b ) {
switch ( _b . label ) {
case 0 :
_a = {
action : "txlist"
} ;
return [ 4 /*yield*/ , this . resolveName ( addressOrName ) ] ;
case 1 :
params = ( _a . address = ( _b . sent ( ) ) ,
_a . startblock = ( ( startBlock == null ) ? 0 : startBlock ) ,
_a . endblock = ( ( endBlock == null ) ? 99999999 : endBlock ) ,
_a . sort = "asc" ,
_a ) ;
return [ 4 /*yield*/ , this . fetch ( "account" , params ) ] ;
case 2 :
result = _b . sent ( ) ;
return [ 2 /*return*/ , result . map ( function ( tx ) {
[ "contractAddress" , "to" ] . forEach ( function ( key ) {
if ( tx [ key ] == "" ) {
delete tx [ key ] ;
}
} ) ;
if ( tx . creates == null && tx . contractAddress != null ) {
tx . creates = tx . contractAddress ;
}
var item = _this . formatter . transactionResponse ( tx ) ;
if ( tx . timeStamp ) {
item . timestamp = parseInt ( tx . timeStamp ) ;
}
return item ;
} ) ] ;
2020-07-14 09:33:30 +03:00
}
2019-05-15 01:48:48 +03:00
} ) ;
} ) ;
} ;
2020-10-08 03:10:50 +03:00
EtherscanProvider . prototype . isCommunityResource = function ( ) {
return ( this . apiKey === defaultApiKey ) ;
} ;
2019-05-15 01:48:48 +03:00
return EtherscanProvider ;
} ( base _provider _1 . BaseProvider ) ) ;
exports . EtherscanProvider = EtherscanProvider ;
2020-07-13 15:03:56 +03:00
//# sourceMappingURL=etherscan-provider.js.map