Skip to content

Commit

Permalink
add latest blockhash context to blockhash subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Mar 19, 2024
1 parent 8edbce4 commit 274ecd7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sdk/src/blockhashSubscriber/BlockhashSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import {
BlockhashWithExpiryBlockHeight,
Commitment,
Connection,
Context,
} from '@solana/web3.js';
import { BlockhashSubscriberConfig } from './types';

export class BlockhashSubscriber {
private connection: Connection;
private isSubscribed = false;
private latestBlockHeight: number;
private latestBlockHeightContext: Context | undefined;
private blockhashes: Array<BlockhashWithExpiryBlockHeight> = [];
private updateBlockhashIntervalId: NodeJS.Timeout | undefined;
private commitment: Commitment;
Expand All @@ -33,6 +35,10 @@ export class BlockhashSubscriber {
return this.latestBlockHeight;
}

getLatestBlockHeightContext(): Context | undefined {
return this.latestBlockHeightContext;
}

getLatestBlockhash(
offset?: number
): BlockhashWithExpiryBlockHeight | undefined {
Expand Down Expand Up @@ -63,6 +69,7 @@ export class BlockhashSubscriber {
this.connection.getBlockHeight({ commitment: this.commitment }),
]);
this.latestBlockHeight = lastConfirmedBlockHeight;
this.latestBlockHeightContext = resp.context;

// avoid caching duplicate blockhashes
if (this.blockhashes.length > 0) {
Expand Down

0 comments on commit 274ecd7

Please sign in to comment.