From a2c879d5478b011c0e35221b7d8e1f4f51dc2152 Mon Sep 17 00:00:00 2001 From: vinamogit Date: Sun, 1 May 2022 22:35:12 +0200 Subject: [PATCH 1/2] Basic implementation of liquidity_pools?account --- .../sdk/requests/LiquidityPoolsRequestBuilder.java | 13 +++++++++++++ .../requests/LiquidityPoolsRequestBuilderTest.java | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java index ed2e3a3ef..6b6f04385 100644 --- a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java @@ -17,6 +17,7 @@ */ public class LiquidityPoolsRequestBuilder extends RequestBuilder { private static final String RESERVES_PARAMETER_NAME = "reserves"; + private static final String ACCOUNT_PARAMETER_NAME = "account"; public LiquidityPoolsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { super(httpClient, serverURI, "liquidity_pools"); @@ -69,6 +70,18 @@ public LiquidityPoolsRequestBuilder forReserves(String... reserves) { uriBuilder.setQueryParameter(RESERVES_PARAMETER_NAME, String.join(",", reserves)); return this; } + + /** + * Returns all liquidity pools the specified account is participating in. + * + * @param account Account ID to filter liquidity pools + * @return current {@link LiquidityPoolsRequestBuilder} instance + * @see LiquidityPools + */ + public LiquidityPoolsRequestBuilder forAccount(String account) { + uriBuilder.setQueryParameter(ACCOUNT_PARAMETER_NAME, account); + return this; + } /** * Requests specific uri and returns {@link Page} of {@link LiquidityPoolResponse}. diff --git a/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java index 4e277ab96..f3885c24f 100644 --- a/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java @@ -26,4 +26,13 @@ public void testForReserves() { .buildUri(); assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?reserves=EURT%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S%2CPHP%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", uri.toString()); } + + @Test + public void testForAccount() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.liquidityPools() + .forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S") + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account=GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", uri.toString()); + } } From 225d483368e5c5b27ef4b9d97b66c92b4121add0 Mon Sep 17 00:00:00 2001 From: vinamogit Date: Tue, 3 May 2022 01:43:15 +0200 Subject: [PATCH 2/2] Add nullable segment test --- .../sdk/requests/LiquidityPoolsRequestBuilderTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java index f3885c24f..fce03a607 100644 --- a/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java @@ -35,4 +35,14 @@ public void testForAccount() { .buildUri(); assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account=GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", uri.toString()); } + + @Test + public void testForAccountClear() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.liquidityPools() + .forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S") + .forAccount(null) + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account", uri.toString()); + } }