feat: add getVersion method
This commit is contained in:
committed by
Michael Vines
parent
979a707c94
commit
f3d9ab75e6
@ -132,6 +132,16 @@ const GetEpochScheduleResult = struct({
|
||||
first_normal_slot: 'number',
|
||||
});
|
||||
|
||||
/**
|
||||
* Version info for a node
|
||||
*
|
||||
* @typedef {Object} Version
|
||||
* @property {string} solana-core Version of solana-core
|
||||
*/
|
||||
const Version = struct({
|
||||
'solana-core': 'string',
|
||||
});
|
||||
|
||||
function createRpcRequest(url): RpcRequest {
|
||||
const server = jayson(async (request, callback) => {
|
||||
const options = {
|
||||
@ -204,6 +214,16 @@ const GetBalanceRpcResult = struct({
|
||||
result: 'number?',
|
||||
});
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getVersion" message
|
||||
*/
|
||||
const GetVersionRpcResult = struct({
|
||||
jsonrpc: struct.literal('2.0'),
|
||||
id: 'string',
|
||||
error: 'any?',
|
||||
result: Version,
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@ -871,6 +891,19 @@ export class Connection {
|
||||
return res.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the node version
|
||||
*/
|
||||
async getVersion(): Promise<Version> {
|
||||
const unsafeRes = await this._rpcRequest('getVersion', []);
|
||||
const res = GetVersionRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
throw new Error(res.error.message);
|
||||
}
|
||||
assert(typeof res.result !== 'undefined');
|
||||
return res.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an allocation of lamports to the specified account
|
||||
*/
|
||||
|
Reference in New Issue
Block a user