diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2dafefe..47e91b87b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ continued engagement as we shape the future of this project together. - chore: Display the original definition in the XDR class documentation. - chore: add some examples, you can find them in the `examples` directory. - chore: bump dependencies. +- feat: add support for Soroban PRC's `getVersionInfo` API. ### Breaking changes - refactor!: Refactored the handling of exceptions. diff --git a/src/main/java/org/stellar/sdk/SorobanServer.java b/src/main/java/org/stellar/sdk/SorobanServer.java index cf7f46586..687d0f920 100644 --- a/src/main/java/org/stellar/sdk/SorobanServer.java +++ b/src/main/java/org/stellar/sdk/SorobanServer.java @@ -43,6 +43,7 @@ import org.stellar.sdk.responses.sorobanrpc.GetNetworkResponse; import org.stellar.sdk.responses.sorobanrpc.GetTransactionResponse; import org.stellar.sdk.responses.sorobanrpc.GetTransactionsResponse; +import org.stellar.sdk.responses.sorobanrpc.GetVersionInfoResponse; import org.stellar.sdk.responses.sorobanrpc.SendTransactionResponse; import org.stellar.sdk.responses.sorobanrpc.SimulateTransactionResponse; import org.stellar.sdk.responses.sorobanrpc.SorobanRpcResponse; @@ -144,8 +145,8 @@ public TransactionBuilderAccount getAccount(String address) { * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see getHealth - * documentation + * @see getHealth documentation */ public GetHealthResponse getHealth() { return this.sendRequest( @@ -240,7 +241,8 @@ public Optional getContractData( * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see getLedgerEntries documentation */ public GetLedgerEntriesResponse getLedgerEntries(Collection keys) { @@ -280,7 +282,8 @@ public GetLedgerEntriesResponse getLedgerEntries(Collection keys) { * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see getTransaction documentation */ public GetTransactionResponse getTransaction(String hash) { @@ -325,14 +328,33 @@ public GetTransactionsResponse getTransactions(GetTransactionsRequest getTransac * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see getEvents - * documentation + * @see getEvents documentation */ public GetEventsResponse getEvents(GetEventsRequest getEventsRequest) { return this.sendRequest( "getEvents", getEventsRequest, new TypeToken>() {}); } + /** + * Fetches version information about the RPC and Captive core. + * + * @return A {@link GetVersionInfoResponse} object containing the version information. + * @throws org.stellar.sdk.exception.NetworkException All the exceptions below are subclasses of + * NetworkError + * @throws SorobanRpcException If the Soroban-RPC instance returns an error response. + * @throws RequestTimeoutException If the request timed out. + * @throws ConnectionErrorException When the request cannot be executed due to cancellation or + * connectivity problems, etc. + * @see getVersionInfo documentation + */ + public GetVersionInfoResponse getVersionInfo() { + return this.sendRequest( + "getVersionInfo", null, new TypeToken>() {}); + } + /** * Fetches metadata about the network which Soroban-RPC is connected to. * @@ -343,8 +365,8 @@ public GetEventsResponse getEvents(GetEventsRequest getEventsRequest) { * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see getNetwork - * documentation + * @see getNetwork documentation */ public GetNetworkResponse getNetwork() { return this.sendRequest( @@ -361,7 +383,8 @@ public GetNetworkResponse getNetwork() { * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see getLatestLedger documentation */ public GetLatestLedgerResponse getLatestLedger() { @@ -387,7 +410,8 @@ public GetLatestLedgerResponse getLatestLedger() { * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see simulateTransaction documentation */ public SimulateTransactionResponse simulateTransaction( @@ -500,7 +524,8 @@ public Transaction prepareTransaction( * @throws RequestTimeoutException If the request timed out. * @throws ConnectionErrorException When the request cannot be executed due to cancellation or * connectivity problems, etc. - * @see sendTransaction documentation */ public SendTransactionResponse sendTransaction(Transaction transaction) { diff --git a/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetEventsRequest.java b/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetEventsRequest.java index ac56bf7cf..279d90795 100644 --- a/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetEventsRequest.java +++ b/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetEventsRequest.java @@ -9,7 +9,7 @@ /** * Request for JSON-RPC method getEvents. * - * @see getEvents documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetLedgerEntriesRequest.java b/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetLedgerEntriesRequest.java index 82fbaacdb..6c536f31a 100644 --- a/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetLedgerEntriesRequest.java +++ b/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetLedgerEntriesRequest.java @@ -6,7 +6,8 @@ /** * Request for JSON-RPC method getLedgerEntries. * - * @see getLedgerEntries documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetTransactionRequest.java b/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetTransactionRequest.java index 0c3376a56..a074ab5bb 100644 --- a/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetTransactionRequest.java +++ b/src/main/java/org/stellar/sdk/requests/sorobanrpc/GetTransactionRequest.java @@ -5,7 +5,7 @@ /** * Request for JSON-RPC method getTransaction. * - * @see getTransaction documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/requests/sorobanrpc/SendTransactionRequest.java b/src/main/java/org/stellar/sdk/requests/sorobanrpc/SendTransactionRequest.java index 84684085e..4e12f6a52 100644 --- a/src/main/java/org/stellar/sdk/requests/sorobanrpc/SendTransactionRequest.java +++ b/src/main/java/org/stellar/sdk/requests/sorobanrpc/SendTransactionRequest.java @@ -5,7 +5,7 @@ /** * Request for JSON-RPC method sendTransaction. * - * @see sendTransaction documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/requests/sorobanrpc/SimulateTransactionRequest.java b/src/main/java/org/stellar/sdk/requests/sorobanrpc/SimulateTransactionRequest.java index f518b8332..394039b2b 100644 --- a/src/main/java/org/stellar/sdk/requests/sorobanrpc/SimulateTransactionRequest.java +++ b/src/main/java/org/stellar/sdk/requests/sorobanrpc/SimulateTransactionRequest.java @@ -8,7 +8,8 @@ /** * Request for JSON-RPC method simulateTransaction. * - * @see simulateTransaction documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java index 5f50600a2..bc10d3993 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java @@ -11,7 +11,7 @@ /** * Response for JSON-RPC method getEvents. * - * @see getEvents documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetHealthResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetHealthResponse.java index da3e9afe3..a475ec5d6 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetHealthResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetHealthResponse.java @@ -5,7 +5,7 @@ /** * Response for JSON-RPC method getHealth. * - * @see getHealth documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLatestLedgerResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLatestLedgerResponse.java index c5c8f4817..ff10cfa82 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLatestLedgerResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLatestLedgerResponse.java @@ -5,7 +5,7 @@ /** * Response for JSON-RPC method getLatestLedger. * - * @see getLatestLedger documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java index d84b63cdd..e79ee69f0 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java @@ -10,7 +10,8 @@ /** * Response for JSON-RPC method getLedgerEntries. * - * @see getLedgerEntries documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetNetworkResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetNetworkResponse.java index a32cfb754..96028d8c2 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetNetworkResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetNetworkResponse.java @@ -6,7 +6,7 @@ /** * Response for JSON-RPC method getNetwork. * - * @see getNetwork documentation */ @AllArgsConstructor diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetTransactionResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetTransactionResponse.java index 1a68d98dd..2c6da0bb9 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetTransactionResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetTransactionResponse.java @@ -9,7 +9,7 @@ /** * Response for JSON-RPC method getTransaction. * - * @see getTransaction documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetVersionInfoResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetVersionInfoResponse.java new file mode 100644 index 000000000..8b77b0e0a --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetVersionInfoResponse.java @@ -0,0 +1,24 @@ +package org.stellar.sdk.responses.sorobanrpc; + +import lombok.AllArgsConstructor; +import lombok.Value; + +/** + * Response for JSON-RPC method getNetwork. + * + * @see getNetwork documentation + */ +@AllArgsConstructor +@Value +public class GetVersionInfoResponse { + String version; + + String commitHash; + + String buildTimestamp; + + String captiveCoreVersion; + + Integer protocolVersion; +} diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/SendTransactionResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/SendTransactionResponse.java index 37f03d0ea..0ee650402 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/SendTransactionResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/SendTransactionResponse.java @@ -10,7 +10,7 @@ /** * Response for JSON-RPC method sendTransaction. * - * @see sendTransaction documentation */ @Value diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java index 6abd2374b..4753393df 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java @@ -22,7 +22,7 @@ * restore operation needed. * *

