fix: add getBlock Connection method
This commit is contained in:
committed by
Michael Vines
parent
3382548a79
commit
890f6f4d9d
@ -390,6 +390,18 @@ const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult('number');
|
||||
*/
|
||||
const GetBlocksSinceRpcResult = jsonRpcResult(struct.list(['number']));
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getBlock" message
|
||||
*/
|
||||
const GetBlockRpcResult = jsonRpcResult(
|
||||
struct.list([
|
||||
struct.tuple([
|
||||
struct.list(['number']),
|
||||
struct.union([struct({Ok: 'null'}), struct({Err: 'object'})]),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getRecentBlockhash" message
|
||||
*/
|
||||
@ -904,6 +916,25 @@ export class Connection {
|
||||
return res.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a list of Transactions and transaction statuses from the cluster
|
||||
*/
|
||||
async getBlock(
|
||||
slot: number,
|
||||
): Promise<
|
||||
Array<[Transaction, SignatureSuccess] | [Transaction, TransactionError]>,
|
||||
> {
|
||||
const unsafeRes = await this._rpcRequest('getBlock', [slot]);
|
||||
const result = GetBlockRpcResult(unsafeRes);
|
||||
if (result.error) {
|
||||
throw new Error(result.error.message);
|
||||
}
|
||||
assert(typeof result.result !== 'undefined');
|
||||
return result.result.map(result => {
|
||||
return [Transaction.from(result[0]), result[1]];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an allocation of lamports to the specified account
|
||||
*/
|
||||
|
Reference in New Issue
Block a user