From 4d87082fc60bd1c7c93f636242937ca630962b22 Mon Sep 17 00:00:00 2001
From: Jun Luo <4catcode@gmail.com>
Date: Fri, 8 Sep 2023 00:29:02 +0800
Subject: [PATCH 1/2] fix the issue of unable to parse liquidity_pool_revoked
effect properly. (#521)
* add jitpack config.
* bump project version to upcoming 0.4.1
* update change log, include #522
---
CHANGELOG.md | 6 ++
build.gradle | 2 +-
jitpack.yml | 7 ++
.../LiquidityPoolsRequestBuilder.java | 9 +-
.../sdk/responses/EffectDeserializer.java | 2 +
.../LiquidityPoolClaimableAssetAmount.java | 4 +
.../LiquidityPoolRevokedEffectResponse.java | 7 +-
.../LiquidityPoolsRequestBuilderTest.java | 26 +++--
.../sdk/responses/EffectDeserializerTest.java | 95 +++++++++++++++++++
9 files changed, 140 insertions(+), 18 deletions(-)
create mode 100644 jitpack.yml
diff --git a/CHANGELOG.md b/CHANGELOG.md
index acec00728..ce615de9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.
## Pending
+## 0.40.1
+* Fix the issue of unable to parse liquidity_pool_revoked effect properly. ([#521](https://github.com/stellar/java-stellar-sdk/pull/521))
+* Define cursor, order and limit in AssetsRequestBuilder object. ([#522](https://github.com/stellar/java-stellar-sdk/pull/522))
+* Add basic implementation of liquidity_pools?account ([#426](https://github.com/stellar/java-stellar-sdk/pull/426))
+* Add source account comparison to `ClawbackClaimableBalanceOperation`, `LiquidityPoolWithdrawOperation`, and `LiquidityPoolDepositOperation` for equality check. ([#484](https://github.com/stellar/java-stellar-sdk/pull/484))
+
## 0.40.0
* Add strkey support for contract ids ([#471](https://github.com/stellar/java-stellar-sdk/pull/471))
* Fix NPE in `KeyPair.equals()` method ([#474](https://github.com/stellar/java-stellar-sdk/pull/474))
diff --git a/build.gradle b/build.gradle
index a8455fde2..07d4c39fc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -25,7 +25,7 @@ spotless {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
-version = '0.40.0'
+version = '0.40.1'
group = 'stellar'
jar.enabled = false
diff --git a/jitpack.yml b/jitpack.yml
new file mode 100644
index 000000000..f81efc783
--- /dev/null
+++ b/jitpack.yml
@@ -0,0 +1,7 @@
+jdk:
+ - openjdk11
+
+before_install:
+ - sdk install java 11.0.23-open
+ - sdk use java 11.0.23-open
+
diff --git a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java
index 906bc35bb..5460f3a96 100644
--- a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java
+++ b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java
@@ -73,17 +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 LiquidityPools
+ * @see LiquidityPools
*/
public LiquidityPoolsRequestBuilder forAccount(String account) {
- uriBuilder.setQueryParameter(ACCOUNT_PARAMETER_NAME, account);
- return this;
+ uriBuilder.setQueryParameter(ACCOUNT_PARAMETER_NAME, account);
+ return this;
}
/**
diff --git a/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java b/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java
index abcc12840..cc841b201 100644
--- a/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java
+++ b/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java
@@ -1,5 +1,6 @@
package org.stellar.sdk.responses;
+import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
@@ -25,6 +26,7 @@ public EffectResponse deserialize(
.registerTypeAdapter(LiquidityPoolID.class, new LiquidityPoolIDDeserializer())
.registerTypeAdapter(LiquidityPoolType.class, new LiquidityPoolTypeDeserializer())
.registerTypeAdapter(Predicate.class, new PredicateDeserializer())
+ .registerTypeAdapter(ImmutableList.class, new ImmutableListDeserializer())
.create();
int type = json.getAsJsonObject().get("type_i").getAsInt();
diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmount.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmount.java
index 97f92de5a..2cac5bdc4 100644
--- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmount.java
+++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmount.java
@@ -1,6 +1,8 @@
package org.stellar.sdk.responses.effects;
import com.google.gson.annotations.SerializedName;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
import org.stellar.sdk.Asset;
/**
@@ -11,6 +13,8 @@
* @see org.stellar.sdk.requests.EffectsRequestBuilder
* @see org.stellar.sdk.Server#effects()
*/
+@EqualsAndHashCode
+@ToString
public class LiquidityPoolClaimableAssetAmount {
@SerializedName("asset")
protected final Asset asset;
diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java
index 5126478d8..228afd871 100644
--- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java
+++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java
@@ -1,5 +1,6 @@
package org.stellar.sdk.responses.effects;
+import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName;
/**
@@ -15,14 +16,14 @@ public class LiquidityPoolRevokedEffectResponse extends EffectResponse {
protected final LiquidityPool liquidityPool;
@SerializedName("reserves_revoked")
- protected final LiquidityPoolClaimableAssetAmount reservesRevoked;
+ protected final ImmutableList reservesRevoked;
@SerializedName("shares_revoked")
protected final String sharesRevoked;
public LiquidityPoolRevokedEffectResponse(
LiquidityPool liquidityPool,
- LiquidityPoolClaimableAssetAmount reservesRevoked,
+ ImmutableList reservesRevoked,
String sharesRevoked) {
this.liquidityPool = liquidityPool;
this.reservesRevoked = reservesRevoked;
@@ -33,7 +34,7 @@ public LiquidityPool getLiquidityPool() {
return liquidityPool;
}
- public LiquidityPoolClaimableAssetAmount getReservesRevoked() {
+ public ImmutableList getReservesRevoked() {
return reservesRevoked;
}
diff --git a/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java
index 9c80794a4..97dd6060d 100644
--- a/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java
+++ b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java
@@ -36,23 +36,29 @@ 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());
+ 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();
+ HttpUrl uri =
+ server
+ .liquidityPools()
+ .forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")
+ .forAccount(null)
+ .buildUri();
assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account", uri.toString());
}
}
diff --git a/src/test/java/org/stellar/sdk/responses/EffectDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/EffectDeserializerTest.java
index 0f8d9ecea..100d106b1 100644
--- a/src/test/java/org/stellar/sdk/responses/EffectDeserializerTest.java
+++ b/src/test/java/org/stellar/sdk/responses/EffectDeserializerTest.java
@@ -1,5 +1,6 @@
package org.stellar.sdk.responses;
+import static org.junit.Assert.assertArrayEquals;
import static org.stellar.sdk.Asset.create;
import java.util.Arrays;
@@ -22,6 +23,8 @@
import org.stellar.sdk.responses.effects.DataRemovedEffectResponse;
import org.stellar.sdk.responses.effects.DataUpdatedEffectResponse;
import org.stellar.sdk.responses.effects.EffectResponse;
+import org.stellar.sdk.responses.effects.LiquidityPoolClaimableAssetAmount;
+import org.stellar.sdk.responses.effects.LiquidityPoolRevokedEffectResponse;
import org.stellar.sdk.responses.effects.LiquidityPoolTradeEffectResponse;
import org.stellar.sdk.responses.effects.SequenceBumpedEffectResponse;
import org.stellar.sdk.responses.effects.SignerCreatedEffectResponse;
@@ -1318,4 +1321,96 @@ public void testDeserializeLiquidityPoolTradeEffect() {
new AssetAmount(
create("ARST:GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO"), "1.0000000"));
}
+
+ @Test
+ public void testDeserializeLiquidityPoolRevokedEffect() {
+ String json =
+ "{\n"
+ + " \"_links\": {\n"
+ + " \"operation\": {\n"
+ + " \"href\": \"https://horizon.stellar.org/operations/166807682144149505\"\n"
+ + " },\n"
+ + " \"succeeds\": {\n"
+ + " \"href\": \"https://horizon.stellar.org/effects?order=desc&cursor=166807682144149505-7\"\n"
+ + " },\n"
+ + " \"precedes\": {\n"
+ + " \"href\": \"https://horizon.stellar.org/effects?order=asc&cursor=166807682144149505-7\"\n"
+ + " }\n"
+ + " },\n"
+ + " \"id\": \"0166807682144149505-0000000007\",\n"
+ + " \"paging_token\": \"166807682144149505-7\",\n"
+ + " \"account\": \"GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y\",\n"
+ + " \"type\": \"liquidity_pool_revoked\",\n"
+ + " \"type_i\": 95,\n"
+ + " \"created_at\": \"2021-12-22T13:50:44Z\",\n"
+ + " \"liquidity_pool\": {\n"
+ + " \"id\": \"d0e6dfe3cb35848c528ba283f8a274b61c0acae73486981e2e49c815ef0fa275\",\n"
+ + " \"fee_bp\": 30,\n"
+ + " \"type\": \"constant_product\",\n"
+ + " \"total_trustlines\": \"2\",\n"
+ + " \"total_shares\": \"12695.9043474\",\n"
+ + " \"reserves\": [\n"
+ + " {\n"
+ + " \"asset\": \"native\",\n"
+ + " \"amount\": \"166.0927633\"\n"
+ + " },\n"
+ + " {\n"
+ + " \"asset\": \"TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y\",\n"
+ + " \"amount\": \"979387.4348690\"\n"
+ + " }\n"
+ + " ]\n"
+ + " },\n"
+ + " \"reserves_revoked\": [\n"
+ + " {\n"
+ + " \"asset\": \"native\",\n"
+ + " \"amount\": \"319.8948139\",\n"
+ + " \"claimable_balance_id\": \"0000000021e897197b8fe396772891ba3ece3244c37ba039fd73bd0ef0ce68a90d5bb688\"\n"
+ + " },\n"
+ + " {\n"
+ + " \"asset\": \"TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y\",\n"
+ + " \"amount\": \"1886301.0948913\",\n"
+ + " \"claimable_balance_id\": \"000000001843f844860fd96541993c96c72157c1a5eb9d522e6f5b99e2ab300ccee8e38d\"\n"
+ + " }\n"
+ + " ],\n"
+ + " \"shares_revoked\": \"24452.3233794\"\n"
+ + "}\n";
+
+ LiquidityPoolRevokedEffectResponse effect =
+ (LiquidityPoolRevokedEffectResponse)
+ GsonSingleton.getInstance().fromJson(json, EffectResponse.class);
+
+ assertEquals(effect.getType(), "liquidity_pool_revoked");
+
+ assertEquals(effect.getAccount(), "GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y");
+ assertEquals(effect.getCreatedAt(), "2021-12-22T13:50:44Z");
+ assertEquals(
+ effect.getLiquidityPool().getID().toString(),
+ "d0e6dfe3cb35848c528ba283f8a274b61c0acae73486981e2e49c815ef0fa275");
+ assertEquals(effect.getLiquidityPool().getFeeBP(), Integer.valueOf(30));
+ assertEquals(
+ effect.getLiquidityPool().getType(), LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT);
+ assertEquals(effect.getLiquidityPool().getTotalTrustlines(), Long.valueOf(2));
+ assertEquals(effect.getLiquidityPool().getTotalShares(), "12695.9043474");
+ assertArrayEquals(
+ effect.getLiquidityPool().getReserves(),
+ new AssetAmount[] {
+ new AssetAmount(create("native"), "166.0927633"),
+ new AssetAmount(
+ create("TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y"),
+ "979387.4348690")
+ });
+ assertArrayEquals(
+ effect.getReservesRevoked().toArray(),
+ new LiquidityPoolClaimableAssetAmount[] {
+ new LiquidityPoolClaimableAssetAmount(
+ create("native"),
+ "319.8948139",
+ "0000000021e897197b8fe396772891ba3ece3244c37ba039fd73bd0ef0ce68a90d5bb688"),
+ new LiquidityPoolClaimableAssetAmount(
+ create("TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y"),
+ "1886301.0948913",
+ "000000001843f844860fd96541993c96c72157c1a5eb9d522e6f5b99e2ab300ccee8e38d")
+ });
+ assertEquals(effect.getSharesRevoked(), "24452.3233794");
+ }
}
From adad474a4928cd3de72889f22ffe58751611bb69 Mon Sep 17 00:00:00 2001
From: Jun Luo <4catcode@gmail.com>
Date: Fri, 8 Sep 2023 00:35:57 +0800
Subject: [PATCH 2/2] define `cursor`, `order` and `limit` in
AssetsRequestBuilder object. (#522)
---
.../sdk/requests/AssetsRequestBuilder.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/main/java/org/stellar/sdk/requests/AssetsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/AssetsRequestBuilder.java
index 515882c98..4db3d0527 100644
--- a/src/main/java/org/stellar/sdk/requests/AssetsRequestBuilder.java
+++ b/src/main/java/org/stellar/sdk/requests/AssetsRequestBuilder.java
@@ -39,4 +39,22 @@ public static Page execute(OkHttpClient httpClient, HttpUrl uri)
public Page execute() throws IOException, TooManyRequestsException {
return this.execute(this.httpClient, this.buildUri());
}
+
+ @Override
+ public AssetsRequestBuilder cursor(String token) {
+ super.cursor(token);
+ return this;
+ }
+
+ @Override
+ public AssetsRequestBuilder limit(int number) {
+ super.limit(number);
+ return this;
+ }
+
+ @Override
+ public AssetsRequestBuilder order(Order direction) {
+ super.order(direction);
+ return this;
+ }
}