-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Soroban PRC's
getLedgers
API interface. (#660)
- Loading branch information
Showing
9 changed files
with
264 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/org/stellar/sdk/requests/sorobanrpc/GetLedgersRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
/** | ||
* Request for JSON-RPC method getLedgers. | ||
* | ||
* @see <a href="https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLedgers" | ||
* target="_blank">getLedgers documentation</a> | ||
*/ | ||
@Value | ||
@Builder(toBuilder = true) | ||
public class GetLedgersRequest { | ||
@NonNull Long startLedger; | ||
|
||
PaginationOptions pagination; | ||
|
||
@Value | ||
@Builder(toBuilder = true) | ||
public static class PaginationOptions { | ||
Long limit; | ||
|
||
String cursor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgersResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.stellar.sdk.responses.sorobanrpc; | ||
|
||
import java.util.List; | ||
import lombok.Value; | ||
import org.stellar.sdk.Util; | ||
import org.stellar.sdk.xdr.LedgerCloseMeta; | ||
import org.stellar.sdk.xdr.LedgerHeaderHistoryEntry; | ||
|
||
/** | ||
* Response for JSON-RPC method getLedgers. | ||
* | ||
* @see <a href="https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLedgers" | ||
* target="_blank">getLedgers documentation</a> | ||
*/ | ||
@Value | ||
public class GetLedgersResponse { | ||
List<LedgerInfo> ledgers; | ||
Long latestLedger; | ||
Long latestLedgerCloseTime; | ||
Long oldestLedger; | ||
Long oldestLedgerCloseTime; | ||
String cursor; | ||
|
||
@Value | ||
public static class LedgerInfo { | ||
String hash; | ||
Long sequence; | ||
Long ledgerCloseTime; | ||
|
||
/** The field can be parsed as {@link LedgerHeaderHistoryEntry} object. */ | ||
String headerXdr; | ||
|
||
/** The field can be parsed as {@link LedgerCloseMeta} object. */ | ||
String metadataXdr; | ||
|
||
/** | ||
* Parses the {@code envelopeXdr} field from a string to an {@link LedgerHeaderHistoryEntry} | ||
* object. | ||
* | ||
* @return the parsed {@link LedgerHeaderHistoryEntry} object | ||
*/ | ||
public LedgerHeaderHistoryEntry parseHeaderXdr() { | ||
return Util.parseXdr(headerXdr, LedgerHeaderHistoryEntry::fromXdrBase64); | ||
} | ||
|
||
/** | ||
* Parses the {@code metadataXdr} field from a string to an {@link LedgerCloseMeta} object. | ||
* | ||
* @return the parsed {@link LedgerCloseMeta} object | ||
*/ | ||
public LedgerCloseMeta parseMetadataXdr() { | ||
return Util.parseXdr(metadataXdr, LedgerCloseMeta::fromXdrBase64); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/java/org/stellar/sdk/responses/sorobanrpc/GetLedgersDeserializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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 GetLedgersDeserializerTest { | ||
@Test | ||
public void testDeserialize() throws IOException { | ||
String filePath = "src/test/resources/responses/sorobanrpc/get_ledgers.json"; | ||
String json = new String(Files.readAllBytes(Paths.get(filePath))); | ||
|
||
SorobanRpcResponse<GetLedgersResponse> getLedgersResponseSorobanRpcResponse = | ||
GsonSingleton.getInstance() | ||
.fromJson(json, new TypeToken<SorobanRpcResponse<GetLedgersResponse>>() {}.getType()); | ||
|
||
GetLedgersResponse getLedgersResponse = getLedgersResponseSorobanRpcResponse.getResult(); | ||
assertEquals(getLedgersResponse.getLatestLedger().longValue(), 113L); | ||
assertEquals(getLedgersResponse.getLatestLedgerCloseTime().longValue(), 1731554518L); | ||
assertEquals(getLedgersResponse.getOldestLedger().longValue(), 8L); | ||
assertEquals(getLedgersResponse.getOldestLedgerCloseTime().longValue(), 1731554412L); | ||
assertEquals(getLedgersResponse.getCursor(), "11"); | ||
assertEquals(getLedgersResponse.getLedgers().size(), 2); | ||
assertEquals( | ||
getLedgersResponse.getLedgers().get(0).getHash(), | ||
"59ccafc5641a44826608a882da10b08f585b2b614be91976ade3927d4422413d"); | ||
assertEquals(getLedgersResponse.getLedgers().get(0).getSequence().longValue(), 10L); | ||
assertEquals( | ||
getLedgersResponse.getLedgers().get(0).getLedgerCloseTime().longValue(), 1731554414L); | ||
for (GetLedgersResponse.LedgerInfo ledgerInfo : getLedgersResponse.getLedgers()) { | ||
assertEquals(ledgerInfo.getHeaderXdr(), ledgerInfo.parseHeaderXdr().toXdrBase64()); | ||
assertEquals(ledgerInfo.getMetadataXdr(), ledgerInfo.parseMetadataXdr().toXdrBase64()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": "0ce70038b1804b3c93ca7abc137f3061", | ||
"result": { | ||
"ledgers": [ | ||
{ | ||
"hash": "59ccafc5641a44826608a882da10b08f585b2b614be91976ade3927d4422413d", | ||
"sequence": 10, | ||
"ledgerCloseTime": "1731554414", | ||
"headerXdr": "WcyvxWQaRIJmCKiC2hCwj1hbK2FL6Rl2reOSfUQiQT0AAAAVwLYrLkYHkh0rJ+GmAbGkeHIQpyDsekpf68ThNNsCXYI2jMO8189Z2jYaMg/mttiL9SVfJXThDGEIYe/klkKWMwAAAABnNWxuAAAAAAAAAAEAAAAApo8dlon1AzCqtWnWdzJ01L+/6QHyNiUhUM5rTILgk/cAAABAnJJp+kohsfTVKJYclwggQFe/Eie6zoL43O0xvKlYoYsd1I09szNQBqserhqzq+9WSTNS3wUZ8YC4U4e8O5+7AN8/YZgEqS/bQFcZLcQ910jqd4rcUrxJjOgFJMAUuBEZTxx260gYA3GwBr7nqsHUDnR+DGVQDc1IyOubd/pi5zcAAAAKDeC2s6dkAAAAAAAAAAPpLwAAAAAAAAAAAAAAAAAAAGQATEtAAAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", | ||
"metadataXdr": "AAAAAQAAAABZzK/FZBpEgmYIqILaELCPWFsrYUvpGXat45J9RCJBPQAAABXAtisuRgeSHSsn4aYBsaR4chCnIOx6Sl/rxOE02wJdgjaMw7zXz1naNhoyD+a22Iv1JV8ldOEMYQhh7+SWQpYzAAAAAGc1bG4AAAAAAAAAAQAAAACmjx2WifUDMKq1adZ3MnTUv7/pAfI2JSFQzmtMguCT9wAAAECckmn6SiGx9NUolhyXCCBAV78SJ7rOgvjc7TG8qVihix3UjT2zM1AGqx6uGrOr71ZJM1LfBRnxgLhTh7w7n7sA3z9hmASpL9tAVxktxD3XSOp3itxSvEmM6AUkwBS4ERlPHHbrSBgDcbAGvueqwdQOdH4MZVANzUjI65t3+mLnNwAAAAoN4Lazp2QAAAAAAAAAA+kvAAAAAAAAAAAAAAAAAAAAZABMS0AAAABkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAtisuRgeSHSsn4aYBsaR4chCnIOx6Sl/rxOE02wJdggAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQAAAAAAAAAAA==" | ||
}, | ||
{ | ||
"hash": "76b188897ab785d81a85508ad4434bb0c33a74c9c0874165120ccd3158f76ed3", | ||
"sequence": 11, | ||
"ledgerCloseTime": "1731554415", | ||
"headerXdr": "drGIiXq3hdgahVCK1ENLsMM6dMnAh0FlEgzNMVj3btMAAAAVWcyvxWQaRIJmCKiC2hCwj1hbK2FL6Rl2reOSfUQiQT37/jXH2AmHKzOU33bzTVlQU8zUjm7dqF8UMsn+7c+c5QAAAABnNWxvAAAAAAAAAAEAAAAApo8dlon1AzCqtWnWdzJ01L+/6QHyNiUhUM5rTILgk/cAAAB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AFZzK/FZBpEgmYIqILaELCPWFsrYUvpGXat45J9RCJBPQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQAAAAAAAAAAA==" | ||
} | ||
], | ||
"latestLedger": 113, | ||
"latestLedgerCloseTime": 1731554518, | ||
"oldestLedger": 8, | ||
"oldestLedgerCloseTime": 1731554412, | ||
"cursor": "11" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": "0ce70038b1804b3c93ca7abc137f3061", | ||
"result": { | ||
"ledgers": [ | ||
{ | ||
"hash": "59ccafc5641a44826608a882da10b08f585b2b614be91976ade3927d4422413d", | ||
"sequence": 10, | ||
"ledgerCloseTime": "1731554414", | ||
"headerXdr": "WcyvxWQaRIJmCKiC2hCwj1hbK2FL6Rl2reOSfUQiQT0AAAAVwLYrLkYHkh0rJ+GmAbGkeHIQpyDsekpf68ThNNsCXYI2jMO8189Z2jYaMg/mttiL9SVfJXThDGEIYe/klkKWMwAAAABnNWxuAAAAAAAAAAEAAAAApo8dlon1AzCqtWnWdzJ01L+/6QHyNiUhUM5rTILgk/cAAABAnJJp+kohsfTVKJYclwggQFe/Eie6zoL43O0xvKlYoYsd1I09szNQBqserhqzq+9WSTNS3wUZ8YC4U4e8O5+7AN8/YZgEqS/bQFcZLcQ910jqd4rcUrxJjOgFJMAUuBEZTxx260gYA3GwBr7nqsHUDnR+DGVQDc1IyOubd/pi5zcAAAAKDeC2s6dkAAAAAAAAAAPpLwAAAAAAAAAAAAAAAAAAAGQATEtAAAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", | ||
"metadataXdr": "AAAAAQAAAABZzK/FZBpEgmYIqILaELCPWFsrYUvpGXat45J9RCJBPQAAABXAtisuRgeSHSsn4aYBsaR4chCnIOx6Sl/rxOE02wJdgjaMw7zXz1naNhoyD+a22Iv1JV8ldOEMYQhh7+SWQpYzAAAAAGc1bG4AAAAAAAAAAQAAAACmjx2WifUDMKq1adZ3MnTUv7/pAfI2JSFQzmtMguCT9wAAAECckmn6SiGx9NUolhyXCCBAV78SJ7rOgvjc7TG8qVihix3UjT2zM1AGqx6uGrOr71ZJM1LfBRnxgLhTh7w7n7sA3z9hmASpL9tAVxktxD3XSOp3itxSvEmM6AUkwBS4ERlPHHbrSBgDcbAGvueqwdQOdH4MZVANzUjI65t3+mLnNwAAAAoN4Lazp2QAAAAAAAAAA+kvAAAAAAAAAAAAAAAAAAAAZABMS0AAAABkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAtisuRgeSHSsn4aYBsaR4chCnIOx6Sl/rxOE02wJdggAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQAAAAAAAAAAA==" | ||
}, | ||
{ | ||
"hash": "76b188897ab785d81a85508ad4434bb0c33a74c9c0874165120ccd3158f76ed3", | ||
"sequence": 11, | ||
"ledgerCloseTime": "1731554415", | ||
"headerXdr": "drGIiXq3hdgahVCK1ENLsMM6dMnAh0FlEgzNMVj3btMAAAAVWcyvxWQaRIJmCKiC2hCwj1hbK2FL6Rl2reOSfUQiQT37/jXH2AmHKzOU33bzTVl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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFZzK/FZBpEgmYIqILaELCPWFsrYUvpGXat45J9RCJBPQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQAAAAAAAAAAA==" | ||
} | ||
], | ||
"latestLedger": 113, | ||
"latestLedgerCloseTime": 1731554518, | ||
"oldestLedger": 8, | ||
"oldestLedgerCloseTime": 1731554412, | ||
"cursor": "11" | ||
} | ||
} | ||
|