@@ -140,8 +140,12 @@ export class EthImpl implements Eth {
140140 * Gets the fee history.
141141 */
142142 async feeHistory ( blockCount : number , newestBlock : string , rewardPercentiles : Array < number > | null , requestId ?: string ) {
143+ const maxResults = Number ( process . env . FEE_HISTORY_MAX_RESULTS ) || constants . DEFAULT_FEE_HISTORY_MAX_RESULTS ;
144+
143145 const requestIdPrefix = formatRequestIdMessage ( requestId ) ;
146+
144147 this . logger . trace ( `${ requestIdPrefix } feeHistory(blockCount=${ blockCount } , newestBlock=${ newestBlock } , rewardPercentiles=${ rewardPercentiles } )` ) ;
148+
145149 try {
146150 const latestBlockNumber = await this . translateBlockTag ( EthImpl . blockLatest , requestId ) ;
147151 const newestBlockNumber = await this . translateBlockTag ( newestBlock , requestId ) ;
@@ -150,7 +154,7 @@ export class EthImpl implements Eth {
150154 return predefined . REQUEST_BEYOND_HEAD_BLOCK ( newestBlockNumber , latestBlockNumber ) ;
151155 }
152156
153- blockCount = blockCount > constants . FEE_HISTORY_MAX_RESULTS ? constants . FEE_HISTORY_MAX_RESULTS : blockCount ;
157+ blockCount = blockCount > maxResults ? maxResults : blockCount ;
154158
155159 if ( blockCount <= 0 ) {
156160 return EthImpl . feeHistoryZeroBlockCountResponse ;
@@ -752,7 +756,7 @@ export class EthImpl implements Eth {
752756 return e ;
753757 }
754758 return predefined . INTERNAL_ERROR ;
755- }
759+ }
756760 }
757761
758762 /**
@@ -901,7 +905,7 @@ export class EthImpl implements Eth {
901905 input : contractResult . function_parameters ,
902906 maxPriorityFeePerGas : maxPriorityFee ,
903907 maxFeePerGas : maxFee ,
904- nonce : EthImpl . nonceNumberTo0x ( contractResult . nonce ) ,
908+ nonce : EthImpl . nanOrNumberTo0x ( contractResult . nonce ) ,
905909 r : rSig ,
906910 s : sSig ,
907911 to : contractResult . to ?. substring ( 0 , 42 ) ,
@@ -963,7 +967,7 @@ export class EthImpl implements Eth {
963967 logsBloom : receiptResponse . bloom ,
964968 transactionHash : EthImpl . toHash32 ( receiptResponse . hash ) ,
965969 transactionIndex : EthImpl . numberTo0x ( receiptResponse . transaction_index ) ,
966- effectiveGasPrice : EthImpl . numberTo0x ( Number . parseInt ( effectiveGas ) * 10_000_000_000 ) ,
970+ effectiveGasPrice : EthImpl . nanOrNumberTo0x ( Number . parseInt ( effectiveGas ) * 10_000_000_000 ) ,
967971 root : receiptResponse . root ,
968972 status : receiptResponse . status ,
969973 } ;
@@ -991,8 +995,11 @@ export class EthImpl implements Eth {
991995 return input === null ? null : EthImpl . numberTo0x ( input ) ;
992996 }
993997
994- static nonceNumberTo0x ( input : number | BigNumber ) : string {
995- return input === null ? EthImpl . numberTo0x ( 0 ) : EthImpl . numberTo0x ( input ) ;
998+ static nanOrNumberTo0x ( input : number | BigNumber ) : string {
999+ // input == null assures to check against both null and undefined.
1000+ // A reliable way for ECMAScript code to test if a value X is a NaN is an expression of the form X !== X.
1001+ // The result will be true if and only if X is a NaN.
1002+ return input == null || input !== input ? EthImpl . numberTo0x ( 0 ) : EthImpl . numberTo0x ( input ) ;
9961003 }
9971004
9981005 static toHash32 ( value : string ) : string {
@@ -1180,7 +1187,7 @@ export class EthImpl implements Eth {
11801187 input : contractResultDetails . function_parameters ,
11811188 maxPriorityFeePerGas : EthImpl . toNullIfEmptyHex ( contractResultDetails . max_priority_fee_per_gas ) ,
11821189 maxFeePerGas : EthImpl . toNullIfEmptyHex ( contractResultDetails . max_fee_per_gas ) ,
1183- nonce : EthImpl . nonceNumberTo0x ( contractResultDetails . nonce ) ,
1190+ nonce : EthImpl . nanOrNumberTo0x ( contractResultDetails . nonce ) ,
11841191 r : rSig ,
11851192 s : sSig ,
11861193 to : contractResultDetails . to . substring ( 0 , 42 ) ,
@@ -1219,6 +1226,7 @@ export class EthImpl implements Eth {
12191226 throw e ;
12201227 }
12211228 } else if ( fromBlock || toBlock ) {
1229+ const blockRangeLimit = Number ( process . env . ETH_GET_LOGS_BLOCK_RANGE_LIMIT ) || constants . DEFAULT_ETH_GET_LOGS_BLOCK_RANGE_LIMIT ;
12221230 let fromBlockTimestamp ;
12231231 let toBlockTimestamp ;
12241232 let fromBlockNum = 0 ;
@@ -1272,8 +1280,8 @@ export class EthImpl implements Eth {
12721280
12731281 if ( fromBlockNum > toBlockNum ) {
12741282 return [ ] ;
1275- } else if ( ( toBlockNum - fromBlockNum ) > constants . ETH_GET_LOGS_BLOCK_RANGE_LIMIT ) {
1276- throw predefined . RANGE_TOO_LARGE ;
1283+ } else if ( ( toBlockNum - fromBlockNum ) > blockRangeLimit ) {
1284+ throw predefined . RANGE_TOO_LARGE ( blockRangeLimit ) ;
12771285 }
12781286 }
12791287
0 commit comments