Skip to content

Commit

Permalink
soroban: add getVersionInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jul 23, 2024
1 parent 9c49f7a commit 040f3c0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/src/soroban/soroban_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetVersionInfoResponse> 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<GetLatestLedgerResponse> getLatestLedger() async {
Expand Down Expand Up @@ -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<String, dynamic> jsonResponse) : super(jsonResponse);

factory GetVersionInfoResponse.fromJson(Map<String, dynamic> 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.
Expand Down
9 changes: 9 additions & 0 deletions test/soroban_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 040f3c0

Please sign in to comment.