feat: add method to return a confirmed block with signatures only
This commit is contained in:
committed by
Tyera Eulberg
parent
4ac17b1ee3
commit
f37c05adeb
@ -583,6 +583,22 @@ export type ConfirmedBlock = {
|
||||
blockTime: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* A ConfirmedBlock on the ledger with signatures only
|
||||
*/
|
||||
export type ConfirmedBlockSignatures = {
|
||||
/** Blockhash of this block */
|
||||
blockhash: Blockhash;
|
||||
/** Blockhash of this block's parent */
|
||||
previousBlockhash: Blockhash;
|
||||
/** Slot index of this block's parent */
|
||||
parentSlot: number;
|
||||
/** Vector of signatures */
|
||||
signatures: Array<string>;
|
||||
/** The unix timestamp of when the block was processed */
|
||||
blockTime: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* A performance sample
|
||||
*/
|
||||
@ -1231,6 +1247,21 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getConfirmedBlockSignatures" message
|
||||
*/
|
||||
const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(
|
||||
nullable(
|
||||
pick({
|
||||
blockhash: string(),
|
||||
previousBlockhash: string(),
|
||||
parentSlot: number(),
|
||||
signatures: array(string()),
|
||||
blockTime: nullable(number()),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getConfirmedTransaction" message
|
||||
*/
|
||||
@ -2477,6 +2508,27 @@ export class Connection {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
|
||||
*/
|
||||
async getConfirmedBlockSignatures(
|
||||
slot: number,
|
||||
): Promise<ConfirmedBlockSignatures> {
|
||||
const unsafeRes = await this._rpcRequest('getConfirmedBlock', [
|
||||
slot,
|
||||
{transactionDetails: 'signatures', rewards: false},
|
||||
]);
|
||||
const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
|
||||
if ('error' in res) {
|
||||
throw new Error('failed to get confirmed block: ' + res.error.message);
|
||||
}
|
||||
const result = res.result;
|
||||
if (!result) {
|
||||
throw new Error('Confirmed block ' + slot + ' not found');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a transaction details for a confirmed transaction
|
||||
*/
|
||||
|
Reference in New Issue
Block a user