Skip to content

Commit

Permalink
Basic implementation of liquidity_pools?account (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinamogit authored Aug 10, 2023
1 parent c258f0d commit 09b8007
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/** Builds requests connected to liquidity pools. */
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");
Expand Down Expand Up @@ -72,6 +73,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 <a href="https://developers.stellar.org/api/resources/liquiditypools/list/">LiquidityPools</a>
*/
public LiquidityPoolsRequestBuilder forAccount(String account) {
uriBuilder.setQueryParameter(ACCOUNT_PARAMETER_NAME, account);
return this;
}

/**
* Requests specific <code>uri</code> and returns {@link Page} of {@link LiquidityPoolResponse}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,23 @@ public void testForReserves() {
"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());
}

@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());
}
}

0 comments on commit 09b8007

Please sign in to comment.