Skip to content

Commit d7fb75a

Browse files
committed
polish
1 parent f2dec75 commit d7fb75a

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

packages/eth-providers/src/base-provider.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ import {
7171
filterLogByTopics,
7272
getAllReceiptsAtBlock,
7373
getHealthResult,
74-
getTimestamp,
7574
getTransactionRequest,
7675
hexlifyRpcResult,
7776
isEvmExtrinsic,
@@ -609,6 +608,12 @@ export abstract class BaseProvider extends AbstractProvider {
609608
: this.bestBlockNumber
610609
);
611610

611+
getTimestamp = async (blockHash: string): Promise<number> => {
612+
const apiAt = await this.getApiAt(blockHash);
613+
const timestamp = await apiAt.query.timestamp.now();
614+
return timestamp.toNumber();
615+
};
616+
612617
getBlockData = async (_blockTag: BlockTag | Promise<BlockTag>, full?: boolean): Promise<BlockData> => {
613618
const blockTag = await this._ensureSafeModeBlockTagFinalization(_blockTag);
614619
const header = await this._getBlockHeader(blockTag);
@@ -629,7 +634,7 @@ export abstract class BaseProvider extends AbstractProvider {
629634
const [block, headerExtended, timestamp, receiptsFromSubql] = await Promise.all([
630635
this.api.rpc.chain.getBlock(blockHash),
631636
this.api.derive.chain.getHeader(blockHash),
632-
getTimestamp(this.api, blockHash),
637+
this.getTimestamp(blockHash),
633638
this.subql?.getAllReceiptsAtBlock(blockHash),
634639
]);
635640

@@ -1408,7 +1413,7 @@ export abstract class BaseProvider extends AbstractProvider {
14081413
result.blockNumber = startBlock;
14091414
result.blockHash = startBlockHash;
14101415

1411-
const timestamp = await getTimestamp(this.api, result.blockHash);
1416+
const timestamp = await this.getTimestamp(result.blockHash);
14121417
result.timestamp = Math.floor(timestamp / 1000);
14131418

14141419
result.wait = async (confirms?: number, timeoutMs?: number) => {

packages/eth-providers/src/utils/parseBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const getAllReceiptsAtBlock = async (
3737
blockHash: string,
3838
targetTxHash?: string
3939
): Promise<TransactionReceipt[]> => {
40-
const apiAtTargetBlock = await api.at(blockHash);
40+
const apiAtTargetBlock = await api.at(blockHash); // TODO: integrate cache for this
4141

4242
const [block, blockEvents] = await Promise.all([
4343
api.rpc.chain.getBlock(blockHash),

packages/eth-providers/src/utils/utils.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,3 @@ export const toBN = (bigNumberis: BigNumberish = 0): BN => {
412412
// eslint-disable-next-line @typescript-eslint/no-explicit-any
413413
return new BN(bigNumberis as any);
414414
};
415-
416-
export const getTimestamp = async (api: ApiPromise, blockHash: string): Promise<number> => {
417-
const apiAt = await api.at(blockHash);
418-
const timestamp = await apiAt.query.timestamp.now();
419-
return timestamp.toNumber();
420-
};

0 commit comments

Comments
 (0)