feat: getBlocks API is added (#19854)

This commit is contained in:
Furkan KAMACI
2021-09-21 06:08:12 +03:00
committed by GitHub
parent afa04f7abd
commit ea5fed937f
2 changed files with 68 additions and 0 deletions

View File

@@ -3107,6 +3107,26 @@ export class Connection {
};
}
/**
* Fetch confirmed blocks between two slots
*/
async getBlocks(
startSlot: number,
endSlot?: number,
commitment?: Finality,
): Promise<Array<number>> {
const args = this._buildArgsAtLeastConfirmed(
endSlot !== undefined ? [startSlot, endSlot] : [startSlot],
commitment,
);
const unsafeRes = await this._rpcRequest('getBlocks', args);
const res = create(unsafeRes, jsonRpcResult(array(number())));
if ('error' in res) {
throw new Error('failed to get blocks: ' + res.error.message);
}
return res.result;
}
/**
* Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
*/