fix: support v0.14 GetRecentBlockhash too

This commit is contained in:
Michael Vines 2019-05-10 20:28:39 -07:00
parent a1ce705d15
commit 4cf234618e
1 changed files with 9 additions and 0 deletions

View File

@ -174,6 +174,7 @@ const GetTransactionCountRpcResult = jsonRpcResult('number');
* Expected JSON RPC response for the "getRecentBlockhash" message
*/
const GetRecentBlockhash = jsonRpcResult(['string', 'object']);
const GetRecentBlockhash_014 = jsonRpcResult('string'); // Legacy v0.14 response. TODO: Remove in July 2019
/**
* Expected JSON RPC response for the "requestAirdrop" message
@ -430,6 +431,14 @@ export class Connection {
*/
async getRecentBlockhash(): Promise<Blockhash> {
const unsafeRes = await this._rpcRequest('getRecentBlockhash', []);
// Legacy v0.14 response. TODO: Remove in July 2019
const res_014 = GetRecentBlockhash_014(unsafeRes);
if (!res_014.error) {
return res_014.result;
}
// End Legacy v0.14 response
const res = GetRecentBlockhash(unsafeRes);
if (res.error) {
throw new Error(res.error.message);