diff --git a/lib/src/soroban/soroban_server.dart b/lib/src/soroban/soroban_server.dart index 8c7d33b..e2e9382 100644 --- a/lib/src/soroban/soroban_server.dart +++ b/lib/src/soroban/soroban_server.dart @@ -70,6 +70,19 @@ class SorobanServer { return GetHealthResponse.fromJson(response.data); } + /// Version information about the RPC and Captive core. RPC manages its own, + /// pared-down version of Stellar Core optimized for its own subset of needs. + /// See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo + Future getVersionInfo() async { + JsonRpcMethod getVersionInfo = JsonRpcMethod("getVersionInfo"); + dio.Response response = await _dio.post(_serverUrl, + data: json.encode(getVersionInfo), options: dio.Options(headers: _headers)); + if (enableLogging) { + print("getVersionInfo response: $response"); + } + return GetVersionInfoResponse.fromJson(response.data); + } + /// For finding out the current latest known ledger. /// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getLatestLedger Future getLatestLedger() async { @@ -340,6 +353,46 @@ class GetHealthResponse extends SorobanRpcResponse { } } +/// Version information about the RPC and Captive core. +/// RPC manages its own, pared-down version of Stellar Core optimized for its own subset of needs. +/// See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo +class GetVersionInfoResponse extends SorobanRpcResponse { + /// The version of the RPC server. + String? version; + String? commitHash; + String? buildTimeStamp; + String? captiveCoreVersion; + int? protocolVersion; + + + GetVersionInfoResponse(Map jsonResponse) : super(jsonResponse); + + factory GetVersionInfoResponse.fromJson(Map json) { + GetVersionInfoResponse response = GetVersionInfoResponse(json); + if (json['result'] != null) { + if (json['result']['version'] != null) { + response.version = json['result']['version']; + } + if (json['result']['commit_hash'] != null) { + response.commitHash = + json['result']['commit_hash']; + } + if (json['result']['build_time_stamp'] != null) { + response.buildTimeStamp = json['result']['build_time_stamp']; + } + if (json['result']['captive_core_version'] != null) { + response.captiveCoreVersion = json['result']['captive_core_version']; + } + if (json['result']['protocol_version'] != null) { + response.protocolVersion = json['result']['protocol_version']; + } + } else if (json['error'] != null) { + response.error = SorobanRpcErrorResponse.fromJson(json); + } + return response; + } +} + /// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getLatestLedger class GetLatestLedgerResponse extends SorobanRpcResponse { /// Hash identifier of the latest ledger (as a hex-encoded string) known to Soroban RPC at the time it handled the request. diff --git a/test/soroban_test.dart b/test/soroban_test.dart index 261709b..f0f1a80 100644 --- a/test/soroban_test.dart +++ b/test/soroban_test.dart @@ -250,6 +250,15 @@ void main() { assert(healthResponse.oldestLedger != null); }); + test('test server version info ', () async { + var response = await sorobanServer.getVersionInfo(); + assert(response.version != null); + assert(response.commitHash != null); + assert(response.buildTimeStamp != null); + assert(response.captiveCoreVersion != null); + assert(response.protocolVersion != null); + }); + test('test network request', () async { GetNetworkResponse networkResponse = await sorobanServer.getNetwork();