fix: better handling if confirmed block not found on node
This commit is contained in:
parent
43e90a1967
commit
3482953757
|
@ -448,6 +448,8 @@ const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult('number');
|
|||
* Expected JSON RPC response for the "getConfirmedBlock" message
|
||||
*/
|
||||
export const GetConfirmedBlockRpcResult = jsonRpcResult(
|
||||
struct.union([
|
||||
'null',
|
||||
struct({
|
||||
blockhash: 'string',
|
||||
previousBlockhash: 'string',
|
||||
|
@ -488,6 +490,7 @@ export const GetConfirmedBlockRpcResult = jsonRpcResult(
|
|||
}),
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -1052,6 +1055,9 @@ export class Connection {
|
|||
throw new Error(result.error.message);
|
||||
}
|
||||
assert(typeof result.result !== 'undefined');
|
||||
if (!result.result) {
|
||||
throw new Error('Confirmed block '+slot+' not found');
|
||||
}
|
||||
return {
|
||||
blockhash: new PublicKey(result.result.blockhash).toString(),
|
||||
previousBlockhash: new PublicKey(
|
||||
|
|
|
@ -646,6 +646,21 @@ test('get confirmed block', async () => {
|
|||
}
|
||||
x++;
|
||||
}
|
||||
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
method: 'getConfirmedBlock',
|
||||
params: [10000],
|
||||
},
|
||||
{
|
||||
error: null,
|
||||
result: null,
|
||||
},
|
||||
]);
|
||||
await expect(
|
||||
connection.getConfirmedBlock(10000),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
test('get recent blockhash', async () => {
|
||||
|
|
Loading…
Reference in New Issue