@@ -38,6 +38,9 @@ import {
38
38
39
39
import { toTxParams } from './util' ;
40
40
41
+ const isBlockNumber = ( blockNum : number ) =>
42
+ Number . isFinite ( blockNum ) && Number . isInteger ( blockNum ) && blockNum >= 0 ;
43
+
41
44
export class Blockchain implements ZilliqaModule {
42
45
signer : Wallet ;
43
46
provider : Provider ;
@@ -427,9 +430,7 @@ export class Blockchain implements ZilliqaModule {
427
430
getTransactionsForTxBlockEx (
428
431
txBlock : number ,
429
432
) : Promise < RPCResponse < any , string > > {
430
- const isBlockNumber =
431
- Number . isFinite ( txBlock ) && Number . isInteger ( txBlock ) && txBlock >= 0 ;
432
- if ( ! isBlockNumber ) {
433
+ if ( ! isBlockNumber ( txBlock ) ) {
433
434
throw new Error ( 'invalid txBlock' ) ;
434
435
}
435
436
return this . provider . send (
@@ -452,9 +453,7 @@ export class Blockchain implements ZilliqaModule {
452
453
// Returns the transactions in batches (or pages) of 2,500
453
454
// This API behaves similar to GetTxBodiesForTxBlock
454
455
getTxnBodiesForTxBlockEx ( txBlock : number ) : Promise < RPCResponse < any , string > > {
455
- const isBlockNumber =
456
- Number . isFinite ( txBlock ) && Number . isInteger ( txBlock ) && txBlock >= 0 ;
457
- if ( ! isBlockNumber ) {
456
+ if ( ! isBlockNumber ( txBlock ) ) {
458
457
throw new Error ( 'invalid txBlock' ) ;
459
458
}
460
459
return this . provider . send (
@@ -569,11 +568,7 @@ export class Blockchain implements ZilliqaModule {
569
568
: contractAddress ;
570
569
571
570
const isLatestStr = txBlock === 'latest' ;
572
-
573
- const isBlockNumber =
574
- Number . isFinite ( txBlock ) && Number . isInteger ( txBlock ) && txBlock >= 0 ;
575
-
576
- const isValid = isLatestStr || isBlockNumber ;
571
+ const isValid = isLatestStr || isBlockNumber ( Number ( txBlock ) ) ;
577
572
if ( ! isValid ) {
578
573
throw new Error ( 'invalid txBlock' ) ;
579
574
}
0 commit comments