Skip to content

Commit

Permalink
fix the decoding of balanceId in `org.stellar.sdk.ClaimClaimableBal…
Browse files Browse the repository at this point in the history
…anceOperation`.
  • Loading branch information
overcat committed Dec 1, 2020
1 parent 9fb2d90 commit 63408f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 63408f8

Please sign in to comment.