From 1f7370a0c80ac9169b276f83e716be4d89e85552 Mon Sep 17 00:00:00 2001 From: Jun Luo <4catcode@gmail.com> Date: Mon, 7 Jul 2025 16:26:22 +0800 Subject: [PATCH] feat: adapt to the changes in the Stellar RPC v23 `getEvents` interface. --- CHANGELOG.md | 3 +++ .../sorobanrpc/GetEventsResponse.java | 21 +++++++++++-------- .../org/stellar/sdk/SorobanServerTest.java | 3 +-- .../sorobanrpc/GetEventsDeserializerTest.java | 8 +++++-- .../responses/sorobanrpc/get_events.json | 12 +++++++++-- .../resources/soroban_server/get_events.json | 10 +++++++-- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22d90ec69..6918a0b7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - feat: add muxed account, liquidity pool and claimable balance support to `Address` class. - feat: add `destinationMuxedId` and `destinationMuxedIdType` to `InvokeHostFunctionOperationResponse.AssetContractBalanceChange`. - feat: add `events` field to `GetTransactionsResponse.Transaction` and `GetTransactionResponse`, see [stellar-rpc#455](https://github.com/stellar/stellar-rpc/pull/455) for more details. +- feat: add `oldestLedger`, `latestLedgerCloseTime` and `oldestLedgerCloseTime` fields to `GetEventsResponse`, and add `transactionIndex` and `operationIndex` fields to `GetEventsResponse.EventInfo`, check [Stellar RPC release log](https://github.com/stellar/stellar-rpc/releases/tag/v23.0.0-rc.1) for more information. ### Breaking changes: - refactor!: the following functions in `StrKey` are marked as deprecated, they will be removed in the next major release; please refer to the documentation for each function to see the corresponding replacement functions: @@ -20,6 +21,8 @@ - `StrKey#encodeToXDRMuxedAccount(String)` - refactor!: remove `numArchivedContracts` and `archivedContractsAmount` from `AssetResponse`. - refactor!: `GetTransactionsResponse.Transaction#getDiagnosticEventsXdr()` and `GetTransactionsResponse.Transaction#parseDiagnosticEventsXdr()` has been marked as deprecated, they will be removed in Stellar RPC soon, use `GetTransactionsResponse.Transaction#getEvents()` instead. +- refactor!: remove deprecated `pagingToken` field from `GetEventsResponse.EventInfo`. +- refactor!: `inSuccessfulContractCall` in `GetEventsResponse.EventInfo` has been marked as deprecated, it will be removed in the next release. ## 1.5.0 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 b66b1b63c..33b4735f7 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java @@ -18,9 +18,13 @@ public class GetEventsResponse { List events; + String cursor; + Long latestLedger; + Long oldestLedger; - String cursor; + Long latestLedgerCloseTime; + Long oldestLedgerCloseTime; @Value public static class EventInfo { @@ -34,11 +38,12 @@ public static class EventInfo { String id; - /** - * The field may will be removed in the next version of the protocol. It remains for backward. - * It is recommended to use {@link #cursor} instead. - */ - String pagingToken; + Long operationIndex; + + Long transactionIndex; + + @SerializedName("txHash") + String transactionHash; /** The elements inside can be parsed as {@link org.stellar.sdk.xdr.SCVal} objects. */ List topic; @@ -46,11 +51,9 @@ public static class EventInfo { /** The field can be parsed as {@link org.stellar.sdk.xdr.SCVal} object. */ String value; + /** The field will be removed in the next version. */ Boolean inSuccessfulContractCall; - @SerializedName("txHash") - String transactionHash; - /** * Parses the {@code topic} field from a list of strings to a list of {@link * org.stellar.sdk.xdr.SCVal} objects. diff --git a/src/test/java/org/stellar/sdk/SorobanServerTest.java b/src/test/java/org/stellar/sdk/SorobanServerTest.java index 2116be02e..dcbbbfc48 100644 --- a/src/test/java/org/stellar/sdk/SorobanServerTest.java +++ b/src/test/java/org/stellar/sdk/SorobanServerTest.java @@ -757,7 +757,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) HttpUrl baseUrl = mockWebServer.url(""); SorobanServer server = new SorobanServer(baseUrl.toString()); GetEventsResponse resp = server.getEvents(getEventsRequest); - assertEquals(resp.getLatestLedger().longValue(), 187L); + assertEquals(resp.getLatestLedger().longValue(), 318987L); assertEquals(resp.getCursor(), "0000000468151439360-0000000000"); assertEquals(resp.getEvents().size(), 2); assertEquals(resp.getEvents().get(0).getType(), EventFilterType.CONTRACT); @@ -767,7 +767,6 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) resp.getEvents().get(0).getContractId(), "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K"); assertEquals(resp.getEvents().get(0).getId(), "0000000459561504768-0000000000"); - assertEquals(resp.getEvents().get(0).getPagingToken(), "0000000459561504768-0000000000"); assertEquals(resp.getEvents().get(0).getTopic().size(), 2); assertEquals(resp.getEvents().get(0).getTopic().get(0), "AAAADwAAAAdDT1VOVEVSAA=="); assertEquals(resp.getEvents().get(0).getTopic().get(1), "AAAADwAAAAlpbmNyZW1lbnQAAAA="); diff --git a/src/test/java/org/stellar/sdk/responses/sorobanrpc/GetEventsDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/sorobanrpc/GetEventsDeserializerTest.java index 2810a5928..bd28cc3a5 100644 --- a/src/test/java/org/stellar/sdk/responses/sorobanrpc/GetEventsDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/sorobanrpc/GetEventsDeserializerTest.java @@ -20,7 +20,10 @@ public void testDeserialize() throws IOException { SorobanRpcResponse getEventsResponse = GsonSingleton.getInstance() .fromJson(json, new TypeToken>() {}.getType()); - assertEquals(getEventsResponse.getResult().getLatestLedger().longValue(), 169L); + assertEquals(getEventsResponse.getResult().getLatestLedger().longValue(), 318987L); + assertEquals(getEventsResponse.getResult().getOldestLedger().longValue(), 317964L); + assertEquals(getEventsResponse.getResult().getLatestLedgerCloseTime().longValue(), 1751863824L); + assertEquals(getEventsResponse.getResult().getOldestLedgerCloseTime().longValue(), 1751858705L); assertEquals(getEventsResponse.getResult().getEvents().size(), 3); assertEquals(getEventsResponse.getResult().getCursor(), "0000000463856472064-0000000000"); @@ -31,7 +34,6 @@ public void testDeserialize() throws IOException { assertEquals( eventInfo0.getContractId(), "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K"); assertEquals(eventInfo0.getId(), "0000000463856472064-0000000000"); - assertEquals(eventInfo0.getPagingToken(), "0000000463856472064-0000000000"); assertEquals(eventInfo0.getTopic().size(), 2); assertEquals(eventInfo0.getTopic().get(0), "AAAADwAAAAdDT1VOVEVSAA=="); assertEquals(eventInfo0.getTopic().get(1), "AAAADwAAAAlpbmNyZW1lbnQAAAA="); @@ -45,6 +47,8 @@ public void testDeserialize() throws IOException { assertEquals(eventInfo0.parseTopic().size(), 2); assertEquals(eventInfo0.parseTopic().get(0).toXdrBase64(), eventInfo0.getTopic().get(0)); assertEquals(eventInfo0.parseTopic().get(1).toXdrBase64(), eventInfo0.getTopic().get(1)); + assertEquals(eventInfo0.getOperationIndex().longValue(), 1L); + assertEquals(eventInfo0.getTransactionIndex().longValue(), 2L); GetEventsResponse.EventInfo eventInfo1 = getEventsResponse.getResult().getEvents().get(1); assertEquals(eventInfo1.getType(), EventFilterType.SYSTEM); diff --git a/src/test/resources/responses/sorobanrpc/get_events.json b/src/test/resources/responses/sorobanrpc/get_events.json index 955eece2d..0dfa8d186 100644 --- a/src/test/resources/responses/sorobanrpc/get_events.json +++ b/src/test/resources/responses/sorobanrpc/get_events.json @@ -9,13 +9,14 @@ "ledgerClosedAt": "2023-07-23T14:47:01Z", "contractId": "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K", "id": "0000000463856472064-0000000000", - "pagingToken": "0000000463856472064-0000000000", "topic": [ "AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA=" ], "value": "AAAAAwAAAAE=", "inSuccessfulContractCall": true, + "operationIndex": 1, + "transactionIndex": 2, "txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d" }, { @@ -30,6 +31,8 @@ "AAAADwAAAAlpbmNyZW1lbnQAAAA=" ], "value": "AAAAAwAAAAI=", + "operationIndex": 3, + "transactionIndex": 4, "inSuccessfulContractCall": true, "txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d" }, @@ -45,11 +48,16 @@ "AAAADwAAAAlpbmNyZW1lbnQAAAA=" ], "value": "AAAAAwAAAAM=", + "operationIndex": 5, + "transactionIndex": 6, "inSuccessfulContractCall": true, "txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d" } ], - "latestLedger": "169", + "latestLedger": 318987, + "oldestLedger": 317964, + "latestLedgerCloseTime": "1751863824", + "oldestLedgerCloseTime": "1751858705", "cursor": "0000000463856472064-0000000000" } } \ No newline at end of file diff --git a/src/test/resources/soroban_server/get_events.json b/src/test/resources/soroban_server/get_events.json index 5d8c4bfcd..17c672ecb 100644 --- a/src/test/resources/soroban_server/get_events.json +++ b/src/test/resources/soroban_server/get_events.json @@ -9,11 +9,12 @@ "ledgerClosedAt": "2023-07-28T14:57:02Z", "contractId": "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K", "id": "0000000459561504768-0000000000", - "pagingToken": "0000000459561504768-0000000000", "topic": [ "AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA=" ], + "operationIndex": 1, + "transactionIndex": 2, "value": "AAAAAwAAAAQ=", "inSuccessfulContractCall": true, "txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d" @@ -29,12 +30,17 @@ "AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA=" ], + "operationIndex": 3, + "transactionIndex": 4, "value": "AAAAAwAAAAU=", "inSuccessfulContractCall": true, "txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d" } ], - "latestLedger": "187", + "latestLedger": 318987, + "oldestLedger": 317964, + "latestLedgerCloseTime": "1751863824", + "oldestLedgerCloseTime": "1751858705", "cursor": "0000000468151439360-0000000000" } } \ No newline at end of file