From 63408f8ec37315d9f38f6ec7bab5e05500a080f3 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Tue, 1 Dec 2020 11:18:52 +0800 Subject: [PATCH] fix the decoding of `balanceId` in `org.stellar.sdk.ClaimClaimableBalanceOperation`. --- CHANGELOG.md | 3 +++ .../sdk/ClaimClaimableBalanceOperation.java | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8474e302f..96cd23e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps. A breaking change will get clearly notified in this log. +## 0.21.2 +- Fix the decoding of `balanceId` in `org.stellar.sdk.ClaimClaimableBalanceOperation`. + ## 0.21.1 - Fix NullPointerException in `org.stellar.sdk.responses.operations.RevokeSponsorshipOperationResponse` accessor methods. diff --git a/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java b/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java index 4438da0e0..ce291a9bc 100644 --- a/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java +++ b/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java @@ -4,6 +4,9 @@ import com.google.common.io.BaseEncoding; import org.stellar.sdk.xdr.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; + import static com.google.common.base.Preconditions.checkNotNull; public class ClaimClaimableBalanceOperation extends Operation { @@ -22,14 +25,16 @@ public String getBalanceId() { org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() { ClaimClaimableBalanceOp op = new ClaimClaimableBalanceOp(); - ClaimableBalanceID id = new ClaimableBalanceID(); - id.setDiscriminant(ClaimableBalanceIDType.CLAIMABLE_BALANCE_ID_TYPE_V0); - Hash hash = new Hash(); - hash.setHash(BaseEncoding.base16().lowerCase().decode(balanceId.toLowerCase())); - id.setV0(hash); + byte[] balanceIdBytes = BaseEncoding.base16().lowerCase().decode(balanceId.toLowerCase()); + XdrDataInputStream balanceIdXdrDataInputStream = new XdrDataInputStream(new ByteArrayInputStream(balanceIdBytes)); + ClaimableBalanceID id; + try { + id = ClaimableBalanceID.decode(balanceIdXdrDataInputStream); + } catch (IOException e) { + throw new IllegalArgumentException("invalid balanceId: " + balanceId, e); + } op.setBalanceID(id); - org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); body.setDiscriminant(OperationType.CLAIM_CLAIMABLE_BALANCE); body.setClaimClaimableBalanceOp(op);