Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for parsing ContractCreditedEffect and ContractDebitedEffect. #535

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.

## 0.41.0-beta.4
* Add support for Soroban Preview 11. ([#530](https://github.com/stellar/java-stellar-sdk/pull/530))
* New effects have been added to support Protocol 20 (Soroban) ([#535](https://github.com/stellar/java-stellar-sdk/pull/535)):
- `ContractCredited` occurs when a Stellar asset moves into its corresponding Stellar Asset Contract instance
- `ContractDebited` occurs when a Stellar asset moves out of its corresponding Stellar Asset Contract instance
* Bump dependencies & Remove unnecessary dependencies. ([#523](https://github.com/stellar/java-stellar-sdk/pull/523))

## 0.41.0-beta.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public EffectResponse deserialize(
return gson.fromJson(json, LiquidityPoolRemovedEffectResponse.class);
case 95:
return gson.fromJson(json, LiquidityPoolRevokedEffectResponse.class);
case 96:
return gson.fromJson(json, ContractCreditedEffectResponse.class);
case 97:
return gson.fromJson(json, ContractDebitedEffectResponse.class);
default:
throw new RuntimeException("Invalid effect type");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.stellar.sdk.responses.effects;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* Represents contract_credited effect response.
*
* @see <a
* href="https://github.com/stellar/go/blob/d41faf8cd619718b9801a62254a513591f6cbc0a/protocols/horizon/effects/main.go#L316-L321"
* target="_blank">Effect definition</a>
* @see org.stellar.sdk.requests.EffectsRequestBuilder
* @see org.stellar.sdk.Server#effects()
*/
@AllArgsConstructor
@Getter
public class ContractCreditedEffectResponse extends EffectResponse {
@SerializedName("asset_type")
private final String assetType;

@SerializedName("asset_code")
private final String assetCode;

@SerializedName("asset_issuer")
private final String assetIssuer;

private final String contract;

private final String amount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.stellar.sdk.responses.effects;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* Represents contract_debited effect response.
*
* @see <a
* href="https://github.com/stellar/go/blob/d41faf8cd619718b9801a62254a513591f6cbc0a/protocols/horizon/effects/main.go#L323-L328"
* target="_blank">Effect definition</a>
* @see org.stellar.sdk.requests.EffectsRequestBuilder
* @see org.stellar.sdk.Server#effects()
*/
@AllArgsConstructor
@Getter
public class ContractDebitedEffectResponse extends EffectResponse {
@SerializedName("asset_type")
private final String assetType;

@SerializedName("asset_code")
private final String assetCode;

@SerializedName("asset_issuer")
private final String assetIssuer;

private final String contract;

private final String amount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.stellar.sdk.responses.effects.AccountThresholdsUpdatedEffectResponse;
import org.stellar.sdk.responses.effects.ClaimableBalanceClaimantCreatedEffectResponse;
import org.stellar.sdk.responses.effects.ClaimableBalanceClawedBackEffectResponse;
import org.stellar.sdk.responses.effects.ContractCreditedEffectResponse;
import org.stellar.sdk.responses.effects.ContractDebitedEffectResponse;
import org.stellar.sdk.responses.effects.DataCreatedEffectResponse;
import org.stellar.sdk.responses.effects.DataRemovedEffectResponse;
import org.stellar.sdk.responses.effects.DataUpdatedEffectResponse;
Expand Down Expand Up @@ -1417,4 +1419,86 @@ public void testDeserializeLiquidityPoolRevokedEffect() {
});
assertEquals(effect.getSharesRevoked(), "24452.3233794");
}

@Test
public void testDeserializeContractCreditedEffect() {
String json =
"{\n"
+ " \"_links\": {\n"
+ " \"operation\": {\n"
+ " \"href\": \"http://100.83.15.43:8000/operations/21517786157057\"\n"
+ " },\n"
+ " \"succeeds\": {\n"
+ " \"href\": \"http://100.83.15.43:8000/effects?order=desc&cursor=21517786157057-2\"\n"
+ " },\n"
+ " \"precedes\": {\n"
+ " \"href\": \"http://100.83.15.43:8000/effects?order=asc&cursor=21517786157057-2\"\n"
+ " }\n"
+ " },\n"
+ " \"id\": \"0000021517786157057-0000000002\",\n"
+ " \"paging_token\": \"21517786157057-2\",\n"
+ " \"account\": \"GDAT5HWTGIU4TSSZ4752OUC4SABDLTLZFRPZUJ3D6LKBNEPA7V2CIG54\",\n"
+ " \"type\": \"contract_credited\",\n"
+ " \"type_i\": 96,\n"
+ " \"created_at\": \"2023-09-19T05:43:12Z\",\n"
+ " \"asset_type\": \"native\",\n"
+ " \"contract\": \"CDCYWK73YTYFJZZSJ5V7EDFNHYBG4QN3VUNG2IGD27KJDDPNCZKBCBXK\",\n"
+ " \"amount\": \"100.0000000\"\n"
+ "}\n";

ContractCreditedEffectResponse effect =
(ContractCreditedEffectResponse)
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getType(), "contract_credited");
assertEquals(effect.getId(), "0000021517786157057-0000000002");
assertEquals(effect.getPagingToken(), "21517786157057-2");
assertEquals(effect.getAccount(), "GDAT5HWTGIU4TSSZ4752OUC4SABDLTLZFRPZUJ3D6LKBNEPA7V2CIG54");
assertEquals(effect.getCreatedAt(), "2023-09-19T05:43:12Z");
assertEquals(effect.getAmount(), "100.0000000");
assertEquals(effect.getAssetType(), "native");
assertNull(effect.getAssetCode());
assertNull(effect.getAssetIssuer());
}

@Test
public void testDeserializeContractDebitedEffect() {
String json =
"{\n"
+ " \"_links\": {\n"
+ " \"operation\": {\n"
+ " \"href\": \"http://100.83.15.43:8000/operations/21517786157057\"\n"
+ " },\n"
+ " \"succeeds\": {\n"
+ " \"href\": \"http://100.83.15.43:8000/effects?order=desc&cursor=21517786157057-2\"\n"
+ " },\n"
+ " \"precedes\": {\n"
+ " \"href\": \"http://100.83.15.43:8000/effects?order=asc&cursor=21517786157057-2\"\n"
+ " }\n"
+ " },\n"
+ " \"id\": \"0000021517786157057-0000000002\",\n"
+ " \"paging_token\": \"21517786157057-2\",\n"
+ " \"account\": \"GDAT5HWTGIU4TSSZ4752OUC4SABDLTLZFRPZUJ3D6LKBNEPA7V2CIG54\",\n"
+ " \"type\": \"contract_debited\",\n"
+ " \"type_i\": 97,\n"
+ " \"created_at\": \"2023-09-19T05:43:12Z\",\n"
+ " \"asset_type\": \"native\",\n"
+ " \"contract\": \"CDCYWK73YTYFJZZSJ5V7EDFNHYBG4QN3VUNG2IGD27KJDDPNCZKBCBXK\",\n"
+ " \"amount\": \"100.0000000\"\n"
+ "}\n";

ContractDebitedEffectResponse effect =
(ContractDebitedEffectResponse)
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getType(), "contract_debited");
assertEquals(effect.getId(), "0000021517786157057-0000000002");
assertEquals(effect.getPagingToken(), "21517786157057-2");
assertEquals(effect.getAccount(), "GDAT5HWTGIU4TSSZ4752OUC4SABDLTLZFRPZUJ3D6LKBNEPA7V2CIG54");
assertEquals(effect.getCreatedAt(), "2023-09-19T05:43:12Z");
assertEquals(effect.getAmount(), "100.0000000");
assertEquals(effect.getAssetType(), "native");
assertNull(effect.getAssetCode());
assertNull(effect.getAssetIssuer());
}
}
Loading