Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
Merge f80809a into 96c014e
Browse files Browse the repository at this point in the history
  • Loading branch information
Noel committed Sep 27, 2021
2 parents 96c014e + f80809a commit c3794be
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/zilliqa-js-blockchain/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import {

import { toTxParams } from './util';

const isBlockNumber = (blockNum: number) =>
Number.isFinite(blockNum) && Number.isInteger(blockNum) && blockNum >= 0;

export class Blockchain implements ZilliqaModule {
signer: Wallet;
provider: Provider;
Expand Down Expand Up @@ -427,9 +430,7 @@ export class Blockchain implements ZilliqaModule {
getTransactionsForTxBlockEx(
txBlock: number,
): Promise<RPCResponse<any, string>> {
const isBlockNumber =
Number.isFinite(txBlock) && Number.isInteger(txBlock) && txBlock >= 0;
if (!isBlockNumber) {
if (!isBlockNumber(txBlock)) {
throw new Error('invalid txBlock');
}
return this.provider.send(
Expand All @@ -452,9 +453,7 @@ export class Blockchain implements ZilliqaModule {
// Returns the transactions in batches (or pages) of 2,500
// This API behaves similar to GetTxBodiesForTxBlock
getTxnBodiesForTxBlockEx(txBlock: number): Promise<RPCResponse<any, string>> {
const isBlockNumber =
Number.isFinite(txBlock) && Number.isInteger(txBlock) && txBlock >= 0;
if (!isBlockNumber) {
if (!isBlockNumber(txBlock)) {
throw new Error('invalid txBlock');
}
return this.provider.send(
Expand Down Expand Up @@ -569,11 +568,7 @@ export class Blockchain implements ZilliqaModule {
: contractAddress;

const isLatestStr = txBlock === 'latest';

const isBlockNumber =
Number.isFinite(txBlock) && Number.isInteger(txBlock) && txBlock >= 0;

const isValid = isLatestStr || isBlockNumber;
const isValid = isLatestStr || isBlockNumber(Number(txBlock));
if (!isValid) {
throw new Error('invalid txBlock');
}
Expand Down

0 comments on commit c3794be

Please sign in to comment.