Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat: Agave v2 RPC: replace getRecentBlockhash with getLatestBlockhash #3419

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2599,20 +2599,6 @@ const GetParsedTransactionRpcResult = jsonRpcResult(
),
);

/**
* Expected JSON RPC response for the "getRecentBlockhash" message
*
* @deprecated Deprecated since RPC v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
*/
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(
pick({
blockhash: string(),
feeCalculator: pick({
lamportsPerSignature: number(),
}),
}),
);

/**
* Expected JSON RPC response for the "getLatestBlockhash" message
*/
Expand Down Expand Up @@ -4567,13 +4553,29 @@ export class Connection {
feeCalculator: FeeCalculator;
}>
> {
const args = this._buildArgs([], commitment);
const unsafeRes = await this._rpcRequest('getRecentBlockhash', args);
const res = create(unsafeRes, GetRecentBlockhashAndContextRpcResult);
if ('error' in res) {
throw new SolanaJSONRPCError(res.error, 'failed to get recent blockhash');
}
return res.result;
const {
context,
value: {blockhash},
} = await this.getLatestBlockhashAndContext(commitment);
const feeCalculator = {
get lamportsPerSignature(): number {
throw new Error(
'The capability to fetch `lamportsPerSignature` using the `getRecentBlockhash` API is ' +
'no longer offered by the network. Use the `getFeeForMessage` API to obtain the fee ' +
'for a given message.',
);
},
toJSON() {
return {};
},
};
return {
context,
value: {
blockhash,
feeCalculator,
},
};
}

/**
Expand Down Expand Up @@ -5225,7 +5227,7 @@ export class Connection {
commitment?: Finality,
): Promise<ConfirmedBlock> {
const args = this._buildArgsAtLeastConfirmed([slot], commitment);
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
const unsafeRes = await this._rpcRequest('getBlock', args);
const res = create(unsafeRes, GetConfirmedBlockRpcResult);

if ('error' in res) {
Expand Down Expand Up @@ -5331,7 +5333,7 @@ export class Connection {
rewards: false,
},
);
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
const unsafeRes = await this._rpcRequest('getBlock', args);
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
if ('error' in res) {
throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
Expand All @@ -5353,7 +5355,7 @@ export class Connection {
commitment?: Finality,
): Promise<ConfirmedTransaction | null> {
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
const unsafeRes = await this._rpcRequest('getTransaction', args);
const res = create(unsafeRes, GetTransactionRpcResult);
if ('error' in res) {
throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
Expand Down Expand Up @@ -5384,7 +5386,7 @@ export class Connection {
commitment,
'jsonParsed',
);
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
const unsafeRes = await this._rpcRequest('getTransaction', args);
const res = create(unsafeRes, GetParsedTransactionRpcResult);
if ('error' in res) {
throw new SolanaJSONRPCError(
Expand All @@ -5411,7 +5413,7 @@ export class Connection {
'jsonParsed',
);
return {
methodName: 'getConfirmedTransaction',
methodName: 'getTransaction',
args,
};
});
Expand Down
Loading
Loading