Please refer to the latest Soroban simulateTransaction documentation for details on which members of the * simulation response model are keyed to each type of response. */ diff --git a/src/test/java/org/stellar/sdk/SorobanServerTest.java b/src/test/java/org/stellar/sdk/SorobanServerTest.java index 26056e7d5..464b2cf58 100644 --- a/src/test/java/org/stellar/sdk/SorobanServerTest.java +++ b/src/test/java/org/stellar/sdk/SorobanServerTest.java @@ -45,6 +45,7 @@ import org.stellar.sdk.responses.sorobanrpc.GetLedgerEntriesResponse; import org.stellar.sdk.responses.sorobanrpc.GetNetworkResponse; import org.stellar.sdk.responses.sorobanrpc.GetTransactionsResponse; +import org.stellar.sdk.responses.sorobanrpc.GetVersionInfoResponse; import org.stellar.sdk.responses.sorobanrpc.SendTransactionResponse; import org.stellar.sdk.responses.sorobanrpc.SimulateTransactionResponse; import org.stellar.sdk.xdr.ContractDataDurability; @@ -698,6 +699,45 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) mockWebServer.close(); } + @Test + public void testGetVersionInfo() throws IOException, SorobanRpcException { + String filePath = "src/test/resources/soroban_server/get_version_info.json"; + String json = new String(Files.readAllBytes(Paths.get(filePath))); + MockWebServer mockWebServer = new MockWebServer(); + Dispatcher dispatcher = + new Dispatcher() { + @NotNull + @Override + public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) + throws InterruptedException { + SorobanRpcRequest sorobanRpcRequest = + gson.fromJson( + recordedRequest.getBody().readUtf8(), + new TypeToken>() {}.getType()); + if ("POST".equals(recordedRequest.getMethod()) + && sorobanRpcRequest.getMethod().equals("getVersionInfo")) { + return new MockResponse().setResponseCode(200).setBody(json); + } + return new MockResponse().setResponseCode(404); + } + }; + mockWebServer.setDispatcher(dispatcher); + mockWebServer.start(); + + HttpUrl baseUrl = mockWebServer.url(""); + SorobanServer server = new SorobanServer(baseUrl.toString()); + GetVersionInfoResponse resp = server.getVersionInfo(); + assertEquals(resp.getVersion(), "21.1.0"); + assertEquals(resp.getCommitHash(), "fcd2f0523f04279bae4502f3e3fa00ca627e6f6a"); + assertEquals(resp.getBuildTimestamp(), "2024-05-10T11:18:38"); + assertEquals( + resp.getCaptiveCoreVersion(), + "stellar-core 21.0.0.rc2 (c6f474133738ae5f6d11b07963ca841909210273)"); + assertEquals(resp.getProtocolVersion().intValue(), 21); + server.close(); + mockWebServer.close(); + } + @Test public void testGetLatestLedger() throws IOException, SorobanRpcException { String filePath = "src/test/resources/soroban_server/get_latest_ledger.json"; diff --git a/src/test/java/org/stellar/sdk/responses/sorobanrpc/GetVersionInfoDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/sorobanrpc/GetVersionInfoDeserializerTest.java new file mode 100644 index 000000000..7e121f969 --- /dev/null +++ b/src/test/java/org/stellar/sdk/responses/sorobanrpc/GetVersionInfoDeserializerTest.java @@ -0,0 +1,31 @@ +package org.stellar.sdk.responses.sorobanrpc; + +import static org.junit.Assert.assertEquals; + +import com.google.gson.reflect.TypeToken; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.junit.Test; +import org.stellar.sdk.responses.gson.GsonSingleton; + +public class GetVersionInfoDeserializerTest { + @Test + public void testDeserialize() throws IOException { + String filePath = "src/test/resources/responses/sorobanrpc/get_version_info.json"; + String json = new String(Files.readAllBytes(Paths.get(filePath))); + SorobanRpcResponse getVersionInfoResponse = + GsonSingleton.getInstance() + .fromJson( + json, new TypeToken>() {}.getType()); + assertEquals(getVersionInfoResponse.getResult().getVersion(), "21.1.0"); + assertEquals( + getVersionInfoResponse.getResult().getCommitHash(), + "fcd2f0523f04279bae4502f3e3fa00ca627e6f6a"); + assertEquals(getVersionInfoResponse.getResult().getBuildTimestamp(), "2024-05-10T11:18:38"); + assertEquals( + getVersionInfoResponse.getResult().getCaptiveCoreVersion(), + "stellar-core 21.0.0.rc2 (c6f474133738ae5f6d11b07963ca841909210273)"); + assertEquals(getVersionInfoResponse.getResult().getProtocolVersion().intValue(), 21); + } +} diff --git a/src/test/resources/responses/sorobanrpc/get_version_info.json b/src/test/resources/responses/sorobanrpc/get_version_info.json new file mode 100644 index 000000000..1510f2a24 --- /dev/null +++ b/src/test/resources/responses/sorobanrpc/get_version_info.json @@ -0,0 +1,11 @@ +{ + "jsonrpc": "2.0", + "id": "198cb1a8-9104-4446-a269-88bf000c2721", + "result": { + "version": "21.1.0", + "commitHash": "fcd2f0523f04279bae4502f3e3fa00ca627e6f6a", + "buildTimestamp": "2024-05-10T11:18:38", + "captiveCoreVersion": "stellar-core 21.0.0.rc2 (c6f474133738ae5f6d11b07963ca841909210273)", + "protocolVersion": 21 + } +} \ No newline at end of file diff --git a/src/test/resources/soroban_server/get_version_info.json b/src/test/resources/soroban_server/get_version_info.json new file mode 100644 index 000000000..1510f2a24 --- /dev/null +++ b/src/test/resources/soroban_server/get_version_info.json @@ -0,0 +1,11 @@ +{ + "jsonrpc": "2.0", + "id": "198cb1a8-9104-4446-a269-88bf000c2721", + "result": { + "version": "21.1.0", + "commitHash": "fcd2f0523f04279bae4502f3e3fa00ca627e6f6a", + "buildTimestamp": "2024-05-10T11:18:38", + "captiveCoreVersion": "stellar-core 21.0.0.rc2 (c6f474133738ae5f6d11b07963ca841909210273)", + "protocolVersion": 21 + } +} \ No newline at end of file