From 047e8c7aeb2ce5e60fd582d3af2b9a4b5d29bb52 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 8 Sep 2021 15:16:02 +0100 Subject: [PATCH 01/21] Update xdr and run xdrgen xdrgen -o src/main/java/org/stellar/sdk/xdr --language=java -n org.stellar.sdk.xdr xdr/Stellar-* --- .../stellar/sdk/xdr/AccountMergeResult.java | 2 +- .../org/stellar/sdk/xdr/AllowTrustOp.java | 2 +- .../stellar/sdk/xdr/AllowTrustResultCode.java | 6 +- .../java/org/stellar/sdk/xdr/AlphaNum12.java | 84 +++++ .../java/org/stellar/sdk/xdr/AlphaNum4.java | 84 +++++ src/main/java/org/stellar/sdk/xdr/Asset.java | 173 +---------- .../java/org/stellar/sdk/xdr/AssetType.java | 5 +- .../BeginSponsoringFutureReservesResult.java | 3 +- .../org/stellar/sdk/xdr/ChangeTrustAsset.java | 151 +++++++++ .../org/stellar/sdk/xdr/ChangeTrustOp.java | 16 +- .../sdk/xdr/ChangeTrustResultCode.java | 11 +- .../java/org/stellar/sdk/xdr/ClaimAtom.java | 140 +++++++++ .../org/stellar/sdk/xdr/ClaimAtomType.java | 53 ++++ .../stellar/sdk/xdr/ClaimLiquidityAtom.java | 139 +++++++++ .../org/stellar/sdk/xdr/ClaimOfferAtomV0.java | 157 ++++++++++ .../stellar/sdk/xdr/ClaimableBalanceID.java | 26 +- .../sdk/xdr/ClaimableBalanceIDType.java | 5 +- .../xdr/ClawbackClaimableBalanceResult.java | 3 +- .../sdk/xdr/CreateClaimableBalanceResult.java | 3 +- .../sdk/xdr/CreatePassiveSellOfferOp.java | 2 +- .../EndSponsoringFutureReservesResult.java | 3 +- .../org/stellar/sdk/xdr/EnvelopeType.java | 5 +- .../java/org/stellar/sdk/xdr/LedgerEntry.java | 26 +- .../org/stellar/sdk/xdr/LedgerEntryType.java | 5 +- .../org/stellar/sdk/xdr/LedgerHeader.java | 26 +- .../sdk/xdr/LedgerHeaderExtensionV1.java | 153 +++++++++ .../stellar/sdk/xdr/LedgerHeaderFlags.java | 54 ++++ .../java/org/stellar/sdk/xdr/LedgerKey.java | 96 +++++- .../org/stellar/sdk/xdr/LedgerUpgrade.java | 26 +- .../stellar/sdk/xdr/LedgerUpgradeType.java | 5 +- ...iquidityPoolConstantProductParameters.java | 101 ++++++ .../sdk/xdr/LiquidityPoolDepositOp.java | 135 ++++++++ .../sdk/xdr/LiquidityPoolDepositResult.java | 87 ++++++ .../xdr/LiquidityPoolDepositResultCode.java | 75 +++++ .../stellar/sdk/xdr/LiquidityPoolEntry.java | 291 ++++++++++++++++++ .../sdk/xdr/LiquidityPoolParameters.java | 96 ++++++ .../stellar/sdk/xdr/LiquidityPoolType.java | 47 +++ .../sdk/xdr/LiquidityPoolWithdrawOp.java | 118 +++++++ .../sdk/xdr/LiquidityPoolWithdrawResult.java | 87 ++++++ .../xdr/LiquidityPoolWithdrawResultCode.java | 68 ++++ .../sdk/xdr/ManageOfferSuccessResult.java | 18 +- .../java/org/stellar/sdk/xdr/Operation.java | 48 ++- .../java/org/stellar/sdk/xdr/OperationID.java | 163 +++++++++- .../org/stellar/sdk/xdr/OperationResult.java | 48 ++- .../org/stellar/sdk/xdr/OperationType.java | 8 +- .../xdr/PathPaymentStrictReceiveResult.java | 21 +- .../sdk/xdr/PathPaymentStrictSendResult.java | 18 +- .../stellar/sdk/xdr/PaymentResultCode.java | 2 +- src/main/java/org/stellar/sdk/xdr/PoolID.java | 60 ++++ .../stellar/sdk/xdr/RevokeSponsorshipOp.java | 3 +- .../sdk/xdr/RevokeSponsorshipResultCode.java | 5 +- .../org/stellar/sdk/xdr/SCPQuorumSet.java | 18 +- .../stellar/sdk/xdr/SetOptionsResultCode.java | 5 +- .../sdk/xdr/SetTrustLineFlagsResultCode.java | 6 +- .../org/stellar/sdk/xdr/StellarValue.java | 2 +- .../sdk/xdr/TransactionResultCode.java | 2 +- .../org/stellar/sdk/xdr/TrustLineAsset.java | 151 +++++++++ .../org/stellar/sdk/xdr/TrustLineEntry.java | 42 ++- .../sdk/xdr/TrustLineEntryExtensionV2.java | 153 +++++++++ .../stellar/sdk/xdr/XdrDataInputStream.java | 1 + .../stellar/sdk/xdr/XdrDataOutputStream.java | 1 + .../java/org/stellar/sdk/xdr/XdrString.java | 2 +- xdr/Stellar-SCP.x | 2 +- xdr/Stellar-ledger-entries.x | 118 +++++-- xdr/Stellar-ledger.x | 32 +- xdr/Stellar-transaction.x | 246 +++++++++++++-- 66 files changed, 3429 insertions(+), 315 deletions(-) create mode 100644 src/main/java/org/stellar/sdk/xdr/AlphaNum12.java create mode 100644 src/main/java/org/stellar/sdk/xdr/AlphaNum4.java create mode 100644 src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java create mode 100644 src/main/java/org/stellar/sdk/xdr/ClaimAtom.java create mode 100644 src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java create mode 100644 src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java create mode 100644 src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java create mode 100644 src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java create mode 100644 src/main/java/org/stellar/sdk/xdr/PoolID.java create mode 100644 src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java create mode 100644 src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java diff --git a/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java b/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java index 0b65e4713..21b70c12c 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java @@ -13,7 +13,7 @@ // union AccountMergeResult switch (AccountMergeResultCode code) // { // case ACCOUNT_MERGE_SUCCESS: -// int64 sourceAccountBalance; // how much got transfered from source account +// int64 sourceAccountBalance; // how much got transferred from source account // default: // void; // }; diff --git a/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java b/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java index 9ba5910ba..017213c26 100644 --- a/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java +++ b/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java @@ -15,7 +15,7 @@ // AccountID trustor; // AssetCode asset; // -// // 0, or any bitwise combination of the AUTHORIZED_* flags of TrustLineFlags +// // One of 0, AUTHORIZED_FLAG, or AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG // uint32 authorize; // }; diff --git a/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java b/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java index c68a64a4e..b51667c2d 100644 --- a/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java @@ -19,7 +19,9 @@ // // source account does not require trust // ALLOW_TRUST_TRUST_NOT_REQUIRED = -3, // ALLOW_TRUST_CANT_REVOKE = -4, // source account can't revoke trust, -// ALLOW_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed +// ALLOW_TRUST_SELF_NOT_ALLOWED = -5, // trusting self is not allowed +// ALLOW_TRUST_LOW_RESERVE = -6 // claimable balances can't be created +// // on revoke due to low reserves // }; // =========================================================================== @@ -30,6 +32,7 @@ public enum AllowTrustResultCode implements XdrElement { ALLOW_TRUST_TRUST_NOT_REQUIRED(-3), ALLOW_TRUST_CANT_REVOKE(-4), ALLOW_TRUST_SELF_NOT_ALLOWED(-5), + ALLOW_TRUST_LOW_RESERVE(-6), ; private int mValue; @@ -50,6 +53,7 @@ public static AllowTrustResultCode decode(XdrDataInputStream stream) throws IOEx case -3: return ALLOW_TRUST_TRUST_NOT_REQUIRED; case -4: return ALLOW_TRUST_CANT_REVOKE; case -5: return ALLOW_TRUST_SELF_NOT_ALLOWED; + case -6: return ALLOW_TRUST_LOW_RESERVE; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/AlphaNum12.java b/src/main/java/org/stellar/sdk/xdr/AlphaNum12.java new file mode 100644 index 000000000..7733b1d27 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/AlphaNum12.java @@ -0,0 +1,84 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct AlphaNum12 +// { +// AssetCode12 assetCode; +// AccountID issuer; +// }; + +// =========================================================================== +public class AlphaNum12 implements XdrElement { + public AlphaNum12 () {} + private AssetCode12 assetCode; + public AssetCode12 getAssetCode() { + return this.assetCode; + } + public void setAssetCode(AssetCode12 value) { + this.assetCode = value; + } + private AccountID issuer; + public AccountID getIssuer() { + return this.issuer; + } + public void setIssuer(AccountID value) { + this.issuer = value; + } + public static void encode(XdrDataOutputStream stream, AlphaNum12 encodedAlphaNum12) throws IOException{ + AssetCode12.encode(stream, encodedAlphaNum12.assetCode); + AccountID.encode(stream, encodedAlphaNum12.issuer); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static AlphaNum12 decode(XdrDataInputStream stream) throws IOException { + AlphaNum12 decodedAlphaNum12 = new AlphaNum12(); + decodedAlphaNum12.assetCode = AssetCode12.decode(stream); + decodedAlphaNum12.issuer = AccountID.decode(stream); + return decodedAlphaNum12; + } + @Override + public int hashCode() { + return Objects.hashCode(this.assetCode, this.issuer); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof AlphaNum12)) { + return false; + } + + AlphaNum12 other = (AlphaNum12) object; + return Objects.equal(this.assetCode, other.assetCode) && Objects.equal(this.issuer, other.issuer); + } + + public static final class Builder { + private AssetCode12 assetCode; + private AccountID issuer; + + public Builder assetCode(AssetCode12 assetCode) { + this.assetCode = assetCode; + return this; + } + + public Builder issuer(AccountID issuer) { + this.issuer = issuer; + return this; + } + + public AlphaNum12 build() { + AlphaNum12 val = new AlphaNum12(); + val.setAssetCode(assetCode); + val.setIssuer(issuer); + return val; + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/AlphaNum4.java b/src/main/java/org/stellar/sdk/xdr/AlphaNum4.java new file mode 100644 index 000000000..3cd8ca134 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/AlphaNum4.java @@ -0,0 +1,84 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct AlphaNum4 +// { +// AssetCode4 assetCode; +// AccountID issuer; +// }; + +// =========================================================================== +public class AlphaNum4 implements XdrElement { + public AlphaNum4 () {} + private AssetCode4 assetCode; + public AssetCode4 getAssetCode() { + return this.assetCode; + } + public void setAssetCode(AssetCode4 value) { + this.assetCode = value; + } + private AccountID issuer; + public AccountID getIssuer() { + return this.issuer; + } + public void setIssuer(AccountID value) { + this.issuer = value; + } + public static void encode(XdrDataOutputStream stream, AlphaNum4 encodedAlphaNum4) throws IOException{ + AssetCode4.encode(stream, encodedAlphaNum4.assetCode); + AccountID.encode(stream, encodedAlphaNum4.issuer); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static AlphaNum4 decode(XdrDataInputStream stream) throws IOException { + AlphaNum4 decodedAlphaNum4 = new AlphaNum4(); + decodedAlphaNum4.assetCode = AssetCode4.decode(stream); + decodedAlphaNum4.issuer = AccountID.decode(stream); + return decodedAlphaNum4; + } + @Override + public int hashCode() { + return Objects.hashCode(this.assetCode, this.issuer); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof AlphaNum4)) { + return false; + } + + AlphaNum4 other = (AlphaNum4) object; + return Objects.equal(this.assetCode, other.assetCode) && Objects.equal(this.issuer, other.issuer); + } + + public static final class Builder { + private AssetCode4 assetCode; + private AccountID issuer; + + public Builder assetCode(AssetCode4 assetCode) { + this.assetCode = assetCode; + return this; + } + + public Builder issuer(AccountID issuer) { + this.issuer = issuer; + return this; + } + + public AlphaNum4 build() { + AlphaNum4 val = new AlphaNum4(); + val.setAssetCode(assetCode); + val.setIssuer(issuer); + return val; + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/Asset.java b/src/main/java/org/stellar/sdk/xdr/Asset.java index 7bfb8fc4e..542c98471 100644 --- a/src/main/java/org/stellar/sdk/xdr/Asset.java +++ b/src/main/java/org/stellar/sdk/xdr/Asset.java @@ -16,18 +16,10 @@ // void; // // case ASSET_TYPE_CREDIT_ALPHANUM4: -// struct -// { -// AssetCode4 assetCode; -// AccountID issuer; -// } alphaNum4; +// AlphaNum4 alphaNum4; // // case ASSET_TYPE_CREDIT_ALPHANUM12: -// struct -// { -// AssetCode12 assetCode; -// AccountID issuer; -// } alphaNum12; +// AlphaNum12 alphaNum12; // // // add other asset types here in the future // }; @@ -42,37 +34,37 @@ public AssetType getDiscriminant() { public void setDiscriminant(AssetType value) { this.type = value; } - private AssetAlphaNum4 alphaNum4; - public AssetAlphaNum4 getAlphaNum4() { + private AlphaNum4 alphaNum4; + public AlphaNum4 getAlphaNum4() { return this.alphaNum4; } - public void setAlphaNum4(AssetAlphaNum4 value) { + public void setAlphaNum4(AlphaNum4 value) { this.alphaNum4 = value; } - private AssetAlphaNum12 alphaNum12; - public AssetAlphaNum12 getAlphaNum12() { + private AlphaNum12 alphaNum12; + public AlphaNum12 getAlphaNum12() { return this.alphaNum12; } - public void setAlphaNum12(AssetAlphaNum12 value) { + public void setAlphaNum12(AlphaNum12 value) { this.alphaNum12 = value; } public static final class Builder { private AssetType discriminant; - private AssetAlphaNum4 alphaNum4; - private AssetAlphaNum12 alphaNum12; + private AlphaNum4 alphaNum4; + private AlphaNum12 alphaNum12; public Builder discriminant(AssetType discriminant) { this.discriminant = discriminant; return this; } - public Builder alphaNum4(AssetAlphaNum4 alphaNum4) { + public Builder alphaNum4(AlphaNum4 alphaNum4) { this.alphaNum4 = alphaNum4; return this; } - public Builder alphaNum12(AssetAlphaNum12 alphaNum12) { + public Builder alphaNum12(AlphaNum12 alphaNum12) { this.alphaNum12 = alphaNum12; return this; } @@ -94,10 +86,10 @@ public static void encode(XdrDataOutputStream stream, Asset encodedAsset) throws case ASSET_TYPE_NATIVE: break; case ASSET_TYPE_CREDIT_ALPHANUM4: - AssetAlphaNum4.encode(stream, encodedAsset.alphaNum4); + AlphaNum4.encode(stream, encodedAsset.alphaNum4); break; case ASSET_TYPE_CREDIT_ALPHANUM12: - AssetAlphaNum12.encode(stream, encodedAsset.alphaNum12); + AlphaNum12.encode(stream, encodedAsset.alphaNum12); break; } } @@ -112,10 +104,10 @@ public static Asset decode(XdrDataInputStream stream) throws IOException { case ASSET_TYPE_NATIVE: break; case ASSET_TYPE_CREDIT_ALPHANUM4: - decodedAsset.alphaNum4 = AssetAlphaNum4.decode(stream); + decodedAsset.alphaNum4 = AlphaNum4.decode(stream); break; case ASSET_TYPE_CREDIT_ALPHANUM12: - decodedAsset.alphaNum12 = AssetAlphaNum12.decode(stream); + decodedAsset.alphaNum12 = AlphaNum12.decode(stream); break; } return decodedAsset; @@ -133,137 +125,4 @@ public boolean equals(Object object) { Asset other = (Asset) object; return Objects.equal(this.alphaNum4, other.alphaNum4) && Objects.equal(this.alphaNum12, other.alphaNum12) && Objects.equal(this.type, other.type); } - - public static class AssetAlphaNum4 { - public AssetAlphaNum4 () {} - private AssetCode4 assetCode; - public AssetCode4 getAssetCode() { - return this.assetCode; - } - public void setAssetCode(AssetCode4 value) { - this.assetCode = value; - } - private AccountID issuer; - public AccountID getIssuer() { - return this.issuer; - } - public void setIssuer(AccountID value) { - this.issuer = value; - } - public static void encode(XdrDataOutputStream stream, AssetAlphaNum4 encodedAssetAlphaNum4) throws IOException{ - AssetCode4.encode(stream, encodedAssetAlphaNum4.assetCode); - AccountID.encode(stream, encodedAssetAlphaNum4.issuer); - } - public void encode(XdrDataOutputStream stream) throws IOException { - encode(stream, this); - } - public static AssetAlphaNum4 decode(XdrDataInputStream stream) throws IOException { - AssetAlphaNum4 decodedAssetAlphaNum4 = new AssetAlphaNum4(); - decodedAssetAlphaNum4.assetCode = AssetCode4.decode(stream); - decodedAssetAlphaNum4.issuer = AccountID.decode(stream); - return decodedAssetAlphaNum4; - } - @Override - public int hashCode() { - return Objects.hashCode(this.assetCode, this.issuer); - } - @Override - public boolean equals(Object object) { - if (!(object instanceof AssetAlphaNum4)) { - return false; - } - - AssetAlphaNum4 other = (AssetAlphaNum4) object; - return Objects.equal(this.assetCode, other.assetCode) && Objects.equal(this.issuer, other.issuer); - } - - public static final class Builder { - private AssetCode4 assetCode; - private AccountID issuer; - - public Builder assetCode(AssetCode4 assetCode) { - this.assetCode = assetCode; - return this; - } - - public Builder issuer(AccountID issuer) { - this.issuer = issuer; - return this; - } - - public AssetAlphaNum4 build() { - AssetAlphaNum4 val = new AssetAlphaNum4(); - val.setAssetCode(assetCode); - val.setIssuer(issuer); - return val; - } - } - - } - public static class AssetAlphaNum12 { - public AssetAlphaNum12 () {} - private AssetCode12 assetCode; - public AssetCode12 getAssetCode() { - return this.assetCode; - } - public void setAssetCode(AssetCode12 value) { - this.assetCode = value; - } - private AccountID issuer; - public AccountID getIssuer() { - return this.issuer; - } - public void setIssuer(AccountID value) { - this.issuer = value; - } - public static void encode(XdrDataOutputStream stream, AssetAlphaNum12 encodedAssetAlphaNum12) throws IOException{ - AssetCode12.encode(stream, encodedAssetAlphaNum12.assetCode); - AccountID.encode(stream, encodedAssetAlphaNum12.issuer); - } - public void encode(XdrDataOutputStream stream) throws IOException { - encode(stream, this); - } - public static AssetAlphaNum12 decode(XdrDataInputStream stream) throws IOException { - AssetAlphaNum12 decodedAssetAlphaNum12 = new AssetAlphaNum12(); - decodedAssetAlphaNum12.assetCode = AssetCode12.decode(stream); - decodedAssetAlphaNum12.issuer = AccountID.decode(stream); - return decodedAssetAlphaNum12; - } - @Override - public int hashCode() { - return Objects.hashCode(this.assetCode, this.issuer); - } - @Override - public boolean equals(Object object) { - if (!(object instanceof AssetAlphaNum12)) { - return false; - } - - AssetAlphaNum12 other = (AssetAlphaNum12) object; - return Objects.equal(this.assetCode, other.assetCode) && Objects.equal(this.issuer, other.issuer); - } - - public static final class Builder { - private AssetCode12 assetCode; - private AccountID issuer; - - public Builder assetCode(AssetCode12 assetCode) { - this.assetCode = assetCode; - return this; - } - - public Builder issuer(AccountID issuer) { - this.issuer = issuer; - return this; - } - - public AssetAlphaNum12 build() { - AssetAlphaNum12 val = new AssetAlphaNum12(); - val.setAssetCode(assetCode); - val.setIssuer(issuer); - return val; - } - } - - } } diff --git a/src/main/java/org/stellar/sdk/xdr/AssetType.java b/src/main/java/org/stellar/sdk/xdr/AssetType.java index c6dec7752..3f0bc24c9 100644 --- a/src/main/java/org/stellar/sdk/xdr/AssetType.java +++ b/src/main/java/org/stellar/sdk/xdr/AssetType.java @@ -13,7 +13,8 @@ // { // ASSET_TYPE_NATIVE = 0, // ASSET_TYPE_CREDIT_ALPHANUM4 = 1, -// ASSET_TYPE_CREDIT_ALPHANUM12 = 2 +// ASSET_TYPE_CREDIT_ALPHANUM12 = 2, +// ASSET_TYPE_POOL_SHARE = 3 // }; // =========================================================================== @@ -21,6 +22,7 @@ public enum AssetType implements XdrElement { ASSET_TYPE_NATIVE(0), ASSET_TYPE_CREDIT_ALPHANUM4(1), ASSET_TYPE_CREDIT_ALPHANUM12(2), + ASSET_TYPE_POOL_SHARE(3), ; private int mValue; @@ -38,6 +40,7 @@ public static AssetType decode(XdrDataInputStream stream) throws IOException { case 0: return ASSET_TYPE_NATIVE; case 1: return ASSET_TYPE_CREDIT_ALPHANUM4; case 2: return ASSET_TYPE_CREDIT_ALPHANUM12; + case 3: return ASSET_TYPE_POOL_SHARE; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java index 858f94a7a..e395828fb 100644 --- a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java +++ b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java @@ -10,7 +10,8 @@ // === xdr source ============================================================ -// union BeginSponsoringFutureReservesResult switch (BeginSponsoringFutureReservesResultCode code) +// union BeginSponsoringFutureReservesResult switch ( +// BeginSponsoringFutureReservesResultCode code) // { // case BEGIN_SPONSORING_FUTURE_RESERVES_SUCCESS: // void; diff --git a/src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java b/src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java new file mode 100644 index 000000000..ca2ff41cd --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java @@ -0,0 +1,151 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// union ChangeTrustAsset switch (AssetType type) +// { +// case ASSET_TYPE_NATIVE: // Not credit +// void; +// +// case ASSET_TYPE_CREDIT_ALPHANUM4: +// AlphaNum4 alphaNum4; +// +// case ASSET_TYPE_CREDIT_ALPHANUM12: +// AlphaNum12 alphaNum12; +// +// case ASSET_TYPE_POOL_SHARE: +// LiquidityPoolParameters liquidityPool; +// +// // add other asset types here in the future +// }; + +// =========================================================================== +public class ChangeTrustAsset implements XdrElement { + public ChangeTrustAsset () {} + AssetType type; + public AssetType getDiscriminant() { + return this.type; + } + public void setDiscriminant(AssetType value) { + this.type = value; + } + private AlphaNum4 alphaNum4; + public AlphaNum4 getAlphaNum4() { + return this.alphaNum4; + } + public void setAlphaNum4(AlphaNum4 value) { + this.alphaNum4 = value; + } + private AlphaNum12 alphaNum12; + public AlphaNum12 getAlphaNum12() { + return this.alphaNum12; + } + public void setAlphaNum12(AlphaNum12 value) { + this.alphaNum12 = value; + } + private LiquidityPoolParameters liquidityPool; + public LiquidityPoolParameters getLiquidityPool() { + return this.liquidityPool; + } + public void setLiquidityPool(LiquidityPoolParameters value) { + this.liquidityPool = value; + } + + public static final class Builder { + private AssetType discriminant; + private AlphaNum4 alphaNum4; + private AlphaNum12 alphaNum12; + private LiquidityPoolParameters liquidityPool; + + public Builder discriminant(AssetType discriminant) { + this.discriminant = discriminant; + return this; + } + + public Builder alphaNum4(AlphaNum4 alphaNum4) { + this.alphaNum4 = alphaNum4; + return this; + } + + public Builder alphaNum12(AlphaNum12 alphaNum12) { + this.alphaNum12 = alphaNum12; + return this; + } + + public Builder liquidityPool(LiquidityPoolParameters liquidityPool) { + this.liquidityPool = liquidityPool; + return this; + } + + public ChangeTrustAsset build() { + ChangeTrustAsset val = new ChangeTrustAsset(); + val.setDiscriminant(discriminant); + val.setAlphaNum4(alphaNum4); + val.setAlphaNum12(alphaNum12); + val.setLiquidityPool(liquidityPool); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, ChangeTrustAsset encodedChangeTrustAsset) throws IOException { + //Xdrgen::AST::Identifier + //AssetType + stream.writeInt(encodedChangeTrustAsset.getDiscriminant().getValue()); + switch (encodedChangeTrustAsset.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + break; + case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4.encode(stream, encodedChangeTrustAsset.alphaNum4); + break; + case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12.encode(stream, encodedChangeTrustAsset.alphaNum12); + break; + case ASSET_TYPE_POOL_SHARE: + LiquidityPoolParameters.encode(stream, encodedChangeTrustAsset.liquidityPool); + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static ChangeTrustAsset decode(XdrDataInputStream stream) throws IOException { + ChangeTrustAsset decodedChangeTrustAsset = new ChangeTrustAsset(); + AssetType discriminant = AssetType.decode(stream); + decodedChangeTrustAsset.setDiscriminant(discriminant); + switch (decodedChangeTrustAsset.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + break; + case ASSET_TYPE_CREDIT_ALPHANUM4: + decodedChangeTrustAsset.alphaNum4 = AlphaNum4.decode(stream); + break; + case ASSET_TYPE_CREDIT_ALPHANUM12: + decodedChangeTrustAsset.alphaNum12 = AlphaNum12.decode(stream); + break; + case ASSET_TYPE_POOL_SHARE: + decodedChangeTrustAsset.liquidityPool = LiquidityPoolParameters.decode(stream); + break; + } + return decodedChangeTrustAsset; + } + @Override + public int hashCode() { + return Objects.hashCode(this.alphaNum4, this.alphaNum12, this.liquidityPool, this.type); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof ChangeTrustAsset)) { + return false; + } + + ChangeTrustAsset other = (ChangeTrustAsset) object; + return Objects.equal(this.alphaNum4, other.alphaNum4) && Objects.equal(this.alphaNum12, other.alphaNum12) && Objects.equal(this.liquidityPool, other.liquidityPool) && Objects.equal(this.type, other.type); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java b/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java index 82a6bdbbd..345342139 100644 --- a/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java @@ -12,7 +12,7 @@ // struct ChangeTrustOp // { -// Asset line; +// ChangeTrustAsset line; // // // if limit is set to 0, deletes the trust line // int64 limit; @@ -21,11 +21,11 @@ // =========================================================================== public class ChangeTrustOp implements XdrElement { public ChangeTrustOp () {} - private Asset line; - public Asset getLine() { + private ChangeTrustAsset line; + public ChangeTrustAsset getLine() { return this.line; } - public void setLine(Asset value) { + public void setLine(ChangeTrustAsset value) { this.line = value; } private Int64 limit; @@ -36,7 +36,7 @@ public void setLimit(Int64 value) { this.limit = value; } public static void encode(XdrDataOutputStream stream, ChangeTrustOp encodedChangeTrustOp) throws IOException{ - Asset.encode(stream, encodedChangeTrustOp.line); + ChangeTrustAsset.encode(stream, encodedChangeTrustOp.line); Int64.encode(stream, encodedChangeTrustOp.limit); } public void encode(XdrDataOutputStream stream) throws IOException { @@ -44,7 +44,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { } public static ChangeTrustOp decode(XdrDataInputStream stream) throws IOException { ChangeTrustOp decodedChangeTrustOp = new ChangeTrustOp(); - decodedChangeTrustOp.line = Asset.decode(stream); + decodedChangeTrustOp.line = ChangeTrustAsset.decode(stream); decodedChangeTrustOp.limit = Int64.decode(stream); return decodedChangeTrustOp; } @@ -63,10 +63,10 @@ public boolean equals(Object object) { } public static final class Builder { - private Asset line; + private ChangeTrustAsset line; private Int64 limit; - public Builder line(Asset line) { + public Builder line(ChangeTrustAsset line) { this.line = line; return this; } diff --git a/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java b/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java index e351dae2e..2495e5100 100644 --- a/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java @@ -20,7 +20,10 @@ // // cannot create with a limit of 0 // CHANGE_TRUST_LOW_RESERVE = // -4, // not enough funds to create a new trust line, -// CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed +// CHANGE_TRUST_SELF_NOT_ALLOWED = -5, // trusting self is not allowed +// CHANGE_TRUST_TRUST_LINE_MISSING = -6, // Asset trustline is missing for pool +// CHANGE_TRUST_CANNOT_DELETE = -7, // Asset trustline is still referenced in a pool +// CHANGE_TRUST_NOT_AUTH_MAINTAIN_LIABILITIES = -8 // Asset trustline is deauthorized // }; // =========================================================================== @@ -31,6 +34,9 @@ public enum ChangeTrustResultCode implements XdrElement { CHANGE_TRUST_INVALID_LIMIT(-3), CHANGE_TRUST_LOW_RESERVE(-4), CHANGE_TRUST_SELF_NOT_ALLOWED(-5), + CHANGE_TRUST_TRUST_LINE_MISSING(-6), + CHANGE_TRUST_CANNOT_DELETE(-7), + CHANGE_TRUST_NOT_AUTH_MAINTAIN_LIABILITIES(-8), ; private int mValue; @@ -51,6 +57,9 @@ public static ChangeTrustResultCode decode(XdrDataInputStream stream) throws IOE case -3: return CHANGE_TRUST_INVALID_LIMIT; case -4: return CHANGE_TRUST_LOW_RESERVE; case -5: return CHANGE_TRUST_SELF_NOT_ALLOWED; + case -6: return CHANGE_TRUST_TRUST_LINE_MISSING; + case -7: return CHANGE_TRUST_CANNOT_DELETE; + case -8: return CHANGE_TRUST_NOT_AUTH_MAINTAIN_LIABILITIES; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimAtom.java b/src/main/java/org/stellar/sdk/xdr/ClaimAtom.java new file mode 100644 index 000000000..3bbf3fb97 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/ClaimAtom.java @@ -0,0 +1,140 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// union ClaimAtom switch (ClaimAtomType type) +// { +// case CLAIM_ATOM_TYPE_V0: +// ClaimOfferAtomV0 v0; +// case CLAIM_ATOM_TYPE_ORDER_BOOK: +// ClaimOfferAtom orderBook; +// case CLAIM_ATOM_TYPE_LIQUIDITY_POOL: +// ClaimLiquidityAtom liquidityPool; +// }; + +// =========================================================================== +public class ClaimAtom implements XdrElement { + public ClaimAtom () {} + ClaimAtomType type; + public ClaimAtomType getDiscriminant() { + return this.type; + } + public void setDiscriminant(ClaimAtomType value) { + this.type = value; + } + private ClaimOfferAtomV0 v0; + public ClaimOfferAtomV0 getV0() { + return this.v0; + } + public void setV0(ClaimOfferAtomV0 value) { + this.v0 = value; + } + private ClaimOfferAtom orderBook; + public ClaimOfferAtom getOrderBook() { + return this.orderBook; + } + public void setOrderBook(ClaimOfferAtom value) { + this.orderBook = value; + } + private ClaimLiquidityAtom liquidityPool; + public ClaimLiquidityAtom getLiquidityPool() { + return this.liquidityPool; + } + public void setLiquidityPool(ClaimLiquidityAtom value) { + this.liquidityPool = value; + } + + public static final class Builder { + private ClaimAtomType discriminant; + private ClaimOfferAtomV0 v0; + private ClaimOfferAtom orderBook; + private ClaimLiquidityAtom liquidityPool; + + public Builder discriminant(ClaimAtomType discriminant) { + this.discriminant = discriminant; + return this; + } + + public Builder v0(ClaimOfferAtomV0 v0) { + this.v0 = v0; + return this; + } + + public Builder orderBook(ClaimOfferAtom orderBook) { + this.orderBook = orderBook; + return this; + } + + public Builder liquidityPool(ClaimLiquidityAtom liquidityPool) { + this.liquidityPool = liquidityPool; + return this; + } + + public ClaimAtom build() { + ClaimAtom val = new ClaimAtom(); + val.setDiscriminant(discriminant); + val.setV0(v0); + val.setOrderBook(orderBook); + val.setLiquidityPool(liquidityPool); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, ClaimAtom encodedClaimAtom) throws IOException { + //Xdrgen::AST::Identifier + //ClaimAtomType + stream.writeInt(encodedClaimAtom.getDiscriminant().getValue()); + switch (encodedClaimAtom.getDiscriminant()) { + case CLAIM_ATOM_TYPE_V0: + ClaimOfferAtomV0.encode(stream, encodedClaimAtom.v0); + break; + case CLAIM_ATOM_TYPE_ORDER_BOOK: + ClaimOfferAtom.encode(stream, encodedClaimAtom.orderBook); + break; + case CLAIM_ATOM_TYPE_LIQUIDITY_POOL: + ClaimLiquidityAtom.encode(stream, encodedClaimAtom.liquidityPool); + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static ClaimAtom decode(XdrDataInputStream stream) throws IOException { + ClaimAtom decodedClaimAtom = new ClaimAtom(); + ClaimAtomType discriminant = ClaimAtomType.decode(stream); + decodedClaimAtom.setDiscriminant(discriminant); + switch (decodedClaimAtom.getDiscriminant()) { + case CLAIM_ATOM_TYPE_V0: + decodedClaimAtom.v0 = ClaimOfferAtomV0.decode(stream); + break; + case CLAIM_ATOM_TYPE_ORDER_BOOK: + decodedClaimAtom.orderBook = ClaimOfferAtom.decode(stream); + break; + case CLAIM_ATOM_TYPE_LIQUIDITY_POOL: + decodedClaimAtom.liquidityPool = ClaimLiquidityAtom.decode(stream); + break; + } + return decodedClaimAtom; + } + @Override + public int hashCode() { + return Objects.hashCode(this.v0, this.orderBook, this.liquidityPool, this.type); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof ClaimAtom)) { + return false; + } + + ClaimAtom other = (ClaimAtom) object; + return Objects.equal(this.v0, other.v0) && Objects.equal(this.orderBook, other.orderBook) && Objects.equal(this.liquidityPool, other.liquidityPool) && Objects.equal(this.type, other.type); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java b/src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java new file mode 100644 index 000000000..a7bfd4976 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java @@ -0,0 +1,53 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + + +// === xdr source ============================================================ + +// enum ClaimAtomType +// { +// CLAIM_ATOM_TYPE_V0 = 0, +// CLAIM_ATOM_TYPE_ORDER_BOOK = 1, +// CLAIM_ATOM_TYPE_LIQUIDITY_POOL = 2 +// }; + +// =========================================================================== +public enum ClaimAtomType implements XdrElement { + CLAIM_ATOM_TYPE_V0(0), + CLAIM_ATOM_TYPE_ORDER_BOOK(1), + CLAIM_ATOM_TYPE_LIQUIDITY_POOL(2), + ; + private int mValue; + + ClaimAtomType(int value) { + mValue = value; + } + + public int getValue() { + return mValue; + } + + public static ClaimAtomType decode(XdrDataInputStream stream) throws IOException { + int value = stream.readInt(); + switch (value) { + case 0: return CLAIM_ATOM_TYPE_V0; + case 1: return CLAIM_ATOM_TYPE_ORDER_BOOK; + case 2: return CLAIM_ATOM_TYPE_LIQUIDITY_POOL; + default: + throw new RuntimeException("Unknown enum value: " + value); + } + } + + public static void encode(XdrDataOutputStream stream, ClaimAtomType value) throws IOException { + stream.writeInt(value.getValue()); + } + + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java b/src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java new file mode 100644 index 000000000..f0a02234e --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java @@ -0,0 +1,139 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct ClaimLiquidityAtom +// { +// PoolID liquidityPoolID; +// +// // amount and asset taken from the pool +// Asset assetSold; +// int64 amountSold; +// +// // amount and asset sent to the pool +// Asset assetBought; +// int64 amountBought; +// }; + +// =========================================================================== +public class ClaimLiquidityAtom implements XdrElement { + public ClaimLiquidityAtom () {} + private PoolID liquidityPoolID; + public PoolID getLiquidityPoolID() { + return this.liquidityPoolID; + } + public void setLiquidityPoolID(PoolID value) { + this.liquidityPoolID = value; + } + private Asset assetSold; + public Asset getAssetSold() { + return this.assetSold; + } + public void setAssetSold(Asset value) { + this.assetSold = value; + } + private Int64 amountSold; + public Int64 getAmountSold() { + return this.amountSold; + } + public void setAmountSold(Int64 value) { + this.amountSold = value; + } + private Asset assetBought; + public Asset getAssetBought() { + return this.assetBought; + } + public void setAssetBought(Asset value) { + this.assetBought = value; + } + private Int64 amountBought; + public Int64 getAmountBought() { + return this.amountBought; + } + public void setAmountBought(Int64 value) { + this.amountBought = value; + } + public static void encode(XdrDataOutputStream stream, ClaimLiquidityAtom encodedClaimLiquidityAtom) throws IOException{ + PoolID.encode(stream, encodedClaimLiquidityAtom.liquidityPoolID); + Asset.encode(stream, encodedClaimLiquidityAtom.assetSold); + Int64.encode(stream, encodedClaimLiquidityAtom.amountSold); + Asset.encode(stream, encodedClaimLiquidityAtom.assetBought); + Int64.encode(stream, encodedClaimLiquidityAtom.amountBought); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static ClaimLiquidityAtom decode(XdrDataInputStream stream) throws IOException { + ClaimLiquidityAtom decodedClaimLiquidityAtom = new ClaimLiquidityAtom(); + decodedClaimLiquidityAtom.liquidityPoolID = PoolID.decode(stream); + decodedClaimLiquidityAtom.assetSold = Asset.decode(stream); + decodedClaimLiquidityAtom.amountSold = Int64.decode(stream); + decodedClaimLiquidityAtom.assetBought = Asset.decode(stream); + decodedClaimLiquidityAtom.amountBought = Int64.decode(stream); + return decodedClaimLiquidityAtom; + } + @Override + public int hashCode() { + return Objects.hashCode(this.liquidityPoolID, this.assetSold, this.amountSold, this.assetBought, this.amountBought); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof ClaimLiquidityAtom)) { + return false; + } + + ClaimLiquidityAtom other = (ClaimLiquidityAtom) object; + return Objects.equal(this.liquidityPoolID, other.liquidityPoolID) && Objects.equal(this.assetSold, other.assetSold) && Objects.equal(this.amountSold, other.amountSold) && Objects.equal(this.assetBought, other.assetBought) && Objects.equal(this.amountBought, other.amountBought); + } + + public static final class Builder { + private PoolID liquidityPoolID; + private Asset assetSold; + private Int64 amountSold; + private Asset assetBought; + private Int64 amountBought; + + public Builder liquidityPoolID(PoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public Builder assetSold(Asset assetSold) { + this.assetSold = assetSold; + return this; + } + + public Builder amountSold(Int64 amountSold) { + this.amountSold = amountSold; + return this; + } + + public Builder assetBought(Asset assetBought) { + this.assetBought = assetBought; + return this; + } + + public Builder amountBought(Int64 amountBought) { + this.amountBought = amountBought; + return this; + } + + public ClaimLiquidityAtom build() { + ClaimLiquidityAtom val = new ClaimLiquidityAtom(); + val.setLiquidityPoolID(liquidityPoolID); + val.setAssetSold(assetSold); + val.setAmountSold(amountSold); + val.setAssetBought(assetBought); + val.setAmountBought(amountBought); + return val; + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java b/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java new file mode 100644 index 000000000..95b0c573b --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java @@ -0,0 +1,157 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct ClaimOfferAtomV0 +// { +// // emitted to identify the offer +// uint256 sellerEd25519; // Account that owns the offer +// int64 offerID; +// +// // amount and asset taken from the owner +// Asset assetSold; +// int64 amountSold; +// +// // amount and asset sent to the owner +// Asset assetBought; +// int64 amountBought; +// }; + +// =========================================================================== +public class ClaimOfferAtomV0 implements XdrElement { + public ClaimOfferAtomV0 () {} + private Uint256 sellerEd25519; + public Uint256 getSellerEd25519() { + return this.sellerEd25519; + } + public void setSellerEd25519(Uint256 value) { + this.sellerEd25519 = value; + } + private Int64 offerID; + public Int64 getOfferID() { + return this.offerID; + } + public void setOfferID(Int64 value) { + this.offerID = value; + } + private Asset assetSold; + public Asset getAssetSold() { + return this.assetSold; + } + public void setAssetSold(Asset value) { + this.assetSold = value; + } + private Int64 amountSold; + public Int64 getAmountSold() { + return this.amountSold; + } + public void setAmountSold(Int64 value) { + this.amountSold = value; + } + private Asset assetBought; + public Asset getAssetBought() { + return this.assetBought; + } + public void setAssetBought(Asset value) { + this.assetBought = value; + } + private Int64 amountBought; + public Int64 getAmountBought() { + return this.amountBought; + } + public void setAmountBought(Int64 value) { + this.amountBought = value; + } + public static void encode(XdrDataOutputStream stream, ClaimOfferAtomV0 encodedClaimOfferAtomV0) throws IOException{ + Uint256.encode(stream, encodedClaimOfferAtomV0.sellerEd25519); + Int64.encode(stream, encodedClaimOfferAtomV0.offerID); + Asset.encode(stream, encodedClaimOfferAtomV0.assetSold); + Int64.encode(stream, encodedClaimOfferAtomV0.amountSold); + Asset.encode(stream, encodedClaimOfferAtomV0.assetBought); + Int64.encode(stream, encodedClaimOfferAtomV0.amountBought); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static ClaimOfferAtomV0 decode(XdrDataInputStream stream) throws IOException { + ClaimOfferAtomV0 decodedClaimOfferAtomV0 = new ClaimOfferAtomV0(); + decodedClaimOfferAtomV0.sellerEd25519 = Uint256.decode(stream); + decodedClaimOfferAtomV0.offerID = Int64.decode(stream); + decodedClaimOfferAtomV0.assetSold = Asset.decode(stream); + decodedClaimOfferAtomV0.amountSold = Int64.decode(stream); + decodedClaimOfferAtomV0.assetBought = Asset.decode(stream); + decodedClaimOfferAtomV0.amountBought = Int64.decode(stream); + return decodedClaimOfferAtomV0; + } + @Override + public int hashCode() { + return Objects.hashCode(this.sellerEd25519, this.offerID, this.assetSold, this.amountSold, this.assetBought, this.amountBought); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof ClaimOfferAtomV0)) { + return false; + } + + ClaimOfferAtomV0 other = (ClaimOfferAtomV0) object; + return Objects.equal(this.sellerEd25519, other.sellerEd25519) && Objects.equal(this.offerID, other.offerID) && Objects.equal(this.assetSold, other.assetSold) && Objects.equal(this.amountSold, other.amountSold) && Objects.equal(this.assetBought, other.assetBought) && Objects.equal(this.amountBought, other.amountBought); + } + + public static final class Builder { + private Uint256 sellerEd25519; + private Int64 offerID; + private Asset assetSold; + private Int64 amountSold; + private Asset assetBought; + private Int64 amountBought; + + public Builder sellerEd25519(Uint256 sellerEd25519) { + this.sellerEd25519 = sellerEd25519; + return this; + } + + public Builder offerID(Int64 offerID) { + this.offerID = offerID; + return this; + } + + public Builder assetSold(Asset assetSold) { + this.assetSold = assetSold; + return this; + } + + public Builder amountSold(Int64 amountSold) { + this.amountSold = amountSold; + return this; + } + + public Builder assetBought(Asset assetBought) { + this.assetBought = assetBought; + return this; + } + + public Builder amountBought(Int64 amountBought) { + this.amountBought = amountBought; + return this; + } + + public ClaimOfferAtomV0 build() { + ClaimOfferAtomV0 val = new ClaimOfferAtomV0(); + val.setSellerEd25519(sellerEd25519); + val.setOfferID(offerID); + val.setAssetSold(assetSold); + val.setAmountSold(amountSold); + val.setAssetBought(assetBought); + val.setAmountBought(amountBought); + return val; + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java index b3e261ef2..d57036769 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java @@ -14,6 +14,8 @@ // { // case CLAIMABLE_BALANCE_ID_TYPE_V0: // Hash v0; +// case CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE: +// Hash fromPoolRevoke; // }; // =========================================================================== @@ -33,10 +35,18 @@ public Hash getV0() { public void setV0(Hash value) { this.v0 = value; } + private Hash fromPoolRevoke; + public Hash getFromPoolRevoke() { + return this.fromPoolRevoke; + } + public void setFromPoolRevoke(Hash value) { + this.fromPoolRevoke = value; + } public static final class Builder { private ClaimableBalanceIDType discriminant; private Hash v0; + private Hash fromPoolRevoke; public Builder discriminant(ClaimableBalanceIDType discriminant) { this.discriminant = discriminant; @@ -48,10 +58,16 @@ public Builder v0(Hash v0) { return this; } + public Builder fromPoolRevoke(Hash fromPoolRevoke) { + this.fromPoolRevoke = fromPoolRevoke; + return this; + } + public ClaimableBalanceID build() { ClaimableBalanceID val = new ClaimableBalanceID(); val.setDiscriminant(discriminant); val.setV0(v0); + val.setFromPoolRevoke(fromPoolRevoke); return val; } } @@ -64,6 +80,9 @@ public static void encode(XdrDataOutputStream stream, ClaimableBalanceID encoded case CLAIMABLE_BALANCE_ID_TYPE_V0: Hash.encode(stream, encodedClaimableBalanceID.v0); break; + case CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE: + Hash.encode(stream, encodedClaimableBalanceID.fromPoolRevoke); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -77,12 +96,15 @@ public static ClaimableBalanceID decode(XdrDataInputStream stream) throws IOExce case CLAIMABLE_BALANCE_ID_TYPE_V0: decodedClaimableBalanceID.v0 = Hash.decode(stream); break; + case CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE: + decodedClaimableBalanceID.fromPoolRevoke = Hash.decode(stream); + break; } return decodedClaimableBalanceID; } @Override public int hashCode() { - return Objects.hashCode(this.v0, this.type); + return Objects.hashCode(this.v0, this.fromPoolRevoke, this.type); } @Override public boolean equals(Object object) { @@ -91,6 +113,6 @@ public boolean equals(Object object) { } ClaimableBalanceID other = (ClaimableBalanceID) object; - return Objects.equal(this.v0, other.v0) && Objects.equal(this.type, other.type); + return Objects.equal(this.v0, other.v0) && Objects.equal(this.fromPoolRevoke, other.fromPoolRevoke) && Objects.equal(this.type, other.type); } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java index 308ad5c89..63c44220c 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java @@ -11,12 +11,14 @@ // enum ClaimableBalanceIDType // { -// CLAIMABLE_BALANCE_ID_TYPE_V0 = 0 +// CLAIMABLE_BALANCE_ID_TYPE_V0 = 0, +// CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE = 1 // }; // =========================================================================== public enum ClaimableBalanceIDType implements XdrElement { CLAIMABLE_BALANCE_ID_TYPE_V0(0), + CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE(1), ; private int mValue; @@ -32,6 +34,7 @@ public static ClaimableBalanceIDType decode(XdrDataInputStream stream) throws IO int value = stream.readInt(); switch (value) { case 0: return CLAIMABLE_BALANCE_ID_TYPE_V0; + case 1: return CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java index 6ea566dfb..4ab24f63e 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java @@ -10,7 +10,8 @@ // === xdr source ============================================================ -// union ClawbackClaimableBalanceResult switch (ClawbackClaimableBalanceResultCode code) +// union ClawbackClaimableBalanceResult switch ( +// ClawbackClaimableBalanceResultCode code) // { // case CLAWBACK_CLAIMABLE_BALANCE_SUCCESS: // void; diff --git a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java index 1a8ac586b..1b433cba9 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java @@ -10,7 +10,8 @@ // === xdr source ============================================================ -// union CreateClaimableBalanceResult switch (CreateClaimableBalanceResultCode code) +// union CreateClaimableBalanceResult switch ( +// CreateClaimableBalanceResultCode code) // { // case CREATE_CLAIMABLE_BALANCE_SUCCESS: // ClaimableBalanceID balanceID; diff --git a/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java b/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java index fc3944344..e52b72110 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java +++ b/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java @@ -14,7 +14,7 @@ // { // Asset selling; // A // Asset buying; // B -// int64 amount; // amount taker gets. if set to 0, delete the offer +// int64 amount; // amount taker gets // Price price; // cost of A in terms of B // }; diff --git a/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java b/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java index 1434f4568..2cc7fb0a4 100644 --- a/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java +++ b/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java @@ -10,7 +10,8 @@ // === xdr source ============================================================ -// union EndSponsoringFutureReservesResult switch (EndSponsoringFutureReservesResultCode code) +// union EndSponsoringFutureReservesResult switch ( +// EndSponsoringFutureReservesResultCode code) // { // case END_SPONSORING_FUTURE_RESERVES_SUCCESS: // void; diff --git a/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java b/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java index 8cf5889f3..7d4399723 100644 --- a/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java +++ b/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java @@ -17,7 +17,8 @@ // ENVELOPE_TYPE_AUTH = 3, // ENVELOPE_TYPE_SCPVALUE = 4, // ENVELOPE_TYPE_TX_FEE_BUMP = 5, -// ENVELOPE_TYPE_OP_ID = 6 +// ENVELOPE_TYPE_OP_ID = 6, +// ENVELOPE_TYPE_POOL_REVOKE_OP_ID = 7 // }; // =========================================================================== @@ -29,6 +30,7 @@ public enum EnvelopeType implements XdrElement { ENVELOPE_TYPE_SCPVALUE(4), ENVELOPE_TYPE_TX_FEE_BUMP(5), ENVELOPE_TYPE_OP_ID(6), + ENVELOPE_TYPE_POOL_REVOKE_OP_ID(7), ; private int mValue; @@ -50,6 +52,7 @@ public static EnvelopeType decode(XdrDataInputStream stream) throws IOException case 4: return ENVELOPE_TYPE_SCPVALUE; case 5: return ENVELOPE_TYPE_TX_FEE_BUMP; case 6: return ENVELOPE_TYPE_OP_ID; + case 7: return ENVELOPE_TYPE_POOL_REVOKE_OP_ID; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java index c5fa5c244..a2e243cc3 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java @@ -26,6 +26,8 @@ // DataEntry data; // case CLAIMABLE_BALANCE: // ClaimableBalanceEntry claimableBalance; +// case LIQUIDITY_POOL: +// LiquidityPoolEntry liquidityPool; // } // data; // @@ -166,6 +168,13 @@ public ClaimableBalanceEntry getClaimableBalance() { public void setClaimableBalance(ClaimableBalanceEntry value) { this.claimableBalance = value; } + private LiquidityPoolEntry liquidityPool; + public LiquidityPoolEntry getLiquidityPool() { + return this.liquidityPool; + } + public void setLiquidityPool(LiquidityPoolEntry value) { + this.liquidityPool = value; + } public static final class Builder { private LedgerEntryType discriminant; @@ -174,6 +183,7 @@ public static final class Builder { private OfferEntry offer; private DataEntry data; private ClaimableBalanceEntry claimableBalance; + private LiquidityPoolEntry liquidityPool; public Builder discriminant(LedgerEntryType discriminant) { this.discriminant = discriminant; @@ -205,6 +215,11 @@ public Builder claimableBalance(ClaimableBalanceEntry claimableBalance) { return this; } + public Builder liquidityPool(LiquidityPoolEntry liquidityPool) { + this.liquidityPool = liquidityPool; + return this; + } + public LedgerEntryData build() { LedgerEntryData val = new LedgerEntryData(); val.setDiscriminant(discriminant); @@ -213,6 +228,7 @@ public LedgerEntryData build() { val.setOffer(offer); val.setData(data); val.setClaimableBalance(claimableBalance); + val.setLiquidityPool(liquidityPool); return val; } } @@ -237,6 +253,9 @@ public static void encode(XdrDataOutputStream stream, LedgerEntryData encodedLed case CLAIMABLE_BALANCE: ClaimableBalanceEntry.encode(stream, encodedLedgerEntryData.claimableBalance); break; + case LIQUIDITY_POOL: + LiquidityPoolEntry.encode(stream, encodedLedgerEntryData.liquidityPool); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -262,12 +281,15 @@ public static LedgerEntryData decode(XdrDataInputStream stream) throws IOExcepti case CLAIMABLE_BALANCE: decodedLedgerEntryData.claimableBalance = ClaimableBalanceEntry.decode(stream); break; + case LIQUIDITY_POOL: + decodedLedgerEntryData.liquidityPool = LiquidityPoolEntry.decode(stream); + break; } return decodedLedgerEntryData; } @Override public int hashCode() { - return Objects.hashCode(this.account, this.trustLine, this.offer, this.data, this.claimableBalance, this.type); + return Objects.hashCode(this.account, this.trustLine, this.offer, this.data, this.claimableBalance, this.liquidityPool, this.type); } @Override public boolean equals(Object object) { @@ -276,7 +298,7 @@ public boolean equals(Object object) { } LedgerEntryData other = (LedgerEntryData) object; - return Objects.equal(this.account, other.account) && Objects.equal(this.trustLine, other.trustLine) && Objects.equal(this.offer, other.offer) && Objects.equal(this.data, other.data) && Objects.equal(this.claimableBalance, other.claimableBalance) && Objects.equal(this.type, other.type); + return Objects.equal(this.account, other.account) && Objects.equal(this.trustLine, other.trustLine) && Objects.equal(this.offer, other.offer) && Objects.equal(this.data, other.data) && Objects.equal(this.claimableBalance, other.claimableBalance) && Objects.equal(this.liquidityPool, other.liquidityPool) && Objects.equal(this.type, other.type); } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java index 4e01f5bc9..69262a7d3 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java @@ -15,7 +15,8 @@ // TRUSTLINE = 1, // OFFER = 2, // DATA = 3, -// CLAIMABLE_BALANCE = 4 +// CLAIMABLE_BALANCE = 4, +// LIQUIDITY_POOL = 5 // }; // =========================================================================== @@ -25,6 +26,7 @@ public enum LedgerEntryType implements XdrElement { OFFER(2), DATA(3), CLAIMABLE_BALANCE(4), + LIQUIDITY_POOL(5), ; private int mValue; @@ -44,6 +46,7 @@ public static LedgerEntryType decode(XdrDataInputStream stream) throws IOExcepti case 2: return OFFER; case 3: return DATA; case 4: return CLAIMABLE_BALANCE; + case 5: return LIQUIDITY_POOL; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java b/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java index b606f50ce..d46e0c063 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java @@ -45,6 +45,8 @@ // { // case 0: // void; +// case 1: +// LedgerHeaderExtensionV1 v1; // } // ext; // }; @@ -339,18 +341,32 @@ public Integer getDiscriminant() { public void setDiscriminant(Integer value) { this.v = value; } + private LedgerHeaderExtensionV1 v1; + public LedgerHeaderExtensionV1 getV1() { + return this.v1; + } + public void setV1(LedgerHeaderExtensionV1 value) { + this.v1 = value; + } public static final class Builder { private Integer discriminant; + private LedgerHeaderExtensionV1 v1; public Builder discriminant(Integer discriminant) { this.discriminant = discriminant; return this; } + public Builder v1(LedgerHeaderExtensionV1 v1) { + this.v1 = v1; + return this; + } + public LedgerHeaderExt build() { LedgerHeaderExt val = new LedgerHeaderExt(); val.setDiscriminant(discriminant); + val.setV1(v1); return val; } } @@ -362,6 +378,9 @@ public static void encode(XdrDataOutputStream stream, LedgerHeaderExt encodedLed switch (encodedLedgerHeaderExt.getDiscriminant()) { case 0: break; + case 1: + LedgerHeaderExtensionV1.encode(stream, encodedLedgerHeaderExt.v1); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -374,12 +393,15 @@ public static LedgerHeaderExt decode(XdrDataInputStream stream) throws IOExcepti switch (decodedLedgerHeaderExt.getDiscriminant()) { case 0: break; + case 1: + decodedLedgerHeaderExt.v1 = LedgerHeaderExtensionV1.decode(stream); + break; } return decodedLedgerHeaderExt; } @Override public int hashCode() { - return Objects.hashCode(this.v); + return Objects.hashCode(this.v1, this.v); } @Override public boolean equals(Object object) { @@ -388,7 +410,7 @@ public boolean equals(Object object) { } LedgerHeaderExt other = (LedgerHeaderExt) object; - return Objects.equal(this.v, other.v); + return Objects.equal(this.v1, other.v1) && Objects.equal(this.v, other.v); } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java new file mode 100644 index 000000000..a78303c1d --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java @@ -0,0 +1,153 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct LedgerHeaderExtensionV1 +// { +// uint32 flags; // UpgradeFlags +// +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// }; + +// =========================================================================== +public class LedgerHeaderExtensionV1 implements XdrElement { + public LedgerHeaderExtensionV1 () {} + private Uint32 flags; + public Uint32 getFlags() { + return this.flags; + } + public void setFlags(Uint32 value) { + this.flags = value; + } + private LedgerHeaderExtensionV1Ext ext; + public LedgerHeaderExtensionV1Ext getExt() { + return this.ext; + } + public void setExt(LedgerHeaderExtensionV1Ext value) { + this.ext = value; + } + public static void encode(XdrDataOutputStream stream, LedgerHeaderExtensionV1 encodedLedgerHeaderExtensionV1) throws IOException{ + Uint32.encode(stream, encodedLedgerHeaderExtensionV1.flags); + LedgerHeaderExtensionV1Ext.encode(stream, encodedLedgerHeaderExtensionV1.ext); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LedgerHeaderExtensionV1 decode(XdrDataInputStream stream) throws IOException { + LedgerHeaderExtensionV1 decodedLedgerHeaderExtensionV1 = new LedgerHeaderExtensionV1(); + decodedLedgerHeaderExtensionV1.flags = Uint32.decode(stream); + decodedLedgerHeaderExtensionV1.ext = LedgerHeaderExtensionV1Ext.decode(stream); + return decodedLedgerHeaderExtensionV1; + } + @Override + public int hashCode() { + return Objects.hashCode(this.flags, this.ext); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LedgerHeaderExtensionV1)) { + return false; + } + + LedgerHeaderExtensionV1 other = (LedgerHeaderExtensionV1) object; + return Objects.equal(this.flags, other.flags) && Objects.equal(this.ext, other.ext); + } + + public static final class Builder { + private Uint32 flags; + private LedgerHeaderExtensionV1Ext ext; + + public Builder flags(Uint32 flags) { + this.flags = flags; + return this; + } + + public Builder ext(LedgerHeaderExtensionV1Ext ext) { + this.ext = ext; + return this; + } + + public LedgerHeaderExtensionV1 build() { + LedgerHeaderExtensionV1 val = new LedgerHeaderExtensionV1(); + val.setFlags(flags); + val.setExt(ext); + return val; + } + } + + public static class LedgerHeaderExtensionV1Ext { + public LedgerHeaderExtensionV1Ext () {} + Integer v; + public Integer getDiscriminant() { + return this.v; + } + public void setDiscriminant(Integer value) { + this.v = value; + } + + public static final class Builder { + private Integer discriminant; + + public Builder discriminant(Integer discriminant) { + this.discriminant = discriminant; + return this; + } + + public LedgerHeaderExtensionV1Ext build() { + LedgerHeaderExtensionV1Ext val = new LedgerHeaderExtensionV1Ext(); + val.setDiscriminant(discriminant); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, LedgerHeaderExtensionV1Ext encodedLedgerHeaderExtensionV1Ext) throws IOException { + //Xdrgen::AST::Typespecs::Int + //Integer + stream.writeInt(encodedLedgerHeaderExtensionV1Ext.getDiscriminant().intValue()); + switch (encodedLedgerHeaderExtensionV1Ext.getDiscriminant()) { + case 0: + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LedgerHeaderExtensionV1Ext decode(XdrDataInputStream stream) throws IOException { + LedgerHeaderExtensionV1Ext decodedLedgerHeaderExtensionV1Ext = new LedgerHeaderExtensionV1Ext(); + Integer discriminant = stream.readInt(); + decodedLedgerHeaderExtensionV1Ext.setDiscriminant(discriminant); + switch (decodedLedgerHeaderExtensionV1Ext.getDiscriminant()) { + case 0: + break; + } + return decodedLedgerHeaderExtensionV1Ext; + } + @Override + public int hashCode() { + return Objects.hashCode(this.v); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LedgerHeaderExtensionV1Ext)) { + return false; + } + + LedgerHeaderExtensionV1Ext other = (LedgerHeaderExtensionV1Ext) object; + return Objects.equal(this.v, other.v); + } + + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java new file mode 100644 index 000000000..4c898b73d --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java @@ -0,0 +1,54 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + + +// === xdr source ============================================================ + +// enum LedgerHeaderFlags +// { // masks for each flag +// +// DISABLE_LIQUIDITY_POOL_TRADING_FLAG = 0x1, +// DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG = 0x2, +// DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 0x4 +// }; + +// =========================================================================== +public enum LedgerHeaderFlags implements XdrElement { + DISABLE_LIQUIDITY_POOL_TRADING_FLAG(1), + DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG(2), + DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG(4), + ; + private int mValue; + + LedgerHeaderFlags(int value) { + mValue = value; + } + + public int getValue() { + return mValue; + } + + public static LedgerHeaderFlags decode(XdrDataInputStream stream) throws IOException { + int value = stream.readInt(); + switch (value) { + case 1: return DISABLE_LIQUIDITY_POOL_TRADING_FLAG; + case 2: return DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG; + case 4: return DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG; + default: + throw new RuntimeException("Unknown enum value: " + value); + } + } + + public static void encode(XdrDataOutputStream stream, LedgerHeaderFlags value) throws IOException { + stream.writeInt(value.getValue()); + } + + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerKey.java b/src/main/java/org/stellar/sdk/xdr/LedgerKey.java index 4c8b63923..fa854ec74 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerKey.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerKey.java @@ -22,7 +22,7 @@ // struct // { // AccountID accountID; -// Asset asset; +// TrustLineAsset asset; // } trustLine; // // case OFFER: @@ -44,6 +44,12 @@ // { // ClaimableBalanceID balanceID; // } claimableBalance; +// +// case LIQUIDITY_POOL: +// struct +// { +// PoolID liquidityPoolID; +// } liquidityPool; // }; // =========================================================================== @@ -91,6 +97,13 @@ public LedgerKeyClaimableBalance getClaimableBalance() { public void setClaimableBalance(LedgerKeyClaimableBalance value) { this.claimableBalance = value; } + private LedgerKeyLiquidityPool liquidityPool; + public LedgerKeyLiquidityPool getLiquidityPool() { + return this.liquidityPool; + } + public void setLiquidityPool(LedgerKeyLiquidityPool value) { + this.liquidityPool = value; + } public static final class Builder { private LedgerEntryType discriminant; @@ -99,6 +112,7 @@ public static final class Builder { private LedgerKeyOffer offer; private LedgerKeyData data; private LedgerKeyClaimableBalance claimableBalance; + private LedgerKeyLiquidityPool liquidityPool; public Builder discriminant(LedgerEntryType discriminant) { this.discriminant = discriminant; @@ -130,6 +144,11 @@ public Builder claimableBalance(LedgerKeyClaimableBalance claimableBalance) { return this; } + public Builder liquidityPool(LedgerKeyLiquidityPool liquidityPool) { + this.liquidityPool = liquidityPool; + return this; + } + public LedgerKey build() { LedgerKey val = new LedgerKey(); val.setDiscriminant(discriminant); @@ -138,6 +157,7 @@ public LedgerKey build() { val.setOffer(offer); val.setData(data); val.setClaimableBalance(claimableBalance); + val.setLiquidityPool(liquidityPool); return val; } } @@ -162,6 +182,9 @@ public static void encode(XdrDataOutputStream stream, LedgerKey encodedLedgerKey case CLAIMABLE_BALANCE: LedgerKeyClaimableBalance.encode(stream, encodedLedgerKey.claimableBalance); break; + case LIQUIDITY_POOL: + LedgerKeyLiquidityPool.encode(stream, encodedLedgerKey.liquidityPool); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -187,12 +210,15 @@ public static LedgerKey decode(XdrDataInputStream stream) throws IOException { case CLAIMABLE_BALANCE: decodedLedgerKey.claimableBalance = LedgerKeyClaimableBalance.decode(stream); break; + case LIQUIDITY_POOL: + decodedLedgerKey.liquidityPool = LedgerKeyLiquidityPool.decode(stream); + break; } return decodedLedgerKey; } @Override public int hashCode() { - return Objects.hashCode(this.account, this.trustLine, this.offer, this.data, this.claimableBalance, this.type); + return Objects.hashCode(this.account, this.trustLine, this.offer, this.data, this.claimableBalance, this.liquidityPool, this.type); } @Override public boolean equals(Object object) { @@ -201,7 +227,7 @@ public boolean equals(Object object) { } LedgerKey other = (LedgerKey) object; - return Objects.equal(this.account, other.account) && Objects.equal(this.trustLine, other.trustLine) && Objects.equal(this.offer, other.offer) && Objects.equal(this.data, other.data) && Objects.equal(this.claimableBalance, other.claimableBalance) && Objects.equal(this.type, other.type); + return Objects.equal(this.account, other.account) && Objects.equal(this.trustLine, other.trustLine) && Objects.equal(this.offer, other.offer) && Objects.equal(this.data, other.data) && Objects.equal(this.claimableBalance, other.claimableBalance) && Objects.equal(this.liquidityPool, other.liquidityPool) && Objects.equal(this.type, other.type); } public static class LedgerKeyAccount { @@ -263,16 +289,16 @@ public AccountID getAccountID() { public void setAccountID(AccountID value) { this.accountID = value; } - private Asset asset; - public Asset getAsset() { + private TrustLineAsset asset; + public TrustLineAsset getAsset() { return this.asset; } - public void setAsset(Asset value) { + public void setAsset(TrustLineAsset value) { this.asset = value; } public static void encode(XdrDataOutputStream stream, LedgerKeyTrustLine encodedLedgerKeyTrustLine) throws IOException{ AccountID.encode(stream, encodedLedgerKeyTrustLine.accountID); - Asset.encode(stream, encodedLedgerKeyTrustLine.asset); + TrustLineAsset.encode(stream, encodedLedgerKeyTrustLine.asset); } public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); @@ -280,7 +306,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { public static LedgerKeyTrustLine decode(XdrDataInputStream stream) throws IOException { LedgerKeyTrustLine decodedLedgerKeyTrustLine = new LedgerKeyTrustLine(); decodedLedgerKeyTrustLine.accountID = AccountID.decode(stream); - decodedLedgerKeyTrustLine.asset = Asset.decode(stream); + decodedLedgerKeyTrustLine.asset = TrustLineAsset.decode(stream); return decodedLedgerKeyTrustLine; } @Override @@ -299,14 +325,14 @@ public boolean equals(Object object) { public static final class Builder { private AccountID accountID; - private Asset asset; + private TrustLineAsset asset; public Builder accountID(AccountID accountID) { this.accountID = accountID; return this; } - public Builder asset(Asset asset) { + public Builder asset(TrustLineAsset asset) { this.asset = asset; return this; } @@ -502,4 +528,54 @@ public LedgerKeyClaimableBalance build() { } } + public static class LedgerKeyLiquidityPool { + public LedgerKeyLiquidityPool () {} + private PoolID liquidityPoolID; + public PoolID getLiquidityPoolID() { + return this.liquidityPoolID; + } + public void setLiquidityPoolID(PoolID value) { + this.liquidityPoolID = value; + } + public static void encode(XdrDataOutputStream stream, LedgerKeyLiquidityPool encodedLedgerKeyLiquidityPool) throws IOException{ + PoolID.encode(stream, encodedLedgerKeyLiquidityPool.liquidityPoolID); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LedgerKeyLiquidityPool decode(XdrDataInputStream stream) throws IOException { + LedgerKeyLiquidityPool decodedLedgerKeyLiquidityPool = new LedgerKeyLiquidityPool(); + decodedLedgerKeyLiquidityPool.liquidityPoolID = PoolID.decode(stream); + return decodedLedgerKeyLiquidityPool; + } + @Override + public int hashCode() { + return Objects.hashCode(this.liquidityPoolID); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LedgerKeyLiquidityPool)) { + return false; + } + + LedgerKeyLiquidityPool other = (LedgerKeyLiquidityPool) object; + return Objects.equal(this.liquidityPoolID, other.liquidityPoolID); + } + + public static final class Builder { + private PoolID liquidityPoolID; + + public Builder liquidityPoolID(PoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public LedgerKeyLiquidityPool build() { + LedgerKeyLiquidityPool val = new LedgerKeyLiquidityPool(); + val.setLiquidityPoolID(liquidityPoolID); + return val; + } + } + + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java b/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java index d052a21d5..0dfb92344 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java @@ -20,6 +20,8 @@ // uint32 newMaxTxSetSize; // update maxTxSetSize // case LEDGER_UPGRADE_BASE_RESERVE: // uint32 newBaseReserve; // update baseReserve +// case LEDGER_UPGRADE_FLAGS: +// uint32 newFlags; // update flags // }; // =========================================================================== @@ -60,6 +62,13 @@ public Uint32 getNewBaseReserve() { public void setNewBaseReserve(Uint32 value) { this.newBaseReserve = value; } + private Uint32 newFlags; + public Uint32 getNewFlags() { + return this.newFlags; + } + public void setNewFlags(Uint32 value) { + this.newFlags = value; + } public static final class Builder { private LedgerUpgradeType discriminant; @@ -67,6 +76,7 @@ public static final class Builder { private Uint32 newBaseFee; private Uint32 newMaxTxSetSize; private Uint32 newBaseReserve; + private Uint32 newFlags; public Builder discriminant(LedgerUpgradeType discriminant) { this.discriminant = discriminant; @@ -93,6 +103,11 @@ public Builder newBaseReserve(Uint32 newBaseReserve) { return this; } + public Builder newFlags(Uint32 newFlags) { + this.newFlags = newFlags; + return this; + } + public LedgerUpgrade build() { LedgerUpgrade val = new LedgerUpgrade(); val.setDiscriminant(discriminant); @@ -100,6 +115,7 @@ public LedgerUpgrade build() { val.setNewBaseFee(newBaseFee); val.setNewMaxTxSetSize(newMaxTxSetSize); val.setNewBaseReserve(newBaseReserve); + val.setNewFlags(newFlags); return val; } } @@ -121,6 +137,9 @@ public static void encode(XdrDataOutputStream stream, LedgerUpgrade encodedLedge case LEDGER_UPGRADE_BASE_RESERVE: Uint32.encode(stream, encodedLedgerUpgrade.newBaseReserve); break; + case LEDGER_UPGRADE_FLAGS: + Uint32.encode(stream, encodedLedgerUpgrade.newFlags); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -143,12 +162,15 @@ public static LedgerUpgrade decode(XdrDataInputStream stream) throws IOException case LEDGER_UPGRADE_BASE_RESERVE: decodedLedgerUpgrade.newBaseReserve = Uint32.decode(stream); break; + case LEDGER_UPGRADE_FLAGS: + decodedLedgerUpgrade.newFlags = Uint32.decode(stream); + break; } return decodedLedgerUpgrade; } @Override public int hashCode() { - return Objects.hashCode(this.newLedgerVersion, this.newBaseFee, this.newMaxTxSetSize, this.newBaseReserve, this.type); + return Objects.hashCode(this.newLedgerVersion, this.newBaseFee, this.newMaxTxSetSize, this.newBaseReserve, this.newFlags, this.type); } @Override public boolean equals(Object object) { @@ -157,6 +179,6 @@ public boolean equals(Object object) { } LedgerUpgrade other = (LedgerUpgrade) object; - return Objects.equal(this.newLedgerVersion, other.newLedgerVersion) && Objects.equal(this.newBaseFee, other.newBaseFee) && Objects.equal(this.newMaxTxSetSize, other.newMaxTxSetSize) && Objects.equal(this.newBaseReserve, other.newBaseReserve) && Objects.equal(this.type, other.type); + return Objects.equal(this.newLedgerVersion, other.newLedgerVersion) && Objects.equal(this.newBaseFee, other.newBaseFee) && Objects.equal(this.newMaxTxSetSize, other.newMaxTxSetSize) && Objects.equal(this.newBaseReserve, other.newBaseReserve) && Objects.equal(this.newFlags, other.newFlags) && Objects.equal(this.type, other.type); } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java b/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java index 75734f5a4..b5eca98da 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java @@ -14,7 +14,8 @@ // LEDGER_UPGRADE_VERSION = 1, // LEDGER_UPGRADE_BASE_FEE = 2, // LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, -// LEDGER_UPGRADE_BASE_RESERVE = 4 +// LEDGER_UPGRADE_BASE_RESERVE = 4, +// LEDGER_UPGRADE_FLAGS = 5 // }; // =========================================================================== @@ -23,6 +24,7 @@ public enum LedgerUpgradeType implements XdrElement { LEDGER_UPGRADE_BASE_FEE(2), LEDGER_UPGRADE_MAX_TX_SET_SIZE(3), LEDGER_UPGRADE_BASE_RESERVE(4), + LEDGER_UPGRADE_FLAGS(5), ; private int mValue; @@ -41,6 +43,7 @@ public static LedgerUpgradeType decode(XdrDataInputStream stream) throws IOExcep case 2: return LEDGER_UPGRADE_BASE_FEE; case 3: return LEDGER_UPGRADE_MAX_TX_SET_SIZE; case 4: return LEDGER_UPGRADE_BASE_RESERVE; + case 5: return LEDGER_UPGRADE_FLAGS; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java new file mode 100644 index 000000000..32dc06c3b --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java @@ -0,0 +1,101 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct LiquidityPoolConstantProductParameters +// { +// Asset assetA; // assetA < assetB +// Asset assetB; +// int32 fee; // Fee is in basis points, so the actual rate is (fee/100)% +// }; + +// =========================================================================== +public class LiquidityPoolConstantProductParameters implements XdrElement { + public LiquidityPoolConstantProductParameters () {} + private Asset assetA; + public Asset getAssetA() { + return this.assetA; + } + public void setAssetA(Asset value) { + this.assetA = value; + } + private Asset assetB; + public Asset getAssetB() { + return this.assetB; + } + public void setAssetB(Asset value) { + this.assetB = value; + } + private Int32 fee; + public Int32 getFee() { + return this.fee; + } + public void setFee(Int32 value) { + this.fee = value; + } + public static void encode(XdrDataOutputStream stream, LiquidityPoolConstantProductParameters encodedLiquidityPoolConstantProductParameters) throws IOException{ + Asset.encode(stream, encodedLiquidityPoolConstantProductParameters.assetA); + Asset.encode(stream, encodedLiquidityPoolConstantProductParameters.assetB); + Int32.encode(stream, encodedLiquidityPoolConstantProductParameters.fee); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolConstantProductParameters decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolConstantProductParameters decodedLiquidityPoolConstantProductParameters = new LiquidityPoolConstantProductParameters(); + decodedLiquidityPoolConstantProductParameters.assetA = Asset.decode(stream); + decodedLiquidityPoolConstantProductParameters.assetB = Asset.decode(stream); + decodedLiquidityPoolConstantProductParameters.fee = Int32.decode(stream); + return decodedLiquidityPoolConstantProductParameters; + } + @Override + public int hashCode() { + return Objects.hashCode(this.assetA, this.assetB, this.fee); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolConstantProductParameters)) { + return false; + } + + LiquidityPoolConstantProductParameters other = (LiquidityPoolConstantProductParameters) object; + return Objects.equal(this.assetA, other.assetA) && Objects.equal(this.assetB, other.assetB) && Objects.equal(this.fee, other.fee); + } + + public static final class Builder { + private Asset assetA; + private Asset assetB; + private Int32 fee; + + public Builder assetA(Asset assetA) { + this.assetA = assetA; + return this; + } + + public Builder assetB(Asset assetB) { + this.assetB = assetB; + return this; + } + + public Builder fee(Int32 fee) { + this.fee = fee; + return this; + } + + public LiquidityPoolConstantProductParameters build() { + LiquidityPoolConstantProductParameters val = new LiquidityPoolConstantProductParameters(); + val.setAssetA(assetA); + val.setAssetB(assetB); + val.setFee(fee); + return val; + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java new file mode 100644 index 000000000..5d5ff5a1d --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java @@ -0,0 +1,135 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct LiquidityPoolDepositOp +// { +// PoolID liquidityPoolID; +// int64 maxAmountA; // maximum amount of first asset to deposit +// int64 maxAmountB; // maximum amount of second asset to deposit +// Price minPrice; // minimum depositA/depositB +// Price maxPrice; // maximum depositA/depositB +// }; + +// =========================================================================== +public class LiquidityPoolDepositOp implements XdrElement { + public LiquidityPoolDepositOp () {} + private PoolID liquidityPoolID; + public PoolID getLiquidityPoolID() { + return this.liquidityPoolID; + } + public void setLiquidityPoolID(PoolID value) { + this.liquidityPoolID = value; + } + private Int64 maxAmountA; + public Int64 getMaxAmountA() { + return this.maxAmountA; + } + public void setMaxAmountA(Int64 value) { + this.maxAmountA = value; + } + private Int64 maxAmountB; + public Int64 getMaxAmountB() { + return this.maxAmountB; + } + public void setMaxAmountB(Int64 value) { + this.maxAmountB = value; + } + private Price minPrice; + public Price getMinPrice() { + return this.minPrice; + } + public void setMinPrice(Price value) { + this.minPrice = value; + } + private Price maxPrice; + public Price getMaxPrice() { + return this.maxPrice; + } + public void setMaxPrice(Price value) { + this.maxPrice = value; + } + public static void encode(XdrDataOutputStream stream, LiquidityPoolDepositOp encodedLiquidityPoolDepositOp) throws IOException{ + PoolID.encode(stream, encodedLiquidityPoolDepositOp.liquidityPoolID); + Int64.encode(stream, encodedLiquidityPoolDepositOp.maxAmountA); + Int64.encode(stream, encodedLiquidityPoolDepositOp.maxAmountB); + Price.encode(stream, encodedLiquidityPoolDepositOp.minPrice); + Price.encode(stream, encodedLiquidityPoolDepositOp.maxPrice); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolDepositOp decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolDepositOp decodedLiquidityPoolDepositOp = new LiquidityPoolDepositOp(); + decodedLiquidityPoolDepositOp.liquidityPoolID = PoolID.decode(stream); + decodedLiquidityPoolDepositOp.maxAmountA = Int64.decode(stream); + decodedLiquidityPoolDepositOp.maxAmountB = Int64.decode(stream); + decodedLiquidityPoolDepositOp.minPrice = Price.decode(stream); + decodedLiquidityPoolDepositOp.maxPrice = Price.decode(stream); + return decodedLiquidityPoolDepositOp; + } + @Override + public int hashCode() { + return Objects.hashCode(this.liquidityPoolID, this.maxAmountA, this.maxAmountB, this.minPrice, this.maxPrice); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolDepositOp)) { + return false; + } + + LiquidityPoolDepositOp other = (LiquidityPoolDepositOp) object; + return Objects.equal(this.liquidityPoolID, other.liquidityPoolID) && Objects.equal(this.maxAmountA, other.maxAmountA) && Objects.equal(this.maxAmountB, other.maxAmountB) && Objects.equal(this.minPrice, other.minPrice) && Objects.equal(this.maxPrice, other.maxPrice); + } + + public static final class Builder { + private PoolID liquidityPoolID; + private Int64 maxAmountA; + private Int64 maxAmountB; + private Price minPrice; + private Price maxPrice; + + public Builder liquidityPoolID(PoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public Builder maxAmountA(Int64 maxAmountA) { + this.maxAmountA = maxAmountA; + return this; + } + + public Builder maxAmountB(Int64 maxAmountB) { + this.maxAmountB = maxAmountB; + return this; + } + + public Builder minPrice(Price minPrice) { + this.minPrice = minPrice; + return this; + } + + public Builder maxPrice(Price maxPrice) { + this.maxPrice = maxPrice; + return this; + } + + public LiquidityPoolDepositOp build() { + LiquidityPoolDepositOp val = new LiquidityPoolDepositOp(); + val.setLiquidityPoolID(liquidityPoolID); + val.setMaxAmountA(maxAmountA); + val.setMaxAmountB(maxAmountB); + val.setMinPrice(minPrice); + val.setMaxPrice(maxPrice); + return val; + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java new file mode 100644 index 000000000..0cffdd31f --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java @@ -0,0 +1,87 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// union LiquidityPoolDepositResult switch ( +// LiquidityPoolDepositResultCode code) +// { +// case LIQUIDITY_POOL_DEPOSIT_SUCCESS: +// void; +// default: +// void; +// }; + +// =========================================================================== +public class LiquidityPoolDepositResult implements XdrElement { + public LiquidityPoolDepositResult () {} + LiquidityPoolDepositResultCode code; + public LiquidityPoolDepositResultCode getDiscriminant() { + return this.code; + } + public void setDiscriminant(LiquidityPoolDepositResultCode value) { + this.code = value; + } + + public static final class Builder { + private LiquidityPoolDepositResultCode discriminant; + + public Builder discriminant(LiquidityPoolDepositResultCode discriminant) { + this.discriminant = discriminant; + return this; + } + + public LiquidityPoolDepositResult build() { + LiquidityPoolDepositResult val = new LiquidityPoolDepositResult(); + val.setDiscriminant(discriminant); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, LiquidityPoolDepositResult encodedLiquidityPoolDepositResult) throws IOException { + //Xdrgen::AST::Identifier + //LiquidityPoolDepositResultCode + stream.writeInt(encodedLiquidityPoolDepositResult.getDiscriminant().getValue()); + switch (encodedLiquidityPoolDepositResult.getDiscriminant()) { + case LIQUIDITY_POOL_DEPOSIT_SUCCESS: + break; + default: + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolDepositResult decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolDepositResult decodedLiquidityPoolDepositResult = new LiquidityPoolDepositResult(); + LiquidityPoolDepositResultCode discriminant = LiquidityPoolDepositResultCode.decode(stream); + decodedLiquidityPoolDepositResult.setDiscriminant(discriminant); + switch (decodedLiquidityPoolDepositResult.getDiscriminant()) { + case LIQUIDITY_POOL_DEPOSIT_SUCCESS: + break; + default: + break; + } + return decodedLiquidityPoolDepositResult; + } + @Override + public int hashCode() { + return Objects.hashCode(this.code); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolDepositResult)) { + return false; + } + + LiquidityPoolDepositResult other = (LiquidityPoolDepositResult) object; + return Objects.equal(this.code, other.code); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java new file mode 100644 index 000000000..6bc1c5394 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java @@ -0,0 +1,75 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + + +// === xdr source ============================================================ + +// enum LiquidityPoolDepositResultCode +// { +// // codes considered as "success" for the operation +// LIQUIDITY_POOL_DEPOSIT_SUCCESS = 0, +// +// // codes considered as "failure" for the operation +// LIQUIDITY_POOL_DEPOSIT_MALFORMED = -1, // bad input +// LIQUIDITY_POOL_DEPOSIT_NO_TRUST = -2, // no trust line for one of the +// // assets +// LIQUIDITY_POOL_DEPOSIT_NOT_AUTHORIZED = -3, // not authorized for one of the +// // assets +// LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED = -4, // not enough balance for one of +// // the assets +// LIQUIDITY_POOL_DEPOSIT_LINE_FULL = -5, // pool share trust line doesn't +// // have sufficient limit +// LIQUIDITY_POOL_DEPOSIT_BAD_PRICE = -6, // deposit price outside bounds +// LIQUIDITY_POOL_DEPOSIT_POOL_FULL = -7 // pool reserves are full +// }; + +// =========================================================================== +public enum LiquidityPoolDepositResultCode implements XdrElement { + LIQUIDITY_POOL_DEPOSIT_SUCCESS(0), + LIQUIDITY_POOL_DEPOSIT_MALFORMED(-1), + LIQUIDITY_POOL_DEPOSIT_NO_TRUST(-2), + LIQUIDITY_POOL_DEPOSIT_NOT_AUTHORIZED(-3), + LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED(-4), + LIQUIDITY_POOL_DEPOSIT_LINE_FULL(-5), + LIQUIDITY_POOL_DEPOSIT_BAD_PRICE(-6), + LIQUIDITY_POOL_DEPOSIT_POOL_FULL(-7), + ; + private int mValue; + + LiquidityPoolDepositResultCode(int value) { + mValue = value; + } + + public int getValue() { + return mValue; + } + + public static LiquidityPoolDepositResultCode decode(XdrDataInputStream stream) throws IOException { + int value = stream.readInt(); + switch (value) { + case 0: return LIQUIDITY_POOL_DEPOSIT_SUCCESS; + case -1: return LIQUIDITY_POOL_DEPOSIT_MALFORMED; + case -2: return LIQUIDITY_POOL_DEPOSIT_NO_TRUST; + case -3: return LIQUIDITY_POOL_DEPOSIT_NOT_AUTHORIZED; + case -4: return LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED; + case -5: return LIQUIDITY_POOL_DEPOSIT_LINE_FULL; + case -6: return LIQUIDITY_POOL_DEPOSIT_BAD_PRICE; + case -7: return LIQUIDITY_POOL_DEPOSIT_POOL_FULL; + default: + throw new RuntimeException("Unknown enum value: " + value); + } + } + + public static void encode(XdrDataOutputStream stream, LiquidityPoolDepositResultCode value) throws IOException { + stream.writeInt(value.getValue()); + } + + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java new file mode 100644 index 000000000..205cc6ea1 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java @@ -0,0 +1,291 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct LiquidityPoolEntry +// { +// PoolID liquidityPoolID; +// +// union switch (LiquidityPoolType type) +// { +// case LIQUIDITY_POOL_CONSTANT_PRODUCT: +// struct +// { +// LiquidityPoolConstantProductParameters params; +// +// int64 reserveA; // amount of A in the pool +// int64 reserveB; // amount of B in the pool +// int64 totalPoolShares; // total number of pool shares issued +// int64 poolSharesTrustLineCount; // number of trust lines for the associated pool shares +// } constantProduct; +// } +// body; +// }; + +// =========================================================================== +public class LiquidityPoolEntry implements XdrElement { + public LiquidityPoolEntry () {} + private PoolID liquidityPoolID; + public PoolID getLiquidityPoolID() { + return this.liquidityPoolID; + } + public void setLiquidityPoolID(PoolID value) { + this.liquidityPoolID = value; + } + private LiquidityPoolEntryBody body; + public LiquidityPoolEntryBody getBody() { + return this.body; + } + public void setBody(LiquidityPoolEntryBody value) { + this.body = value; + } + public static void encode(XdrDataOutputStream stream, LiquidityPoolEntry encodedLiquidityPoolEntry) throws IOException{ + PoolID.encode(stream, encodedLiquidityPoolEntry.liquidityPoolID); + LiquidityPoolEntryBody.encode(stream, encodedLiquidityPoolEntry.body); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolEntry decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolEntry decodedLiquidityPoolEntry = new LiquidityPoolEntry(); + decodedLiquidityPoolEntry.liquidityPoolID = PoolID.decode(stream); + decodedLiquidityPoolEntry.body = LiquidityPoolEntryBody.decode(stream); + return decodedLiquidityPoolEntry; + } + @Override + public int hashCode() { + return Objects.hashCode(this.liquidityPoolID, this.body); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolEntry)) { + return false; + } + + LiquidityPoolEntry other = (LiquidityPoolEntry) object; + return Objects.equal(this.liquidityPoolID, other.liquidityPoolID) && Objects.equal(this.body, other.body); + } + + public static final class Builder { + private PoolID liquidityPoolID; + private LiquidityPoolEntryBody body; + + public Builder liquidityPoolID(PoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public Builder body(LiquidityPoolEntryBody body) { + this.body = body; + return this; + } + + public LiquidityPoolEntry build() { + LiquidityPoolEntry val = new LiquidityPoolEntry(); + val.setLiquidityPoolID(liquidityPoolID); + val.setBody(body); + return val; + } + } + + public static class LiquidityPoolEntryBody { + public LiquidityPoolEntryBody () {} + LiquidityPoolType type; + public LiquidityPoolType getDiscriminant() { + return this.type; + } + public void setDiscriminant(LiquidityPoolType value) { + this.type = value; + } + private LiquidityPoolEntryConstantProduct constantProduct; + public LiquidityPoolEntryConstantProduct getConstantProduct() { + return this.constantProduct; + } + public void setConstantProduct(LiquidityPoolEntryConstantProduct value) { + this.constantProduct = value; + } + + public static final class Builder { + private LiquidityPoolType discriminant; + private LiquidityPoolEntryConstantProduct constantProduct; + + public Builder discriminant(LiquidityPoolType discriminant) { + this.discriminant = discriminant; + return this; + } + + public Builder constantProduct(LiquidityPoolEntryConstantProduct constantProduct) { + this.constantProduct = constantProduct; + return this; + } + + public LiquidityPoolEntryBody build() { + LiquidityPoolEntryBody val = new LiquidityPoolEntryBody(); + val.setDiscriminant(discriminant); + val.setConstantProduct(constantProduct); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, LiquidityPoolEntryBody encodedLiquidityPoolEntryBody) throws IOException { + //Xdrgen::AST::Identifier + //LiquidityPoolType + stream.writeInt(encodedLiquidityPoolEntryBody.getDiscriminant().getValue()); + switch (encodedLiquidityPoolEntryBody.getDiscriminant()) { + case LIQUIDITY_POOL_CONSTANT_PRODUCT: + LiquidityPoolEntryConstantProduct.encode(stream, encodedLiquidityPoolEntryBody.constantProduct); + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolEntryBody decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolEntryBody decodedLiquidityPoolEntryBody = new LiquidityPoolEntryBody(); + LiquidityPoolType discriminant = LiquidityPoolType.decode(stream); + decodedLiquidityPoolEntryBody.setDiscriminant(discriminant); + switch (decodedLiquidityPoolEntryBody.getDiscriminant()) { + case LIQUIDITY_POOL_CONSTANT_PRODUCT: + decodedLiquidityPoolEntryBody.constantProduct = LiquidityPoolEntryConstantProduct.decode(stream); + break; + } + return decodedLiquidityPoolEntryBody; + } + @Override + public int hashCode() { + return Objects.hashCode(this.constantProduct, this.type); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolEntryBody)) { + return false; + } + + LiquidityPoolEntryBody other = (LiquidityPoolEntryBody) object; + return Objects.equal(this.constantProduct, other.constantProduct) && Objects.equal(this.type, other.type); + } + + public static class LiquidityPoolEntryConstantProduct { + public LiquidityPoolEntryConstantProduct () {} + private LiquidityPoolConstantProductParameters params; + public LiquidityPoolConstantProductParameters getParams() { + return this.params; + } + public void setParams(LiquidityPoolConstantProductParameters value) { + this.params = value; + } + private Int64 reserveA; + public Int64 getReserveA() { + return this.reserveA; + } + public void setReserveA(Int64 value) { + this.reserveA = value; + } + private Int64 reserveB; + public Int64 getReserveB() { + return this.reserveB; + } + public void setReserveB(Int64 value) { + this.reserveB = value; + } + private Int64 totalPoolShares; + public Int64 getTotalPoolShares() { + return this.totalPoolShares; + } + public void setTotalPoolShares(Int64 value) { + this.totalPoolShares = value; + } + private Int64 poolSharesTrustLineCount; + public Int64 getPoolSharesTrustLineCount() { + return this.poolSharesTrustLineCount; + } + public void setPoolSharesTrustLineCount(Int64 value) { + this.poolSharesTrustLineCount = value; + } + public static void encode(XdrDataOutputStream stream, LiquidityPoolEntryConstantProduct encodedLiquidityPoolEntryConstantProduct) throws IOException{ + LiquidityPoolConstantProductParameters.encode(stream, encodedLiquidityPoolEntryConstantProduct.params); + Int64.encode(stream, encodedLiquidityPoolEntryConstantProduct.reserveA); + Int64.encode(stream, encodedLiquidityPoolEntryConstantProduct.reserveB); + Int64.encode(stream, encodedLiquidityPoolEntryConstantProduct.totalPoolShares); + Int64.encode(stream, encodedLiquidityPoolEntryConstantProduct.poolSharesTrustLineCount); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolEntryConstantProduct decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolEntryConstantProduct decodedLiquidityPoolEntryConstantProduct = new LiquidityPoolEntryConstantProduct(); + decodedLiquidityPoolEntryConstantProduct.params = LiquidityPoolConstantProductParameters.decode(stream); + decodedLiquidityPoolEntryConstantProduct.reserveA = Int64.decode(stream); + decodedLiquidityPoolEntryConstantProduct.reserveB = Int64.decode(stream); + decodedLiquidityPoolEntryConstantProduct.totalPoolShares = Int64.decode(stream); + decodedLiquidityPoolEntryConstantProduct.poolSharesTrustLineCount = Int64.decode(stream); + return decodedLiquidityPoolEntryConstantProduct; + } + @Override + public int hashCode() { + return Objects.hashCode(this.params, this.reserveA, this.reserveB, this.totalPoolShares, this.poolSharesTrustLineCount); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolEntryConstantProduct)) { + return false; + } + + LiquidityPoolEntryConstantProduct other = (LiquidityPoolEntryConstantProduct) object; + return Objects.equal(this.params, other.params) && Objects.equal(this.reserveA, other.reserveA) && Objects.equal(this.reserveB, other.reserveB) && Objects.equal(this.totalPoolShares, other.totalPoolShares) && Objects.equal(this.poolSharesTrustLineCount, other.poolSharesTrustLineCount); + } + + public static final class Builder { + private LiquidityPoolConstantProductParameters params; + private Int64 reserveA; + private Int64 reserveB; + private Int64 totalPoolShares; + private Int64 poolSharesTrustLineCount; + + public Builder params(LiquidityPoolConstantProductParameters params) { + this.params = params; + return this; + } + + public Builder reserveA(Int64 reserveA) { + this.reserveA = reserveA; + return this; + } + + public Builder reserveB(Int64 reserveB) { + this.reserveB = reserveB; + return this; + } + + public Builder totalPoolShares(Int64 totalPoolShares) { + this.totalPoolShares = totalPoolShares; + return this; + } + + public Builder poolSharesTrustLineCount(Int64 poolSharesTrustLineCount) { + this.poolSharesTrustLineCount = poolSharesTrustLineCount; + return this; + } + + public LiquidityPoolEntryConstantProduct build() { + LiquidityPoolEntryConstantProduct val = new LiquidityPoolEntryConstantProduct(); + val.setParams(params); + val.setReserveA(reserveA); + val.setReserveB(reserveB); + val.setTotalPoolShares(totalPoolShares); + val.setPoolSharesTrustLineCount(poolSharesTrustLineCount); + return val; + } + } + + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java new file mode 100644 index 000000000..84fb2d630 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java @@ -0,0 +1,96 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// union LiquidityPoolParameters switch (LiquidityPoolType type) +// { +// case LIQUIDITY_POOL_CONSTANT_PRODUCT: +// LiquidityPoolConstantProductParameters constantProduct; +// }; + +// =========================================================================== +public class LiquidityPoolParameters implements XdrElement { + public LiquidityPoolParameters () {} + LiquidityPoolType type; + public LiquidityPoolType getDiscriminant() { + return this.type; + } + public void setDiscriminant(LiquidityPoolType value) { + this.type = value; + } + private LiquidityPoolConstantProductParameters constantProduct; + public LiquidityPoolConstantProductParameters getConstantProduct() { + return this.constantProduct; + } + public void setConstantProduct(LiquidityPoolConstantProductParameters value) { + this.constantProduct = value; + } + + public static final class Builder { + private LiquidityPoolType discriminant; + private LiquidityPoolConstantProductParameters constantProduct; + + public Builder discriminant(LiquidityPoolType discriminant) { + this.discriminant = discriminant; + return this; + } + + public Builder constantProduct(LiquidityPoolConstantProductParameters constantProduct) { + this.constantProduct = constantProduct; + return this; + } + + public LiquidityPoolParameters build() { + LiquidityPoolParameters val = new LiquidityPoolParameters(); + val.setDiscriminant(discriminant); + val.setConstantProduct(constantProduct); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, LiquidityPoolParameters encodedLiquidityPoolParameters) throws IOException { + //Xdrgen::AST::Identifier + //LiquidityPoolType + stream.writeInt(encodedLiquidityPoolParameters.getDiscriminant().getValue()); + switch (encodedLiquidityPoolParameters.getDiscriminant()) { + case LIQUIDITY_POOL_CONSTANT_PRODUCT: + LiquidityPoolConstantProductParameters.encode(stream, encodedLiquidityPoolParameters.constantProduct); + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolParameters decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolParameters decodedLiquidityPoolParameters = new LiquidityPoolParameters(); + LiquidityPoolType discriminant = LiquidityPoolType.decode(stream); + decodedLiquidityPoolParameters.setDiscriminant(discriminant); + switch (decodedLiquidityPoolParameters.getDiscriminant()) { + case LIQUIDITY_POOL_CONSTANT_PRODUCT: + decodedLiquidityPoolParameters.constantProduct = LiquidityPoolConstantProductParameters.decode(stream); + break; + } + return decodedLiquidityPoolParameters; + } + @Override + public int hashCode() { + return Objects.hashCode(this.constantProduct, this.type); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolParameters)) { + return false; + } + + LiquidityPoolParameters other = (LiquidityPoolParameters) object; + return Objects.equal(this.constantProduct, other.constantProduct) && Objects.equal(this.type, other.type); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java new file mode 100644 index 000000000..96a856e30 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java @@ -0,0 +1,47 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + + +// === xdr source ============================================================ + +// enum LiquidityPoolType +// { +// LIQUIDITY_POOL_CONSTANT_PRODUCT = 0 +// }; + +// =========================================================================== +public enum LiquidityPoolType implements XdrElement { + LIQUIDITY_POOL_CONSTANT_PRODUCT(0), + ; + private int mValue; + + LiquidityPoolType(int value) { + mValue = value; + } + + public int getValue() { + return mValue; + } + + public static LiquidityPoolType decode(XdrDataInputStream stream) throws IOException { + int value = stream.readInt(); + switch (value) { + case 0: return LIQUIDITY_POOL_CONSTANT_PRODUCT; + default: + throw new RuntimeException("Unknown enum value: " + value); + } + } + + public static void encode(XdrDataOutputStream stream, LiquidityPoolType value) throws IOException { + stream.writeInt(value.getValue()); + } + + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java new file mode 100644 index 000000000..ff3a54855 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java @@ -0,0 +1,118 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct LiquidityPoolWithdrawOp +// { +// PoolID liquidityPoolID; +// int64 amount; // amount of pool shares to withdraw +// int64 minAmountA; // minimum amount of first asset to withdraw +// int64 minAmountB; // minimum amount of second asset to withdraw +// }; + +// =========================================================================== +public class LiquidityPoolWithdrawOp implements XdrElement { + public LiquidityPoolWithdrawOp () {} + private PoolID liquidityPoolID; + public PoolID getLiquidityPoolID() { + return this.liquidityPoolID; + } + public void setLiquidityPoolID(PoolID value) { + this.liquidityPoolID = value; + } + private Int64 amount; + public Int64 getAmount() { + return this.amount; + } + public void setAmount(Int64 value) { + this.amount = value; + } + private Int64 minAmountA; + public Int64 getMinAmountA() { + return this.minAmountA; + } + public void setMinAmountA(Int64 value) { + this.minAmountA = value; + } + private Int64 minAmountB; + public Int64 getMinAmountB() { + return this.minAmountB; + } + public void setMinAmountB(Int64 value) { + this.minAmountB = value; + } + public static void encode(XdrDataOutputStream stream, LiquidityPoolWithdrawOp encodedLiquidityPoolWithdrawOp) throws IOException{ + PoolID.encode(stream, encodedLiquidityPoolWithdrawOp.liquidityPoolID); + Int64.encode(stream, encodedLiquidityPoolWithdrawOp.amount); + Int64.encode(stream, encodedLiquidityPoolWithdrawOp.minAmountA); + Int64.encode(stream, encodedLiquidityPoolWithdrawOp.minAmountB); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolWithdrawOp decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolWithdrawOp decodedLiquidityPoolWithdrawOp = new LiquidityPoolWithdrawOp(); + decodedLiquidityPoolWithdrawOp.liquidityPoolID = PoolID.decode(stream); + decodedLiquidityPoolWithdrawOp.amount = Int64.decode(stream); + decodedLiquidityPoolWithdrawOp.minAmountA = Int64.decode(stream); + decodedLiquidityPoolWithdrawOp.minAmountB = Int64.decode(stream); + return decodedLiquidityPoolWithdrawOp; + } + @Override + public int hashCode() { + return Objects.hashCode(this.liquidityPoolID, this.amount, this.minAmountA, this.minAmountB); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolWithdrawOp)) { + return false; + } + + LiquidityPoolWithdrawOp other = (LiquidityPoolWithdrawOp) object; + return Objects.equal(this.liquidityPoolID, other.liquidityPoolID) && Objects.equal(this.amount, other.amount) && Objects.equal(this.minAmountA, other.minAmountA) && Objects.equal(this.minAmountB, other.minAmountB); + } + + public static final class Builder { + private PoolID liquidityPoolID; + private Int64 amount; + private Int64 minAmountA; + private Int64 minAmountB; + + public Builder liquidityPoolID(PoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public Builder amount(Int64 amount) { + this.amount = amount; + return this; + } + + public Builder minAmountA(Int64 minAmountA) { + this.minAmountA = minAmountA; + return this; + } + + public Builder minAmountB(Int64 minAmountB) { + this.minAmountB = minAmountB; + return this; + } + + public LiquidityPoolWithdrawOp build() { + LiquidityPoolWithdrawOp val = new LiquidityPoolWithdrawOp(); + val.setLiquidityPoolID(liquidityPoolID); + val.setAmount(amount); + val.setMinAmountA(minAmountA); + val.setMinAmountB(minAmountB); + return val; + } + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java new file mode 100644 index 000000000..070ed976d --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java @@ -0,0 +1,87 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// union LiquidityPoolWithdrawResult switch ( +// LiquidityPoolWithdrawResultCode code) +// { +// case LIQUIDITY_POOL_WITHDRAW_SUCCESS: +// void; +// default: +// void; +// }; + +// =========================================================================== +public class LiquidityPoolWithdrawResult implements XdrElement { + public LiquidityPoolWithdrawResult () {} + LiquidityPoolWithdrawResultCode code; + public LiquidityPoolWithdrawResultCode getDiscriminant() { + return this.code; + } + public void setDiscriminant(LiquidityPoolWithdrawResultCode value) { + this.code = value; + } + + public static final class Builder { + private LiquidityPoolWithdrawResultCode discriminant; + + public Builder discriminant(LiquidityPoolWithdrawResultCode discriminant) { + this.discriminant = discriminant; + return this; + } + + public LiquidityPoolWithdrawResult build() { + LiquidityPoolWithdrawResult val = new LiquidityPoolWithdrawResult(); + val.setDiscriminant(discriminant); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, LiquidityPoolWithdrawResult encodedLiquidityPoolWithdrawResult) throws IOException { + //Xdrgen::AST::Identifier + //LiquidityPoolWithdrawResultCode + stream.writeInt(encodedLiquidityPoolWithdrawResult.getDiscriminant().getValue()); + switch (encodedLiquidityPoolWithdrawResult.getDiscriminant()) { + case LIQUIDITY_POOL_WITHDRAW_SUCCESS: + break; + default: + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static LiquidityPoolWithdrawResult decode(XdrDataInputStream stream) throws IOException { + LiquidityPoolWithdrawResult decodedLiquidityPoolWithdrawResult = new LiquidityPoolWithdrawResult(); + LiquidityPoolWithdrawResultCode discriminant = LiquidityPoolWithdrawResultCode.decode(stream); + decodedLiquidityPoolWithdrawResult.setDiscriminant(discriminant); + switch (decodedLiquidityPoolWithdrawResult.getDiscriminant()) { + case LIQUIDITY_POOL_WITHDRAW_SUCCESS: + break; + default: + break; + } + return decodedLiquidityPoolWithdrawResult; + } + @Override + public int hashCode() { + return Objects.hashCode(this.code); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolWithdrawResult)) { + return false; + } + + LiquidityPoolWithdrawResult other = (LiquidityPoolWithdrawResult) object; + return Objects.equal(this.code, other.code); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java new file mode 100644 index 000000000..dd8b95831 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java @@ -0,0 +1,68 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + + +// === xdr source ============================================================ + +// enum LiquidityPoolWithdrawResultCode +// { +// // codes considered as "success" for the operation +// LIQUIDITY_POOL_WITHDRAW_SUCCESS = 0, +// +// // codes considered as "failure" for the operation +// LIQUIDITY_POOL_WITHDRAW_MALFORMED = -1, // bad input +// LIQUIDITY_POOL_WITHDRAW_NO_TRUST = -2, // no trust line for one of the +// // assets +// LIQUIDITY_POOL_WITHDRAW_UNDERFUNDED = -3, // not enough balance of the +// // pool share +// LIQUIDITY_POOL_WITHDRAW_LINE_FULL = -4, // would go above limit for one +// // of the assets +// LIQUIDITY_POOL_WITHDRAW_UNDER_MINIMUM = -5 // didn't withdraw enough +// }; + +// =========================================================================== +public enum LiquidityPoolWithdrawResultCode implements XdrElement { + LIQUIDITY_POOL_WITHDRAW_SUCCESS(0), + LIQUIDITY_POOL_WITHDRAW_MALFORMED(-1), + LIQUIDITY_POOL_WITHDRAW_NO_TRUST(-2), + LIQUIDITY_POOL_WITHDRAW_UNDERFUNDED(-3), + LIQUIDITY_POOL_WITHDRAW_LINE_FULL(-4), + LIQUIDITY_POOL_WITHDRAW_UNDER_MINIMUM(-5), + ; + private int mValue; + + LiquidityPoolWithdrawResultCode(int value) { + mValue = value; + } + + public int getValue() { + return mValue; + } + + public static LiquidityPoolWithdrawResultCode decode(XdrDataInputStream stream) throws IOException { + int value = stream.readInt(); + switch (value) { + case 0: return LIQUIDITY_POOL_WITHDRAW_SUCCESS; + case -1: return LIQUIDITY_POOL_WITHDRAW_MALFORMED; + case -2: return LIQUIDITY_POOL_WITHDRAW_NO_TRUST; + case -3: return LIQUIDITY_POOL_WITHDRAW_UNDERFUNDED; + case -4: return LIQUIDITY_POOL_WITHDRAW_LINE_FULL; + case -5: return LIQUIDITY_POOL_WITHDRAW_UNDER_MINIMUM; + default: + throw new RuntimeException("Unknown enum value: " + value); + } + } + + public static void encode(XdrDataOutputStream stream, LiquidityPoolWithdrawResultCode value) throws IOException { + stream.writeInt(value.getValue()); + } + + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java b/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java index d93a59133..e8adeede3 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java @@ -14,7 +14,7 @@ // struct ManageOfferSuccessResult // { // // offers that got claimed while creating this offer -// ClaimOfferAtom offersClaimed<>; +// ClaimAtom offersClaimed<>; // // union switch (ManageOfferEffect effect) // { @@ -30,11 +30,11 @@ // =========================================================================== public class ManageOfferSuccessResult implements XdrElement { public ManageOfferSuccessResult () {} - private ClaimOfferAtom[] offersClaimed; - public ClaimOfferAtom[] getOffersClaimed() { + private ClaimAtom[] offersClaimed; + public ClaimAtom[] getOffersClaimed() { return this.offersClaimed; } - public void setOffersClaimed(ClaimOfferAtom[] value) { + public void setOffersClaimed(ClaimAtom[] value) { this.offersClaimed = value; } private ManageOfferSuccessResultOffer offer; @@ -48,7 +48,7 @@ public static void encode(XdrDataOutputStream stream, ManageOfferSuccessResult e int offersClaimedsize = encodedManageOfferSuccessResult.getOffersClaimed().length; stream.writeInt(offersClaimedsize); for (int i = 0; i < offersClaimedsize; i++) { - ClaimOfferAtom.encode(stream, encodedManageOfferSuccessResult.offersClaimed[i]); + ClaimAtom.encode(stream, encodedManageOfferSuccessResult.offersClaimed[i]); } ManageOfferSuccessResultOffer.encode(stream, encodedManageOfferSuccessResult.offer); } @@ -58,9 +58,9 @@ public void encode(XdrDataOutputStream stream) throws IOException { public static ManageOfferSuccessResult decode(XdrDataInputStream stream) throws IOException { ManageOfferSuccessResult decodedManageOfferSuccessResult = new ManageOfferSuccessResult(); int offersClaimedsize = stream.readInt(); - decodedManageOfferSuccessResult.offersClaimed = new ClaimOfferAtom[offersClaimedsize]; + decodedManageOfferSuccessResult.offersClaimed = new ClaimAtom[offersClaimedsize]; for (int i = 0; i < offersClaimedsize; i++) { - decodedManageOfferSuccessResult.offersClaimed[i] = ClaimOfferAtom.decode(stream); + decodedManageOfferSuccessResult.offersClaimed[i] = ClaimAtom.decode(stream); } decodedManageOfferSuccessResult.offer = ManageOfferSuccessResultOffer.decode(stream); return decodedManageOfferSuccessResult; @@ -80,10 +80,10 @@ public boolean equals(Object object) { } public static final class Builder { - private ClaimOfferAtom[] offersClaimed; + private ClaimAtom[] offersClaimed; private ManageOfferSuccessResultOffer offer; - public Builder offersClaimed(ClaimOfferAtom[] offersClaimed) { + public Builder offersClaimed(ClaimAtom[] offersClaimed) { this.offersClaimed = offersClaimed; return this; } diff --git a/src/main/java/org/stellar/sdk/xdr/Operation.java b/src/main/java/org/stellar/sdk/xdr/Operation.java index e4450b3e2..d5de5ecb9 100644 --- a/src/main/java/org/stellar/sdk/xdr/Operation.java +++ b/src/main/java/org/stellar/sdk/xdr/Operation.java @@ -63,6 +63,10 @@ // ClawbackClaimableBalanceOp clawbackClaimableBalanceOp; // case SET_TRUST_LINE_FLAGS: // SetTrustLineFlagsOp setTrustLineFlagsOp; +// case LIQUIDITY_POOL_DEPOSIT: +// LiquidityPoolDepositOp liquidityPoolDepositOp; +// case LIQUIDITY_POOL_WITHDRAW: +// LiquidityPoolWithdrawOp liquidityPoolWithdrawOp; // } // body; // }; @@ -290,6 +294,20 @@ public SetTrustLineFlagsOp getSetTrustLineFlagsOp() { public void setSetTrustLineFlagsOp(SetTrustLineFlagsOp value) { this.setTrustLineFlagsOp = value; } + private LiquidityPoolDepositOp liquidityPoolDepositOp; + public LiquidityPoolDepositOp getLiquidityPoolDepositOp() { + return this.liquidityPoolDepositOp; + } + public void setLiquidityPoolDepositOp(LiquidityPoolDepositOp value) { + this.liquidityPoolDepositOp = value; + } + private LiquidityPoolWithdrawOp liquidityPoolWithdrawOp; + public LiquidityPoolWithdrawOp getLiquidityPoolWithdrawOp() { + return this.liquidityPoolWithdrawOp; + } + public void setLiquidityPoolWithdrawOp(LiquidityPoolWithdrawOp value) { + this.liquidityPoolWithdrawOp = value; + } public static final class Builder { private OperationType discriminant; @@ -313,6 +331,8 @@ public static final class Builder { private ClawbackOp clawbackOp; private ClawbackClaimableBalanceOp clawbackClaimableBalanceOp; private SetTrustLineFlagsOp setTrustLineFlagsOp; + private LiquidityPoolDepositOp liquidityPoolDepositOp; + private LiquidityPoolWithdrawOp liquidityPoolWithdrawOp; public Builder discriminant(OperationType discriminant) { this.discriminant = discriminant; @@ -419,6 +439,16 @@ public Builder setTrustLineFlagsOp(SetTrustLineFlagsOp setTrustLineFlagsOp) { return this; } + public Builder liquidityPoolDepositOp(LiquidityPoolDepositOp liquidityPoolDepositOp) { + this.liquidityPoolDepositOp = liquidityPoolDepositOp; + return this; + } + + public Builder liquidityPoolWithdrawOp(LiquidityPoolWithdrawOp liquidityPoolWithdrawOp) { + this.liquidityPoolWithdrawOp = liquidityPoolWithdrawOp; + return this; + } + public OperationBody build() { OperationBody val = new OperationBody(); val.setDiscriminant(discriminant); @@ -442,6 +472,8 @@ public OperationBody build() { val.setClawbackOp(clawbackOp); val.setClawbackClaimableBalanceOp(clawbackClaimableBalanceOp); val.setSetTrustLineFlagsOp(setTrustLineFlagsOp); + val.setLiquidityPoolDepositOp(liquidityPoolDepositOp); + val.setLiquidityPoolWithdrawOp(liquidityPoolWithdrawOp); return val; } } @@ -515,6 +547,12 @@ public static void encode(XdrDataOutputStream stream, OperationBody encodedOpera case SET_TRUST_LINE_FLAGS: SetTrustLineFlagsOp.encode(stream, encodedOperationBody.setTrustLineFlagsOp); break; + case LIQUIDITY_POOL_DEPOSIT: + LiquidityPoolDepositOp.encode(stream, encodedOperationBody.liquidityPoolDepositOp); + break; + case LIQUIDITY_POOL_WITHDRAW: + LiquidityPoolWithdrawOp.encode(stream, encodedOperationBody.liquidityPoolWithdrawOp); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -589,12 +627,18 @@ public static OperationBody decode(XdrDataInputStream stream) throws IOException case SET_TRUST_LINE_FLAGS: decodedOperationBody.setTrustLineFlagsOp = SetTrustLineFlagsOp.decode(stream); break; + case LIQUIDITY_POOL_DEPOSIT: + decodedOperationBody.liquidityPoolDepositOp = LiquidityPoolDepositOp.decode(stream); + break; + case LIQUIDITY_POOL_WITHDRAW: + decodedOperationBody.liquidityPoolWithdrawOp = LiquidityPoolWithdrawOp.decode(stream); + break; } return decodedOperationBody; } @Override public int hashCode() { - return Objects.hashCode(this.createAccountOp, this.paymentOp, this.pathPaymentStrictReceiveOp, this.manageSellOfferOp, this.createPassiveSellOfferOp, this.setOptionsOp, this.changeTrustOp, this.allowTrustOp, this.destination, this.manageDataOp, this.bumpSequenceOp, this.manageBuyOfferOp, this.pathPaymentStrictSendOp, this.createClaimableBalanceOp, this.claimClaimableBalanceOp, this.beginSponsoringFutureReservesOp, this.revokeSponsorshipOp, this.clawbackOp, this.clawbackClaimableBalanceOp, this.setTrustLineFlagsOp, this.type); + return Objects.hashCode(this.createAccountOp, this.paymentOp, this.pathPaymentStrictReceiveOp, this.manageSellOfferOp, this.createPassiveSellOfferOp, this.setOptionsOp, this.changeTrustOp, this.allowTrustOp, this.destination, this.manageDataOp, this.bumpSequenceOp, this.manageBuyOfferOp, this.pathPaymentStrictSendOp, this.createClaimableBalanceOp, this.claimClaimableBalanceOp, this.beginSponsoringFutureReservesOp, this.revokeSponsorshipOp, this.clawbackOp, this.clawbackClaimableBalanceOp, this.setTrustLineFlagsOp, this.liquidityPoolDepositOp, this.liquidityPoolWithdrawOp, this.type); } @Override public boolean equals(Object object) { @@ -603,7 +647,7 @@ public boolean equals(Object object) { } OperationBody other = (OperationBody) object; - return Objects.equal(this.createAccountOp, other.createAccountOp) && Objects.equal(this.paymentOp, other.paymentOp) && Objects.equal(this.pathPaymentStrictReceiveOp, other.pathPaymentStrictReceiveOp) && Objects.equal(this.manageSellOfferOp, other.manageSellOfferOp) && Objects.equal(this.createPassiveSellOfferOp, other.createPassiveSellOfferOp) && Objects.equal(this.setOptionsOp, other.setOptionsOp) && Objects.equal(this.changeTrustOp, other.changeTrustOp) && Objects.equal(this.allowTrustOp, other.allowTrustOp) && Objects.equal(this.destination, other.destination) && Objects.equal(this.manageDataOp, other.manageDataOp) && Objects.equal(this.bumpSequenceOp, other.bumpSequenceOp) && Objects.equal(this.manageBuyOfferOp, other.manageBuyOfferOp) && Objects.equal(this.pathPaymentStrictSendOp, other.pathPaymentStrictSendOp) && Objects.equal(this.createClaimableBalanceOp, other.createClaimableBalanceOp) && Objects.equal(this.claimClaimableBalanceOp, other.claimClaimableBalanceOp) && Objects.equal(this.beginSponsoringFutureReservesOp, other.beginSponsoringFutureReservesOp) && Objects.equal(this.revokeSponsorshipOp, other.revokeSponsorshipOp) && Objects.equal(this.clawbackOp, other.clawbackOp) && Objects.equal(this.clawbackClaimableBalanceOp, other.clawbackClaimableBalanceOp) && Objects.equal(this.setTrustLineFlagsOp, other.setTrustLineFlagsOp) && Objects.equal(this.type, other.type); + return Objects.equal(this.createAccountOp, other.createAccountOp) && Objects.equal(this.paymentOp, other.paymentOp) && Objects.equal(this.pathPaymentStrictReceiveOp, other.pathPaymentStrictReceiveOp) && Objects.equal(this.manageSellOfferOp, other.manageSellOfferOp) && Objects.equal(this.createPassiveSellOfferOp, other.createPassiveSellOfferOp) && Objects.equal(this.setOptionsOp, other.setOptionsOp) && Objects.equal(this.changeTrustOp, other.changeTrustOp) && Objects.equal(this.allowTrustOp, other.allowTrustOp) && Objects.equal(this.destination, other.destination) && Objects.equal(this.manageDataOp, other.manageDataOp) && Objects.equal(this.bumpSequenceOp, other.bumpSequenceOp) && Objects.equal(this.manageBuyOfferOp, other.manageBuyOfferOp) && Objects.equal(this.pathPaymentStrictSendOp, other.pathPaymentStrictSendOp) && Objects.equal(this.createClaimableBalanceOp, other.createClaimableBalanceOp) && Objects.equal(this.claimClaimableBalanceOp, other.claimClaimableBalanceOp) && Objects.equal(this.beginSponsoringFutureReservesOp, other.beginSponsoringFutureReservesOp) && Objects.equal(this.revokeSponsorshipOp, other.revokeSponsorshipOp) && Objects.equal(this.clawbackOp, other.clawbackOp) && Objects.equal(this.clawbackClaimableBalanceOp, other.clawbackClaimableBalanceOp) && Objects.equal(this.setTrustLineFlagsOp, other.setTrustLineFlagsOp) && Objects.equal(this.liquidityPoolDepositOp, other.liquidityPoolDepositOp) && Objects.equal(this.liquidityPoolWithdrawOp, other.liquidityPoolWithdrawOp) && Objects.equal(this.type, other.type); } } diff --git a/src/main/java/org/stellar/sdk/xdr/OperationID.java b/src/main/java/org/stellar/sdk/xdr/OperationID.java index 90183459c..900c94170 100644 --- a/src/main/java/org/stellar/sdk/xdr/OperationID.java +++ b/src/main/java/org/stellar/sdk/xdr/OperationID.java @@ -15,10 +15,19 @@ // case ENVELOPE_TYPE_OP_ID: // struct // { -// MuxedAccount sourceAccount; +// AccountID sourceAccount; // SequenceNumber seqNum; // uint32 opNum; // } id; +// case ENVELOPE_TYPE_POOL_REVOKE_OP_ID: +// struct +// { +// AccountID sourceAccount; +// SequenceNumber seqNum; +// uint32 opNum; +// PoolID liquidityPoolID; +// Asset asset; +// } revokeId; // }; // =========================================================================== @@ -38,10 +47,18 @@ public OperationIDId getId() { public void setId(OperationIDId value) { this.id = value; } + private OperationIDRevokeId revokeId; + public OperationIDRevokeId getRevokeId() { + return this.revokeId; + } + public void setRevokeId(OperationIDRevokeId value) { + this.revokeId = value; + } public static final class Builder { private EnvelopeType discriminant; private OperationIDId id; + private OperationIDRevokeId revokeId; public Builder discriminant(EnvelopeType discriminant) { this.discriminant = discriminant; @@ -53,10 +70,16 @@ public Builder id(OperationIDId id) { return this; } + public Builder revokeId(OperationIDRevokeId revokeId) { + this.revokeId = revokeId; + return this; + } + public OperationID build() { OperationID val = new OperationID(); val.setDiscriminant(discriminant); val.setId(id); + val.setRevokeId(revokeId); return val; } } @@ -69,6 +92,9 @@ public static void encode(XdrDataOutputStream stream, OperationID encodedOperati case ENVELOPE_TYPE_OP_ID: OperationIDId.encode(stream, encodedOperationID.id); break; + case ENVELOPE_TYPE_POOL_REVOKE_OP_ID: + OperationIDRevokeId.encode(stream, encodedOperationID.revokeId); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -82,12 +108,15 @@ public static OperationID decode(XdrDataInputStream stream) throws IOException { case ENVELOPE_TYPE_OP_ID: decodedOperationID.id = OperationIDId.decode(stream); break; + case ENVELOPE_TYPE_POOL_REVOKE_OP_ID: + decodedOperationID.revokeId = OperationIDRevokeId.decode(stream); + break; } return decodedOperationID; } @Override public int hashCode() { - return Objects.hashCode(this.id, this.type); + return Objects.hashCode(this.id, this.revokeId, this.type); } @Override public boolean equals(Object object) { @@ -96,16 +125,16 @@ public boolean equals(Object object) { } OperationID other = (OperationID) object; - return Objects.equal(this.id, other.id) && Objects.equal(this.type, other.type); + return Objects.equal(this.id, other.id) && Objects.equal(this.revokeId, other.revokeId) && Objects.equal(this.type, other.type); } public static class OperationIDId { public OperationIDId () {} - private MuxedAccount sourceAccount; - public MuxedAccount getSourceAccount() { + private AccountID sourceAccount; + public AccountID getSourceAccount() { return this.sourceAccount; } - public void setSourceAccount(MuxedAccount value) { + public void setSourceAccount(AccountID value) { this.sourceAccount = value; } private SequenceNumber seqNum; @@ -123,7 +152,7 @@ public void setOpNum(Uint32 value) { this.opNum = value; } public static void encode(XdrDataOutputStream stream, OperationIDId encodedOperationIDId) throws IOException{ - MuxedAccount.encode(stream, encodedOperationIDId.sourceAccount); + AccountID.encode(stream, encodedOperationIDId.sourceAccount); SequenceNumber.encode(stream, encodedOperationIDId.seqNum); Uint32.encode(stream, encodedOperationIDId.opNum); } @@ -132,7 +161,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { } public static OperationIDId decode(XdrDataInputStream stream) throws IOException { OperationIDId decodedOperationIDId = new OperationIDId(); - decodedOperationIDId.sourceAccount = MuxedAccount.decode(stream); + decodedOperationIDId.sourceAccount = AccountID.decode(stream); decodedOperationIDId.seqNum = SequenceNumber.decode(stream); decodedOperationIDId.opNum = Uint32.decode(stream); return decodedOperationIDId; @@ -152,11 +181,11 @@ public boolean equals(Object object) { } public static final class Builder { - private MuxedAccount sourceAccount; + private AccountID sourceAccount; private SequenceNumber seqNum; private Uint32 opNum; - public Builder sourceAccount(MuxedAccount sourceAccount) { + public Builder sourceAccount(AccountID sourceAccount) { this.sourceAccount = sourceAccount; return this; } @@ -181,4 +210,118 @@ public OperationIDId build() { } } + public static class OperationIDRevokeId { + public OperationIDRevokeId () {} + private AccountID sourceAccount; + public AccountID getSourceAccount() { + return this.sourceAccount; + } + public void setSourceAccount(AccountID value) { + this.sourceAccount = value; + } + private SequenceNumber seqNum; + public SequenceNumber getSeqNum() { + return this.seqNum; + } + public void setSeqNum(SequenceNumber value) { + this.seqNum = value; + } + private Uint32 opNum; + public Uint32 getOpNum() { + return this.opNum; + } + public void setOpNum(Uint32 value) { + this.opNum = value; + } + private PoolID liquidityPoolID; + public PoolID getLiquidityPoolID() { + return this.liquidityPoolID; + } + public void setLiquidityPoolID(PoolID value) { + this.liquidityPoolID = value; + } + private Asset asset; + public Asset getAsset() { + return this.asset; + } + public void setAsset(Asset value) { + this.asset = value; + } + public static void encode(XdrDataOutputStream stream, OperationIDRevokeId encodedOperationIDRevokeId) throws IOException{ + AccountID.encode(stream, encodedOperationIDRevokeId.sourceAccount); + SequenceNumber.encode(stream, encodedOperationIDRevokeId.seqNum); + Uint32.encode(stream, encodedOperationIDRevokeId.opNum); + PoolID.encode(stream, encodedOperationIDRevokeId.liquidityPoolID); + Asset.encode(stream, encodedOperationIDRevokeId.asset); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static OperationIDRevokeId decode(XdrDataInputStream stream) throws IOException { + OperationIDRevokeId decodedOperationIDRevokeId = new OperationIDRevokeId(); + decodedOperationIDRevokeId.sourceAccount = AccountID.decode(stream); + decodedOperationIDRevokeId.seqNum = SequenceNumber.decode(stream); + decodedOperationIDRevokeId.opNum = Uint32.decode(stream); + decodedOperationIDRevokeId.liquidityPoolID = PoolID.decode(stream); + decodedOperationIDRevokeId.asset = Asset.decode(stream); + return decodedOperationIDRevokeId; + } + @Override + public int hashCode() { + return Objects.hashCode(this.sourceAccount, this.seqNum, this.opNum, this.liquidityPoolID, this.asset); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof OperationIDRevokeId)) { + return false; + } + + OperationIDRevokeId other = (OperationIDRevokeId) object; + return Objects.equal(this.sourceAccount, other.sourceAccount) && Objects.equal(this.seqNum, other.seqNum) && Objects.equal(this.opNum, other.opNum) && Objects.equal(this.liquidityPoolID, other.liquidityPoolID) && Objects.equal(this.asset, other.asset); + } + + public static final class Builder { + private AccountID sourceAccount; + private SequenceNumber seqNum; + private Uint32 opNum; + private PoolID liquidityPoolID; + private Asset asset; + + public Builder sourceAccount(AccountID sourceAccount) { + this.sourceAccount = sourceAccount; + return this; + } + + public Builder seqNum(SequenceNumber seqNum) { + this.seqNum = seqNum; + return this; + } + + public Builder opNum(Uint32 opNum) { + this.opNum = opNum; + return this; + } + + public Builder liquidityPoolID(PoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public Builder asset(Asset asset) { + this.asset = asset; + return this; + } + + public OperationIDRevokeId build() { + OperationIDRevokeId val = new OperationIDRevokeId(); + val.setSourceAccount(sourceAccount); + val.setSeqNum(seqNum); + val.setOpNum(opNum); + val.setLiquidityPoolID(liquidityPoolID); + val.setAsset(asset); + return val; + } + } + + } } diff --git a/src/main/java/org/stellar/sdk/xdr/OperationResult.java b/src/main/java/org/stellar/sdk/xdr/OperationResult.java index e3ad7b46b..62e680fe2 100644 --- a/src/main/java/org/stellar/sdk/xdr/OperationResult.java +++ b/src/main/java/org/stellar/sdk/xdr/OperationResult.java @@ -59,6 +59,10 @@ // ClawbackClaimableBalanceResult clawbackClaimableBalanceResult; // case SET_TRUST_LINE_FLAGS: // SetTrustLineFlagsResult setTrustLineFlagsResult; +// case LIQUIDITY_POOL_DEPOSIT: +// LiquidityPoolDepositResult liquidityPoolDepositResult; +// case LIQUIDITY_POOL_WITHDRAW: +// LiquidityPoolWithdrawResult liquidityPoolWithdrawResult; // } // tr; // default: @@ -310,6 +314,20 @@ public SetTrustLineFlagsResult getSetTrustLineFlagsResult() { public void setSetTrustLineFlagsResult(SetTrustLineFlagsResult value) { this.setTrustLineFlagsResult = value; } + private LiquidityPoolDepositResult liquidityPoolDepositResult; + public LiquidityPoolDepositResult getLiquidityPoolDepositResult() { + return this.liquidityPoolDepositResult; + } + public void setLiquidityPoolDepositResult(LiquidityPoolDepositResult value) { + this.liquidityPoolDepositResult = value; + } + private LiquidityPoolWithdrawResult liquidityPoolWithdrawResult; + public LiquidityPoolWithdrawResult getLiquidityPoolWithdrawResult() { + return this.liquidityPoolWithdrawResult; + } + public void setLiquidityPoolWithdrawResult(LiquidityPoolWithdrawResult value) { + this.liquidityPoolWithdrawResult = value; + } public static final class Builder { private OperationType discriminant; @@ -335,6 +353,8 @@ public static final class Builder { private ClawbackResult clawbackResult; private ClawbackClaimableBalanceResult clawbackClaimableBalanceResult; private SetTrustLineFlagsResult setTrustLineFlagsResult; + private LiquidityPoolDepositResult liquidityPoolDepositResult; + private LiquidityPoolWithdrawResult liquidityPoolWithdrawResult; public Builder discriminant(OperationType discriminant) { this.discriminant = discriminant; @@ -451,6 +471,16 @@ public Builder setTrustLineFlagsResult(SetTrustLineFlagsResult setTrustLineFlags return this; } + public Builder liquidityPoolDepositResult(LiquidityPoolDepositResult liquidityPoolDepositResult) { + this.liquidityPoolDepositResult = liquidityPoolDepositResult; + return this; + } + + public Builder liquidityPoolWithdrawResult(LiquidityPoolWithdrawResult liquidityPoolWithdrawResult) { + this.liquidityPoolWithdrawResult = liquidityPoolWithdrawResult; + return this; + } + public OperationResultTr build() { OperationResultTr val = new OperationResultTr(); val.setDiscriminant(discriminant); @@ -476,6 +506,8 @@ public OperationResultTr build() { val.setClawbackResult(clawbackResult); val.setClawbackClaimableBalanceResult(clawbackClaimableBalanceResult); val.setSetTrustLineFlagsResult(setTrustLineFlagsResult); + val.setLiquidityPoolDepositResult(liquidityPoolDepositResult); + val.setLiquidityPoolWithdrawResult(liquidityPoolWithdrawResult); return val; } } @@ -551,6 +583,12 @@ public static void encode(XdrDataOutputStream stream, OperationResultTr encodedO case SET_TRUST_LINE_FLAGS: SetTrustLineFlagsResult.encode(stream, encodedOperationResultTr.setTrustLineFlagsResult); break; + case LIQUIDITY_POOL_DEPOSIT: + LiquidityPoolDepositResult.encode(stream, encodedOperationResultTr.liquidityPoolDepositResult); + break; + case LIQUIDITY_POOL_WITHDRAW: + LiquidityPoolWithdrawResult.encode(stream, encodedOperationResultTr.liquidityPoolWithdrawResult); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -627,12 +665,18 @@ public static OperationResultTr decode(XdrDataInputStream stream) throws IOExcep case SET_TRUST_LINE_FLAGS: decodedOperationResultTr.setTrustLineFlagsResult = SetTrustLineFlagsResult.decode(stream); break; + case LIQUIDITY_POOL_DEPOSIT: + decodedOperationResultTr.liquidityPoolDepositResult = LiquidityPoolDepositResult.decode(stream); + break; + case LIQUIDITY_POOL_WITHDRAW: + decodedOperationResultTr.liquidityPoolWithdrawResult = LiquidityPoolWithdrawResult.decode(stream); + break; } return decodedOperationResultTr; } @Override public int hashCode() { - return Objects.hashCode(this.createAccountResult, this.paymentResult, this.pathPaymentStrictReceiveResult, this.manageSellOfferResult, this.createPassiveSellOfferResult, this.setOptionsResult, this.changeTrustResult, this.allowTrustResult, this.accountMergeResult, this.inflationResult, this.manageDataResult, this.bumpSeqResult, this.manageBuyOfferResult, this.pathPaymentStrictSendResult, this.createClaimableBalanceResult, this.claimClaimableBalanceResult, this.beginSponsoringFutureReservesResult, this.endSponsoringFutureReservesResult, this.revokeSponsorshipResult, this.clawbackResult, this.clawbackClaimableBalanceResult, this.setTrustLineFlagsResult, this.type); + return Objects.hashCode(this.createAccountResult, this.paymentResult, this.pathPaymentStrictReceiveResult, this.manageSellOfferResult, this.createPassiveSellOfferResult, this.setOptionsResult, this.changeTrustResult, this.allowTrustResult, this.accountMergeResult, this.inflationResult, this.manageDataResult, this.bumpSeqResult, this.manageBuyOfferResult, this.pathPaymentStrictSendResult, this.createClaimableBalanceResult, this.claimClaimableBalanceResult, this.beginSponsoringFutureReservesResult, this.endSponsoringFutureReservesResult, this.revokeSponsorshipResult, this.clawbackResult, this.clawbackClaimableBalanceResult, this.setTrustLineFlagsResult, this.liquidityPoolDepositResult, this.liquidityPoolWithdrawResult, this.type); } @Override public boolean equals(Object object) { @@ -641,7 +685,7 @@ public boolean equals(Object object) { } OperationResultTr other = (OperationResultTr) object; - return Objects.equal(this.createAccountResult, other.createAccountResult) && Objects.equal(this.paymentResult, other.paymentResult) && Objects.equal(this.pathPaymentStrictReceiveResult, other.pathPaymentStrictReceiveResult) && Objects.equal(this.manageSellOfferResult, other.manageSellOfferResult) && Objects.equal(this.createPassiveSellOfferResult, other.createPassiveSellOfferResult) && Objects.equal(this.setOptionsResult, other.setOptionsResult) && Objects.equal(this.changeTrustResult, other.changeTrustResult) && Objects.equal(this.allowTrustResult, other.allowTrustResult) && Objects.equal(this.accountMergeResult, other.accountMergeResult) && Objects.equal(this.inflationResult, other.inflationResult) && Objects.equal(this.manageDataResult, other.manageDataResult) && Objects.equal(this.bumpSeqResult, other.bumpSeqResult) && Objects.equal(this.manageBuyOfferResult, other.manageBuyOfferResult) && Objects.equal(this.pathPaymentStrictSendResult, other.pathPaymentStrictSendResult) && Objects.equal(this.createClaimableBalanceResult, other.createClaimableBalanceResult) && Objects.equal(this.claimClaimableBalanceResult, other.claimClaimableBalanceResult) && Objects.equal(this.beginSponsoringFutureReservesResult, other.beginSponsoringFutureReservesResult) && Objects.equal(this.endSponsoringFutureReservesResult, other.endSponsoringFutureReservesResult) && Objects.equal(this.revokeSponsorshipResult, other.revokeSponsorshipResult) && Objects.equal(this.clawbackResult, other.clawbackResult) && Objects.equal(this.clawbackClaimableBalanceResult, other.clawbackClaimableBalanceResult) && Objects.equal(this.setTrustLineFlagsResult, other.setTrustLineFlagsResult) && Objects.equal(this.type, other.type); + return Objects.equal(this.createAccountResult, other.createAccountResult) && Objects.equal(this.paymentResult, other.paymentResult) && Objects.equal(this.pathPaymentStrictReceiveResult, other.pathPaymentStrictReceiveResult) && Objects.equal(this.manageSellOfferResult, other.manageSellOfferResult) && Objects.equal(this.createPassiveSellOfferResult, other.createPassiveSellOfferResult) && Objects.equal(this.setOptionsResult, other.setOptionsResult) && Objects.equal(this.changeTrustResult, other.changeTrustResult) && Objects.equal(this.allowTrustResult, other.allowTrustResult) && Objects.equal(this.accountMergeResult, other.accountMergeResult) && Objects.equal(this.inflationResult, other.inflationResult) && Objects.equal(this.manageDataResult, other.manageDataResult) && Objects.equal(this.bumpSeqResult, other.bumpSeqResult) && Objects.equal(this.manageBuyOfferResult, other.manageBuyOfferResult) && Objects.equal(this.pathPaymentStrictSendResult, other.pathPaymentStrictSendResult) && Objects.equal(this.createClaimableBalanceResult, other.createClaimableBalanceResult) && Objects.equal(this.claimClaimableBalanceResult, other.claimClaimableBalanceResult) && Objects.equal(this.beginSponsoringFutureReservesResult, other.beginSponsoringFutureReservesResult) && Objects.equal(this.endSponsoringFutureReservesResult, other.endSponsoringFutureReservesResult) && Objects.equal(this.revokeSponsorshipResult, other.revokeSponsorshipResult) && Objects.equal(this.clawbackResult, other.clawbackResult) && Objects.equal(this.clawbackClaimableBalanceResult, other.clawbackClaimableBalanceResult) && Objects.equal(this.setTrustLineFlagsResult, other.setTrustLineFlagsResult) && Objects.equal(this.liquidityPoolDepositResult, other.liquidityPoolDepositResult) && Objects.equal(this.liquidityPoolWithdrawResult, other.liquidityPoolWithdrawResult) && Objects.equal(this.type, other.type); } } diff --git a/src/main/java/org/stellar/sdk/xdr/OperationType.java b/src/main/java/org/stellar/sdk/xdr/OperationType.java index 971e1d413..44830abbf 100644 --- a/src/main/java/org/stellar/sdk/xdr/OperationType.java +++ b/src/main/java/org/stellar/sdk/xdr/OperationType.java @@ -32,7 +32,9 @@ // REVOKE_SPONSORSHIP = 18, // CLAWBACK = 19, // CLAWBACK_CLAIMABLE_BALANCE = 20, -// SET_TRUST_LINE_FLAGS = 21 +// SET_TRUST_LINE_FLAGS = 21, +// LIQUIDITY_POOL_DEPOSIT = 22, +// LIQUIDITY_POOL_WITHDRAW = 23 // }; // =========================================================================== @@ -59,6 +61,8 @@ public enum OperationType implements XdrElement { CLAWBACK(19), CLAWBACK_CLAIMABLE_BALANCE(20), SET_TRUST_LINE_FLAGS(21), + LIQUIDITY_POOL_DEPOSIT(22), + LIQUIDITY_POOL_WITHDRAW(23), ; private int mValue; @@ -95,6 +99,8 @@ public static OperationType decode(XdrDataInputStream stream) throws IOException case 19: return CLAWBACK; case 20: return CLAWBACK_CLAIMABLE_BALANCE; case 21: return SET_TRUST_LINE_FLAGS; + case 22: return LIQUIDITY_POOL_DEPOSIT; + case 23: return LIQUIDITY_POOL_WITHDRAW; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java index fde24306f..4b2287d22 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java @@ -11,12 +11,13 @@ // === xdr source ============================================================ -// union PathPaymentStrictReceiveResult switch (PathPaymentStrictReceiveResultCode code) +// union PathPaymentStrictReceiveResult switch ( +// PathPaymentStrictReceiveResultCode code) // { // case PATH_PAYMENT_STRICT_RECEIVE_SUCCESS: // struct // { -// ClaimOfferAtom offers<>; +// ClaimAtom offers<>; // SimplePaymentResult last; // } success; // case PATH_PAYMENT_STRICT_RECEIVE_NO_ISSUER: @@ -129,11 +130,11 @@ public boolean equals(Object object) { public static class PathPaymentStrictReceiveResultSuccess { public PathPaymentStrictReceiveResultSuccess () {} - private ClaimOfferAtom[] offers; - public ClaimOfferAtom[] getOffers() { + private ClaimAtom[] offers; + public ClaimAtom[] getOffers() { return this.offers; } - public void setOffers(ClaimOfferAtom[] value) { + public void setOffers(ClaimAtom[] value) { this.offers = value; } private SimplePaymentResult last; @@ -147,7 +148,7 @@ public static void encode(XdrDataOutputStream stream, PathPaymentStrictReceiveRe int offerssize = encodedPathPaymentStrictReceiveResultSuccess.getOffers().length; stream.writeInt(offerssize); for (int i = 0; i < offerssize; i++) { - ClaimOfferAtom.encode(stream, encodedPathPaymentStrictReceiveResultSuccess.offers[i]); + ClaimAtom.encode(stream, encodedPathPaymentStrictReceiveResultSuccess.offers[i]); } SimplePaymentResult.encode(stream, encodedPathPaymentStrictReceiveResultSuccess.last); } @@ -157,9 +158,9 @@ public void encode(XdrDataOutputStream stream) throws IOException { public static PathPaymentStrictReceiveResultSuccess decode(XdrDataInputStream stream) throws IOException { PathPaymentStrictReceiveResultSuccess decodedPathPaymentStrictReceiveResultSuccess = new PathPaymentStrictReceiveResultSuccess(); int offerssize = stream.readInt(); - decodedPathPaymentStrictReceiveResultSuccess.offers = new ClaimOfferAtom[offerssize]; + decodedPathPaymentStrictReceiveResultSuccess.offers = new ClaimAtom[offerssize]; for (int i = 0; i < offerssize; i++) { - decodedPathPaymentStrictReceiveResultSuccess.offers[i] = ClaimOfferAtom.decode(stream); + decodedPathPaymentStrictReceiveResultSuccess.offers[i] = ClaimAtom.decode(stream); } decodedPathPaymentStrictReceiveResultSuccess.last = SimplePaymentResult.decode(stream); return decodedPathPaymentStrictReceiveResultSuccess; @@ -179,10 +180,10 @@ public boolean equals(Object object) { } public static final class Builder { - private ClaimOfferAtom[] offers; + private ClaimAtom[] offers; private SimplePaymentResult last; - public Builder offers(ClaimOfferAtom[] offers) { + public Builder offers(ClaimAtom[] offers) { this.offers = offers; return this; } diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java index c73ab9fbf..464365303 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java @@ -16,7 +16,7 @@ // case PATH_PAYMENT_STRICT_SEND_SUCCESS: // struct // { -// ClaimOfferAtom offers<>; +// ClaimAtom offers<>; // SimplePaymentResult last; // } success; // case PATH_PAYMENT_STRICT_SEND_NO_ISSUER: @@ -129,11 +129,11 @@ public boolean equals(Object object) { public static class PathPaymentStrictSendResultSuccess { public PathPaymentStrictSendResultSuccess () {} - private ClaimOfferAtom[] offers; - public ClaimOfferAtom[] getOffers() { + private ClaimAtom[] offers; + public ClaimAtom[] getOffers() { return this.offers; } - public void setOffers(ClaimOfferAtom[] value) { + public void setOffers(ClaimAtom[] value) { this.offers = value; } private SimplePaymentResult last; @@ -147,7 +147,7 @@ public static void encode(XdrDataOutputStream stream, PathPaymentStrictSendResul int offerssize = encodedPathPaymentStrictSendResultSuccess.getOffers().length; stream.writeInt(offerssize); for (int i = 0; i < offerssize; i++) { - ClaimOfferAtom.encode(stream, encodedPathPaymentStrictSendResultSuccess.offers[i]); + ClaimAtom.encode(stream, encodedPathPaymentStrictSendResultSuccess.offers[i]); } SimplePaymentResult.encode(stream, encodedPathPaymentStrictSendResultSuccess.last); } @@ -157,9 +157,9 @@ public void encode(XdrDataOutputStream stream) throws IOException { public static PathPaymentStrictSendResultSuccess decode(XdrDataInputStream stream) throws IOException { PathPaymentStrictSendResultSuccess decodedPathPaymentStrictSendResultSuccess = new PathPaymentStrictSendResultSuccess(); int offerssize = stream.readInt(); - decodedPathPaymentStrictSendResultSuccess.offers = new ClaimOfferAtom[offerssize]; + decodedPathPaymentStrictSendResultSuccess.offers = new ClaimAtom[offerssize]; for (int i = 0; i < offerssize; i++) { - decodedPathPaymentStrictSendResultSuccess.offers[i] = ClaimOfferAtom.decode(stream); + decodedPathPaymentStrictSendResultSuccess.offers[i] = ClaimAtom.decode(stream); } decodedPathPaymentStrictSendResultSuccess.last = SimplePaymentResult.decode(stream); return decodedPathPaymentStrictSendResultSuccess; @@ -179,10 +179,10 @@ public boolean equals(Object object) { } public static final class Builder { - private ClaimOfferAtom[] offers; + private ClaimAtom[] offers; private SimplePaymentResult last; - public Builder offers(ClaimOfferAtom[] offers) { + public Builder offers(ClaimAtom[] offers) { this.offers = offers; return this; } diff --git a/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java b/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java index 1c79d2ac0..7dfeb4c0a 100644 --- a/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java @@ -12,7 +12,7 @@ // enum PaymentResultCode // { // // codes considered as "success" for the operation -// PAYMENT_SUCCESS = 0, // payment successfuly completed +// PAYMENT_SUCCESS = 0, // payment successfully completed // // // codes considered as "failure" for the operation // PAYMENT_MALFORMED = -1, // bad input diff --git a/src/main/java/org/stellar/sdk/xdr/PoolID.java b/src/main/java/org/stellar/sdk/xdr/PoolID.java new file mode 100644 index 000000000..92e9800cf --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/PoolID.java @@ -0,0 +1,60 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// typedef Hash PoolID; + +// =========================================================================== +public class PoolID implements XdrElement { + private Hash PoolID; + + public PoolID() {} + + public PoolID(Hash PoolID) { + this.PoolID = PoolID; + } + + public Hash getPoolID() { + return this.PoolID; + } + + public void setPoolID(Hash value) { + this.PoolID = value; + } + + public static void encode(XdrDataOutputStream stream, PoolID encodedPoolID) throws IOException { + Hash.encode(stream, encodedPoolID.PoolID); + } + + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static PoolID decode(XdrDataInputStream stream) throws IOException { + PoolID decodedPoolID = new PoolID(); + decodedPoolID.PoolID = Hash.decode(stream); + return decodedPoolID; + } + + @Override + public int hashCode() { + return Objects.hashCode(this.PoolID); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof PoolID)) { + return false; + } + + PoolID other = (PoolID) object; + return Objects.equal(this.PoolID, other.PoolID); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java index e0856022c..b12c58764 100644 --- a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java +++ b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java @@ -19,8 +19,7 @@ // { // AccountID accountID; // SignerKey signerKey; -// } -// signer; +// } signer; // }; // =========================================================================== diff --git a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java index 82e2e0d76..9c89c45fb 100644 --- a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java @@ -18,7 +18,8 @@ // REVOKE_SPONSORSHIP_DOES_NOT_EXIST = -1, // REVOKE_SPONSORSHIP_NOT_SPONSOR = -2, // REVOKE_SPONSORSHIP_LOW_RESERVE = -3, -// REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE = -4 +// REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE = -4, +// REVOKE_SPONSORSHIP_MALFORMED = -5 // }; // =========================================================================== @@ -28,6 +29,7 @@ public enum RevokeSponsorshipResultCode implements XdrElement { REVOKE_SPONSORSHIP_NOT_SPONSOR(-2), REVOKE_SPONSORSHIP_LOW_RESERVE(-3), REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE(-4), + REVOKE_SPONSORSHIP_MALFORMED(-5), ; private int mValue; @@ -47,6 +49,7 @@ public static RevokeSponsorshipResultCode decode(XdrDataInputStream stream) thro case -2: return REVOKE_SPONSORSHIP_NOT_SPONSOR; case -3: return REVOKE_SPONSORSHIP_LOW_RESERVE; case -4: return REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE; + case -5: return REVOKE_SPONSORSHIP_MALFORMED; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java b/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java index 457a02e95..c4ea68f25 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java @@ -14,7 +14,7 @@ // struct SCPQuorumSet // { // uint32 threshold; -// PublicKey validators<>; +// NodeID validators<>; // SCPQuorumSet innerSets<>; // }; @@ -28,11 +28,11 @@ public Uint32 getThreshold() { public void setThreshold(Uint32 value) { this.threshold = value; } - private PublicKey[] validators; - public PublicKey[] getValidators() { + private NodeID[] validators; + public NodeID[] getValidators() { return this.validators; } - public void setValidators(PublicKey[] value) { + public void setValidators(NodeID[] value) { this.validators = value; } private SCPQuorumSet[] innerSets; @@ -47,7 +47,7 @@ public static void encode(XdrDataOutputStream stream, SCPQuorumSet encodedSCPQuo int validatorssize = encodedSCPQuorumSet.getValidators().length; stream.writeInt(validatorssize); for (int i = 0; i < validatorssize; i++) { - PublicKey.encode(stream, encodedSCPQuorumSet.validators[i]); + NodeID.encode(stream, encodedSCPQuorumSet.validators[i]); } int innerSetssize = encodedSCPQuorumSet.getInnerSets().length; stream.writeInt(innerSetssize); @@ -62,9 +62,9 @@ public static SCPQuorumSet decode(XdrDataInputStream stream) throws IOException SCPQuorumSet decodedSCPQuorumSet = new SCPQuorumSet(); decodedSCPQuorumSet.threshold = Uint32.decode(stream); int validatorssize = stream.readInt(); - decodedSCPQuorumSet.validators = new PublicKey[validatorssize]; + decodedSCPQuorumSet.validators = new NodeID[validatorssize]; for (int i = 0; i < validatorssize; i++) { - decodedSCPQuorumSet.validators[i] = PublicKey.decode(stream); + decodedSCPQuorumSet.validators[i] = NodeID.decode(stream); } int innerSetssize = stream.readInt(); decodedSCPQuorumSet.innerSets = new SCPQuorumSet[innerSetssize]; @@ -89,7 +89,7 @@ public boolean equals(Object object) { public static final class Builder { private Uint32 threshold; - private PublicKey[] validators; + private NodeID[] validators; private SCPQuorumSet[] innerSets; public Builder threshold(Uint32 threshold) { @@ -97,7 +97,7 @@ public Builder threshold(Uint32 threshold) { return this; } - public Builder validators(PublicKey[] validators) { + public Builder validators(NodeID[] validators) { this.validators = validators; return this; } diff --git a/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java b/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java index e58e279ec..a225d6d0a 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java @@ -22,8 +22,9 @@ // SET_OPTIONS_UNKNOWN_FLAG = -6, // can't set an unknown flag // SET_OPTIONS_THRESHOLD_OUT_OF_RANGE = -7, // bad value for weight/threshold // SET_OPTIONS_BAD_SIGNER = -8, // signer cannot be masterkey -// SET_OPTIONS_INVALID_HOME_DOMAIN = -9, // malformed home domain -// SET_OPTIONS_AUTH_REVOCABLE_REQUIRED = -10 // auth revocable is required for clawback +// SET_OPTIONS_INVALID_HOME_DOMAIN = -9, // malformed home domain +// SET_OPTIONS_AUTH_REVOCABLE_REQUIRED = +// -10 // auth revocable is required for clawback // }; // =========================================================================== diff --git a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java index 85028803e..b935b2411 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java @@ -18,7 +18,9 @@ // SET_TRUST_LINE_FLAGS_MALFORMED = -1, // SET_TRUST_LINE_FLAGS_NO_TRUST_LINE = -2, // SET_TRUST_LINE_FLAGS_CANT_REVOKE = -3, -// SET_TRUST_LINE_FLAGS_INVALID_STATE = -4 +// SET_TRUST_LINE_FLAGS_INVALID_STATE = -4, +// SET_TRUST_LINE_FLAGS_LOW_RESERVE = -5 // claimable balances can't be created +// // on revoke due to low reserves // }; // =========================================================================== @@ -28,6 +30,7 @@ public enum SetTrustLineFlagsResultCode implements XdrElement { SET_TRUST_LINE_FLAGS_NO_TRUST_LINE(-2), SET_TRUST_LINE_FLAGS_CANT_REVOKE(-3), SET_TRUST_LINE_FLAGS_INVALID_STATE(-4), + SET_TRUST_LINE_FLAGS_LOW_RESERVE(-5), ; private int mValue; @@ -47,6 +50,7 @@ public static SetTrustLineFlagsResultCode decode(XdrDataInputStream stream) thro case -2: return SET_TRUST_LINE_FLAGS_NO_TRUST_LINE; case -3: return SET_TRUST_LINE_FLAGS_CANT_REVOKE; case -4: return SET_TRUST_LINE_FLAGS_INVALID_STATE; + case -5: return SET_TRUST_LINE_FLAGS_LOW_RESERVE; default: throw new RuntimeException("Unknown enum value: " + value); } diff --git a/src/main/java/org/stellar/sdk/xdr/StellarValue.java b/src/main/java/org/stellar/sdk/xdr/StellarValue.java index 7fd7f1640..6954c7e9c 100644 --- a/src/main/java/org/stellar/sdk/xdr/StellarValue.java +++ b/src/main/java/org/stellar/sdk/xdr/StellarValue.java @@ -20,7 +20,7 @@ // // this is a vector of encoded 'LedgerUpgrade' so that nodes can drop // // unknown steps during consensus if needed. // // see notes below on 'LedgerUpgrade' for more detail -// // max size is dictated by number of upgrade types (+ room for future) +// // max size is dictated by number of upgrade types ( room for future) // UpgradeType upgrades<6>; // // // reserved for future use diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java b/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java index c3871510e..ba809fa91 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java @@ -26,7 +26,7 @@ // txNO_ACCOUNT = -8, // source account not found // txINSUFFICIENT_FEE = -9, // fee is too small // txBAD_AUTH_EXTRA = -10, // unused signatures attached to transaction -// txINTERNAL_ERROR = -11, // an unknown error occured +// txINTERNAL_ERROR = -11, // an unknown error occurred // // txNOT_SUPPORTED = -12, // transaction type not supported // txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed diff --git a/src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java b/src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java new file mode 100644 index 000000000..a58a12521 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java @@ -0,0 +1,151 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// union TrustLineAsset switch (AssetType type) +// { +// case ASSET_TYPE_NATIVE: // Not credit +// void; +// +// case ASSET_TYPE_CREDIT_ALPHANUM4: +// AlphaNum4 alphaNum4; +// +// case ASSET_TYPE_CREDIT_ALPHANUM12: +// AlphaNum12 alphaNum12; +// +// case ASSET_TYPE_POOL_SHARE: +// PoolID liquidityPoolID; +// +// // add other asset types here in the future +// }; + +// =========================================================================== +public class TrustLineAsset implements XdrElement { + public TrustLineAsset () {} + AssetType type; + public AssetType getDiscriminant() { + return this.type; + } + public void setDiscriminant(AssetType value) { + this.type = value; + } + private AlphaNum4 alphaNum4; + public AlphaNum4 getAlphaNum4() { + return this.alphaNum4; + } + public void setAlphaNum4(AlphaNum4 value) { + this.alphaNum4 = value; + } + private AlphaNum12 alphaNum12; + public AlphaNum12 getAlphaNum12() { + return this.alphaNum12; + } + public void setAlphaNum12(AlphaNum12 value) { + this.alphaNum12 = value; + } + private PoolID liquidityPoolID; + public PoolID getLiquidityPoolID() { + return this.liquidityPoolID; + } + public void setLiquidityPoolID(PoolID value) { + this.liquidityPoolID = value; + } + + public static final class Builder { + private AssetType discriminant; + private AlphaNum4 alphaNum4; + private AlphaNum12 alphaNum12; + private PoolID liquidityPoolID; + + public Builder discriminant(AssetType discriminant) { + this.discriminant = discriminant; + return this; + } + + public Builder alphaNum4(AlphaNum4 alphaNum4) { + this.alphaNum4 = alphaNum4; + return this; + } + + public Builder alphaNum12(AlphaNum12 alphaNum12) { + this.alphaNum12 = alphaNum12; + return this; + } + + public Builder liquidityPoolID(PoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public TrustLineAsset build() { + TrustLineAsset val = new TrustLineAsset(); + val.setDiscriminant(discriminant); + val.setAlphaNum4(alphaNum4); + val.setAlphaNum12(alphaNum12); + val.setLiquidityPoolID(liquidityPoolID); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, TrustLineAsset encodedTrustLineAsset) throws IOException { + //Xdrgen::AST::Identifier + //AssetType + stream.writeInt(encodedTrustLineAsset.getDiscriminant().getValue()); + switch (encodedTrustLineAsset.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + break; + case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4.encode(stream, encodedTrustLineAsset.alphaNum4); + break; + case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12.encode(stream, encodedTrustLineAsset.alphaNum12); + break; + case ASSET_TYPE_POOL_SHARE: + PoolID.encode(stream, encodedTrustLineAsset.liquidityPoolID); + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static TrustLineAsset decode(XdrDataInputStream stream) throws IOException { + TrustLineAsset decodedTrustLineAsset = new TrustLineAsset(); + AssetType discriminant = AssetType.decode(stream); + decodedTrustLineAsset.setDiscriminant(discriminant); + switch (decodedTrustLineAsset.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + break; + case ASSET_TYPE_CREDIT_ALPHANUM4: + decodedTrustLineAsset.alphaNum4 = AlphaNum4.decode(stream); + break; + case ASSET_TYPE_CREDIT_ALPHANUM12: + decodedTrustLineAsset.alphaNum12 = AlphaNum12.decode(stream); + break; + case ASSET_TYPE_POOL_SHARE: + decodedTrustLineAsset.liquidityPoolID = PoolID.decode(stream); + break; + } + return decodedTrustLineAsset; + } + @Override + public int hashCode() { + return Objects.hashCode(this.alphaNum4, this.alphaNum12, this.liquidityPoolID, this.type); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof TrustLineAsset)) { + return false; + } + + TrustLineAsset other = (TrustLineAsset) object; + return Objects.equal(this.alphaNum4, other.alphaNum4) && Objects.equal(this.alphaNum12, other.alphaNum12) && Objects.equal(this.liquidityPoolID, other.liquidityPoolID) && Objects.equal(this.type, other.type); + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java b/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java index 302f6fba8..668c07d37 100644 --- a/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java @@ -13,7 +13,7 @@ // struct TrustLineEntry // { // AccountID accountID; // account this trustline belongs to -// Asset asset; // type of asset (with issuer) +// TrustLineAsset asset; // type of asset (with issuer) // int64 balance; // how much of this asset the user has. // // Asset defines the unit for this; // @@ -34,6 +34,8 @@ // { // case 0: // void; +// case 2: +// TrustLineEntryExtensionV2 v2; // } // ext; // } v1; @@ -51,11 +53,11 @@ public AccountID getAccountID() { public void setAccountID(AccountID value) { this.accountID = value; } - private Asset asset; - public Asset getAsset() { + private TrustLineAsset asset; + public TrustLineAsset getAsset() { return this.asset; } - public void setAsset(Asset value) { + public void setAsset(TrustLineAsset value) { this.asset = value; } private Int64 balance; @@ -88,7 +90,7 @@ public void setExt(TrustLineEntryExt value) { } public static void encode(XdrDataOutputStream stream, TrustLineEntry encodedTrustLineEntry) throws IOException{ AccountID.encode(stream, encodedTrustLineEntry.accountID); - Asset.encode(stream, encodedTrustLineEntry.asset); + TrustLineAsset.encode(stream, encodedTrustLineEntry.asset); Int64.encode(stream, encodedTrustLineEntry.balance); Int64.encode(stream, encodedTrustLineEntry.limit); Uint32.encode(stream, encodedTrustLineEntry.flags); @@ -100,7 +102,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { public static TrustLineEntry decode(XdrDataInputStream stream) throws IOException { TrustLineEntry decodedTrustLineEntry = new TrustLineEntry(); decodedTrustLineEntry.accountID = AccountID.decode(stream); - decodedTrustLineEntry.asset = Asset.decode(stream); + decodedTrustLineEntry.asset = TrustLineAsset.decode(stream); decodedTrustLineEntry.balance = Int64.decode(stream); decodedTrustLineEntry.limit = Int64.decode(stream); decodedTrustLineEntry.flags = Uint32.decode(stream); @@ -123,7 +125,7 @@ public boolean equals(Object object) { public static final class Builder { private AccountID accountID; - private Asset asset; + private TrustLineAsset asset; private Int64 balance; private Int64 limit; private Uint32 flags; @@ -134,7 +136,7 @@ public Builder accountID(AccountID accountID) { return this; } - public Builder asset(Asset asset) { + public Builder asset(TrustLineAsset asset) { this.asset = asset; return this; } @@ -326,18 +328,32 @@ public Integer getDiscriminant() { public void setDiscriminant(Integer value) { this.v = value; } + private TrustLineEntryExtensionV2 v2; + public TrustLineEntryExtensionV2 getV2() { + return this.v2; + } + public void setV2(TrustLineEntryExtensionV2 value) { + this.v2 = value; + } public static final class Builder { private Integer discriminant; + private TrustLineEntryExtensionV2 v2; public Builder discriminant(Integer discriminant) { this.discriminant = discriminant; return this; } + public Builder v2(TrustLineEntryExtensionV2 v2) { + this.v2 = v2; + return this; + } + public TrustLineEntryV1Ext build() { TrustLineEntryV1Ext val = new TrustLineEntryV1Ext(); val.setDiscriminant(discriminant); + val.setV2(v2); return val; } } @@ -349,6 +365,9 @@ public static void encode(XdrDataOutputStream stream, TrustLineEntryV1Ext encode switch (encodedTrustLineEntryV1Ext.getDiscriminant()) { case 0: break; + case 2: + TrustLineEntryExtensionV2.encode(stream, encodedTrustLineEntryV1Ext.v2); + break; } } public void encode(XdrDataOutputStream stream) throws IOException { @@ -361,12 +380,15 @@ public static TrustLineEntryV1Ext decode(XdrDataInputStream stream) throws IOExc switch (decodedTrustLineEntryV1Ext.getDiscriminant()) { case 0: break; + case 2: + decodedTrustLineEntryV1Ext.v2 = TrustLineEntryExtensionV2.decode(stream); + break; } return decodedTrustLineEntryV1Ext; } @Override public int hashCode() { - return Objects.hashCode(this.v); + return Objects.hashCode(this.v2, this.v); } @Override public boolean equals(Object object) { @@ -375,7 +397,7 @@ public boolean equals(Object object) { } TrustLineEntryV1Ext other = (TrustLineEntryV1Ext) object; - return Objects.equal(this.v, other.v); + return Objects.equal(this.v2, other.v2) && Objects.equal(this.v, other.v); } } diff --git a/src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java b/src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java new file mode 100644 index 000000000..f65de8b92 --- /dev/null +++ b/src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java @@ -0,0 +1,153 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +package org.stellar.sdk.xdr; + + +import java.io.IOException; + +import com.google.common.base.Objects; + +// === xdr source ============================================================ + +// struct TrustLineEntryExtensionV2 +// { +// int32 liquidityPoolUseCount; +// +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// }; + +// =========================================================================== +public class TrustLineEntryExtensionV2 implements XdrElement { + public TrustLineEntryExtensionV2 () {} + private Int32 liquidityPoolUseCount; + public Int32 getLiquidityPoolUseCount() { + return this.liquidityPoolUseCount; + } + public void setLiquidityPoolUseCount(Int32 value) { + this.liquidityPoolUseCount = value; + } + private TrustLineEntryExtensionV2Ext ext; + public TrustLineEntryExtensionV2Ext getExt() { + return this.ext; + } + public void setExt(TrustLineEntryExtensionV2Ext value) { + this.ext = value; + } + public static void encode(XdrDataOutputStream stream, TrustLineEntryExtensionV2 encodedTrustLineEntryExtensionV2) throws IOException{ + Int32.encode(stream, encodedTrustLineEntryExtensionV2.liquidityPoolUseCount); + TrustLineEntryExtensionV2Ext.encode(stream, encodedTrustLineEntryExtensionV2.ext); + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static TrustLineEntryExtensionV2 decode(XdrDataInputStream stream) throws IOException { + TrustLineEntryExtensionV2 decodedTrustLineEntryExtensionV2 = new TrustLineEntryExtensionV2(); + decodedTrustLineEntryExtensionV2.liquidityPoolUseCount = Int32.decode(stream); + decodedTrustLineEntryExtensionV2.ext = TrustLineEntryExtensionV2Ext.decode(stream); + return decodedTrustLineEntryExtensionV2; + } + @Override + public int hashCode() { + return Objects.hashCode(this.liquidityPoolUseCount, this.ext); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof TrustLineEntryExtensionV2)) { + return false; + } + + TrustLineEntryExtensionV2 other = (TrustLineEntryExtensionV2) object; + return Objects.equal(this.liquidityPoolUseCount, other.liquidityPoolUseCount) && Objects.equal(this.ext, other.ext); + } + + public static final class Builder { + private Int32 liquidityPoolUseCount; + private TrustLineEntryExtensionV2Ext ext; + + public Builder liquidityPoolUseCount(Int32 liquidityPoolUseCount) { + this.liquidityPoolUseCount = liquidityPoolUseCount; + return this; + } + + public Builder ext(TrustLineEntryExtensionV2Ext ext) { + this.ext = ext; + return this; + } + + public TrustLineEntryExtensionV2 build() { + TrustLineEntryExtensionV2 val = new TrustLineEntryExtensionV2(); + val.setLiquidityPoolUseCount(liquidityPoolUseCount); + val.setExt(ext); + return val; + } + } + + public static class TrustLineEntryExtensionV2Ext { + public TrustLineEntryExtensionV2Ext () {} + Integer v; + public Integer getDiscriminant() { + return this.v; + } + public void setDiscriminant(Integer value) { + this.v = value; + } + + public static final class Builder { + private Integer discriminant; + + public Builder discriminant(Integer discriminant) { + this.discriminant = discriminant; + return this; + } + + public TrustLineEntryExtensionV2Ext build() { + TrustLineEntryExtensionV2Ext val = new TrustLineEntryExtensionV2Ext(); + val.setDiscriminant(discriminant); + return val; + } + } + + public static void encode(XdrDataOutputStream stream, TrustLineEntryExtensionV2Ext encodedTrustLineEntryExtensionV2Ext) throws IOException { + //Xdrgen::AST::Typespecs::Int + //Integer + stream.writeInt(encodedTrustLineEntryExtensionV2Ext.getDiscriminant().intValue()); + switch (encodedTrustLineEntryExtensionV2Ext.getDiscriminant()) { + case 0: + break; + } + } + public void encode(XdrDataOutputStream stream) throws IOException { + encode(stream, this); + } + public static TrustLineEntryExtensionV2Ext decode(XdrDataInputStream stream) throws IOException { + TrustLineEntryExtensionV2Ext decodedTrustLineEntryExtensionV2Ext = new TrustLineEntryExtensionV2Ext(); + Integer discriminant = stream.readInt(); + decodedTrustLineEntryExtensionV2Ext.setDiscriminant(discriminant); + switch (decodedTrustLineEntryExtensionV2Ext.getDiscriminant()) { + case 0: + break; + } + return decodedTrustLineEntryExtensionV2Ext; + } + @Override + public int hashCode() { + return Objects.hashCode(this.v); + } + @Override + public boolean equals(Object object) { + if (!(object instanceof TrustLineEntryExtensionV2Ext)) { + return false; + } + + TrustLineEntryExtensionV2Ext other = (TrustLineEntryExtensionV2Ext) object; + return Objects.equal(this.v, other.v); + } + + } +} diff --git a/src/main/java/org/stellar/sdk/xdr/XdrDataInputStream.java b/src/main/java/org/stellar/sdk/xdr/XdrDataInputStream.java index 65feac221..ae317dd58 100644 --- a/src/main/java/org/stellar/sdk/xdr/XdrDataInputStream.java +++ b/src/main/java/org/stellar/sdk/xdr/XdrDataInputStream.java @@ -3,6 +3,7 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.Charset; public class XdrDataInputStream extends DataInputStream { diff --git a/src/main/java/org/stellar/sdk/xdr/XdrDataOutputStream.java b/src/main/java/org/stellar/sdk/xdr/XdrDataOutputStream.java index 93f671be7..9bb857a64 100644 --- a/src/main/java/org/stellar/sdk/xdr/XdrDataOutputStream.java +++ b/src/main/java/org/stellar/sdk/xdr/XdrDataOutputStream.java @@ -3,6 +3,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.Charset; public class XdrDataOutputStream extends DataOutputStream { diff --git a/src/main/java/org/stellar/sdk/xdr/XdrString.java b/src/main/java/org/stellar/sdk/xdr/XdrString.java index c4087f281..d15e01e7e 100644 --- a/src/main/java/org/stellar/sdk/xdr/XdrString.java +++ b/src/main/java/org/stellar/sdk/xdr/XdrString.java @@ -43,7 +43,7 @@ public int hashCode() { @Override public boolean equals(Object object) { - if (!(object instanceof XdrString)) { + if (object == null || !(object instanceof XdrString)) { return false; } diff --git a/xdr/Stellar-SCP.x b/xdr/Stellar-SCP.x index 1234776f1..7ec99216f 100644 --- a/xdr/Stellar-SCP.x +++ b/xdr/Stellar-SCP.x @@ -80,7 +80,7 @@ struct SCPEnvelope struct SCPQuorumSet { uint32 threshold; - PublicKey validators<>; + NodeID validators<>; SCPQuorumSet innerSets<>; }; } diff --git a/xdr/Stellar-ledger-entries.x b/xdr/Stellar-ledger-entries.x index 26ff33d43..198e93dd8 100644 --- a/xdr/Stellar-ledger-entries.x +++ b/xdr/Stellar-ledger-entries.x @@ -14,6 +14,7 @@ typedef string string64<64>; typedef int64 SequenceNumber; typedef uint64 TimePoint; typedef opaque DataValue<64>; +typedef Hash PoolID; // SHA256(LiquidityPoolParameters) // 1-4 alphanumeric characters right-padded with 0 bytes typedef opaque AssetCode4[4]; @@ -25,7 +26,8 @@ enum AssetType { ASSET_TYPE_NATIVE = 0, ASSET_TYPE_CREDIT_ALPHANUM4 = 1, - ASSET_TYPE_CREDIT_ALPHANUM12 = 2 + ASSET_TYPE_CREDIT_ALPHANUM12 = 2, + ASSET_TYPE_POOL_SHARE = 3 }; union AssetCode switch (AssetType type) @@ -39,24 +41,28 @@ case ASSET_TYPE_CREDIT_ALPHANUM12: // add other asset types here in the future }; +struct AlphaNum4 +{ + AssetCode4 assetCode; + AccountID issuer; +}; + +struct AlphaNum12 +{ + AssetCode12 assetCode; + AccountID issuer; +}; + union Asset switch (AssetType type) { case ASSET_TYPE_NATIVE: // Not credit void; case ASSET_TYPE_CREDIT_ALPHANUM4: - struct - { - AssetCode4 assetCode; - AccountID issuer; - } alphaNum4; + AlphaNum4 alphaNum4; case ASSET_TYPE_CREDIT_ALPHANUM12: - struct - { - AssetCode12 assetCode; - AccountID issuer; - } alphaNum12; + AlphaNum12 alphaNum12; // add other asset types here in the future }; @@ -90,7 +96,8 @@ enum LedgerEntryType TRUSTLINE = 1, OFFER = 2, DATA = 3, - CLAIMABLE_BALANCE = 4 + CLAIMABLE_BALANCE = 4, + LIQUIDITY_POOL = 5 }; struct Signer @@ -119,7 +126,7 @@ enum AccountFlags // mask for all valid flags const MASK_ACCOUNT_FLAGS = 0x7; -const MASK_ACCOUNT_FLAGS_V16 = 0xF; +const MASK_ACCOUNT_FLAGS_V17 = 0xF; // maximum number of signers const MAX_SIGNERS = 20; @@ -212,12 +219,46 @@ enum TrustLineFlags // mask for all trustline flags const MASK_TRUSTLINE_FLAGS = 1; const MASK_TRUSTLINE_FLAGS_V13 = 3; -const MASK_TRUSTLINE_FLAGS_V16 = 7; +const MASK_TRUSTLINE_FLAGS_V17 = 7; + +enum LiquidityPoolType +{ + LIQUIDITY_POOL_CONSTANT_PRODUCT = 0 +}; + +union TrustLineAsset switch (AssetType type) +{ +case ASSET_TYPE_NATIVE: // Not credit + void; + +case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4 alphaNum4; + +case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12 alphaNum12; + +case ASSET_TYPE_POOL_SHARE: + PoolID liquidityPoolID; + + // add other asset types here in the future +}; + +struct TrustLineEntryExtensionV2 +{ + int32 liquidityPoolUseCount; + + union switch (int v) + { + case 0: + void; + } + ext; +}; struct TrustLineEntry { AccountID accountID; // account this trustline belongs to - Asset asset; // type of asset (with issuer) + TrustLineAsset asset; // type of asset (with issuer) int64 balance; // how much of this asset the user has. // Asset defines the unit for this; @@ -238,6 +279,8 @@ struct TrustLineEntry { case 0: void; + case 2: + TrustLineEntryExtensionV2 v2; } ext; } v1; @@ -348,13 +391,16 @@ case CLAIMANT_TYPE_V0: enum ClaimableBalanceIDType { - CLAIMABLE_BALANCE_ID_TYPE_V0 = 0 + CLAIMABLE_BALANCE_ID_TYPE_V0 = 0, + CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE = 1 }; union ClaimableBalanceID switch (ClaimableBalanceIDType type) { case CLAIMABLE_BALANCE_ID_TYPE_V0: Hash v0; +case CLAIMABLE_BALANCE_ID_TYPE_FROM_POOL_REVOKE: + Hash fromPoolRevoke; }; enum ClaimableBalanceFlags @@ -403,6 +449,33 @@ struct ClaimableBalanceEntry ext; }; +struct LiquidityPoolConstantProductParameters +{ + Asset assetA; // assetA < assetB + Asset assetB; + int32 fee; // Fee is in basis points, so the actual rate is (fee/100)% +}; + +struct LiquidityPoolEntry +{ + PoolID liquidityPoolID; + + union switch (LiquidityPoolType type) + { + case LIQUIDITY_POOL_CONSTANT_PRODUCT: + struct + { + LiquidityPoolConstantProductParameters params; + + int64 reserveA; // amount of A in the pool + int64 reserveB; // amount of B in the pool + int64 totalPoolShares; // total number of pool shares issued + int64 poolSharesTrustLineCount; // number of trust lines for the associated pool shares + } constantProduct; + } + body; +}; + struct LedgerEntryExtensionV1 { SponsorshipDescriptor sponsoringID; @@ -431,6 +504,8 @@ struct LedgerEntry DataEntry data; case CLAIMABLE_BALANCE: ClaimableBalanceEntry claimableBalance; + case LIQUIDITY_POOL: + LiquidityPoolEntry liquidityPool; } data; @@ -457,7 +532,7 @@ case TRUSTLINE: struct { AccountID accountID; - Asset asset; + TrustLineAsset asset; } trustLine; case OFFER: @@ -479,6 +554,12 @@ case CLAIMABLE_BALANCE: { ClaimableBalanceID balanceID; } claimableBalance; + +case LIQUIDITY_POOL: + struct + { + PoolID liquidityPoolID; + } liquidityPool; }; // list of all envelope types used in the application @@ -492,6 +573,7 @@ enum EnvelopeType ENVELOPE_TYPE_AUTH = 3, ENVELOPE_TYPE_SCPVALUE = 4, ENVELOPE_TYPE_TX_FEE_BUMP = 5, - ENVELOPE_TYPE_OP_ID = 6 + ENVELOPE_TYPE_OP_ID = 6, + ENVELOPE_TYPE_POOL_REVOKE_OP_ID = 7 }; } diff --git a/xdr/Stellar-ledger.x b/xdr/Stellar-ledger.x index a21c577ae..8a45985c8 100644 --- a/xdr/Stellar-ledger.x +++ b/xdr/Stellar-ledger.x @@ -33,7 +33,7 @@ struct StellarValue // this is a vector of encoded 'LedgerUpgrade' so that nodes can drop // unknown steps during consensus if needed. // see notes below on 'LedgerUpgrade' for more detail - // max size is dictated by number of upgrade types (+ room for future) + // max size is dictated by number of upgrade types ( room for future) UpgradeType upgrades<6>; // reserved for future use @@ -47,6 +47,29 @@ struct StellarValue ext; }; +const MASK_LEDGERHEADER_FLAGS = 0x7; + +enum LedgerHeaderFlags +{ // masks for each flag + + DISABLE_LIQUIDITY_POOL_TRADING_FLAG = 0x1, + DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG = 0x2, + DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 0x4 +}; + +struct LedgerHeaderExtensionV1 +{ + uint32 flags; // UpgradeFlags + + union switch (int v) + { + case 0: + void; + } + ext; +}; + + /* The LedgerHeader is the highest level structure representing the * state of a ledger, cryptographically linked to previous ledgers. */ @@ -84,6 +107,8 @@ struct LedgerHeader { case 0: void; + case 1: + LedgerHeaderExtensionV1 v1; } ext; }; @@ -98,7 +123,8 @@ enum LedgerUpgradeType LEDGER_UPGRADE_VERSION = 1, LEDGER_UPGRADE_BASE_FEE = 2, LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, - LEDGER_UPGRADE_BASE_RESERVE = 4 + LEDGER_UPGRADE_BASE_RESERVE = 4, + LEDGER_UPGRADE_FLAGS = 5 }; union LedgerUpgrade switch (LedgerUpgradeType type) @@ -111,6 +137,8 @@ case LEDGER_UPGRADE_MAX_TX_SET_SIZE: uint32 newMaxTxSetSize; // update maxTxSetSize case LEDGER_UPGRADE_BASE_RESERVE: uint32 newBaseReserve; // update baseReserve +case LEDGER_UPGRADE_FLAGS: + uint32 newFlags; // update flags }; /* Entries used to define the bucket list */ diff --git a/xdr/Stellar-transaction.x b/xdr/Stellar-transaction.x index 25b210d89..19d0240d0 100644 --- a/xdr/Stellar-transaction.x +++ b/xdr/Stellar-transaction.x @@ -7,6 +7,12 @@ namespace stellar { +union LiquidityPoolParameters switch (LiquidityPoolType type) +{ +case LIQUIDITY_POOL_CONSTANT_PRODUCT: + LiquidityPoolConstantProductParameters constantProduct; +}; + // Source or destination of a payment operation union MuxedAccount switch (CryptoKeyType type) { @@ -49,7 +55,9 @@ enum OperationType REVOKE_SPONSORSHIP = 18, CLAWBACK = 19, CLAWBACK_CLAIMABLE_BALANCE = 20, - SET_TRUST_LINE_FLAGS = 21 + SET_TRUST_LINE_FLAGS = 21, + LIQUIDITY_POOL_DEPOSIT = 22, + LIQUIDITY_POOL_WITHDRAW = 23 }; /* CreateAccount @@ -179,7 +187,7 @@ struct CreatePassiveSellOfferOp { Asset selling; // A Asset buying; // B - int64 amount; // amount taker gets. if set to 0, delete the offer + int64 amount; // amount taker gets Price price; // cost of A in terms of B }; @@ -212,6 +220,23 @@ struct SetOptionsOp Signer* signer; }; +union ChangeTrustAsset switch (AssetType type) +{ +case ASSET_TYPE_NATIVE: // Not credit + void; + +case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4 alphaNum4; + +case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12 alphaNum12; + +case ASSET_TYPE_POOL_SHARE: + LiquidityPoolParameters liquidityPool; + + // add other asset types here in the future +}; + /* Creates, updates or deletes a trust line Threshold: med @@ -221,7 +246,7 @@ struct SetOptionsOp */ struct ChangeTrustOp { - Asset line; + ChangeTrustAsset line; // if limit is set to 0, deletes the trust line int64 limit; @@ -241,7 +266,7 @@ struct AllowTrustOp AccountID trustor; AssetCode asset; - // 0, or any bitwise combination of the AUTHORIZED_* flags of TrustLineFlags + // One of 0, AUTHORIZED_FLAG, or AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG uint32 authorize; }; @@ -364,8 +389,7 @@ case REVOKE_SPONSORSHIP_SIGNER: { AccountID accountID; SignerKey signerKey; - } - signer; + } signer; }; /* Claws back an amount of an asset from an account @@ -410,6 +434,37 @@ struct SetTrustLineFlagsOp uint32 setFlags; // which flags to set }; +const LIQUIDITY_POOL_FEE_V18 = 30; + +/* Deposit assets into a liquidity pool + + Threshold: med + + Result: LiquidityPoolDepositResult +*/ +struct LiquidityPoolDepositOp +{ + PoolID liquidityPoolID; + int64 maxAmountA; // maximum amount of first asset to deposit + int64 maxAmountB; // maximum amount of second asset to deposit + Price minPrice; // minimum depositA/depositB + Price maxPrice; // maximum depositA/depositB +}; + +/* Withdraw assets from a liquidity pool + + Threshold: med + + Result: LiquidityPoolWithdrawResult +*/ +struct LiquidityPoolWithdrawOp +{ + PoolID liquidityPoolID; + int64 amount; // amount of pool shares to withdraw + int64 minAmountA; // minimum amount of first asset to withdraw + int64 minAmountB; // minimum amount of second asset to withdraw +}; + /* An operation is the lowest unit of work that a transaction does */ struct Operation { @@ -464,6 +519,10 @@ struct Operation ClawbackClaimableBalanceOp clawbackClaimableBalanceOp; case SET_TRUST_LINE_FLAGS: SetTrustLineFlagsOp setTrustLineFlagsOp; + case LIQUIDITY_POOL_DEPOSIT: + LiquidityPoolDepositOp liquidityPoolDepositOp; + case LIQUIDITY_POOL_WITHDRAW: + LiquidityPoolWithdrawOp liquidityPoolWithdrawOp; } body; }; @@ -473,10 +532,19 @@ union OperationID switch (EnvelopeType type) case ENVELOPE_TYPE_OP_ID: struct { - MuxedAccount sourceAccount; + AccountID sourceAccount; SequenceNumber seqNum; uint32 opNum; } id; +case ENVELOPE_TYPE_POOL_REVOKE_OP_ID: + struct + { + AccountID sourceAccount; + SequenceNumber seqNum; + uint32 opNum; + PoolID liquidityPoolID; + Asset asset; + } revokeId; }; enum MemoType @@ -636,7 +704,33 @@ struct TransactionSignaturePayload /* Operation Results section */ -/* This result is used when offers are taken during an operation */ +enum ClaimAtomType +{ + CLAIM_ATOM_TYPE_V0 = 0, + CLAIM_ATOM_TYPE_ORDER_BOOK = 1, + CLAIM_ATOM_TYPE_LIQUIDITY_POOL = 2 +}; + +// ClaimOfferAtomV0 is a ClaimOfferAtom with the AccountID discriminant stripped +// off, leaving a raw ed25519 public key to identify the source account. This is +// used for backwards compatibility starting from the protocol 17/18 boundary. +// If an "old-style" ClaimOfferAtom is parsed with this XDR definition, it will +// be parsed as a "new-style" ClaimAtom containing a ClaimOfferAtomV0. +struct ClaimOfferAtomV0 +{ + // emitted to identify the offer + uint256 sellerEd25519; // Account that owns the offer + int64 offerID; + + // amount and asset taken from the owner + Asset assetSold; + int64 amountSold; + + // amount and asset sent to the owner + Asset assetBought; + int64 amountBought; +}; + struct ClaimOfferAtom { // emitted to identify the offer @@ -652,6 +746,32 @@ struct ClaimOfferAtom int64 amountBought; }; +struct ClaimLiquidityAtom +{ + PoolID liquidityPoolID; + + // amount and asset taken from the pool + Asset assetSold; + int64 amountSold; + + // amount and asset sent to the pool + Asset assetBought; + int64 amountBought; +}; + +/* This result is used when offers are taken or liquidity is exchanged with a + liquidity pool during an operation +*/ +union ClaimAtom switch (ClaimAtomType type) +{ +case CLAIM_ATOM_TYPE_V0: + ClaimOfferAtomV0 v0; +case CLAIM_ATOM_TYPE_ORDER_BOOK: + ClaimOfferAtom orderBook; +case CLAIM_ATOM_TYPE_LIQUIDITY_POOL: + ClaimLiquidityAtom liquidityPool; +}; + /******* CreateAccount Result ********/ enum CreateAccountResultCode @@ -680,7 +800,7 @@ default: enum PaymentResultCode { // codes considered as "success" for the operation - PAYMENT_SUCCESS = 0, // payment successfuly completed + PAYMENT_SUCCESS = 0, // payment successfully completed // codes considered as "failure" for the operation PAYMENT_MALFORMED = -1, // bad input @@ -740,12 +860,13 @@ struct SimplePaymentResult int64 amount; }; -union PathPaymentStrictReceiveResult switch (PathPaymentStrictReceiveResultCode code) +union PathPaymentStrictReceiveResult switch ( + PathPaymentStrictReceiveResultCode code) { case PATH_PAYMENT_STRICT_RECEIVE_SUCCESS: struct { - ClaimOfferAtom offers<>; + ClaimAtom offers<>; SimplePaymentResult last; } success; case PATH_PAYMENT_STRICT_RECEIVE_NO_ISSUER: @@ -789,7 +910,7 @@ union PathPaymentStrictSendResult switch (PathPaymentStrictSendResultCode code) case PATH_PAYMENT_STRICT_SEND_SUCCESS: struct { - ClaimOfferAtom offers<>; + ClaimAtom offers<>; SimplePaymentResult last; } success; case PATH_PAYMENT_STRICT_SEND_NO_ISSUER: @@ -837,7 +958,7 @@ enum ManageOfferEffect struct ManageOfferSuccessResult { // offers that got claimed while creating this offer - ClaimOfferAtom offersClaimed<>; + ClaimAtom offersClaimed<>; union switch (ManageOfferEffect effect) { @@ -907,8 +1028,9 @@ enum SetOptionsResultCode SET_OPTIONS_UNKNOWN_FLAG = -6, // can't set an unknown flag SET_OPTIONS_THRESHOLD_OUT_OF_RANGE = -7, // bad value for weight/threshold SET_OPTIONS_BAD_SIGNER = -8, // signer cannot be masterkey - SET_OPTIONS_INVALID_HOME_DOMAIN = -9, // malformed home domain - SET_OPTIONS_AUTH_REVOCABLE_REQUIRED = -10 // auth revocable is required for clawback + SET_OPTIONS_INVALID_HOME_DOMAIN = -9, // malformed home domain + SET_OPTIONS_AUTH_REVOCABLE_REQUIRED = + -10 // auth revocable is required for clawback }; union SetOptionsResult switch (SetOptionsResultCode code) @@ -932,7 +1054,10 @@ enum ChangeTrustResultCode // cannot create with a limit of 0 CHANGE_TRUST_LOW_RESERVE = -4, // not enough funds to create a new trust line, - CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed + CHANGE_TRUST_SELF_NOT_ALLOWED = -5, // trusting self is not allowed + CHANGE_TRUST_TRUST_LINE_MISSING = -6, // Asset trustline is missing for pool + CHANGE_TRUST_CANNOT_DELETE = -7, // Asset trustline is still referenced in a pool + CHANGE_TRUST_NOT_AUTH_MAINTAIN_LIABILITIES = -8 // Asset trustline is deauthorized }; union ChangeTrustResult switch (ChangeTrustResultCode code) @@ -955,7 +1080,9 @@ enum AllowTrustResultCode // source account does not require trust ALLOW_TRUST_TRUST_NOT_REQUIRED = -3, ALLOW_TRUST_CANT_REVOKE = -4, // source account can't revoke trust, - ALLOW_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed + ALLOW_TRUST_SELF_NOT_ALLOWED = -5, // trusting self is not allowed + ALLOW_TRUST_LOW_RESERVE = -6 // claimable balances can't be created + // on revoke due to low reserves }; union AllowTrustResult switch (AllowTrustResultCode code) @@ -986,7 +1113,7 @@ enum AccountMergeResultCode union AccountMergeResult switch (AccountMergeResultCode code) { case ACCOUNT_MERGE_SUCCESS: - int64 sourceAccountBalance; // how much got transfered from source account + int64 sourceAccountBalance; // how much got transferred from source account default: void; }; @@ -1068,7 +1195,8 @@ enum CreateClaimableBalanceResultCode CREATE_CLAIMABLE_BALANCE_UNDERFUNDED = -5 }; -union CreateClaimableBalanceResult switch (CreateClaimableBalanceResultCode code) +union CreateClaimableBalanceResult switch ( + CreateClaimableBalanceResultCode code) { case CREATE_CLAIMABLE_BALANCE_SUCCESS: ClaimableBalanceID balanceID; @@ -1110,7 +1238,8 @@ enum BeginSponsoringFutureReservesResultCode BEGIN_SPONSORING_FUTURE_RESERVES_RECURSIVE = -3 }; -union BeginSponsoringFutureReservesResult switch (BeginSponsoringFutureReservesResultCode code) +union BeginSponsoringFutureReservesResult switch ( + BeginSponsoringFutureReservesResultCode code) { case BEGIN_SPONSORING_FUTURE_RESERVES_SUCCESS: void; @@ -1129,7 +1258,8 @@ enum EndSponsoringFutureReservesResultCode END_SPONSORING_FUTURE_RESERVES_NOT_SPONSORED = -1 }; -union EndSponsoringFutureReservesResult switch (EndSponsoringFutureReservesResultCode code) +union EndSponsoringFutureReservesResult switch ( + EndSponsoringFutureReservesResultCode code) { case END_SPONSORING_FUTURE_RESERVES_SUCCESS: void; @@ -1148,7 +1278,8 @@ enum RevokeSponsorshipResultCode REVOKE_SPONSORSHIP_DOES_NOT_EXIST = -1, REVOKE_SPONSORSHIP_NOT_SPONSOR = -2, REVOKE_SPONSORSHIP_LOW_RESERVE = -3, - REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE = -4 + REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE = -4, + REVOKE_SPONSORSHIP_MALFORMED = -5 }; union RevokeSponsorshipResult switch (RevokeSponsorshipResultCode code) @@ -1194,7 +1325,8 @@ enum ClawbackClaimableBalanceResultCode CLAWBACK_CLAIMABLE_BALANCE_NOT_CLAWBACK_ENABLED = -3 }; -union ClawbackClaimableBalanceResult switch (ClawbackClaimableBalanceResultCode code) +union ClawbackClaimableBalanceResult switch ( + ClawbackClaimableBalanceResultCode code) { case CLAWBACK_CLAIMABLE_BALANCE_SUCCESS: void; @@ -1213,7 +1345,9 @@ enum SetTrustLineFlagsResultCode SET_TRUST_LINE_FLAGS_MALFORMED = -1, SET_TRUST_LINE_FLAGS_NO_TRUST_LINE = -2, SET_TRUST_LINE_FLAGS_CANT_REVOKE = -3, - SET_TRUST_LINE_FLAGS_INVALID_STATE = -4 + SET_TRUST_LINE_FLAGS_INVALID_STATE = -4, + SET_TRUST_LINE_FLAGS_LOW_RESERVE = -5 // claimable balances can't be created + // on revoke due to low reserves }; union SetTrustLineFlagsResult switch (SetTrustLineFlagsResultCode code) @@ -1224,6 +1358,64 @@ default: void; }; +/******* LiquidityPoolDeposit Result ********/ + +enum LiquidityPoolDepositResultCode +{ + // codes considered as "success" for the operation + LIQUIDITY_POOL_DEPOSIT_SUCCESS = 0, + + // codes considered as "failure" for the operation + LIQUIDITY_POOL_DEPOSIT_MALFORMED = -1, // bad input + LIQUIDITY_POOL_DEPOSIT_NO_TRUST = -2, // no trust line for one of the + // assets + LIQUIDITY_POOL_DEPOSIT_NOT_AUTHORIZED = -3, // not authorized for one of the + // assets + LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED = -4, // not enough balance for one of + // the assets + LIQUIDITY_POOL_DEPOSIT_LINE_FULL = -5, // pool share trust line doesn't + // have sufficient limit + LIQUIDITY_POOL_DEPOSIT_BAD_PRICE = -6, // deposit price outside bounds + LIQUIDITY_POOL_DEPOSIT_POOL_FULL = -7 // pool reserves are full +}; + +union LiquidityPoolDepositResult switch ( + LiquidityPoolDepositResultCode code) +{ +case LIQUIDITY_POOL_DEPOSIT_SUCCESS: + void; +default: + void; +}; + +/******* LiquidityPoolWithdraw Result ********/ + +enum LiquidityPoolWithdrawResultCode +{ + // codes considered as "success" for the operation + LIQUIDITY_POOL_WITHDRAW_SUCCESS = 0, + + // codes considered as "failure" for the operation + LIQUIDITY_POOL_WITHDRAW_MALFORMED = -1, // bad input + LIQUIDITY_POOL_WITHDRAW_NO_TRUST = -2, // no trust line for one of the + // assets + LIQUIDITY_POOL_WITHDRAW_UNDERFUNDED = -3, // not enough balance of the + // pool share + LIQUIDITY_POOL_WITHDRAW_LINE_FULL = -4, // would go above limit for one + // of the assets + LIQUIDITY_POOL_WITHDRAW_UNDER_MINIMUM = -5 // didn't withdraw enough +}; + +union LiquidityPoolWithdrawResult switch ( + LiquidityPoolWithdrawResultCode code) +{ +case LIQUIDITY_POOL_WITHDRAW_SUCCESS: + void; +default: + void; +}; + + /* High level Operation Result */ enum OperationResultCode { @@ -1286,6 +1478,10 @@ case opINNER: ClawbackClaimableBalanceResult clawbackClaimableBalanceResult; case SET_TRUST_LINE_FLAGS: SetTrustLineFlagsResult setTrustLineFlagsResult; + case LIQUIDITY_POOL_DEPOSIT: + LiquidityPoolDepositResult liquidityPoolDepositResult; + case LIQUIDITY_POOL_WITHDRAW: + LiquidityPoolWithdrawResult liquidityPoolWithdrawResult; } tr; default: @@ -1309,7 +1505,7 @@ enum TransactionResultCode txNO_ACCOUNT = -8, // source account not found txINSUFFICIENT_FEE = -9, // fee is too small txBAD_AUTH_EXTRA = -10, // unused signatures attached to transaction - txINTERNAL_ERROR = -11, // an unknown error occured + txINTERNAL_ERROR = -11, // an unknown error occurred txNOT_SUPPORTED = -12, // transaction type not supported txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed From 193d41002bacc1b122bcb6e4e75ce9a621cf88a5 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 8 Sep 2021 15:18:02 +0100 Subject: [PATCH 02/21] AssetAlphaNum -> AlphaNum --- src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java | 2 +- src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java index 68722e55d..6ecd67489 100644 --- a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java +++ b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java @@ -29,7 +29,7 @@ public String getType() { public org.stellar.sdk.xdr.Asset toXdr() { org.stellar.sdk.xdr.Asset xdr = new org.stellar.sdk.xdr.Asset(); xdr.setDiscriminant(AssetType.ASSET_TYPE_CREDIT_ALPHANUM12); - org.stellar.sdk.xdr.Asset.AssetAlphaNum12 credit = new org.stellar.sdk.xdr.Asset.AssetAlphaNum12(); + org.stellar.sdk.xdr.AlphaNum12 credit = new org.stellar.sdk.xdr.AlphaNum12(); AssetCode12 assetCode12 = new AssetCode12(); assetCode12.setAssetCode12(Util.paddedByteArray(mCode, 12)); credit.setAssetCode(assetCode12); diff --git a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java index b737dbf07..e097bb1d0 100644 --- a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java +++ b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java @@ -29,7 +29,7 @@ public String getType() { public org.stellar.sdk.xdr.Asset toXdr() { org.stellar.sdk.xdr.Asset xdr = new org.stellar.sdk.xdr.Asset(); xdr.setDiscriminant(AssetType.ASSET_TYPE_CREDIT_ALPHANUM4); - org.stellar.sdk.xdr.Asset.AssetAlphaNum4 credit = new org.stellar.sdk.xdr.Asset.AssetAlphaNum4(); + org.stellar.sdk.xdr.AlphaNum4 credit = new org.stellar.sdk.xdr.AlphaNum4(); AssetCode4 assetCode4 = new AssetCode4(); assetCode4.setAssetCode4(Util.paddedByteArray(mCode, 4)); credit.setAssetCode(assetCode4); From 4ba687701054e2526f4368e446ebd290afefb753 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 10 Sep 2021 15:31:02 +0100 Subject: [PATCH 03/21] WIP amm stuff --- src/main/java/org/stellar/sdk/Asset.java | 8 ++ .../org/stellar/sdk/ChangeTrustAsset.java | 101 ++++++++++++++++ .../org/stellar/sdk/ChangeTrustOperation.java | 12 +- ...iquidityPoolConstantProductParameters.java | 78 ++++++++++++ .../java/org/stellar/sdk/LiquidityPoolID.java | 67 +++++++++++ .../stellar/sdk/LiquidityPoolParameters.java | 49 ++++++++ .../LiquidityPoolShareChangeTrustAsset.java | 62 ++++++++++ .../sdk/LiquidityPoolShareTrustLineAsset.java | 63 ++++++++++ .../RevokeTrustlineSponsorshipOperation.java | 12 +- .../java/org/stellar/sdk/TrustLineAsset.java | 112 ++++++++++++++++++ 10 files changed, 552 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/stellar/sdk/ChangeTrustAsset.java create mode 100644 src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java create mode 100644 src/main/java/org/stellar/sdk/LiquidityPoolID.java create mode 100644 src/main/java/org/stellar/sdk/LiquidityPoolParameters.java create mode 100644 src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java create mode 100644 src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java create mode 100644 src/main/java/org/stellar/sdk/TrustLineAsset.java diff --git a/src/main/java/org/stellar/sdk/Asset.java b/src/main/java/org/stellar/sdk/Asset.java index 6692d8d49..16e577159 100644 --- a/src/main/java/org/stellar/sdk/Asset.java +++ b/src/main/java/org/stellar/sdk/Asset.java @@ -32,6 +32,13 @@ public static Asset create(String type, String code, String issuer) { } } + public static Asset create(ChangeTrustAsset.Wrapper wrapped) { + return wrapped.getAsset(); + } + public static Asset create(TrustLineAsset.Wrapper wrapped) { + return wrapped.getAsset(); + } + /** * Creates one of AssetTypeCreditAlphaNum4 or AssetTypeCreditAlphaNum12 object based on a code length * @param code Asset code @@ -75,6 +82,7 @@ public static Asset fromXdr(org.stellar.sdk.xdr.Asset xdr) { *
  • native
  • *
  • credit_alphanum4
  • *
  • credit_alphanum12
  • + *
  • pool_share
  • * */ public abstract String getType(); diff --git a/src/main/java/org/stellar/sdk/ChangeTrustAsset.java b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java new file mode 100644 index 000000000..2ce694e53 --- /dev/null +++ b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java @@ -0,0 +1,101 @@ +package org.stellar.sdk; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * ChangeTrustAsset class. + * @see Assets + */ +public abstract class ChangeTrustAsset { + ChangeTrustAsset() {} + + /** + * Parses an asset string and returns the equivalent ChangeTrustAsset instance. + * The asset string is expected to either be "native" or a string of the form "CODE:ISSUER" + * + * @param canonicalForm Canonical string representation of an asset + */ + public static ChangeTrustAsset create(String canonicalForm) { + return new Wrapper(Asset.create(canonicalForm)); + } + + public static ChangeTrustAsset create(String type, String code, String issuer) { + return new Wrapper(Asset.create(type, code, issuer)); + } + public static ChangeTrustAsset create(Asset asset) { + return new Wrapper(asset); + } + public static ChangeTrustAsset create(LiquidityPoolParameters params) { + return new LiquidityPoolShareChangeTrustAsset(params); + } + public static ChangeTrustAsset create(TrustLineAsset.Wrapper wrapper) { + return new Wrapper(wrapper.getAsset()); + } + // Cannot convert from LiquidityPoolShareTrustLineAsset, as that only has a + // liquidity pool id, not parameters. + + /** + * Creates one of AssetTypeCreditAlphaNum4 or AssetTypeCreditAlphaNum12 object based on a code length + * @param code ChangeTrustAsset code + * @param issuer ChangeTrustAsset issuer + */ + public static ChangeTrustAsset createNonNativeAsset(String code, String issuer) { + return ChangeTrustAsset.create(Asset.createNonNativeAsset(code, issuer)); + } + + /** + * Generates ChangeTrustAsset object from a given XDR object + * @param xdr XDR object + */ + public static ChangeTrustAsset fromXdr(org.stellar.sdk.xdr.ChangeTrustAsset xdr) { + // TODO: Figure out how we can re-use Asset.fromXdr here + String accountId; + switch (xdr.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + return ChangeTrustAsset.create(new AssetTypeNative()); + case ASSET_TYPE_CREDIT_ALPHANUM4: + String assetCode4 = Util.paddedByteArrayToString(xdr.getAlphaNum4().getAssetCode().getAssetCode4()); + accountId = StrKey.encodeStellarAccountId(xdr.getAlphaNum4().getIssuer()); + return ChangeTrustAsset.create(new AssetTypeCreditAlphaNum4(assetCode4, accountId)); + case ASSET_TYPE_CREDIT_ALPHANUM12: + String assetCode12 = Util.paddedByteArrayToString(xdr.getAlphaNum12().getAssetCode().getAssetCode12()); + accountId = StrKey.encodeStellarAccountId(xdr.getAlphaNum12().getIssuer()); + return ChangeTrustAsset.create(new AssetTypeCreditAlphaNum12(assetCode12, accountId)); + case ASSET_TYPE_POOL_SHARE: + return new LiquidityPoolShareChangeTrustAsset(LiquidityPoolParameters.fromXdr(xdr.getLiquidityPool())); + default: + throw new IllegalArgumentException("Unknown asset type " + xdr.getDiscriminant()); + } + } + + /** + * Generates XDR object from a given ChangeTrustAsset object + */ + public abstract org.stellar.sdk.xdr.ChangeTrustAsset toXdr(); + + public static final class Wrapper extends ChangeTrustAsset { + private Asset asset; + + public Wrapper(Asset baseAsset) { + super(); + checkNotNull(baseAsset, "asset cannot be null"); + asset = baseAsset; + } + + public Asset getAsset() { + return asset; + } + + @Override + public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { + org.stellar.sdk.xdr.ChangeTrustAsset xdr = new org.stellar.sdk.xdr.ChangeTrustAsset(); + + org.stellar.sdk.xdr.Asset assetXdr = asset.toXdr(); + xdr.setDiscriminant(assetXdr.getDiscriminant()); + xdr.setAlphaNum4(assetXdr.getAlphaNum4()); + xdr.setAlphaNum12(assetXdr.getAlphaNum12()); + + return xdr; + } + } +} diff --git a/src/main/java/org/stellar/sdk/ChangeTrustOperation.java b/src/main/java/org/stellar/sdk/ChangeTrustOperation.java index 21afccdd0..90ace1bef 100644 --- a/src/main/java/org/stellar/sdk/ChangeTrustOperation.java +++ b/src/main/java/org/stellar/sdk/ChangeTrustOperation.java @@ -14,10 +14,10 @@ */ public class ChangeTrustOperation extends Operation { - private final Asset asset; + private final ChangeTrustAsset asset; private final String limit; - private ChangeTrustOperation(Asset asset, String limit) { + private ChangeTrustOperation(ChangeTrustAsset asset, String limit) { this.asset = checkNotNull(asset, "asset cannot be null"); this.limit = checkNotNull(limit, "limit cannot be null"); } @@ -25,7 +25,7 @@ private ChangeTrustOperation(Asset asset, String limit) { /** * The asset of the trustline. For example, if a gateway extends a trustline of up to 200 USD to a user, the line is USD. */ - public Asset getAsset() { + public ChangeTrustAsset getAsset() { return asset; } @@ -55,13 +55,13 @@ org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter acc * @see ChangeTrustOperation */ public static class Builder { - private final Asset asset; + private final ChangeTrustAsset asset; private final String limit; private String mSourceAccount; Builder(ChangeTrustOp op) { - asset = Asset.fromXdr(op.getLine()); + asset = ChangeTrustAsset.fromXdr(op.getLine()); limit = Operation.fromXdrAmount(op.getLimit().getInt64().longValue()); } @@ -71,7 +71,7 @@ public static class Builder { * @param limit The limit of the trustline. For example, if a gateway extends a trustline of up to 200 USD to a user, the limit is 200. * @throws ArithmeticException when limit has more than 7 decimal places. */ - public Builder(Asset asset, String limit) { + public Builder(ChangeTrustAsset asset, String limit) { this.asset = checkNotNull(asset, "asset cannot be null"); this.limit = checkNotNull(limit, "limit cannot be null"); } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java new file mode 100644 index 000000000..168ff8e4c --- /dev/null +++ b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java @@ -0,0 +1,78 @@ +package org.stellar.sdk; + +import com.google.common.base.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Base LiquidityPoolConstantProductParameters class. + * @see Assets + */ +public final class LiquidityPoolConstantProductParameters extends LiquidityPoolParameters { + protected final Asset assetA; + protected final Asset assetB; + protected final int fee; + + /** + * TODO: Write something here + * + * @param a First asset in the liquidity pool + * @param b Second asset in the liquidity pool + * @param feeBP Fee amount in base-points + */ + public LiquidityPoolConstantProductParameters(Asset a, Asset b, int feeBP) { + checkNotNull(a, "asset A cannot be null"); + checkNotNull(b, "asset B cannot be null"); + checkNotNull(feeBP, "fee cannot be null"); + assetA = a; + assetB = b; + fee = feeBP; + } + + @Override + public final boolean equals(Object object) { + throw new RuntimeException("TODO: Implement LiquidityPoolConstantProductParameters.equals"); + } + + /** + * Generates XDR object from a given LiquidityPoolParameters object + */ + @Override + public final org.stellar.sdk.xdr.LiquidityPoolParameters toXdr() { + org.stellar.sdk.xdr.LiquidityPoolParameters xdr = new org.stellar.sdk.xdr.LiquidityPoolParameters(); + xdr.setDiscriminant(org.stellar.sdk.xdr.LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT); + + org.stellar.sdk.xdr.LiquidityPoolConstantProductParameters params = new org.stellar.sdk.xdr.LiquidityPoolConstantProductParameters(); + params.setAssetA(assetA.toXdr()); + params.setAssetB(assetB.toXdr()); + params.setFee(new org.stellar.sdk.xdr.Int32(fee)); + + xdr.setConstantProduct(params); + + return xdr; + } + + /** + * Generates LiquidityPoolConstantProductParameters object from a given XDR object + * @param xdr XDR object + */ + public static LiquidityPoolConstantProductParameters fromXdr(org.stellar.sdk.xdr.LiquidityPoolConstantProductParameters xdr) { + return new LiquidityPoolConstantProductParameters( + Asset.fromXdr(xdr.getAssetA()), + Asset.fromXdr(xdr.getAssetB()), + xdr.getFee().getInt32().intValue() + ); + } + + + @Override + public final org.stellar.sdk.LiquidityPoolID getId() { + // TODO: I think we need to pass the type here as well? + return new LiquidityPoolID( + org.stellar.sdk.xdr.LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, + assetA, + assetB, + fee + ); + } +} diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolID.java b/src/main/java/org/stellar/sdk/LiquidityPoolID.java new file mode 100644 index 000000000..b1163c45d --- /dev/null +++ b/src/main/java/org/stellar/sdk/LiquidityPoolID.java @@ -0,0 +1,67 @@ +package org.stellar.sdk; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.stellar.sdk.xdr.*; + +/** + * Base LiquidityPoolID class. + * @see Assets + */ +public final class LiquidityPoolID { + protected final byte[] hash; + + LiquidityPoolID(LiquidityPoolType type, Asset a, Asset b, int fee) { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + try { + LiquidityPoolParameters.create(type, a, b, fee).toXdr().encode(xdrDataOutputStream); + } catch (IOException e) { + throw new IllegalArgumentException("invalid liquidity pool id.", e); + } + hash = Util.hash(byteArrayOutputStream.toByteArray()); + } + + LiquidityPoolID(String hex) { + hash = Util.hexToBytes(hex.toUpperCase()); + } + + LiquidityPoolID(byte[] bytes) { + hash = bytes; + } + + /** + * Generates LiquidityPoolID object from a given XDR object + * @param xdr XDR object + */ + public static LiquidityPoolID fromXdr(org.stellar.sdk.xdr.PoolID xdr) { + return new LiquidityPoolID(xdr.getPoolID().getHash()); + } + + @Override + public String toString() { + return Util.bytesToHex(hash).toLowerCase(); + } + + @Override + public boolean equals(Object object) { + if (object == null || !this.getClass().equals(object.getClass())) { + return false; + } + + LiquidityPoolID o = (LiquidityPoolID) object; + + return this.toString() == o.toString(); + } + + /** + * Generates XDR object from a given LiquidityPoolID object + */ + public org.stellar.sdk.xdr.PoolID toXdr() { + org.stellar.sdk.xdr.PoolID xdr = new org.stellar.sdk.xdr.PoolID(); + xdr.setPoolID(new org.stellar.sdk.xdr.Hash(hash)); + return xdr; + } +} diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java new file mode 100644 index 000000000..b32d4ac48 --- /dev/null +++ b/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java @@ -0,0 +1,49 @@ +package org.stellar.sdk; + +import org.stellar.sdk.xdr.*; + +/** + * Base LiquidityPoolParameters class. + * @see Assets + */ +public abstract class LiquidityPoolParameters { + LiquidityPoolParameters() {} + + /** + * TODO: Write something here + * + * @param type Type of the liquidity pool + * @param a First asset in the liquidity pool + * @param b Second asset in the liquidity pool + * @param feeBP Fee amount in base-points + */ + public static LiquidityPoolParameters create(LiquidityPoolType type, Asset a, Asset b, int feeBP) { + if (type != LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT) { + throw new IllegalArgumentException("Unknown liquidity pool type type " + type); + } + return new LiquidityPoolConstantProductParameters(a, b, feeBP); + } + + /** + * Generates LiquidityPoolParameters object from a given XDR object + * @param xdr XDR object + */ + public static LiquidityPoolParameters fromXdr(org.stellar.sdk.xdr.LiquidityPoolParameters xdr) { + switch (xdr.getDiscriminant()) { + case LIQUIDITY_POOL_CONSTANT_PRODUCT: + return LiquidityPoolConstantProductParameters.fromXdr(xdr.getConstantProduct()); + default: + throw new IllegalArgumentException("Unknown liquidity pool type " + xdr.getDiscriminant()); + } + } + + @Override + public abstract boolean equals(Object object); + + /** + * Generates XDR object from a given LiquidityPoolParameters object + */ + public abstract org.stellar.sdk.xdr.LiquidityPoolParameters toXdr(); + + public abstract org.stellar.sdk.LiquidityPoolID getId(); +} diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java new file mode 100644 index 000000000..57a71c135 --- /dev/null +++ b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java @@ -0,0 +1,62 @@ +package org.stellar.sdk; + +import com.google.common.base.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.stellar.sdk.xdr.*; + +/** + * Class for LiquidityPoolShareChangeTrustAsset + * @see Assets + */ +public final class LiquidityPoolShareChangeTrustAsset extends ChangeTrustAsset { + protected final LiquidityPoolParameters mParams; + + public LiquidityPoolShareChangeTrustAsset(LiquidityPoolParameters params) { + checkNotNull(params, "params cannot be null"); + mParams = params; + } + + public LiquidityPoolID getLiquidityPoolID() { + return mParams.getId(); + } + + public LiquidityPoolParameters getLiquidityPoolParams() { + return mParams; + } + + public String getType() { + return "pool_share"; + } + + @Override + public String toString() { + return this.getLiquidityPoolID().toString(); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.mParams); + } + + @Override + public boolean equals(Object object) { + if (object == null || !this.getClass().equals(object.getClass())) { + return false; + } + + LiquidityPoolShareChangeTrustAsset o = (LiquidityPoolShareChangeTrustAsset) object; + + return this.getLiquidityPoolParams().equals(o.getLiquidityPoolParams()); + } + + @Override + public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { + org.stellar.sdk.xdr.ChangeTrustAsset xdr = new org.stellar.sdk.xdr.ChangeTrustAsset(); + xdr.setDiscriminant(AssetType.ASSET_TYPE_POOL_SHARE); + org.stellar.sdk.xdr.LiquidityPoolParameters params = mParams.toXdr(); + xdr.setLiquidityPool(params); + return xdr; + } +} diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java b/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java new file mode 100644 index 000000000..71efd6d76 --- /dev/null +++ b/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java @@ -0,0 +1,63 @@ +package org.stellar.sdk; + +import com.google.common.base.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.stellar.sdk.xdr.*; + +/** + * Class for LiquidityPoolShareTrustLineAsset + * @see Assets + */ +public final class LiquidityPoolShareTrustLineAsset extends TrustLineAsset { + protected final LiquidityPoolID mId; + + public LiquidityPoolShareTrustLineAsset(LiquidityPoolParameters params) { + checkNotNull(params, "params cannot be null"); + mId = params.getId(); + } + + public LiquidityPoolShareTrustLineAsset(LiquidityPoolID id) { + checkNotNull(id, "id cannot be null"); + mId = id; + } + + public LiquidityPoolID getLiquidityPoolID() { + return mId; + } + + @Override + public String getType() { + return "pool_share"; + } + + @Override + public String toString() { + return this.getLiquidityPoolID().toString(); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.mId); + } + + @Override + public boolean equals(Object object) { + if (object == null || !this.getClass().equals(object.getClass())) { + return false; + } + + LiquidityPoolShareTrustLineAsset o = (LiquidityPoolShareTrustLineAsset) object; + + return this.toString() == o.toString(); + } + + @Override + public org.stellar.sdk.xdr.TrustLineAsset toXdr() { + org.stellar.sdk.xdr.TrustLineAsset xdr = new org.stellar.sdk.xdr.TrustLineAsset(); + xdr.setDiscriminant(AssetType.ASSET_TYPE_POOL_SHARE); + xdr.setLiquidityPoolID(mId.toXdr()); + return xdr; + } +} diff --git a/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java index 3bdb831b8..ac44d7869 100644 --- a/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java @@ -7,9 +7,9 @@ public class RevokeTrustlineSponsorshipOperation extends Operation { private final String accountId; - private final Asset asset; + private final TrustLineAsset asset; - private RevokeTrustlineSponsorshipOperation(String accountId, Asset asset) { + private RevokeTrustlineSponsorshipOperation(String accountId, TrustLineAsset asset) { this.accountId = accountId; this.asset = asset; } @@ -18,7 +18,7 @@ public String getAccountId() { return accountId; } - public Asset getAsset() { + public TrustLineAsset getAsset() { return asset; } @@ -44,7 +44,7 @@ org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter acc public static class Builder { private final String accountId; - private final Asset asset; + private final TrustLineAsset asset; private String mSourceAccount; @@ -54,7 +54,7 @@ public static class Builder { */ Builder(RevokeSponsorshipOp op) { accountId = StrKey.encodeStellarAccountId(op.getLedgerKey().getTrustLine().getAccountID()); - asset = Asset.fromXdr(op.getLedgerKey().getTrustLine().getAsset()); + asset = TrustLineAsset.fromXdr(op.getLedgerKey().getTrustLine().getAsset()); } /** @@ -62,7 +62,7 @@ public static class Builder { * @param accountId The id of the account whose trustline will be revoked. * @param asset The asset of the trustline which will be revoked. */ - public Builder(String accountId, Asset asset) { + public Builder(String accountId, TrustLineAsset asset) { this.accountId = accountId; this.asset = asset; } diff --git a/src/main/java/org/stellar/sdk/TrustLineAsset.java b/src/main/java/org/stellar/sdk/TrustLineAsset.java new file mode 100644 index 000000000..521ce90cb --- /dev/null +++ b/src/main/java/org/stellar/sdk/TrustLineAsset.java @@ -0,0 +1,112 @@ +package org.stellar.sdk; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * TrustLineAsset class. + * @see Assets + */ +public abstract class TrustLineAsset { + TrustLineAsset() {} + + /** + * Parses an asset string and returns the equivalent TrustLineAsset instance. + * The asset string is expected to either be "native" or a string of the form "CODE:ISSUER" + * + * @param canonicalForm Canonical string representation of an asset + */ + public static TrustLineAsset create(String canonicalForm) { + return new Wrapper(Asset.create(canonicalForm)); + } + + public static TrustLineAsset create(String type, String code, String issuer) { + return new Wrapper(Asset.create(type, code, issuer)); + } + public static TrustLineAsset create(Asset asset) { + return new Wrapper(asset); + } + public static TrustLineAsset create(LiquidityPoolParameters params) { + return new LiquidityPoolShareTrustLineAsset(params); + } + public static TrustLineAsset create(LiquidityPoolID id) { + return new LiquidityPoolShareTrustLineAsset(id); + } + public static TrustLineAsset create(ChangeTrustAsset.Wrapper wrapper) { + return new Wrapper(wrapper.getAsset()); + } + public static TrustLineAsset create(LiquidityPoolShareChangeTrustAsset share) { + return new LiquidityPoolShareTrustLineAsset(share.getLiquidityPoolParams()); + } + + /** + * Creates one of AssetTypeCreditAlphaNum4 or AssetTypeCreditAlphaNum12 object based on a code length + * @param code TrustLineAsset code + * @param issuer TrustLineAsset issuer + */ + public static TrustLineAsset createNonNativeAsset(String code, String issuer) { + return TrustLineAsset.create(Asset.createNonNativeAsset(code, issuer)); + } + + /** + * Generates TrustLineAsset object from a given XDR object + * @param xdr XDR object + */ + public static TrustLineAsset fromXdr(org.stellar.sdk.xdr.TrustLineAsset xdr) { + // TODO: Figure out how we can re-use Asset.fromXdr here + String accountId; + switch (xdr.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + return TrustLineAsset.create(new AssetTypeNative()); + case ASSET_TYPE_CREDIT_ALPHANUM4: + String assetCode4 = Util.paddedByteArrayToString(xdr.getAlphaNum4().getAssetCode().getAssetCode4()); + accountId = StrKey.encodeStellarAccountId(xdr.getAlphaNum4().getIssuer()); + return TrustLineAsset.create(new AssetTypeCreditAlphaNum4(assetCode4, accountId)); + case ASSET_TYPE_CREDIT_ALPHANUM12: + String assetCode12 = Util.paddedByteArrayToString(xdr.getAlphaNum12().getAssetCode().getAssetCode12()); + accountId = StrKey.encodeStellarAccountId(xdr.getAlphaNum12().getIssuer()); + return TrustLineAsset.create(new AssetTypeCreditAlphaNum12(assetCode12, accountId)); + case ASSET_TYPE_POOL_SHARE: + return new LiquidityPoolShareTrustLineAsset(LiquidityPoolID.fromXdr(xdr.getLiquidityPoolID())); + default: + throw new IllegalArgumentException("Unknown asset type " + xdr.getDiscriminant()); + } + } + + public abstract String getType(); + + /** + * Generates XDR object from a given TrustLineAsset object + */ + public abstract org.stellar.sdk.xdr.TrustLineAsset toXdr(); + + public static final class Wrapper extends TrustLineAsset { + private Asset asset; + + public Wrapper(Asset baseAsset) { + super(); + checkNotNull(baseAsset, "asset cannot be null"); + asset = baseAsset; + } + + public Asset getAsset() { + return asset; + } + + @Override + public org.stellar.sdk.xdr.TrustLineAsset toXdr() { + org.stellar.sdk.xdr.TrustLineAsset xdr = new org.stellar.sdk.xdr.TrustLineAsset(); + + org.stellar.sdk.xdr.Asset assetXdr = asset.toXdr(); + xdr.setDiscriminant(assetXdr.getDiscriminant()); + xdr.setAlphaNum4(assetXdr.getAlphaNum4()); + xdr.setAlphaNum12(assetXdr.getAlphaNum12()); + + return xdr; + } + + @Override + public String getType() { + return asset.getType(); + } + } +} From 7a963d70bb3f7435b27cd1a8225a93b1a358c547 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 13 Sep 2021 12:55:09 +0100 Subject: [PATCH 04/21] Fixing up tests and equality --- .../org/stellar/sdk/ChangeTrustAsset.java | 19 +++++++++++++++ ...iquidityPoolConstantProductParameters.java | 24 +++++++++++++++---- .../LiquidityPoolShareChangeTrustAsset.java | 1 + .../java/org/stellar/sdk/Transaction.java | 2 +- .../java/org/stellar/sdk/TrustLineAsset.java | 13 ++++++++++ .../java/org/stellar/sdk/OperationTest.java | 6 ++--- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/stellar/sdk/ChangeTrustAsset.java b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java index 2ce694e53..8abafe921 100644 --- a/src/main/java/org/stellar/sdk/ChangeTrustAsset.java +++ b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java @@ -68,6 +68,10 @@ public static ChangeTrustAsset fromXdr(org.stellar.sdk.xdr.ChangeTrustAsset xdr) } } + public abstract boolean equals(Object object); + + public abstract String getType(); + /** * Generates XDR object from a given ChangeTrustAsset object */ @@ -86,6 +90,16 @@ public Asset getAsset() { return asset; } + @Override + public final boolean equals(Object object) { + if (object == null || !this.getClass().equals(object.getClass())) { + return false; + } + + ChangeTrustAsset.Wrapper o = (ChangeTrustAsset.Wrapper) object; + return this.getAsset().equals(o.getAsset()); + } + @Override public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { org.stellar.sdk.xdr.ChangeTrustAsset xdr = new org.stellar.sdk.xdr.ChangeTrustAsset(); @@ -97,5 +111,10 @@ public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { return xdr; } + + @Override + public String getType() { + return asset.getType(); + } } } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java index 168ff8e4c..452b12718 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java @@ -29,9 +29,26 @@ public LiquidityPoolConstantProductParameters(Asset a, Asset b, int feeBP) { fee = feeBP; } + public Asset getAssetA() { + return assetA; + } + + public Asset getAssetB() { + return assetB; + } + + public int getFee() { + return fee; + } + @Override public final boolean equals(Object object) { - throw new RuntimeException("TODO: Implement LiquidityPoolConstantProductParameters.equals"); + if (object == null || !this.getClass().equals(object.getClass())) { + return false; + } + + LiquidityPoolConstantProductParameters o = (LiquidityPoolConstantProductParameters) object; + return this.getAssetA().equals(o.getAssetA()) && this.getAssetB().equals(o.getAssetB()) && this.getFee() == o.getFee(); } /** @@ -58,8 +75,8 @@ public final org.stellar.sdk.xdr.LiquidityPoolParameters toXdr() { */ public static LiquidityPoolConstantProductParameters fromXdr(org.stellar.sdk.xdr.LiquidityPoolConstantProductParameters xdr) { return new LiquidityPoolConstantProductParameters( - Asset.fromXdr(xdr.getAssetA()), - Asset.fromXdr(xdr.getAssetB()), + Asset.fromXdr(xdr.getAssetA()), + Asset.fromXdr(xdr.getAssetB()), xdr.getFee().getInt32().intValue() ); } @@ -67,7 +84,6 @@ public static LiquidityPoolConstantProductParameters fromXdr(org.stellar.sdk.xdr @Override public final org.stellar.sdk.LiquidityPoolID getId() { - // TODO: I think we need to pass the type here as well? return new LiquidityPoolID( org.stellar.sdk.xdr.LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, assetA, diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java index 57a71c135..73755d7b4 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java @@ -26,6 +26,7 @@ public LiquidityPoolParameters getLiquidityPoolParams() { return mParams; } + @Override public String getType() { return "pool_share"; } diff --git a/src/main/java/org/stellar/sdk/Transaction.java b/src/main/java/org/stellar/sdk/Transaction.java index ab2d413d0..5c39ec956 100644 --- a/src/main/java/org/stellar/sdk/Transaction.java +++ b/src/main/java/org/stellar/sdk/Transaction.java @@ -115,7 +115,7 @@ public String getClaimableBalanceId(int index) throws IOException { OperationID.OperationIDId body = new OperationID.OperationIDId(); body.setOpNum(new Uint32(index)); body.setSeqNum(new SequenceNumber(new Int64(getSequenceNumber()))); - body.setSourceAccount(AccountConverter.disableMuxed().encode(getSourceAccount())); + body.setSourceAccount(StrKey.muxedAccountToAccountId(AccountConverter.disableMuxed().encode(getSourceAccount()))); id.setId(body); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); diff --git a/src/main/java/org/stellar/sdk/TrustLineAsset.java b/src/main/java/org/stellar/sdk/TrustLineAsset.java index 521ce90cb..880c1449f 100644 --- a/src/main/java/org/stellar/sdk/TrustLineAsset.java +++ b/src/main/java/org/stellar/sdk/TrustLineAsset.java @@ -72,6 +72,9 @@ public static TrustLineAsset fromXdr(org.stellar.sdk.xdr.TrustLineAsset xdr) { } } + @Override + public abstract boolean equals(Object object); + public abstract String getType(); /** @@ -92,6 +95,16 @@ public Asset getAsset() { return asset; } + @Override + public final boolean equals(Object object) { + if (object == null || !this.getClass().equals(object.getClass())) { + return false; + } + + TrustLineAsset.Wrapper o = (TrustLineAsset.Wrapper) object; + return this.getAsset().equals(o.getAsset()); + } + @Override public org.stellar.sdk.xdr.TrustLineAsset toXdr() { org.stellar.sdk.xdr.TrustLineAsset xdr = new org.stellar.sdk.xdr.TrustLineAsset(); diff --git a/src/test/java/org/stellar/sdk/OperationTest.java b/src/test/java/org/stellar/sdk/OperationTest.java index aff303cc2..2ecd519a3 100644 --- a/src/test/java/org/stellar/sdk/OperationTest.java +++ b/src/test/java/org/stellar/sdk/OperationTest.java @@ -325,7 +325,7 @@ public void testChangeTrustOperation() throws FormatException, IOException { // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF KeyPair source = KeyPair.fromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - Asset asset = new AssetTypeNative(); + ChangeTrustAsset asset = ChangeTrustAsset.create(new AssetTypeNative()); String limit = "922337203685.4775807"; ChangeTrustOperation operation = new ChangeTrustOperation.Builder(asset, limit) @@ -337,7 +337,7 @@ public void testChangeTrustOperation() throws FormatException, IOException { assertEquals(9223372036854775807L, xdr.getBody().getChangeTrustOp().getLimit().getInt64().longValue()); assertEquals(source.getAccountId(), parsedOperation.getSourceAccount()); - assertTrue(parsedOperation.getAsset() instanceof AssetTypeNative); + assertEquals("native", parsedOperation.getAsset().getType()); assertEquals(limit, parsedOperation.getLimit()); assertEquals( @@ -984,7 +984,7 @@ public void testRevokeSignerSponsorshipOperation() { public void testRevokeTrustlineSponsorshipOperation() { String source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; String accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; - Asset asset = new AssetTypeCreditAlphaNum4("DEMO", "GCWPICV6IV35FQ2MVZSEDLORHEMMIAODRQPVDEIKZOW2GC2JGGDCXVVV"); + TrustLineAsset asset = TrustLineAsset.createNonNativeAsset("DEMO", "GCWPICV6IV35FQ2MVZSEDLORHEMMIAODRQPVDEIKZOW2GC2JGGDCXVVV"); RevokeTrustlineSponsorshipOperation operation = new RevokeTrustlineSponsorshipOperation.Builder(accountId, asset).setSourceAccount(source).build(); assertEquals("AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAQAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAFERU1PAAAAAKz0Cr5Fd9LDTK5kQa3RORjEAcOMH1GRCsutowtJMYYr", operation.toXdrBase64(AccountConverter.enableMuxed())); From 12695c3e9688486401c5d2dee92b62615e49af05 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 13 Sep 2021 18:52:29 +0100 Subject: [PATCH 05/21] First (janky) pass at deposit/withdraw operations --- .../java/org/stellar/sdk/AssetAmount.java | 37 ++++ .../sdk/LiquidityPoolDepositOperation.java | 159 ++++++++++++++++++ .../sdk/LiquidityPoolWithdrawOperation.java | 142 ++++++++++++++++ src/main/java/org/stellar/sdk/Operation.java | 6 + 4 files changed, 344 insertions(+) create mode 100644 src/main/java/org/stellar/sdk/AssetAmount.java create mode 100644 src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java create mode 100644 src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java diff --git a/src/main/java/org/stellar/sdk/AssetAmount.java b/src/main/java/org/stellar/sdk/AssetAmount.java new file mode 100644 index 000000000..01ff08390 --- /dev/null +++ b/src/main/java/org/stellar/sdk/AssetAmount.java @@ -0,0 +1,37 @@ +package org.stellar.sdk; + +import com.google.common.base.Objects; + +public final class AssetAmount { + private final Asset asset; + private final String amount; + + private AssetAmount(Asset asset, String amount) { + this.asset = asset; + this.amount = amount; + } + + public Asset getAsset() { + return this.asset; + } + + public String getAmount() { + return this.amount; + } + + + public int hashCode() { + return Objects.hashCode(asset, amount); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof AssetAmount)) { + return false; + } + + AssetAmount o = (AssetAmount) object; + return Objects.equal(this.getAsset(), o.getAsset()) && + Objects.equal(this.getAmount(), o.getAmount()); + } +} diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java new file mode 100644 index 000000000..628e4f89c --- /dev/null +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -0,0 +1,159 @@ +package org.stellar.sdk; + +import com.google.common.base.Objects; +import org.stellar.sdk.xdr.Operation.OperationBody; +import org.stellar.sdk.xdr.LiquidityPoolDepositOp; +import org.stellar.sdk.xdr.LiquidityPoolType; +import org.stellar.sdk.xdr.OperationType; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Represents LiquidityPoolDeposit operation. + * @see List of Operations + */ +public class LiquidityPoolDepositOperation extends Operation { + private final LiquidityPoolID liquidityPoolID; + private final String maxAmountA; + private final String maxAmountB; + private final Price minPrice; + private final Price maxPrice; + + private LiquidityPoolDepositOperation(LiquidityPoolID liquidityPoolID, String maxAmountA, String maxAmountB, Price minPrice, Price maxPrice) { + this.liquidityPoolID = checkNotNull(liquidityPoolID, "liquidityPoolID cannot be null"); + this.maxAmountA = checkNotNull(maxAmountA, "amountA cannot be null"); + this.maxAmountB = checkNotNull(maxAmountB, "amountB cannot be null"); + this.minPrice = checkNotNull(minPrice, "minPrice cannot be null"); + this.maxPrice = checkNotNull(maxPrice, "maxPrice cannot be null"); + } + + public LiquidityPoolID getLiquidityPoolID() { + return liquidityPoolID; + } + + public String getMaxAmountA() { + return maxAmountA; + } + + public String getMaxAmountB() { + return maxAmountB; + } + + public Price getMinPrice() { + return minPrice; + } + + public Price getMaxPrice() { + return maxPrice; + } + + @Override + OperationBody toOperationBody(AccountConverter accountConverter) { + LiquidityPoolDepositOp op = new LiquidityPoolDepositOp(); + op.setLiquidityPoolID(this.getLiquidityPoolID().toXdr()); + op.setMaxAmountA(new org.stellar.sdk.xdr.Int64(Operation.toXdrAmount(this.getMaxAmountA()))); + op.setMaxAmountB(new org.stellar.sdk.xdr.Int64(Operation.toXdrAmount(this.getMaxAmountB()))); + op.setMinPrice(this.getMinPrice().toXdr()); + op.setMaxPrice(this.getMaxPrice().toXdr()); + + OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); + body.setDiscriminant(OperationType.LIQUIDITY_POOL_DEPOSIT); + body.setLiquidityPoolDepositOp(op); + return body; + } + + /** + * Builds LiquidityPoolDeposit operation. + * @see LiquidityPoolDepositOperation + */ + public static class Builder { + private final LiquidityPoolID liquidityPoolID; + private final String maxAmountA; + private final String maxAmountB; + private final Price minPrice; + private final Price maxPrice; + + private String sourceAccount; + + Builder(LiquidityPoolDepositOp op) { + this.liquidityPoolID = LiquidityPoolID.fromXdr(op.getLiquidityPoolID()); + this.maxAmountA = Operation.fromXdrAmount(op.getMaxAmountA().getInt64().longValue()); + this.maxAmountB = Operation.fromXdrAmount(op.getMaxAmountB().getInt64().longValue()); + this.minPrice = Price.fromXdr(op.getMinPrice()); + this.maxPrice = Price.fromXdr(op.getMaxPrice()); + } + + /** + * Creates a new LiquidityPoolDeposit builder. + */ + public Builder(AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { + this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolFeeV18); + this.maxAmountA = a.getAmount(); + this.maxAmountB = b.getAmount(); + this.minPrice = minPrice; + this.maxPrice = maxPrice; + } + + /** + * Creates a new LiquidityPoolDeposit builder. + */ + public Builder(LiquidityPoolID liquidityPoolID, String amountA, String amountB, Price minPrice, Price maxPrice) { + this.liquidityPoolID = liquidityPoolID; + this.maxAmountA = amountA; + this.maxAmountB = amountB; + this.minPrice = minPrice; + this.maxPrice = maxPrice; + } + + public Builder setA(AssetAmount _a) { + a = _a; + return this; + } + public Builder setA(Asset asset, String amount) { + a = new AssetAmount(asset, amount); + return this; + } + public Builder setB(AssetAmount _b) { + b = _b; + return this; + } + public Builder setB(Asset asset, String amount) { + b = new AssetAmount(asset, amount); + return this; + } + + /** + * Set source account of this operation + * @param sourceAccount Source account + * @return Builder object so you can chain methods. + */ + public Builder setSourceAccount(String sourceAccount) { + this.sourceAccount = sourceAccount; + return this; + } + + /** + * Builds an operation + */ + public LiquidityPoolDepositOperation build() { + throw new Exception("TODO: Implement LiquidityPoolDepositOperation.Builder.build"); + } + } + + public int hashCode() { + return Objects.hashCode(liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolDepositOperation)) { + return false; + } + + LiquidityPoolDepositOperation o = (LiquidityPoolDepositOperation) object; + return Objects.equal(this.getA(), o.getA()) && + Objects.equal(this.getB(), o.getB()) && + Objects.equal(this.getMinPrice(), o.getMinPrice()) && + Objects.equal(this.getMaxPrice(), o.getMaxPrice()); + } +} diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java new file mode 100644 index 000000000..516ca9df0 --- /dev/null +++ b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java @@ -0,0 +1,142 @@ +package org.stellar.sdk; + +import com.google.common.base.Objects; +import org.stellar.sdk.xdr.Operation.OperationBody; +import org.stellar.sdk.xdr.LiquidityPoolWithdrawOp; +import org.stellar.sdk.xdr.OperationType; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Represents LiquidityPoolDeposit operation. + * @see List of Operations + */ +public class LiquidityPoolWithdrawOperation extends Operation { + private final LiquidityPoolID liquidityPoolID; + private final String amount; + private final String minAmountA; + private final String minAmountB; + + private LiquidityPoolWithdrawOperation(LiquidityPoolID liquidityPoolID, String amount, String minAmountA, String minAmountB) { + this.liquidityPoolID = checkNotNull(liquidityPoolID, "liquidityPoolID cannot be null"); + this.amount = checkNotNull(amount, "amount cannot be null"); + this.minAmountA = checkNotNull(minAmountA, "minAmountA cannot be null"); + this.minAmountB = checkNotNull(minAmountB, "minAmountB cannot be null"); + } + + public LiquidityPoolID getLiquidityPoolID() { + return liquidityPoolID; + } + + public String getAmount() { + return amount; + } + + public String getMinAmountA() { + return minAmountA; + } + + public String getMinAmountB() { + return minAmountB; + } + + @Override + OperationBody toOperationBody(AccountConverter accountConverter) { + LiquidityPoolWithdrawOp op = new LiquidityPoolWithdrawOp(); + op.setLiquidityPoolID(this.getLiquidityPoolID().toXdr()); + op.setAmount(new org.stellar.sdk.xdr.Int64(Operation.toXdrAmount(this.getAmount()))); + op.setMinAmountA(new org.stellar.sdk.xdr.Int64(Operation.toXdrAmount(this.getMinAmountA()))); + op.setMinAmountB(new org.stellar.sdk.xdr.Int64(Operation.toXdrAmount(this.getMinAmountB()))); + + OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); + body.setDiscriminant(OperationType.LIQUIDITY_POOL_WITHDRAW); + body.setLiquidityPoolWithdrawOp(op); + return body; + } + + /** + * Builds LiquidityPoolWithdraw operation. + * @see LiquidityPoolWithdrawOperation + */ + public static class Builder { + private LiquidityPoolID liquidityPoolID; + private String amount; + private String minAmountA; + private String minAmountB; + + private String sourceAccount; + + Builder(LiquidityPoolWithdrawOp op) { + this.liquidityPoolID = LiquidityPoolID.fromXdr(op.getLiquidityPoolID()); + this.amount = Operation.fromXdrAmount(op.getAmount().getInt64().longValue()); + this.minAmountA = Operation.fromXdrAmount(op.getMinAmountA().getInt64().longValue()); + this.minAmountB = Operation.fromXdrAmount(op.getMinAmountB().getInt64().longValue()); + } + + /** + * Creates a new LiquidityPoolDeposit builder. + */ + public Builder(LiquidityPoolID liquidityPoolID, String amount, String minAmountA, String minAmountB) { + this.liquidityPoolID = liquidityPoolID; + this.amount = amount; + this.minAmountA = minAmountA; + this.minAmountB = minAmountB; + } + + public Builder setLiquidityPoolID(LiquidityPoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + return this; + } + + public Builder setAmount(String amount) { + this.amount = amount; + return this; + } + + public Builder setMinAmountA(String minAmountA) { + this.minAmountA = minAmountA; + return this; + } + + public Builder setMinAmountB(String minAmountB) { + this.minAmountB = minAmountB; + return this; + } + + /** + * Set source account of this operation + * @param sourceAccount Source account + * @return Builder object so you can chain methods. + */ + public Builder setSourceAccount(String sourceAccount) { + this.sourceAccount = sourceAccount; + return this; + } + + /** + * Builds an operation + */ + public LiquidityPoolWithdrawOperation build() { + LiquidityPoolWithdrawOperation op = new LiquidityPoolWithdrawOperation(liquidityPoolID, amount, minAmountA, minAmountB); + op.setSourceAccount(sourceAccount); + return op; + } + } + + public int hashCode() { + return Objects.hashCode(liquidityPoolID, amount, minAmountA, minAmountB); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof LiquidityPoolWithdrawOperation)) { + return false; + } + + LiquidityPoolWithdrawOperation o = (LiquidityPoolWithdrawOperation) object; + return Objects.equal(this.getLiquidityPoolID(), o.getLiquidityPoolID()) && + Objects.equal(this.getAmount(), o.getAmount()) && + Objects.equal(this.getMinAmountA(), o.getMinAmountA()) && + Objects.equal(this.getMinAmountB(), o.getMinAmountB()); + } +} diff --git a/src/main/java/org/stellar/sdk/Operation.java b/src/main/java/org/stellar/sdk/Operation.java index c1bb91775..e8da78f4c 100644 --- a/src/main/java/org/stellar/sdk/Operation.java +++ b/src/main/java/org/stellar/sdk/Operation.java @@ -176,6 +176,12 @@ public static Operation fromXdr(AccountConverter accountConverter, org.stellar.s case SET_TRUST_LINE_FLAGS: operation = new SetTrustlineFlagsOperation.Builder(body.getSetTrustLineFlagsOp()).build(); break; + case LIQUIDITY_POOL_DEPOSIT: + operation = new SetTrustlineFlagsOperation.Builder(body.getSetLiquidityPoolDepositOp()).build(); + break; + case LIQUIDITY_POOL_WITHDRAW: + operation = new SetTrustlineFlagsOperation.Builder(body.getSetLiquidityPoolWithdrawOp()).build(); + break; default: throw new RuntimeException("Unknown operation body " + body.getDiscriminant()); } From 040d47b797c6d271738b13b92bdf3d2888426819 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 14 Sep 2021 12:12:12 +0100 Subject: [PATCH 06/21] Adding fields to AssetResponse --- src/main/java/org/stellar/sdk/AssetAmount.java | 2 +- .../sdk/LiquidityPoolDepositOperation.java | 4 +++- .../org/stellar/sdk/responses/AssetResponse.java | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/stellar/sdk/AssetAmount.java b/src/main/java/org/stellar/sdk/AssetAmount.java index 01ff08390..4128c19bf 100644 --- a/src/main/java/org/stellar/sdk/AssetAmount.java +++ b/src/main/java/org/stellar/sdk/AssetAmount.java @@ -6,7 +6,7 @@ public final class AssetAmount { private final Asset asset; private final String amount; - private AssetAmount(Asset asset, String amount) { + AssetAmount(Asset asset, String amount) { this.asset = asset; this.amount = amount; } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index 628e4f89c..d4e20791b 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -136,7 +136,9 @@ public Builder setSourceAccount(String sourceAccount) { * Builds an operation */ public LiquidityPoolDepositOperation build() { - throw new Exception("TODO: Implement LiquidityPoolDepositOperation.Builder.build"); + LiquidityPoolDepositOperation op = new LiquidityPoolDepositOperation(liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice); + op.setSourceAccount(sourceAccount); + return op; } } diff --git a/src/main/java/org/stellar/sdk/responses/AssetResponse.java b/src/main/java/org/stellar/sdk/responses/AssetResponse.java index 0fa669d40..bd29472d1 100644 --- a/src/main/java/org/stellar/sdk/responses/AssetResponse.java +++ b/src/main/java/org/stellar/sdk/responses/AssetResponse.java @@ -20,16 +20,20 @@ public class AssetResponse extends Response implements Pageable { private final String amount; @SerializedName("claimable_balances_amount") private final String claimableBalancesAmount; + @SerializedName("liquidity_pools_amount") + private final String liquidityPoolsAmount; @SerializedName("num_accounts") private final int numAccounts; @SerializedName("num_claimable_balances") private final int numClaimableBalances; + @SerializedName("num_liquidity_pools") + private final int numLiquidityPools; @SerializedName("flags") private final AssetResponse.Flags flags; @SerializedName("_links") private final AssetResponse.Links links; - public AssetResponse(String assetType, String assetCode, String assetIssuer, String pagingToken, Accounts accounts, Balances balances, String amount, String claimableBalancesAmount, int numAccounts, int numClaimableBalances, Flags flags, Links links) { + public AssetResponse(String assetType, String assetCode, String assetIssuer, String pagingToken, Accounts accounts, Balances balances, String amount, String claimableBalancesAmount, String liquidityPoolsAmount, int numAccounts, int numClaimableBalances, int numLiquidityPools, Flags flags, Links links) { this.assetType = assetType; this.assetCode = assetCode; this.assetIssuer = assetIssuer; @@ -38,8 +42,10 @@ public AssetResponse(String assetType, String assetCode, String assetIssuer, Str this.balances = balances; this.amount = amount; this.claimableBalancesAmount = claimableBalancesAmount; + this.liquidityPoolsAmount = liquidityPoolsAmount; this.numAccounts = numAccounts; this.numClaimableBalances = numClaimableBalances; + this.numLiquidityPools = numLiquidityPools; this.flags = flags; this.links = links; } @@ -76,10 +82,18 @@ public String getClaimableBalancesAmount() { return claimableBalancesAmount; } + public String getLiquidityPoolsAmount() { + return liquidityPoolsAmount; + } + public int getNumClaimableBalances() { return numClaimableBalances; } + public int getNumLiquidityPools() { + return numLiquidityPools; + } + public String getAmount() { return amount; } From fa8c7bc2493dfa43fc447aee7c9a6a6c5b36d001 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 14 Sep 2021 12:55:53 +0100 Subject: [PATCH 07/21] WIP trades and accounts request updates --- .../sdk/requests/AccountsRequestBuilder.java | 52 +++++++++++++++++-- .../sdk/requests/TradesRequestBuilder.java | 16 ++++++ .../sdk/responses/AccountResponse.java | 11 +++- .../stellar/sdk/responses/TradeResponse.java | 16 +++++- 4 files changed, 88 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java index 6bf7579db..2f42f88e7 100644 --- a/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java @@ -16,6 +16,7 @@ */ public class AccountsRequestBuilder extends RequestBuilder { private static final String ASSET_PARAMETER_NAME = "asset"; + private static final String LIQUIDITY_POOL_PARAMETER_NAME = "liquidity_pool"; private static final String SIGNER_PARAMETER_NAME = "signer"; private static final String SPONSOR_PARAMETER_NAME = "sponsor"; @@ -58,10 +59,13 @@ public AccountResponse account(String account) throws IOException { */ public AccountsRequestBuilder forSigner(String signer) { if (uriBuilder.build().queryParameter(ASSET_PARAMETER_NAME) != null) { - throw new RuntimeException("cannot set both signer and asset"); + throw new RuntimeException("cannot set both asset and signer"); + } + if (uriBuilder.build().queryParameter(LIQUIDITY_POOL_PARAMETER_NAME) != null) { + throw new RuntimeException("cannot set both liquidity_pool and signer"); } if (uriBuilder.build().queryParameter(SPONSOR_PARAMETER_NAME) != null) { - throw new RuntimeException("cannot set both signer and sponsor"); + throw new RuntimeException("cannot set both sponsor and signer"); } uriBuilder.setQueryParameter(SIGNER_PARAMETER_NAME, signer); return this; @@ -75,6 +79,9 @@ public AccountsRequestBuilder forSigner(String signer) { * @see Accounts */ public AccountsRequestBuilder forAsset(AssetTypeCreditAlphaNum asset) { + if (uriBuilder.build().queryParameter(LIQUIDITY_POOL_PARAMETER_NAME) != null) { + throw new RuntimeException("cannot set both liquidity_pool and asset"); + } if (uriBuilder.build().queryParameter(SIGNER_PARAMETER_NAME) != null) { throw new RuntimeException("cannot set both signer and asset"); } @@ -85,6 +92,38 @@ public AccountsRequestBuilder forAsset(AssetTypeCreditAlphaNum asset) { return this; } + /** + * Returns all accounts who have trustlines to the specified liquidity pool. + * + * @param Liquidity Pool ID + * @return current {@link AccountsRequestBuilder} instance + * @see Accounts + */ + public AccountsRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { + return this.forLiquidityPool(liquidityPoolID.toString()); + } + + /** + * Returns all accounts who have trustlines to the specified liquidity pool. + * + * @param Liquidity Pool ID + * @return current {@link AccountsRequestBuilder} instance + * @see Accounts + */ + public AccountsRequestBuilder forLiquidityPool(String liquidityPoolID) { + if (uriBuilder.build().queryParameter(ASSET_PARAMETER_NAME) != null) { + throw new RuntimeException("cannot set both asset and liquidity_pool"); + } + if (uriBuilder.build().queryParameter(SIGNER_PARAMETER_NAME) != null) { + throw new RuntimeException("cannot set both signer and liquidity_pool"); + } + if (uriBuilder.build().queryParameter(SPONSOR_PARAMETER_NAME) != null) { + throw new RuntimeException("cannot set both sponsor and liquidity_pool"); + } + uriBuilder.setQueryParameter(LIQUIDITY_POOL_PARAMETER_NAME, liquidityPoolID); + return this; + } + /** * Returns all accounts who are sponsored by a given account or have subentries which are sponsored by a given account. * @@ -93,12 +132,15 @@ public AccountsRequestBuilder forAsset(AssetTypeCreditAlphaNum asset) { * @see Accounts */ public AccountsRequestBuilder forSponsor(String sponsor) { - if (uriBuilder.build().queryParameter(SIGNER_PARAMETER_NAME) != null) { - throw new RuntimeException("cannot set both signer and sponsor"); - } if (uriBuilder.build().queryParameter(ASSET_PARAMETER_NAME) != null) { throw new RuntimeException("cannot set both asset and sponsor"); } + if (uriBuilder.build().queryParameter(LIQUIDITY_POOL_PARAMETER_NAME) != null) { + throw new RuntimeException("cannot set both liquidity_pool and sponsor"); + } + if (uriBuilder.build().queryParameter(SIGNER_PARAMETER_NAME) != null) { + throw new RuntimeException("cannot set both signer and sponsor"); + } uriBuilder.setQueryParameter(SPONSOR_PARAMETER_NAME, sponsor); return this; } diff --git a/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java index f220b439c..c822275e9 100644 --- a/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java @@ -17,6 +17,8 @@ * Builds requests connected to trades. */ public class TradesRequestBuilder extends RequestBuilder { + private static final String TRADE_TYPE_PARAMETER_NAME = "trade_type"; + public TradesRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { super(httpClient, serverURI, "trades"); } @@ -52,6 +54,20 @@ public TradesRequestBuilder forAccount(String account) { return this; } + /** + * Returns all trades that of a specific type. + * + * @param trade type + * @return current {@link TradesRequestBuilder} instance + * @see Trades + */ + public TradesRequestBuilder forTradeType(String tradeType) { + tradeType = checkNotNull(tradeType, "tradeType cannot be null"); + uriBuilder.setQueryParameter(TRADE_TYPE_PARAMETER_NAME, tradeType); + return this; + } + + public static Page execute(OkHttpClient httpClient, HttpUrl uri) throws IOException, TooManyRequestsException { TypeToken type = new TypeToken>() {}; diff --git a/src/main/java/org/stellar/sdk/responses/AccountResponse.java b/src/main/java/org/stellar/sdk/responses/AccountResponse.java index 2e43b7bf2..4c1d3258d 100644 --- a/src/main/java/org/stellar/sdk/responses/AccountResponse.java +++ b/src/main/java/org/stellar/sdk/responses/AccountResponse.java @@ -202,6 +202,8 @@ public static class Balance { private final String assetCode; @SerializedName("asset_issuer") private final String assetIssuer; + @SerializedName("liquidity_pool_shares"); + private final String liquidityPoolID; @SerializedName("limit") private final String limit; @SerializedName("balance") @@ -219,12 +221,13 @@ public static class Balance { @SerializedName("sponsor") private String sponsor; - Balance(String assetType, String assetCode, String assetIssuer, String balance, String limit, String buyingLiabilities, String sellingLiabilities, Boolean isAuthorized, Boolean isAuthorizedToMaintainLiabilities, Integer lastModifiedLedger, String sponsor) { + Balance(String assetType, String assetCode, String assetIssuer, String liquidityPoolID, String balance, String limit, String buyingLiabilities, String sellingLiabilities, Boolean isAuthorized, Boolean isAuthorizedToMaintainLiabilities, Integer lastModifiedLedger, String sponsor) { this.assetType = checkNotNull(assetType, "assertType cannot be null"); this.balance = checkNotNull(balance, "balance cannot be null"); this.limit = limit; this.assetCode = assetCode; this.assetIssuer = assetIssuer; + this.liquidityPoolID = liquidityPoolID; this.buyingLiabilities = checkNotNull(buyingLiabilities, "buyingLiabilities cannot be null"); this.sellingLiabilities = checkNotNull(sellingLiabilities, "sellingLiabilities cannot be null"); this.isAuthorized = isAuthorized; @@ -237,6 +240,8 @@ public static class Balance { public Asset getAsset() { if (assetType.equals("native")) { return new AssetTypeNative(); + } else if (assetType.equals("liquidity_pool_shares")) { + return TrustLineAsset.create(getLiquidityPoolID()); } else { return Asset.createNonNativeAsset(assetCode, getAssetIssuer()); } @@ -254,6 +259,10 @@ public String getAssetIssuer() { return assetIssuer; } + public LiquidityPoolID getLiquidityPoolID() { + return new LiquidityPoolID(liquidityPoolID); + } + public String getBalance() { return balance; } diff --git a/src/main/java/org/stellar/sdk/responses/TradeResponse.java b/src/main/java/org/stellar/sdk/responses/TradeResponse.java index 6f8ded1cd..f4e5e3a72 100644 --- a/src/main/java/org/stellar/sdk/responses/TradeResponse.java +++ b/src/main/java/org/stellar/sdk/responses/TradeResponse.java @@ -27,6 +27,8 @@ public class TradeResponse extends Response implements Pageable { @SerializedName("base_account") protected final String baseAccount; + @SerializedName("base_liquidity_pool_id") + protected final String baseLiquidityPoolID; @SerializedName("base_offer_id") private final String baseOfferId; @SerializedName("base_amount") @@ -40,6 +42,8 @@ public class TradeResponse extends Response implements Pageable { @SerializedName("counter_account") protected final String counterAccount; + @SerializedName("counter_liquidity_pool_id") + protected final String counterLiquidityPoolID; @SerializedName("counter_offer_id") private final String counterOfferId; @SerializedName("counter_amount") @@ -57,19 +61,21 @@ public class TradeResponse extends Response implements Pageable { @SerializedName("_links") private TradeResponse.Links links; - public TradeResponse(String id, String pagingToken, String ledgerCloseTime, String offerId, boolean baseIsSeller, String baseAccount, String baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, String counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, Price price) { + public TradeResponse(String id, String pagingToken, String ledgerCloseTime, String offerId, boolean baseIsSeller, String baseAccount, String baseLiquidityPoolID, String baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, String counterLiquidityPoolID, String counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, Price price) { this.id = id; this.pagingToken = pagingToken; this.ledgerCloseTime = ledgerCloseTime; this.offerId = offerId; this.baseIsSeller = baseIsSeller; this.baseAccount = baseAccount; + this.baseLiquidityPoolID = baseLiquidityPoolID; this.baseOfferId = baseOfferId; this.baseAmount = baseAmount; this.baseAssetType = baseAssetType; this.baseAssetCode = baseAssetCode; this.baseAssetIssuer = baseAssetIssuer; this.counterAccount = counterAccount; + this.counterLiquidityPoolID = counterLiquidityPoolID; this.counterOfferId = counterOfferId; this.counterAmount = counterAmount; this.counterAssetType = counterAssetType; @@ -106,6 +112,10 @@ public String getBaseAccount() { return baseAccount; } + public LiquidityPoolID getBaseLiquidityPoolID() { + return new LiquidityPoolID(baseLiquidityPoolID); + } + public String getBaseAmount() { return baseAmount; } @@ -130,6 +140,10 @@ public String getCounterAccount() { return counterAccount; } + public LiquidityPoolID getCounterLiquidityPoolID() { + return new LiquidityPoolID(counterLiquidityPoolID); + } + public String getCounterOfferId() { return counterOfferId; } From 66c1be881524ab58709c96879951b796870eb296 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 14 Sep 2021 14:20:27 +0100 Subject: [PATCH 08/21] Adding liquidity pools requests and responses --- .../sdk/LiquidityPoolDepositOperation.java | 2 +- .../stellar/sdk/LiquidityPoolParameters.java | 2 + src/main/java/org/stellar/sdk/Operation.java | 4 +- src/main/java/org/stellar/sdk/Server.java | 7 + .../sdk/requests/AccountsRequestBuilder.java | 1 + .../sdk/requests/EffectsRequestBuilder.java | 12 ++ .../LiquidityPoolsRequestBuilder.java | 133 +++++++++++++++++ .../requests/OperationsRequestBuilder.java | 12 ++ .../requests/TransactionsRequestBuilder.java | 12 ++ .../sdk/responses/AccountResponse.java | 41 +++--- .../sdk/responses/LiquidityPoolResponse.java | 135 ++++++++++++++++++ .../stellar/sdk/responses/TradeResponse.java | 42 +++--- 12 files changed, 361 insertions(+), 42 deletions(-) create mode 100644 src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java create mode 100644 src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index d4e20791b..6b9f58944 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -87,7 +87,7 @@ public static class Builder { * Creates a new LiquidityPoolDeposit builder. */ public Builder(AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { - this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolFeeV18); + this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee); this.maxAmountA = a.getAmount(); this.maxAmountB = b.getAmount(); this.minPrice = minPrice; diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java index b32d4ac48..2ca3e8646 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java @@ -9,6 +9,8 @@ public abstract class LiquidityPoolParameters { LiquidityPoolParameters() {} + public static Integer Fee = 30; + /** * TODO: Write something here * diff --git a/src/main/java/org/stellar/sdk/Operation.java b/src/main/java/org/stellar/sdk/Operation.java index e8da78f4c..7edd9837e 100644 --- a/src/main/java/org/stellar/sdk/Operation.java +++ b/src/main/java/org/stellar/sdk/Operation.java @@ -177,10 +177,10 @@ public static Operation fromXdr(AccountConverter accountConverter, org.stellar.s operation = new SetTrustlineFlagsOperation.Builder(body.getSetTrustLineFlagsOp()).build(); break; case LIQUIDITY_POOL_DEPOSIT: - operation = new SetTrustlineFlagsOperation.Builder(body.getSetLiquidityPoolDepositOp()).build(); + operation = new LiquidityPoolDepositOperation.Builder(body.getLiquidityPoolDepositOp()).build(); break; case LIQUIDITY_POOL_WITHDRAW: - operation = new SetTrustlineFlagsOperation.Builder(body.getSetLiquidityPoolWithdrawOp()).build(); + operation = new LiquidityPoolWithdrawOperation.Builder(body.getLiquidityPoolWithdrawOp()).build(); break; default: throw new RuntimeException("Unknown operation body " + body.getDiscriminant()); diff --git a/src/main/java/org/stellar/sdk/Server.java b/src/main/java/org/stellar/sdk/Server.java index 481e72f85..c4b16d02e 100644 --- a/src/main/java/org/stellar/sdk/Server.java +++ b/src/main/java/org/stellar/sdk/Server.java @@ -216,6 +216,13 @@ public TransactionsRequestBuilder transactions() { return new TransactionsRequestBuilder(httpClient, serverURI); } + /** + * Returns {@link LiquidityPoolsRequestBuilder} instance. + */ + public LiquidityPoolsRequestBuilder liquidityPools() { + return new LiquidityPoolsRequestBuilder(httpClient, serverURI); + } + private Optional getNetwork() { Lock readLock = this.networkLock.readLock(); readLock.lock(); diff --git a/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java index 2f42f88e7..2f925524e 100644 --- a/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/AccountsRequestBuilder.java @@ -6,6 +6,7 @@ import okhttp3.Request; import okhttp3.Response; import org.stellar.sdk.AssetTypeCreditAlphaNum; +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.responses.AccountResponse; import org.stellar.sdk.responses.Page; diff --git a/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java index 5d9450a72..31fa4f5d3 100644 --- a/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java @@ -5,6 +5,8 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; + +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.responses.Page; import org.stellar.sdk.responses.effects.EffectResponse; @@ -52,6 +54,16 @@ public EffectsRequestBuilder forTransaction(String transactionId) { return this; } + /** + * Builds request to GET /liquidity_pools/{ledgerSeq}/effects + * @see Transactions for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get effects + */ + public EffectsRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { + this.setSegments("liquidity_pools", String.valueOf(liquidityPoolID), "effects"); + return this; + } + /** * Builds request to GET /operation/{operationId}/effects * @see Effect for Operation diff --git a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java new file mode 100644 index 000000000..6964f5a00 --- /dev/null +++ b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java @@ -0,0 +1,133 @@ +package org.stellar.sdk.requests; + +import com.google.gson.reflect.TypeToken; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.stellar.sdk.AssetTypeCreditAlphaNum; +import org.stellar.sdk.LiquidityPoolID; +import org.stellar.sdk.responses.LiquidityPoolResponse; +import org.stellar.sdk.responses.Page; + +import java.io.IOException; + +/** + * Builds requests connected to liquidity pools. + */ +public class LiquidityPoolsRequestBuilder extends RequestBuilder { + private static final String RESERVES_PARAMETER_NAME = "reserves"; + + public LiquidityPoolsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { + super(httpClient, serverURI, "liquidity_pools"); + } + + /** + * Requests specific uri and returns {@link LiquidityPoolResponse}. + * This method is helpful for getting the links. + * @throws IOException + */ + public LiquidityPoolResponse liquidityPool(HttpUrl uri) throws IOException { + TypeToken type = new TypeToken() {}; + ResponseHandler responseHandler = new ResponseHandler(type); + + Request request = new Request.Builder().get().url(uri).build(); + Response response = httpClient.newCall(request).execute(); + + return responseHandler.handleResponse(response); + } + + /** + * Requests GET /liquidity_pools/{liquidity_pool_id} + * @see Liquidity Pool Details + * @param liquidityPoolID Liquidity Pool to fetch + * @throws IOException + */ + public LiquidityPoolResponse liquidityPool(String liquidityPoolID) throws IOException { + this.setSegments("liquidity_pools", liquidityPoolID); + return this.liquidityPool(this.buildUri()); + } + + /** + * Requests GET /liquidity_pools/{liquidity_pool_id} + * @see Liquidity Pool Details + * @param liquidityPoolID Liquidity Pool to fetch + * @throws IOException + */ + public LiquidityPoolResponse liquidityPool(LiquidityPoolID liquidityPoolID) throws IOException { + return this.liquidityPool(liquidityPoolID.toString()); + } + + + /** + * Returns all liquidity pools that contain reserves in all specified assets. + * + * @param signer Liquidity Pool ID + * @return current {@link LiquidityPoolsRequestBuilder} instance + * @see LiquidityPools + */ + public LiquidityPoolsRequestBuilder forReserves(String[] reserves) { + uriBuilder.setQueryParameter(RESERVES_PARAMETER_NAME, String.join(",", reserves)); + return this; + } + + /** + * Requests specific uri and returns {@link Page} of {@link LiquidityPoolResponse}. + * This method is helpful for getting the next set of results. + * @return {@link Page} of {@link LiquidityPoolResponse} + * @throws TooManyRequestsException when too many requests were sent to the Horizon server. + * @throws IOException + */ + public static Page execute(OkHttpClient httpClient, HttpUrl uri) throws IOException, TooManyRequestsException { + TypeToken type = new TypeToken>() {}; + ResponseHandler> responseHandler = new ResponseHandler>(type); + + Request request = new Request.Builder().get().url(uri).build(); + Response response = httpClient.newCall(request).execute(); + + return responseHandler.handleResponse(response); + } + + /** + * Allows to stream SSE events from horizon. + * Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events. + * This mode will keep the connection to horizon open and horizon will continue to return + * responses as ledgers close. + * @see Server-Sent Events + * @see Response Format documentation + * @param listener {@link EventListener} implementation with {@link LiquidityPoolResponse} type + * @return EventSource object, so you can close() connection when not needed anymore + */ + public SSEStream stream(final EventListener listener) { + + return SSEStream.create(httpClient,this,LiquidityPoolResponse.class,listener); + } + + /** + * Build and execute request. Warning! {@link LiquidityPoolResponse}s in {@link Page} will contain only keypair field. + * @return {@link Page} of {@link LiquidityPoolResponse} + * @throws TooManyRequestsException when too many requests were sent to the Horizon server. + * @throws IOException + */ + public Page execute() throws IOException, TooManyRequestsException { + return this.execute(this.httpClient, this.buildUri()); + } + + @Override + public LiquidityPoolsRequestBuilder cursor(String token) { + super.cursor(token); + return this; + } + + @Override + public LiquidityPoolsRequestBuilder limit(int number) { + super.limit(number); + return this; + } + + @Override + public LiquidityPoolsRequestBuilder order(Order direction) { + super.order(direction); + return this; + } +} diff --git a/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java index 5ea8d87d2..d53f12dc4 100644 --- a/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java @@ -7,6 +7,8 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; + +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.responses.Page; import org.stellar.sdk.responses.operations.OperationResponse; @@ -95,6 +97,16 @@ public OperationsRequestBuilder forTransaction(String transactionId) { return this; } + /** + * Builds request to GET /liquidity_pools/{ledgerSeq}/operations + * @see Transactions for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get operations + */ + public OperationsRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { + this.setSegments("liquidity_pools", String.valueOf(liquidityPoolID), "operations"); + return this; + } + /** * Adds a parameter defining whether to include operations of failed transactions. By default only operations of * successful transactions are returned. diff --git a/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java index 81b34a7c5..52253d748 100644 --- a/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java @@ -5,6 +5,8 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; + +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.responses.Page; import org.stellar.sdk.responses.TransactionResponse; @@ -78,6 +80,16 @@ public TransactionsRequestBuilder forLedger(long ledgerSeq) { return this; } + /** + * Builds request to GET /liquidity_pools/{ledgerSeq}/transactions + * @see Transactions for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get transactions + */ + public TransactionsRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { + this.setSegments("liquidity_pools", String.valueOf(liquidityPoolID), "transactions"); + return this; + } + /** * Adds a parameter defining whether to include failed transactions. By default only successful transactions are * returned. diff --git a/src/main/java/org/stellar/sdk/responses/AccountResponse.java b/src/main/java/org/stellar/sdk/responses/AccountResponse.java index 4c1d3258d..36c357247 100644 --- a/src/main/java/org/stellar/sdk/responses/AccountResponse.java +++ b/src/main/java/org/stellar/sdk/responses/AccountResponse.java @@ -7,6 +7,8 @@ import org.stellar.sdk.Asset; import org.stellar.sdk.AssetTypeNative; import org.stellar.sdk.KeyPair; +import org.stellar.sdk.LiquidityPoolID; +import org.stellar.sdk.TrustLineAsset; import java.util.HashMap; @@ -199,11 +201,11 @@ public static class Balance { @SerializedName("asset_type") private final String assetType; @SerializedName("asset_code") - private final String assetCode; + private String assetCode; @SerializedName("asset_issuer") - private final String assetIssuer; - @SerializedName("liquidity_pool_shares"); - private final String liquidityPoolID; + private String assetIssuer; + @SerializedName("liquidity_pool_shares") + private LiquidityPoolID liquidityPoolID; @SerializedName("limit") private final String limit; @SerializedName("balance") @@ -221,7 +223,7 @@ public static class Balance { @SerializedName("sponsor") private String sponsor; - Balance(String assetType, String assetCode, String assetIssuer, String liquidityPoolID, String balance, String limit, String buyingLiabilities, String sellingLiabilities, Boolean isAuthorized, Boolean isAuthorizedToMaintainLiabilities, Integer lastModifiedLedger, String sponsor) { + Balance(String assetType, String assetCode, String assetIssuer, LiquidityPoolID liquidityPoolID, String balance, String limit, String buyingLiabilities, String sellingLiabilities, Boolean isAuthorized, Boolean isAuthorizedToMaintainLiabilities, Integer lastModifiedLedger, String sponsor) { this.assetType = checkNotNull(assetType, "assertType cannot be null"); this.balance = checkNotNull(balance, "balance cannot be null"); this.limit = limit; @@ -237,13 +239,14 @@ public static class Balance { this.sponsor = sponsor; } - public Asset getAsset() { + public Optional getAsset() { if (assetType.equals("native")) { - return new AssetTypeNative(); + return Optional.of((Asset)new AssetTypeNative()); } else if (assetType.equals("liquidity_pool_shares")) { - return TrustLineAsset.create(getLiquidityPoolID()); + // TODO: Decide if this is the right way to handle this... + return Optional.absent(); } else { - return Asset.createNonNativeAsset(assetCode, getAssetIssuer()); + return Optional.of(Asset.createNonNativeAsset(assetCode, assetIssuer)); } } @@ -251,28 +254,28 @@ public String getAssetType() { return assetType; } - public String getAssetCode() { - return assetCode; + public Optional getAssetCode() { + return Optional.fromNullable(assetCode); } - public String getAssetIssuer() { - return assetIssuer; + public Optional getAssetIssuer() { + return Optional.fromNullable(assetIssuer); } - public LiquidityPoolID getLiquidityPoolID() { - return new LiquidityPoolID(liquidityPoolID); + public Optional getLiquidityPoolID() { + return Optional.fromNullable(liquidityPoolID); } public String getBalance() { return balance; } - public String getBuyingLiabilities() { - return buyingLiabilities; + public Optional getBuyingLiabilities() { + return Optional.fromNullable(buyingLiabilities); } - public String getSellingLiabilities() { - return sellingLiabilities; + public Optional getSellingLiabilities() { + return Optional.fromNullable(sellingLiabilities); } public String getLimit() { diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java new file mode 100644 index 000000000..333e3e381 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java @@ -0,0 +1,135 @@ +package org.stellar.sdk.responses; + +import com.google.common.base.Optional; +import com.google.common.io.BaseEncoding; +import com.google.gson.annotations.SerializedName; + +import org.stellar.sdk.Asset; +import org.stellar.sdk.AssetTypeNative; +import org.stellar.sdk.KeyPair; +import org.stellar.sdk.LiquidityPoolID; + +import java.util.HashMap; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Represents liquidity pool response. + * @see Liquidity Pool documentation + * @see org.stellar.sdk.requests.LiquidityPoolsRequestBuilder + * @see org.stellar.sdk.Server#liquidityPools() + */ +public class LiquidityPoolResponse extends Response { + @SerializedName("id") + private LiquidityPoolID liquidityPoolID; + @SerializedName("paging_token") + private String pagingToken; + @SerializedName("fee_bp") + private Integer feeBP; + @SerializedName("type") + private String type; + @SerializedName("total_trustlines") + private String totalTrustlines; + @SerializedName("total_shares") + private String totalShares; + @SerializedName("reserves") + private Reserve[] reserves; + @SerializedName("_links") + private Links links; + + LiquidityPoolResponse(LiquidityPoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + } + + public LiquidityPoolID getLiquidityPoolID() { + return liquidityPoolID; + } + + public String getPagingToken() { + return pagingToken; + } + + public Integer getFeeBP() { + return feeBP; + } + + public String getType() { + return type; + } + + public String getTotalTrustlines() { + return totalTrustlines; + } + + public String getTotalShares() { + return totalShares; + } + + public Reserve[] getReserves() { + return reserves; + } + + /** + * Represents liquidity pool reserves. + */ + public static class Reserve { + @SerializedName("amount") + private final String amount; + @SerializedName("asset") + private final String asset; + + Reserve(String amount, String asset) { + this.amount = checkNotNull(amount, "amount cannot be null"); + this.asset = checkNotNull(asset, "asset cannot be null"); + } + + public Asset getAsset() { + return Asset.create(asset); + } + + public String getAmount() { + return amount; + } + } + + public Links getLinks() { + return links; + } + + /** + * Links connected to account. + */ + public static class Links { + @SerializedName("effects") + private final Link effects; + @SerializedName("operations") + private final Link operations; + @SerializedName("self") + private final Link self; + @SerializedName("transactions") + private final Link transactions; + + Links(Link effects, Link operations, Link self, Link transactions) { + this.effects = effects; + this.operations = operations; + this.self = self; + this.transactions = transactions; + } + + public Link getEffects() { + return effects; + } + + public Link getOperations() { + return operations; + } + + public Link getSelf() { + return self; + } + + public Link getTransactions() { + return transactions; + } + } +} diff --git a/src/main/java/org/stellar/sdk/responses/TradeResponse.java b/src/main/java/org/stellar/sdk/responses/TradeResponse.java index f4e5e3a72..cf8ff9e7d 100644 --- a/src/main/java/org/stellar/sdk/responses/TradeResponse.java +++ b/src/main/java/org/stellar/sdk/responses/TradeResponse.java @@ -1,9 +1,11 @@ package org.stellar.sdk.responses; +import com.google.common.base.Optional; + import com.google.gson.annotations.SerializedName; import org.stellar.sdk.Asset; import org.stellar.sdk.Price; -; +import org.stellar.sdk.LiquidityPoolID; /** * Represents trades response. @@ -26,11 +28,11 @@ public class TradeResponse extends Response implements Pageable { protected final boolean baseIsSeller; @SerializedName("base_account") - protected final String baseAccount; + protected String baseAccount; @SerializedName("base_liquidity_pool_id") - protected final String baseLiquidityPoolID; + protected LiquidityPoolID baseLiquidityPoolID; @SerializedName("base_offer_id") - private final String baseOfferId; + private String baseOfferId; @SerializedName("base_amount") protected final String baseAmount; @SerializedName("base_asset_type") @@ -41,11 +43,11 @@ public class TradeResponse extends Response implements Pageable { protected final String baseAssetIssuer; @SerializedName("counter_account") - protected final String counterAccount; + protected String counterAccount; @SerializedName("counter_liquidity_pool_id") - protected final String counterLiquidityPoolID; + protected LiquidityPoolID counterLiquidityPoolID; @SerializedName("counter_offer_id") - private final String counterOfferId; + private String counterOfferId; @SerializedName("counter_amount") protected final String counterAmount; @SerializedName("counter_asset_type") @@ -61,7 +63,7 @@ public class TradeResponse extends Response implements Pageable { @SerializedName("_links") private TradeResponse.Links links; - public TradeResponse(String id, String pagingToken, String ledgerCloseTime, String offerId, boolean baseIsSeller, String baseAccount, String baseLiquidityPoolID, String baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, String counterLiquidityPoolID, String counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, Price price) { + public TradeResponse(String id, String pagingToken, String ledgerCloseTime, String offerId, boolean baseIsSeller, String baseAccount, LiquidityPoolID baseLiquidityPoolID, String baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, LiquidityPoolID counterLiquidityPoolID, String counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, Price price) { this.id = id; this.pagingToken = pagingToken; this.ledgerCloseTime = ledgerCloseTime; @@ -104,16 +106,16 @@ public boolean isBaseSeller() { return baseIsSeller; } - public String getBaseOfferId() { - return baseOfferId; + public Optional getBaseOfferId() { + return Optional.fromNullable(baseOfferId); } - public String getBaseAccount() { - return baseAccount; + public Optional getBaseAccount() { + return Optional.fromNullable(baseAccount); } - public LiquidityPoolID getBaseLiquidityPoolID() { - return new LiquidityPoolID(baseLiquidityPoolID); + public Optional getBaseLiquidityPoolID() { + return Optional.fromNullable(baseLiquidityPoolID); } public String getBaseAmount() { @@ -136,16 +138,16 @@ public String getBaseAssetIssuer() { return baseAssetIssuer; } - public String getCounterAccount() { - return counterAccount; + public Optional getCounterAccount() { + return Optional.fromNullable(counterAccount); } - public LiquidityPoolID getCounterLiquidityPoolID() { - return new LiquidityPoolID(counterLiquidityPoolID); + public Optional getCounterLiquidityPoolID() { + return Optional.fromNullable(counterLiquidityPoolID); } - public String getCounterOfferId() { - return counterOfferId; + public Optional getCounterOfferId() { + return Optional.fromNullable(counterOfferId); } public Asset getCounterAsset() { From 00c3bd844f744210bc35983348eafdca69a4c144 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 14 Sep 2021 16:45:40 +0100 Subject: [PATCH 09/21] Implement asset sorting --- src/main/java/org/stellar/sdk/Asset.java | 4 +++- .../sdk/AssetTypeCreditAlphaNum12.java | 15 ++++++++++++++ .../stellar/sdk/AssetTypeCreditAlphaNum4.java | 17 ++++++++++++++++ .../java/org/stellar/sdk/AssetTypeNative.java | 8 ++++++++ .../org/stellar/sdk/ChangeTrustAsset.java | 20 +++++++++++++------ .../LiquidityPoolShareChangeTrustAsset.java | 8 ++++++++ .../sdk/LiquidityPoolShareTrustLineAsset.java | 8 ++++++++ .../java/org/stellar/sdk/TrustLineAsset.java | 20 +++++++++++++------ 8 files changed, 87 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/stellar/sdk/Asset.java b/src/main/java/org/stellar/sdk/Asset.java index 16e577159..bf086924a 100644 --- a/src/main/java/org/stellar/sdk/Asset.java +++ b/src/main/java/org/stellar/sdk/Asset.java @@ -4,7 +4,7 @@ * Base Asset class. * @see Assets */ -public abstract class Asset { +public abstract class Asset implements Comparable { Asset() {} /** @@ -94,4 +94,6 @@ public static Asset fromXdr(org.stellar.sdk.xdr.Asset xdr) { * Generates XDR object from a given Asset object */ public abstract org.stellar.sdk.xdr.Asset toXdr(); + + public abstract int compareTo(Asset other); } diff --git a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java index 6ecd67489..da71c388e 100644 --- a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java +++ b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java @@ -37,4 +37,19 @@ public org.stellar.sdk.xdr.Asset toXdr() { xdr.setAlphaNum12(credit); return xdr; } + + @Override + public int compareTo(Asset other) { + if (other.getType() != "credit_alphanum12") { + return 1; + } + + AssetTypeCreditAlphaNum o = (AssetTypeCreditAlphaNum) other; + + if (this.getCode() != o.getCode()) { + return this.getCode().compareTo(o.getCode()); + } + + return this.getIssuer().compareTo(o.getIssuer()); + } } diff --git a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java index e097bb1d0..dfa95e73c 100644 --- a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java +++ b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java @@ -37,4 +37,21 @@ public org.stellar.sdk.xdr.Asset toXdr() { xdr.setAlphaNum4(credit); return xdr; } + + @Override + public int compareTo(Asset other) { + if (other.getType() == "credit_alphanum12") { + return -1; + } else if (other.getType() == "native") { + return 1; + } + + AssetTypeCreditAlphaNum o = (AssetTypeCreditAlphaNum) other; + + if (this.getCode() != o.getCode()) { + return this.getCode().compareTo(o.getCode()); + } + + return this.getIssuer().compareTo(o.getIssuer()); + } } diff --git a/src/main/java/org/stellar/sdk/AssetTypeNative.java b/src/main/java/org/stellar/sdk/AssetTypeNative.java index a09588c89..2e881bf99 100644 --- a/src/main/java/org/stellar/sdk/AssetTypeNative.java +++ b/src/main/java/org/stellar/sdk/AssetTypeNative.java @@ -40,4 +40,12 @@ public org.stellar.sdk.xdr.Asset toXdr() { xdr.setDiscriminant(AssetType.ASSET_TYPE_NATIVE); return xdr; } + + @Override + public int compareTo(Asset other) { + if (other.getType() == "native") { + return 0; + } + return -1; + } } diff --git a/src/main/java/org/stellar/sdk/ChangeTrustAsset.java b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java index 8abafe921..4505e5f6a 100644 --- a/src/main/java/org/stellar/sdk/ChangeTrustAsset.java +++ b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java @@ -6,7 +6,7 @@ * ChangeTrustAsset class. * @see Assets */ -public abstract class ChangeTrustAsset { +public abstract class ChangeTrustAsset implements Comparable { ChangeTrustAsset() {} /** @@ -90,6 +90,11 @@ public Asset getAsset() { return asset; } + @Override + public String getType() { + return asset.getType(); + } + @Override public final boolean equals(Object object) { if (object == null || !this.getClass().equals(object.getClass())) { @@ -100,6 +105,14 @@ public final boolean equals(Object object) { return this.getAsset().equals(o.getAsset()); } + @Override + public int compareTo(ChangeTrustAsset other) { + if (other.getType() == "pool_share") { + return -1; + } + return this.getAsset().compareTo(((ChangeTrustAsset.Wrapper) other).getAsset()); + } + @Override public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { org.stellar.sdk.xdr.ChangeTrustAsset xdr = new org.stellar.sdk.xdr.ChangeTrustAsset(); @@ -111,10 +124,5 @@ public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { return xdr; } - - @Override - public String getType() { - return asset.getType(); - } } } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java index 73755d7b4..1343d5446 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java @@ -52,6 +52,14 @@ public boolean equals(Object object) { return this.getLiquidityPoolParams().equals(o.getLiquidityPoolParams()); } + @Override + public int compareTo(ChangeTrustAsset other) { + if (other.getType() != "pool_share") { + return 1; + } + return this.toString().compareTo(((LiquidityPoolShareChangeTrustAsset) other).toString()); + } + @Override public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { org.stellar.sdk.xdr.ChangeTrustAsset xdr = new org.stellar.sdk.xdr.ChangeTrustAsset(); diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java b/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java index 71efd6d76..f2d02fe75 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java @@ -53,6 +53,14 @@ public boolean equals(Object object) { return this.toString() == o.toString(); } + @Override + public int compareTo(TrustLineAsset other) { + if (other.getType() != "pool_share") { + return 1; + } + return this.toString().compareTo(((LiquidityPoolShareTrustLineAsset) other).toString()); + } + @Override public org.stellar.sdk.xdr.TrustLineAsset toXdr() { org.stellar.sdk.xdr.TrustLineAsset xdr = new org.stellar.sdk.xdr.TrustLineAsset(); diff --git a/src/main/java/org/stellar/sdk/TrustLineAsset.java b/src/main/java/org/stellar/sdk/TrustLineAsset.java index 880c1449f..538a7548e 100644 --- a/src/main/java/org/stellar/sdk/TrustLineAsset.java +++ b/src/main/java/org/stellar/sdk/TrustLineAsset.java @@ -6,7 +6,7 @@ * TrustLineAsset class. * @see Assets */ -public abstract class TrustLineAsset { +public abstract class TrustLineAsset implements Comparable { TrustLineAsset() {} /** @@ -95,6 +95,11 @@ public Asset getAsset() { return asset; } + @Override + public String getType() { + return asset.getType(); + } + @Override public final boolean equals(Object object) { if (object == null || !this.getClass().equals(object.getClass())) { @@ -105,6 +110,14 @@ public final boolean equals(Object object) { return this.getAsset().equals(o.getAsset()); } + @Override + public int compareTo(TrustLineAsset other) { + if (other.getType() == "pool_share") { + return -1; + } + return this.getAsset().compareTo(((TrustLineAsset.Wrapper) other).getAsset()); + } + @Override public org.stellar.sdk.xdr.TrustLineAsset toXdr() { org.stellar.sdk.xdr.TrustLineAsset xdr = new org.stellar.sdk.xdr.TrustLineAsset(); @@ -116,10 +129,5 @@ public org.stellar.sdk.xdr.TrustLineAsset toXdr() { return xdr; } - - @Override - public String getType() { - return asset.getType(); - } } } From c4b7f0f427f655688ca0f306bf9fb9f9348ace46 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 14 Sep 2021 16:50:12 +0100 Subject: [PATCH 10/21] Fixing some compile errors --- .../sdk/LiquidityPoolDepositOperation.java | 22 +++---------------- .../java/org/stellar/sdk/LiquidityPoolID.java | 4 ++++ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index 6b9f58944..6bb9cfc33 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -105,23 +105,6 @@ public Builder(LiquidityPoolID liquidityPoolID, String amountA, String amountB, this.maxPrice = maxPrice; } - public Builder setA(AssetAmount _a) { - a = _a; - return this; - } - public Builder setA(Asset asset, String amount) { - a = new AssetAmount(asset, amount); - return this; - } - public Builder setB(AssetAmount _b) { - b = _b; - return this; - } - public Builder setB(Asset asset, String amount) { - b = new AssetAmount(asset, amount); - return this; - } - /** * Set source account of this operation * @param sourceAccount Source account @@ -153,8 +136,9 @@ public boolean equals(Object object) { } LiquidityPoolDepositOperation o = (LiquidityPoolDepositOperation) object; - return Objects.equal(this.getA(), o.getA()) && - Objects.equal(this.getB(), o.getB()) && + return Objects.equal(this.getLiquidityPoolID(), o.getLiquidityPoolID()) && + Objects.equal(this.getMaxAmountA(), o.getMaxAmountA()) && + Objects.equal(this.getMaxAmountB(), o.getMaxAmountB()) && Objects.equal(this.getMinPrice(), o.getMinPrice()) && Objects.equal(this.getMaxPrice(), o.getMaxPrice()); } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolID.java b/src/main/java/org/stellar/sdk/LiquidityPoolID.java index b1163c45d..f7cc1319b 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolID.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolID.java @@ -14,6 +14,10 @@ public final class LiquidityPoolID { protected final byte[] hash; LiquidityPoolID(LiquidityPoolType type, Asset a, Asset b, int fee) { + if (a.compareTo(b) >= 0) { + throw new RuntimeException("AssetA must be < AssetB"); + } + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); try { From e9cbd9f395d1c7d54f43d4ffcd9151265a00e52c Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 14 Sep 2021 18:29:44 +0100 Subject: [PATCH 11/21] Fixing up deposit builder --- .../sdk/LiquidityPoolDepositOperation.java | 76 ++++++++++++++++--- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index 6bb9cfc33..5c63a20db 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -1,9 +1,11 @@ package org.stellar.sdk; import com.google.common.base.Objects; -import org.stellar.sdk.xdr.Operation.OperationBody; +import com.google.common.base.Optional; + import org.stellar.sdk.xdr.LiquidityPoolDepositOp; import org.stellar.sdk.xdr.LiquidityPoolType; +import org.stellar.sdk.xdr.Operation.OperationBody; import org.stellar.sdk.xdr.OperationType; import static com.google.common.base.Preconditions.checkNotNull; @@ -67,16 +69,18 @@ OperationBody toOperationBody(AccountConverter accountConverter) { * @see LiquidityPoolDepositOperation */ public static class Builder { - private final LiquidityPoolID liquidityPoolID; - private final String maxAmountA; - private final String maxAmountB; - private final Price minPrice; - private final Price maxPrice; + private Optional liquidityPoolID; + private Optional a; + private Optional b; + private String maxAmountA; + private String maxAmountB; + private Price minPrice; + private Price maxPrice; private String sourceAccount; Builder(LiquidityPoolDepositOp op) { - this.liquidityPoolID = LiquidityPoolID.fromXdr(op.getLiquidityPoolID()); + this.liquidityPoolID = Optional.fromNullable(LiquidityPoolID.fromXdr(op.getLiquidityPoolID())); this.maxAmountA = Operation.fromXdrAmount(op.getMaxAmountA().getInt64().longValue()); this.maxAmountB = Operation.fromXdrAmount(op.getMaxAmountB().getInt64().longValue()); this.minPrice = Price.fromXdr(op.getMinPrice()); @@ -87,7 +91,9 @@ public static class Builder { * Creates a new LiquidityPoolDeposit builder. */ public Builder(AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { - this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee); + this.liquidityPoolID = Optional.of(new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee)); + this.a = Optional.of(a.getAsset()); + this.b = Optional.of(b.getAsset()); this.maxAmountA = a.getAmount(); this.maxAmountB = b.getAmount(); this.minPrice = minPrice; @@ -98,13 +104,59 @@ public Builder(AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { * Creates a new LiquidityPoolDeposit builder. */ public Builder(LiquidityPoolID liquidityPoolID, String amountA, String amountB, Price minPrice, Price maxPrice) { - this.liquidityPoolID = liquidityPoolID; + this.liquidityPoolID = Optional.fromNullable(liquidityPoolID); this.maxAmountA = amountA; this.maxAmountB = amountB; this.minPrice = minPrice; this.maxPrice = maxPrice; } + /** + * Set asset and amount A of this operation + * @param asset Asset A + * @param maxAmount Max amount of asset A to deposit + * @return Builder object so you can chain methods. + */ + public Builder setA(Asset asset, String maxAmount) { + this.liquidityPoolID = Optional.absent(); + this.a = Optional.of(asset); + this.maxAmountA = maxAmount; + return this; + } + + /** + * Set asset and amount B of this operation + * @param asset Asset B + * @param maxAmount Max amount of asset B to deposit + * @return Builder object so you can chain methods. + */ + public Builder setB(Asset asset, String maxAmount) { + this.liquidityPoolID = Optional.absent(); + this.b = Optional.of(asset); + this.maxAmountB = maxAmount; + return this; + } + + /** + * Set minimum price for this deposit. + * @param value Min price for this operation + * @return Builder object so you can chain methods. + */ + public Builder setMinPrice(Price value) { + this.minPrice = value; + return this; + } + + /** + * Set maximum price for this deposit. + * @param value Max price for this operation + * @return Builder object so you can chain methods. + */ + public Builder setMaxPrice(Price value) { + this.maxPrice = value; + return this; + } + /** * Set source account of this operation * @param sourceAccount Source account @@ -119,7 +171,11 @@ public Builder setSourceAccount(String sourceAccount) { * Builds an operation */ public LiquidityPoolDepositOperation build() { - LiquidityPoolDepositOperation op = new LiquidityPoolDepositOperation(liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice); + if (!liquidityPoolID.isPresent() && a.isPresent() && b.isPresent()) { + liquidityPoolID = Optional.of(new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.get(), b.get(), LiquidityPoolParameters.Fee)); + } + + LiquidityPoolDepositOperation op = new LiquidityPoolDepositOperation(liquidityPoolID.get(), maxAmountA, maxAmountB, minPrice, maxPrice); op.setSourceAccount(sourceAccount); return op; } From ea0ffca8892fe0bd02cac0a2ab2199227a995711 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 15 Sep 2021 14:05:53 +0100 Subject: [PATCH 12/21] enforce asset ordering --- .../stellar/sdk/LiquidityPoolDepositOperation.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index 5c63a20db..29c548e79 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -91,6 +91,9 @@ public static class Builder { * Creates a new LiquidityPoolDeposit builder. */ public Builder(AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { + if (a.getAsset().compareTo(b.getAsset()) >= 0) { + throw new RuntimeException("AssetA must be < AssetB"); + } this.liquidityPoolID = Optional.of(new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee)); this.a = Optional.of(a.getAsset()); this.b = Optional.of(b.getAsset()); @@ -171,8 +174,14 @@ public Builder setSourceAccount(String sourceAccount) { * Builds an operation */ public LiquidityPoolDepositOperation build() { - if (!liquidityPoolID.isPresent() && a.isPresent() && b.isPresent()) { - liquidityPoolID = Optional.of(new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.get(), b.get(), LiquidityPoolParameters.Fee)); + if (a.isPresent() && b.isPresent()) { + if (a.getAsset().compareTo(b.getAsset()) >= 0) { + throw new RuntimeException("AssetA must be < AssetB"); + } + + if (!liquidityPoolID.isPresent()) { + liquidityPoolID = Optional.of(new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.get(), b.get(), LiquidityPoolParameters.Fee)); + } } LiquidityPoolDepositOperation op = new LiquidityPoolDepositOperation(liquidityPoolID.get(), maxAmountA, maxAmountB, minPrice, maxPrice); From a66c174a24f21bea5959f867a21f51f0a4a44def Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 15 Sep 2021 15:09:35 +0100 Subject: [PATCH 13/21] Fixing up build and tests --- .../org/stellar/sdk/ChangeTrustAsset.java | 6 +- ...iquidityPoolConstantProductParameters.java | 4 +- .../sdk/LiquidityPoolDepositOperation.java | 2 +- .../java/org/stellar/sdk/LiquidityPoolID.java | 1 - .../java/org/stellar/sdk/TrustLineAsset.java | 5 +- .../LiquidityPoolsRequestBuilder.java | 2 +- .../sdk/responses/LiquidityPoolResponse.java | 6 -- src/main/java/org/stellar/sdk/xdr/Asset.java | 57 ++++++++++--------- .../LiquidityPoolDepositOperationTest.java | 30 ++++++++++ .../org/stellar/sdk/LiquidityPoolIDTest.java | 28 +++++++++ .../responses/AccountDeserializerTest.java | 37 ++++++------ .../responses/TradesPageDeserializerTest.java | 8 +-- 12 files changed, 126 insertions(+), 60 deletions(-) create mode 100644 src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java create mode 100644 src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java diff --git a/src/main/java/org/stellar/sdk/ChangeTrustAsset.java b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java index 4505e5f6a..b9e7d3f43 100644 --- a/src/main/java/org/stellar/sdk/ChangeTrustAsset.java +++ b/src/main/java/org/stellar/sdk/ChangeTrustAsset.java @@ -68,9 +68,13 @@ public static ChangeTrustAsset fromXdr(org.stellar.sdk.xdr.ChangeTrustAsset xdr) } } + public abstract String getType(); + + @Override public abstract boolean equals(Object object); - public abstract String getType(); + @Override + public abstract int compareTo(ChangeTrustAsset other); /** * Generates XDR object from a given ChangeTrustAsset object diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java index 452b12718..515e7cbf5 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java @@ -48,7 +48,9 @@ public final boolean equals(Object object) { } LiquidityPoolConstantProductParameters o = (LiquidityPoolConstantProductParameters) object; - return this.getAssetA().equals(o.getAssetA()) && this.getAssetB().equals(o.getAssetB()) && this.getFee() == o.getFee(); + return Objects.equal(this.getAssetA(), o.getAssetA()) + && Objects.equal(this.getAssetB(), o.getAssetB()) + && Objects.equal(this.getFee(), o.getFee()); } /** diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index 29c548e79..e00554703 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -175,7 +175,7 @@ public Builder setSourceAccount(String sourceAccount) { */ public LiquidityPoolDepositOperation build() { if (a.isPresent() && b.isPresent()) { - if (a.getAsset().compareTo(b.getAsset()) >= 0) { + if (a.get().compareTo(b.get()) >= 0) { throw new RuntimeException("AssetA must be < AssetB"); } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolID.java b/src/main/java/org/stellar/sdk/LiquidityPoolID.java index f7cc1319b..fb9b2cbfd 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolID.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolID.java @@ -2,7 +2,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import org.stellar.sdk.xdr.*; diff --git a/src/main/java/org/stellar/sdk/TrustLineAsset.java b/src/main/java/org/stellar/sdk/TrustLineAsset.java index 538a7548e..ef9deae87 100644 --- a/src/main/java/org/stellar/sdk/TrustLineAsset.java +++ b/src/main/java/org/stellar/sdk/TrustLineAsset.java @@ -72,10 +72,13 @@ public static TrustLineAsset fromXdr(org.stellar.sdk.xdr.TrustLineAsset xdr) { } } + public abstract String getType(); + @Override public abstract boolean equals(Object object); - public abstract String getType(); + @Override + public abstract int compareTo(TrustLineAsset other); /** * Generates XDR object from a given TrustLineAsset object diff --git a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java index 6964f5a00..254787c06 100644 --- a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java @@ -5,7 +5,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import org.stellar.sdk.AssetTypeCreditAlphaNum; + import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.responses.LiquidityPoolResponse; import org.stellar.sdk.responses.Page; diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java index 333e3e381..46c0e75a2 100644 --- a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java @@ -1,16 +1,10 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; -import com.google.common.io.BaseEncoding; import com.google.gson.annotations.SerializedName; import org.stellar.sdk.Asset; -import org.stellar.sdk.AssetTypeNative; -import org.stellar.sdk.KeyPair; import org.stellar.sdk.LiquidityPoolID; -import java.util.HashMap; - import static com.google.common.base.Preconditions.checkNotNull; /** diff --git a/src/main/java/org/stellar/sdk/xdr/Asset.java b/src/main/java/org/stellar/sdk/xdr/Asset.java index 542c98471..3093903bf 100644 --- a/src/main/java/org/stellar/sdk/xdr/Asset.java +++ b/src/main/java/org/stellar/sdk/xdr/Asset.java @@ -79,39 +79,44 @@ public Asset build() { } public static void encode(XdrDataOutputStream stream, Asset encodedAsset) throws IOException { - //Xdrgen::AST::Identifier - //AssetType - stream.writeInt(encodedAsset.getDiscriminant().getValue()); - switch (encodedAsset.getDiscriminant()) { - case ASSET_TYPE_NATIVE: - break; - case ASSET_TYPE_CREDIT_ALPHANUM4: - AlphaNum4.encode(stream, encodedAsset.alphaNum4); - break; - case ASSET_TYPE_CREDIT_ALPHANUM12: - AlphaNum12.encode(stream, encodedAsset.alphaNum12); - break; - } + //Xdrgen::AST::Identifier + //AssetType + stream.writeInt(encodedAsset.getDiscriminant().getValue()); + switch (encodedAsset.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + break; + case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4.encode(stream, encodedAsset.alphaNum4); + break; + case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12.encode(stream, encodedAsset.alphaNum12); + break; + case ASSET_TYPE_POOL_SHARE: + throw new RuntimeException("Invalid asset type"); + } } public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } public static Asset decode(XdrDataInputStream stream) throws IOException { - Asset decodedAsset = new Asset(); - AssetType discriminant = AssetType.decode(stream); - decodedAsset.setDiscriminant(discriminant); - switch (decodedAsset.getDiscriminant()) { - case ASSET_TYPE_NATIVE: - break; - case ASSET_TYPE_CREDIT_ALPHANUM4: - decodedAsset.alphaNum4 = AlphaNum4.decode(stream); - break; - case ASSET_TYPE_CREDIT_ALPHANUM12: - decodedAsset.alphaNum12 = AlphaNum12.decode(stream); - break; - } + Asset decodedAsset = new Asset(); + AssetType discriminant = AssetType.decode(stream); + decodedAsset.setDiscriminant(discriminant); + switch (decodedAsset.getDiscriminant()) { + case ASSET_TYPE_NATIVE: + break; + case ASSET_TYPE_CREDIT_ALPHANUM4: + decodedAsset.alphaNum4 = AlphaNum4.decode(stream); + break; + case ASSET_TYPE_CREDIT_ALPHANUM12: + decodedAsset.alphaNum12 = AlphaNum12.decode(stream); + break; + case ASSET_TYPE_POOL_SHARE: + throw new RuntimeException("Invalid asset type"); + } return decodedAsset; } + @Override public int hashCode() { return Objects.hashCode(this.alphaNum4, this.alphaNum12, this.type); diff --git a/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java b/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java new file mode 100644 index 000000000..82150ead6 --- /dev/null +++ b/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java @@ -0,0 +1,30 @@ +package org.stellar.sdk; + +import com.google.common.collect.Lists; +import org.junit.Test; +import org.stellar.sdk.xdr.SignerKey; +import org.stellar.sdk.xdr.TrustLineFlags; +import org.stellar.sdk.xdr.XdrDataInputStream; + +import com.google.common.io.BaseEncoding; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.EnumSet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class LiquidityPoolDepositOperationTest { + @Test + public void testLiquidityPoolDepositOperationValid() { + fail(); + } + + @Test + public void testLiquidityPoolDepositOperationMisorderedAssets() { + fail(); + } +} diff --git a/src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java b/src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java new file mode 100644 index 000000000..b64e0ed8d --- /dev/null +++ b/src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java @@ -0,0 +1,28 @@ +package org.stellar.sdk; + +import org.junit.Test; + +import org.stellar.sdk.xdr.LiquidityPoolType; + +import static org.junit.Assert.*; + +public class LiquidityPoolIDTest { + private final Asset a = Asset.create("native"); + private final Asset b = Asset.createNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); + + @Test + public void testLiquidityPoolID() { + LiquidityPoolID id = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a, b, LiquidityPoolParameters.Fee); + assertEquals("cc22414997d7e3d9a9ac3b1d65ca9cc3e5f35ce33e0bd6a885648b11aaa3b72d", id.toString()); + } + + @Test + public void testLiquidityPoolIDMisorderedAssets() { + try { + new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, b, a, LiquidityPoolParameters.Fee); + fail(); + } catch (RuntimeException e) { + assertEquals("AssetA must be < AssetB", e.getMessage()); + } + } +} diff --git a/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java index 745c88a46..6860e4102 100644 --- a/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java @@ -1,5 +1,6 @@ package org.stellar.sdk.responses; +import com.google.common.base.Optional; import junit.framework.TestCase; import org.junit.Test; @@ -12,19 +13,19 @@ public void testDeserializeBalanceAuth() { AccountResponse account = GsonSingleton.getInstance().fromJson(jsonAuthorizedToMaintainLiabilities, AccountResponse.class); assertEquals(account.getBalances()[0].getAssetType(), "credit_alphanum4"); - assertEquals(account.getBalances()[0].getAssetCode(), "ABC"); - assertEquals(account.getBalances()[0].getAssetIssuer(), "GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU"); + assertEquals(account.getBalances()[0].getAssetCode(), Optional.of("ABC")); + assertEquals(account.getBalances()[0].getAssetIssuer(), Optional.of("GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU")); assertEquals(account.getBalances()[0].getBalance(), "1001.0000000"); assertEquals(account.getBalances()[0].getLimit(), "12000.4775807"); - assertEquals(account.getBalances()[0].getBuyingLiabilities(), "100.1234567"); - assertEquals(account.getBalances()[0].getSellingLiabilities(), "100.7654321"); + assertEquals(account.getBalances()[0].getBuyingLiabilities(), Optional.of("100.1234567")); + assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.of("100.7654321")); assertEquals(account.getBalances()[0].getAuthorized(), Boolean.FALSE); assertEquals(account.getBalances()[0].getAuthorizedToMaintainLiabilities(), Boolean.TRUE); assertEquals(account.getBalances()[1].getAssetType(), "native"); assertEquals(account.getBalances()[1].getBalance(), "20.0000300"); - assertEquals(account.getBalances()[1].getBuyingLiabilities(), "5.1234567"); - assertEquals(account.getBalances()[1].getSellingLiabilities(), "1.7654321"); + assertEquals(account.getBalances()[1].getBuyingLiabilities(), Optional.of("5.1234567")); + assertEquals(account.getBalances()[1].getSellingLiabilities(), Optional.of("1.7654321")); assertEquals(account.getBalances()[1].getLimit(), null); } @@ -47,18 +48,18 @@ public void testDeserialize() { assertEquals(account.getFlags().getAuthImmutable(), true); assertEquals(account.getBalances()[0].getAssetType(), "credit_alphanum4"); - assertEquals(account.getBalances()[0].getAssetCode(), "ABC"); - assertEquals(account.getBalances()[0].getAssetIssuer(), "GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU"); + assertEquals(account.getBalances()[0].getAssetCode(), Optional.of("ABC")); + assertEquals(account.getBalances()[0].getAssetIssuer(), Optional.of("GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU")); assertEquals(account.getBalances()[0].getBalance(), "1001.0000000"); assertEquals(account.getBalances()[0].getLimit(), "12000.4775807"); - assertEquals(account.getBalances()[0].getBuyingLiabilities(), "100.1234567"); - assertEquals(account.getBalances()[0].getSellingLiabilities(), "100.7654321"); + assertEquals(account.getBalances()[0].getBuyingLiabilities(), Optional.of("100.1234567")); + assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.of("100.7654321")); assertFalse(account.getBalances()[0].getSponsor().isPresent()); assertEquals(account.getBalances()[1].getAssetType(), "native"); assertEquals(account.getBalances()[1].getBalance(), "20.0000300"); - assertEquals(account.getBalances()[1].getBuyingLiabilities(), "5.1234567"); - assertEquals(account.getBalances()[1].getSellingLiabilities(), "1.7654321"); + assertEquals(account.getBalances()[1].getBuyingLiabilities(), Optional.of("5.1234567")); + assertEquals(account.getBalances()[1].getSellingLiabilities(), Optional.of("1.7654321")); assertEquals(account.getBalances()[1].getLimit(), null); assertFalse(account.getBalances()[1].getSponsor().isPresent()); @@ -101,17 +102,17 @@ public void testDeserializeV9() { AccountResponse account = GsonSingleton.getInstance().fromJson(jsonV9, AccountResponse.class); assertEquals(account.getBalances()[0].getAssetType(), "credit_alphanum4"); - assertEquals(account.getBalances()[0].getAssetCode(), "ABC"); - assertEquals(account.getBalances()[0].getAssetIssuer(), "GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU"); + assertEquals(account.getBalances()[0].getAssetCode(), Optional.of("ABC")); + assertEquals(account.getBalances()[0].getAssetIssuer(), Optional.of("GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU")); assertEquals(account.getBalances()[0].getBalance(), "1001.0000000"); assertEquals(account.getBalances()[0].getLimit(), "12000.4775807"); - assertEquals(account.getBalances()[0].getBuyingLiabilities(), null); - assertEquals(account.getBalances()[0].getSellingLiabilities(), null); + assertEquals(account.getBalances()[0].getBuyingLiabilities(), Optional.absent()); + assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.absent()); assertEquals(account.getBalances()[1].getAssetType(), "native"); assertEquals(account.getBalances()[1].getBalance(), "20.0000300"); - assertEquals(account.getBalances()[1].getBuyingLiabilities(), null); - assertEquals(account.getBalances()[1].getSellingLiabilities(), null); + assertEquals(account.getBalances()[1].getBuyingLiabilities(), Optional.absent()); + assertEquals(account.getBalances()[1].getSellingLiabilities(), Optional.absent()); assertEquals(account.getBalances()[1].getLimit(), null); } diff --git a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java index 3dae35d2f..6092b65bd 100644 --- a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java @@ -1,11 +1,11 @@ package org.stellar.sdk.responses; +import com.google.common.base.Optional; import com.google.gson.reflect.TypeToken; import junit.framework.TestCase; import org.junit.Test; import org.stellar.sdk.Asset; import org.stellar.sdk.AssetTypeNative; -import org.stellar.sdk.KeyPair; public class TradesPageDeserializerTest extends TestCase { @Test @@ -20,14 +20,14 @@ public void testDeserialize() { assertEquals(tradesPage.getRecords().get(0).getPagingToken(), "3697472920621057-0"); assertEquals(tradesPage.getRecords().get(0).getLedgerCloseTime(), "2015-11-18T03:47:47Z"); assertEquals(tradesPage.getRecords().get(0).getOfferId(), "9"); - assertEquals(tradesPage.getRecords().get(0).getBaseOfferId(), "10"); - assertEquals(tradesPage.getRecords().get(0).getCounterOfferId(), "11"); + assertEquals(tradesPage.getRecords().get(0).getBaseOfferId(), Optional.of("10")); + assertEquals(tradesPage.getRecords().get(0).getCounterOfferId(), Optional.of("11")); assertEquals(tradesPage.getRecords().get(0).getBaseAsset(), new AssetTypeNative()); assertEquals(tradesPage.getRecords().get(0).getCounterAsset(), Asset.createNonNativeAsset("JPY", "GBVAOIACNSB7OVUXJYC5UE2D4YK2F7A24T7EE5YOMN4CE6GCHUTOUQXM")); assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), 267); assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), 1000); - assertEquals(tradesPage.getRecords().get(1).getBaseAccount(), "GAVH5JM5OKXGMQDS7YPRJ4MQCPXJUGH26LYQPQJ4SOMOJ4SXY472ZM7G"); + assertEquals(tradesPage.getRecords().get(1).getBaseAccount(), Optional.of("GAVH5JM5OKXGMQDS7YPRJ4MQCPXJUGH26LYQPQJ4SOMOJ4SXY472ZM7G")); } String json = "{\n" + From e4abedc3d5c7a4e09530fcf91421409e8e730444 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 16 Sep 2021 17:56:06 +0100 Subject: [PATCH 14/21] WIP --- .../sdk/LiquidityPoolDepositOperation.java | 14 ++- .../java/org/stellar/sdk/LiquidityPoolID.java | 9 +- .../sdk/LiquidityPoolWithdrawOperation.java | 19 ++- .../sdk/requests/EffectsRequestBuilder.java | 15 ++- .../LiquidityPoolsRequestBuilder.java | 5 +- .../requests/OperationsRequestBuilder.java | 15 ++- .../sdk/requests/TradesRequestBuilder.java | 20 +++ .../requests/TransactionsRequestBuilder.java | 11 +- .../sdk/responses/AssetDeserializer.java | 4 + .../stellar/sdk/responses/GsonSingleton.java | 6 + .../LiquidityPoolIDDeserializer.java | 17 +++ .../sdk/responses/LiquidityPoolResponse.java | 30 ++++- .../LiquidityPoolTypeDeserializer.java | 19 +++ .../org/stellar/sdk/responses/TradePrice.java | 68 ++++++++++ .../stellar/sdk/responses/TradeResponse.java | 7 +- src/test/java/org/stellar/sdk/AssetTest.java | 116 ++++++++++++++++++ .../LiquidityPoolDepositOperationTest.java | 92 +++++++++++--- .../org/stellar/sdk/LiquidityPoolIDTest.java | 14 +++ .../LiquidityPoolWithdrawOperationTest.java | 85 +++++++++++++ .../requests/EffectsRequestBuilderTest.java | 10 ++ .../requests/LedgersRequestBuilderTest.java | 2 +- .../LiquidityPoolsRequestBuilderTest.java | 29 +++++ .../OperationsRequestBuilderTest.java | 10 ++ .../requests/TradesRequestBuilderTest.java | 11 +- .../TransactionsRequestBuilderTest.java | 10 ++ .../sdk/responses/AssetDeserializerTest.java | 17 +++ .../LiquidityPoolIDDeserializerTest.java | 16 +++ .../responses/LiquidityPoolResponseTest.java | 81 ++++++++++++ 28 files changed, 703 insertions(+), 49 deletions(-) create mode 100644 src/main/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializer.java create mode 100644 src/main/java/org/stellar/sdk/responses/LiquidityPoolTypeDeserializer.java create mode 100644 src/main/java/org/stellar/sdk/responses/TradePrice.java create mode 100644 src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java create mode 100644 src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java create mode 100644 src/test/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializerTest.java create mode 100644 src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index e00554703..5a8b62f75 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -69,15 +69,15 @@ OperationBody toOperationBody(AccountConverter accountConverter) { * @see LiquidityPoolDepositOperation */ public static class Builder { - private Optional liquidityPoolID; - private Optional a; - private Optional b; + private Optional liquidityPoolID = Optional.absent(); + private Optional a = Optional.absent(); + private Optional b = Optional.absent(); private String maxAmountA; private String maxAmountB; private Price minPrice; private Price maxPrice; - private String sourceAccount; + private String mSourceAccount; Builder(LiquidityPoolDepositOp op) { this.liquidityPoolID = Optional.fromNullable(LiquidityPoolID.fromXdr(op.getLiquidityPoolID())); @@ -166,7 +166,7 @@ public Builder setMaxPrice(Price value) { * @return Builder object so you can chain methods. */ public Builder setSourceAccount(String sourceAccount) { - this.sourceAccount = sourceAccount; + mSourceAccount = sourceAccount; return this; } @@ -185,7 +185,9 @@ public LiquidityPoolDepositOperation build() { } LiquidityPoolDepositOperation op = new LiquidityPoolDepositOperation(liquidityPoolID.get(), maxAmountA, maxAmountB, minPrice, maxPrice); - op.setSourceAccount(sourceAccount); + if (mSourceAccount != null) { + op.setSourceAccount(mSourceAccount); + } return op; } } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolID.java b/src/main/java/org/stellar/sdk/LiquidityPoolID.java index fb9b2cbfd..6557b2772 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolID.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolID.java @@ -1,5 +1,6 @@ package org.stellar.sdk; +import com.google.common.base.Objects; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -12,7 +13,7 @@ public final class LiquidityPoolID { protected final byte[] hash; - LiquidityPoolID(LiquidityPoolType type, Asset a, Asset b, int fee) { + public LiquidityPoolID(LiquidityPoolType type, Asset a, Asset b, int fee) { if (a.compareTo(b) >= 0) { throw new RuntimeException("AssetA must be < AssetB"); } @@ -27,11 +28,11 @@ public final class LiquidityPoolID { hash = Util.hash(byteArrayOutputStream.toByteArray()); } - LiquidityPoolID(String hex) { + public LiquidityPoolID(String hex) { hash = Util.hexToBytes(hex.toUpperCase()); } - LiquidityPoolID(byte[] bytes) { + public LiquidityPoolID(byte[] bytes) { hash = bytes; } @@ -56,7 +57,7 @@ public boolean equals(Object object) { LiquidityPoolID o = (LiquidityPoolID) object; - return this.toString() == o.toString(); + return Objects.equal(this.toString(), o.toString()); } /** diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java index 516ca9df0..f1da62820 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java @@ -2,6 +2,7 @@ import com.google.common.base.Objects; import org.stellar.sdk.xdr.Operation.OperationBody; +import org.stellar.sdk.xdr.LiquidityPoolType; import org.stellar.sdk.xdr.LiquidityPoolWithdrawOp; import org.stellar.sdk.xdr.OperationType; @@ -64,7 +65,7 @@ public static class Builder { private String minAmountA; private String minAmountB; - private String sourceAccount; + private String mSourceAccount; Builder(LiquidityPoolWithdrawOp op) { this.liquidityPoolID = LiquidityPoolID.fromXdr(op.getLiquidityPoolID()); @@ -83,6 +84,16 @@ public Builder(LiquidityPoolID liquidityPoolID, String amount, String minAmountA this.minAmountB = minAmountB; } + /** + * Creates a new LiquidityPoolDeposit builder. + */ + public Builder(AssetAmount a, AssetAmount b, String amount) { + this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee); + this.amount = amount; + this.minAmountA = a.getAmount(); + this.minAmountB = b.getAmount(); + } + public Builder setLiquidityPoolID(LiquidityPoolID liquidityPoolID) { this.liquidityPoolID = liquidityPoolID; return this; @@ -109,7 +120,7 @@ public Builder setMinAmountB(String minAmountB) { * @return Builder object so you can chain methods. */ public Builder setSourceAccount(String sourceAccount) { - this.sourceAccount = sourceAccount; + mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); return this; } @@ -118,7 +129,9 @@ public Builder setSourceAccount(String sourceAccount) { */ public LiquidityPoolWithdrawOperation build() { LiquidityPoolWithdrawOperation op = new LiquidityPoolWithdrawOperation(liquidityPoolID, amount, minAmountA, minAmountB); - op.setSourceAccount(sourceAccount); + if (mSourceAccount != null) { + op.setSourceAccount(mSourceAccount); + } return op; } } diff --git a/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java index 31fa4f5d3..40301c11c 100644 --- a/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java @@ -55,12 +55,21 @@ public EffectsRequestBuilder forTransaction(String transactionId) { } /** - * Builds request to GET /liquidity_pools/{ledgerSeq}/effects - * @see Transactions for Liquidity Pool + * Builds request to GET /liquidity_pools/{poolID}/effects + * @see Effects for Liquidity Pool * @param liquidityPoolID Liquidity pool for which to get effects */ public EffectsRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { - this.setSegments("liquidity_pools", String.valueOf(liquidityPoolID), "effects"); + return this.forLiquidityPool(String.valueOf(liquidityPoolID)); + } + + /** + * Builds request to GET /liquidity_pools/{poolID}/effects + * @see Effects for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get effects + */ + public EffectsRequestBuilder forLiquidityPool(String liquidityPoolID) { + this.setSegments("liquidity_pools", liquidityPoolID, "effects"); return this; } diff --git a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java index 254787c06..e6562f341 100644 --- a/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilder.java @@ -58,15 +58,14 @@ public LiquidityPoolResponse liquidityPool(LiquidityPoolID liquidityPoolID) thro return this.liquidityPool(liquidityPoolID.toString()); } - /** * Returns all liquidity pools that contain reserves in all specified assets. * - * @param signer Liquidity Pool ID + * @param reserves Reserve assets to filter liquidity pools * @return current {@link LiquidityPoolsRequestBuilder} instance * @see LiquidityPools */ - public LiquidityPoolsRequestBuilder forReserves(String[] reserves) { + public LiquidityPoolsRequestBuilder forReserves(String... reserves) { uriBuilder.setQueryParameter(RESERVES_PARAMETER_NAME, String.join(",", reserves)); return this; } diff --git a/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java index d53f12dc4..90066f2d2 100644 --- a/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java @@ -98,12 +98,21 @@ public OperationsRequestBuilder forTransaction(String transactionId) { } /** - * Builds request to GET /liquidity_pools/{ledgerSeq}/operations - * @see Transactions for Liquidity Pool + * Builds request to GET /liquidity_pools/{poolID}/operations + * @see Operations for Liquidity Pool * @param liquidityPoolID Liquidity pool for which to get operations */ public OperationsRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { - this.setSegments("liquidity_pools", String.valueOf(liquidityPoolID), "operations"); + return this.forLiquidityPool(String.valueOf(liquidityPoolID)); + } + + /** + * Builds request to GET /liquidity_pools/{poolID}/operations + * @see Operations for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get operations + */ + public OperationsRequestBuilder forLiquidityPool(String liquidityPoolID) { + this.setSegments("liquidity_pools", liquidityPoolID, "operations"); return this; } diff --git a/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java index c822275e9..6eae2457c 100644 --- a/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java @@ -8,6 +8,7 @@ import okhttp3.Response; import org.stellar.sdk.Asset; import org.stellar.sdk.AssetTypeCreditAlphaNum; +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.responses.Page; import org.stellar.sdk.responses.TradeResponse; @@ -54,6 +55,25 @@ public TradesRequestBuilder forAccount(String account) { return this; } + /** + * Builds request to GET /liquidity_pools/{poolID}/trades + * @see Trades for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get trades + */ + public TradesRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { + return this.forLiquidityPool(String.valueOf(liquidityPoolID)); + } + + /** + * Builds request to GET /liquidity_pools/{poolID}/trades + * @see Trades for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get trades + */ + public TradesRequestBuilder forLiquidityPool(String liquidityPoolID) { + this.setSegments("liquidity_pools", String.valueOf(liquidityPoolID), "trades"); + return this; + } + /** * Returns all trades that of a specific type. * diff --git a/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java index 52253d748..78d30c81e 100644 --- a/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java @@ -86,7 +86,16 @@ public TransactionsRequestBuilder forLedger(long ledgerSeq) { * @param liquidityPoolID Liquidity pool for which to get transactions */ public TransactionsRequestBuilder forLiquidityPool(LiquidityPoolID liquidityPoolID) { - this.setSegments("liquidity_pools", String.valueOf(liquidityPoolID), "transactions"); + return this.forLiquidityPool(String.valueOf(liquidityPoolID)); + } + + /** + * Builds request to GET /liquidity_pools/{ledgerSeq}/transactions + * @see Transactions for Liquidity Pool + * @param liquidityPoolID Liquidity pool for which to get transactions + */ + public TransactionsRequestBuilder forLiquidityPool(String liquidityPoolID) { + this.setSegments("liquidity_pools", liquidityPoolID, "transactions"); return this; } diff --git a/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java b/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java index 6cfc79cc7..4cd05f66a 100644 --- a/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java @@ -13,6 +13,10 @@ class AssetDeserializer implements JsonDeserializer { @Override public Asset deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (!json.isJsonObject()) { + // Probably a canonical string + return Asset.create(json.getAsString()); + } String type = json.getAsJsonObject().get("asset_type").getAsString(); if (type.equals("native")) { return new AssetTypeNative(); diff --git a/src/main/java/org/stellar/sdk/responses/GsonSingleton.java b/src/main/java/org/stellar/sdk/responses/GsonSingleton.java index bdcaf746a..70e9afb15 100644 --- a/src/main/java/org/stellar/sdk/responses/GsonSingleton.java +++ b/src/main/java/org/stellar/sdk/responses/GsonSingleton.java @@ -6,8 +6,10 @@ import org.stellar.sdk.Asset; import org.stellar.sdk.Predicate; +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.responses.effects.EffectResponse; import org.stellar.sdk.responses.operations.OperationResponse; +import org.stellar.sdk.xdr.LiquidityPoolType; public class GsonSingleton { private static Gson instance = null; @@ -20,6 +22,7 @@ public static Gson getInstance() { TypeToken assetPageType = new TypeToken>() {}; TypeToken effectPageType = new TypeToken>() {}; TypeToken ledgerPageType = new TypeToken>() {}; + TypeToken liquidityPoolPageType = new TypeToken>() {}; TypeToken offerPageType = new TypeToken>() {}; TypeToken operationPageType = new TypeToken>() {}; TypeToken pathPageType = new TypeToken>() {}; @@ -33,11 +36,14 @@ public static Gson getInstance() { .registerTypeAdapter(Predicate.class, new PredicateDeserializer()) .registerTypeAdapter(OperationResponse.class, new OperationDeserializer()) .registerTypeAdapter(EffectResponse.class, new EffectDeserializer()) + .registerTypeAdapter(LiquidityPoolID.class, new LiquidityPoolIDDeserializer()) + .registerTypeAdapter(LiquidityPoolType.class, new LiquidityPoolTypeDeserializer()) .registerTypeAdapter(TransactionResponse.class, new TransactionDeserializer()) .registerTypeAdapter(accountPageType.getType(), new PageDeserializer(accountPageType)) .registerTypeAdapter(assetPageType.getType(), new PageDeserializer(assetPageType)) .registerTypeAdapter(effectPageType.getType(), new PageDeserializer(effectPageType)) .registerTypeAdapter(ledgerPageType.getType(), new PageDeserializer(ledgerPageType)) + .registerTypeAdapter(liquidityPoolPageType.getType(), new PageDeserializer(liquidityPoolPageType)) .registerTypeAdapter(offerPageType.getType(), new PageDeserializer(offerPageType)) .registerTypeAdapter(operationPageType.getType(), new PageDeserializer(operationPageType)) .registerTypeAdapter(pathPageType.getType(), new PageDeserializer(pathPageType)) diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializer.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializer.java new file mode 100644 index 000000000..87c39b941 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializer.java @@ -0,0 +1,17 @@ +package org.stellar.sdk.responses; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; + +import org.stellar.sdk.LiquidityPoolID; + +import java.lang.reflect.Type; + +class LiquidityPoolIDDeserializer implements JsonDeserializer { + @Override + public LiquidityPoolID deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + return new LiquidityPoolID(json.getAsString()); + } +} diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java index 46c0e75a2..666d720fd 100644 --- a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java @@ -1,12 +1,16 @@ package org.stellar.sdk.responses; +import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; import org.stellar.sdk.Asset; import org.stellar.sdk.LiquidityPoolID; +import org.stellar.sdk.xdr.LiquidityPoolType; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.errorprone.annotations.ForOverride; + /** * Represents liquidity pool response. * @see Liquidity Pool documentation @@ -21,7 +25,7 @@ public class LiquidityPoolResponse extends Response { @SerializedName("fee_bp") private Integer feeBP; @SerializedName("type") - private String type; + private LiquidityPoolType type; @SerializedName("total_trustlines") private String totalTrustlines; @SerializedName("total_shares") @@ -47,7 +51,7 @@ public Integer getFeeBP() { return feeBP; } - public String getType() { + public LiquidityPoolType getType() { return type; } @@ -70,20 +74,36 @@ public static class Reserve { @SerializedName("amount") private final String amount; @SerializedName("asset") - private final String asset; + private final Asset asset; + + public Reserve(String amount, String asset) { + this.amount = checkNotNull(amount, "amount cannot be null"); + this.asset = Asset.create(checkNotNull(asset, "asset cannot be null")); + } - Reserve(String amount, String asset) { + public Reserve(String amount, Asset asset) { this.amount = checkNotNull(amount, "amount cannot be null"); this.asset = checkNotNull(asset, "asset cannot be null"); } public Asset getAsset() { - return Asset.create(asset); + return asset; } public String getAmount() { return amount; } + + @Override + public boolean equals(Object other) { + if (!(other instanceof LiquidityPoolResponse.Reserve)) { + return false; + } + + LiquidityPoolResponse.Reserve o = (LiquidityPoolResponse.Reserve) other; + return Objects.equal(this.getAsset(), o.getAsset()) + && Objects.equal(this.getAmount(), o.getAmount()); + } } public Links getLinks() { diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolTypeDeserializer.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolTypeDeserializer.java new file mode 100644 index 000000000..baf7fc640 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolTypeDeserializer.java @@ -0,0 +1,19 @@ +package org.stellar.sdk.responses; + +import com.google.gson.*; +import org.stellar.sdk.xdr.LiquidityPoolType; + +import java.lang.reflect.Type; + +public class LiquidityPoolTypeDeserializer implements JsonDeserializer { + @Override + public LiquidityPoolType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + String s = json.getAsString(); + if (s.equals("constant_product")) { + return LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT; + } + + throw new IllegalArgumentException("Unsupported liquidity pool type: "+json.toString()); + } + +} diff --git a/src/main/java/org/stellar/sdk/responses/TradePrice.java b/src/main/java/org/stellar/sdk/responses/TradePrice.java new file mode 100644 index 000000000..3d3d270e6 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/TradePrice.java @@ -0,0 +1,68 @@ +package org.stellar.sdk.responses; + +import com.google.common.base.Objects; +import com.google.gson.annotations.SerializedName; + +import java.math.BigDecimal; +import java.math.MathContext; + +/** + * Represents Price. Price in Stellar is represented as a fraction. + */ +public class TradePrice { + @SerializedName("n") + private final String n; + @SerializedName("d") + private final String d; + + /** + * Create a new price. Price in Stellar is represented as a fraction. + * @param n numerator + * @param d denominator + */ + public TradePrice(String n, String d) { + this.n = n; + this.d = d; + } + + /** + * Returns numerator. + */ + public String getNumerator() { + return n; + } + + /** + * Returns denominator + */ + public String getDenominator() { + return d; + } + + /** + * Returns price as a string. + */ + public String toString() { + MathContext mc = MathContext.DECIMAL64; + BigDecimal result = new BigDecimal(this.n).divide(new BigDecimal(this.d), mc); + + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.getNumerator(), this.getDenominator()); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof TradePrice)) { + return false; + } + + TradePrice other = (TradePrice) object; + return this.getNumerator() == other.getNumerator() && + this.getDenominator() == other.getDenominator(); + + } +} diff --git a/src/main/java/org/stellar/sdk/responses/TradeResponse.java b/src/main/java/org/stellar/sdk/responses/TradeResponse.java index cf8ff9e7d..7ac14e697 100644 --- a/src/main/java/org/stellar/sdk/responses/TradeResponse.java +++ b/src/main/java/org/stellar/sdk/responses/TradeResponse.java @@ -4,7 +4,6 @@ import com.google.gson.annotations.SerializedName; import org.stellar.sdk.Asset; -import org.stellar.sdk.Price; import org.stellar.sdk.LiquidityPoolID; /** @@ -58,12 +57,12 @@ public class TradeResponse extends Response implements Pageable { protected final String counterAssetIssuer; @SerializedName("price") - protected final Price price; + protected final TradePrice price; @SerializedName("_links") private TradeResponse.Links links; - public TradeResponse(String id, String pagingToken, String ledgerCloseTime, String offerId, boolean baseIsSeller, String baseAccount, LiquidityPoolID baseLiquidityPoolID, String baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, LiquidityPoolID counterLiquidityPoolID, String counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, Price price) { + public TradeResponse(String id, String pagingToken, String ledgerCloseTime, String offerId, boolean baseIsSeller, String baseAccount, LiquidityPoolID baseLiquidityPoolID, String baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, LiquidityPoolID counterLiquidityPoolID, String counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, TradePrice price) { this.id = id; this.pagingToken = pagingToken; this.ledgerCloseTime = ledgerCloseTime; @@ -170,7 +169,7 @@ public String getCounterAssetIssuer() { return counterAssetIssuer; } - public Price getPrice() { + public TradePrice getPrice() { return price; } diff --git a/src/test/java/org/stellar/sdk/AssetTest.java b/src/test/java/org/stellar/sdk/AssetTest.java index ceddf3e22..9c0a5168e 100644 --- a/src/test/java/org/stellar/sdk/AssetTest.java +++ b/src/test/java/org/stellar/sdk/AssetTest.java @@ -1,7 +1,11 @@ package org.stellar.sdk; import org.junit.Test; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -11,6 +15,7 @@ * Created by andrewrogers on 7/1/15. */ public class AssetTest { + Asset xlm = Asset.create("native"); @Test public void testAssetTypeNative() { @@ -79,4 +84,115 @@ public void testAssetEquals() { assertFalse(new AssetTypeCreditAlphaNum12("ABCDE", issuer1).equals(new AssetTypeCreditAlphaNum12("EDCBA", issuer1))); assertFalse(new AssetTypeCreditAlphaNum12("ABCDE", issuer1).equals(new AssetTypeCreditAlphaNum12("ABCDE", issuer2))); } + + @Test + public void testAssetCompareTo0IfAssetsEqual() { + Asset assetA = Asset.createNonNativeAsset( + "ARST", + "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO" + ); + + Asset assetB = Asset.createNonNativeAsset( + "USD", + "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ" + ); + + assertEquals(0, xlm.compareTo(xlm)); + assertEquals(0, assetA.compareTo(assetA)); + assertEquals(0, assetB.compareTo(assetB)); + } + + @Test + public void testAssetCompareToOrderingByType() { + Asset anum4 = Asset.createNonNativeAsset( + "ARSZ", + "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO" + ); + Asset anum12 = Asset.createNonNativeAsset( + "ARSTANUM12", + "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO" + ); + + assertEquals(0, xlm.compareTo(xlm)); + assertEquals(-1, xlm.compareTo(anum4)); + assertEquals(-1, xlm.compareTo(anum12)); + + assertEquals(1, anum4.compareTo(xlm)); + assertEquals(0, anum4.compareTo(anum4)); + assertEquals(-1, anum4.compareTo(anum12)); + + assertEquals(1, anum12.compareTo(xlm)); + assertEquals(1, anum12.compareTo(anum4)); + assertEquals(0, anum12.compareTo(anum12)); + } + + @Test + public void testAssetCompareToOrderingByCode() { + Asset assetARST = Asset.createNonNativeAsset( + "ARST", + "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO" + ); + Asset assetUSDX = Asset.createNonNativeAsset( + "USDX", + "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO" + ); + + assertEquals(0, assetARST.compareTo(assetARST)); + assertTrue(assetARST.compareTo(assetUSDX) < 0); + + assertTrue(assetUSDX.compareTo(assetARST) > 0); + assertEquals(0, assetUSDX.compareTo(assetUSDX)); + } + + @Test + public void testAssetCompareToOrderingByIssuer() { + Asset assetIssuerA = Asset.createNonNativeAsset( + "ARST", + "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO" + ); + Asset assetIssuerB = Asset.createNonNativeAsset( + "ARST", + "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ" + ); + + assertTrue(assetIssuerA.compareTo(assetIssuerB) < 0); + assertEquals(0, assetIssuerA.compareTo(assetIssuerA)); + + assertTrue(assetIssuerB.compareTo(assetIssuerA) > 0); + assertEquals(0, assetIssuerB.compareTo(assetIssuerB)); + } + + @Test + public void testAssetsAreSortable() { + // Native is always first + Asset a = Asset.create("native"); + // Type is Alphanum4 + Asset b = Asset.createNonNativeAsset("BCDE", "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO"); + + // Type is Alphanum12 + Asset c = Asset.createNonNativeAsset("ABCD1", "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO"); + + // Code is > + Asset d = Asset.createNonNativeAsset("ABCD2", "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO"); + + // Issuer is > + Asset e = Asset.createNonNativeAsset("ABCD2", "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ"); + + Asset[] expected = {a, b, c, d, e}; + + // Basic sorting check that it doesn't reorder stuff + List assets = Arrays.asList(new Asset[]{a, b, c, d, e}); + Collections.sort(assets); + assertArrayEquals(expected, assets.toArray()); + + // Reverse it and check it still sorts the same + Collections.reverse(assets); + Collections.sort(assets); + assertArrayEquals(expected, assets.toArray()); + + // Shuffle it and check it still sorts to the same + Collections.shuffle(assets); + Collections.sort(assets); + assertArrayEquals(expected, assets.toArray()); + } } diff --git a/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java b/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java index 82150ead6..ae7af44ab 100644 --- a/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java +++ b/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java @@ -1,30 +1,92 @@ package org.stellar.sdk; -import com.google.common.collect.Lists; import org.junit.Test; -import org.stellar.sdk.xdr.SignerKey; -import org.stellar.sdk.xdr.TrustLineFlags; -import org.stellar.sdk.xdr.XdrDataInputStream; - -import com.google.common.io.BaseEncoding; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Arrays; -import java.util.EnumSet; +import org.stellar.sdk.xdr.LiquidityPoolType; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; public class LiquidityPoolDepositOperationTest { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair source = KeyPair.fromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + Asset nativeAsset = Asset.create("native"); + Asset creditAsset = Asset.createNonNativeAsset("ABC", "GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU"); + LiquidityPoolID liquidityPoolID = new LiquidityPoolID( + LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, + nativeAsset, + creditAsset, + LiquidityPoolParameters.Fee + ); + @Test public void testLiquidityPoolDepositOperationValid() { - fail(); + String maxAmountA = "1000"; + String maxAmountB = "2000"; + Price minPrice = Price.fromString("0.01"); + Price maxPrice = Price.fromString("0.02"); + LiquidityPoolDepositOperation operation = new LiquidityPoolDepositOperation.Builder(liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice) + .setSourceAccount(source.getAccountId()) + .build(); + + org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); + LiquidityPoolDepositOperation parsedOperation = (LiquidityPoolDepositOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); + + assertEquals(source.getAccountId(), parsedOperation.getSourceAccount()); + assertEquals(liquidityPoolID, parsedOperation.getLiquidityPoolID()); + assertEquals(maxAmountA, parsedOperation.getMaxAmountA()); + assertEquals(maxAmountB, parsedOperation.getMaxAmountB()); + assertEquals(minPrice, parsedOperation.getMinPrice()); + assertEquals(maxPrice, parsedOperation.getMaxPrice()); + + assertEquals( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAABb5NUX4ubtAgBk7zCsrbB/oCH2ADwtupaNB0FyfhxedxwAAAAJUC+QAAAAABKgXyAAAAAABAAAAZAAAAAEAAAAy", + operation.toXdrBase64(AccountConverter.enableMuxed())); + } + + @Test + public void testBuilderPairs() { + String maxAmountA = "1000"; + String maxAmountB = "2000"; + Price minPrice = Price.fromString("0.01"); + Price maxPrice = Price.fromString("0.02"); + LiquidityPoolDepositOperation operation = new LiquidityPoolDepositOperation.Builder( + new AssetAmount(nativeAsset, maxAmountA), + new AssetAmount(creditAsset, maxAmountB), + minPrice, + maxPrice + ).setSourceAccount(source.getAccountId()).build(); + + org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); + LiquidityPoolDepositOperation parsedOperation = (LiquidityPoolDepositOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); + + assertEquals(source.getAccountId(), parsedOperation.getSourceAccount()); + assertEquals(liquidityPoolID, parsedOperation.getLiquidityPoolID()); + assertEquals(maxAmountA, parsedOperation.getMaxAmountA()); + assertEquals(maxAmountB, parsedOperation.getMaxAmountB()); + assertEquals(minPrice, parsedOperation.getMinPrice()); + assertEquals(maxPrice, parsedOperation.getMaxPrice()); + + assertEquals( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAABb5NUX4ubtAgBk7zCsrbB/oCH2ADwtupaNB0FyfhxedxwAAAAJUC+QAAAAABKgXyAAAAAABAAAAZAAAAAEAAAAy", + operation.toXdrBase64(AccountConverter.enableMuxed())); } @Test - public void testLiquidityPoolDepositOperationMisorderedAssets() { - fail(); + public void testBuilderPairsMisorderedAssets() { + String maxAmountA = "1000"; + String maxAmountB = "2000"; + Price minPrice = Price.fromString("0.01"); + Price maxPrice = Price.fromString("0.02"); + try { + new LiquidityPoolDepositOperation.Builder( + new AssetAmount(creditAsset, maxAmountB), + new AssetAmount(nativeAsset, maxAmountA), + minPrice, + maxPrice + ).setSourceAccount(source.getAccountId()).build(); + fail(); + } catch (RuntimeException e) { + assertEquals("AssetA must be < AssetB", e.getMessage()); + } } } diff --git a/src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java b/src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java index b64e0ed8d..67db45abd 100644 --- a/src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java +++ b/src/test/java/org/stellar/sdk/LiquidityPoolIDTest.java @@ -9,6 +9,7 @@ public class LiquidityPoolIDTest { private final Asset a = Asset.create("native"); private final Asset b = Asset.createNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); + private final Asset c = Asset.createNonNativeAsset("ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); @Test public void testLiquidityPoolID() { @@ -25,4 +26,17 @@ public void testLiquidityPoolIDMisorderedAssets() { assertEquals("AssetA must be < AssetB", e.getMessage()); } } + + @Test + public void testEquality() { + LiquidityPoolID pool1 = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a, b, LiquidityPoolParameters.Fee); + assertEquals(pool1, pool1); + } + + @Test + public void testInequality() { + LiquidityPoolID pool1 = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a, b, LiquidityPoolParameters.Fee); + LiquidityPoolID pool2 = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, b, c, LiquidityPoolParameters.Fee); + assertNotEquals(pool1, pool2); + } } diff --git a/src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java b/src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java new file mode 100644 index 000000000..c8707561b --- /dev/null +++ b/src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java @@ -0,0 +1,85 @@ +package org.stellar.sdk; + +import org.junit.Test; +import org.stellar.sdk.xdr.LiquidityPoolType; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class LiquidityPoolWithdrawOperationTest { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair source = KeyPair.fromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + Asset nativeAsset = Asset.create("native"); + Asset creditAsset = Asset.createNonNativeAsset("ABC", "GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU"); + LiquidityPoolID liquidityPoolID = new LiquidityPoolID( + LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, + nativeAsset, + creditAsset, + LiquidityPoolParameters.Fee + ); + + @Test + public void testLiquidityPoolWithdrawOperationValid() { + String amount = "5"; + String minAmountA = "1000"; + String minAmountB = "2000"; + LiquidityPoolWithdrawOperation operation = new LiquidityPoolWithdrawOperation.Builder(liquidityPoolID, amount, minAmountA, minAmountB) + .setSourceAccount(source.getAccountId()) + .build(); + + org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); + LiquidityPoolWithdrawOperation parsedOperation = (LiquidityPoolWithdrawOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); + + assertEquals(source.getAccountId(), parsedOperation.getSourceAccount()); + assertEquals(liquidityPoolID, parsedOperation.getLiquidityPoolID()); + assertEquals(amount, parsedOperation.getAmount()); + assertEquals(minAmountA, parsedOperation.getMinAmountA()); + assertEquals(minAmountB, parsedOperation.getMinAmountB()); + + assertEquals( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAABf5NUX4ubtAgBk7zCsrbB/oCH2ADwtupaNB0FyfhxedxwAAAAAC+vCAAAAAAlQL5AAAAAAEqBfIAA==", + operation.toXdrBase64(AccountConverter.enableMuxed())); + } + + @Test + public void testBuilderPairs() { + String amount = "5"; + String minAmountA = "1000"; + String minAmountB = "2000"; + LiquidityPoolWithdrawOperation operation = new LiquidityPoolWithdrawOperation.Builder( + new AssetAmount(nativeAsset, minAmountA), + new AssetAmount(creditAsset, minAmountB), + amount + ).setSourceAccount(source.getAccountId()).build(); + + org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); + LiquidityPoolWithdrawOperation parsedOperation = (LiquidityPoolWithdrawOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); + + assertEquals(source.getAccountId(), parsedOperation.getSourceAccount()); + assertEquals(liquidityPoolID, parsedOperation.getLiquidityPoolID()); + assertEquals(amount, parsedOperation.getAmount()); + assertEquals(minAmountA, parsedOperation.getMinAmountA()); + assertEquals(minAmountB, parsedOperation.getMinAmountB()); + + assertEquals( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAABf5NUX4ubtAgBk7zCsrbB/oCH2ADwtupaNB0FyfhxedxwAAAAAC+vCAAAAAAlQL5AAAAAAEqBfIAA==", + operation.toXdrBase64(AccountConverter.enableMuxed())); + } + + @Test + public void testBuilderPairsMisorderedAssets() { + String amount = "5"; + String minAmountA = "1000"; + String minAmountB = "2000"; + try { + new LiquidityPoolWithdrawOperation.Builder( + new AssetAmount(creditAsset, minAmountA), + new AssetAmount(nativeAsset, minAmountB), + amount + ).setSourceAccount(source.getAccountId()).build(); + fail(); + } catch (RuntimeException e) { + assertEquals("AssetA must be < AssetB", e.getMessage()); + } + } +} diff --git a/src/test/java/org/stellar/sdk/requests/EffectsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/EffectsRequestBuilderTest.java index 8fff5a0f7..82e9c2c39 100644 --- a/src/test/java/org/stellar/sdk/requests/EffectsRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/EffectsRequestBuilderTest.java @@ -3,6 +3,7 @@ import okhttp3.HttpUrl; import org.junit.Test; import org.stellar.sdk.KeyPair; +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.Network; import org.stellar.sdk.Server; @@ -41,6 +42,15 @@ public void testForLedger() { assertEquals("https://horizon-testnet.stellar.org/ledgers/200000000000/effects?limit=50&order=asc", uri.toString()); } + @Test + public void testForLiquidityPool() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.effects() + .forLiquidityPool(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9")) + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/effects", uri.toString()); + } + @Test public void testForTransaction() { Server server = new Server("https://horizon-testnet.stellar.org"); diff --git a/src/test/java/org/stellar/sdk/requests/LedgersRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/LedgersRequestBuilderTest.java index d89c3de28..b0b73ee60 100644 --- a/src/test/java/org/stellar/sdk/requests/LedgersRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/LedgersRequestBuilderTest.java @@ -9,7 +9,7 @@ public class LedgersRequestBuilderTest { @Test - public void testAccounts() { + public void testLedgers() { Server server = new Server("https://horizon-testnet.stellar.org"); HttpUrl uri = server.ledgers() .limit(200) diff --git a/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java new file mode 100644 index 000000000..4e277ab96 --- /dev/null +++ b/src/test/java/org/stellar/sdk/requests/LiquidityPoolsRequestBuilderTest.java @@ -0,0 +1,29 @@ +package org.stellar.sdk.requests; + +import okhttp3.HttpUrl; +import org.junit.Test; +import org.stellar.sdk.*; + +import static org.junit.Assert.assertEquals; + +public class LiquidityPoolsRequestBuilderTest { + @Test + public void testLiquidityPools() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.liquidityPools() + .cursor("13537736921089") + .limit(200) + .order(RequestBuilder.Order.ASC) + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?cursor=13537736921089&limit=200&order=asc", uri.toString()); + } + + @Test + public void testForReserves() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.liquidityPools() + .forReserves("EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", "PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S") + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?reserves=EURT%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S%2CPHP%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", uri.toString()); + } +} diff --git a/src/test/java/org/stellar/sdk/requests/OperationsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/OperationsRequestBuilderTest.java index f821d17e3..4b3aab796 100644 --- a/src/test/java/org/stellar/sdk/requests/OperationsRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/OperationsRequestBuilderTest.java @@ -6,6 +6,7 @@ import okhttp3.mockwebserver.RecordedRequest; import org.junit.Test; import org.stellar.sdk.KeyPair; +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.Network; import org.stellar.sdk.Server; import org.stellar.sdk.responses.operations.OperationResponse; @@ -106,6 +107,15 @@ public void testForLedger() { assertEquals("https://horizon-testnet.stellar.org/ledgers/200000000000/operations?limit=50&order=asc", uri.toString()); } + @Test + public void testForLiquidityPool() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.operations() + .forLiquidityPool(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9")) + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/operations", uri.toString()); + } + @Test public void testForTransaction() { Server server = new Server("https://horizon-testnet.stellar.org"); diff --git a/src/test/java/org/stellar/sdk/requests/TradesRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/TradesRequestBuilderTest.java index 941c07410..c53ab150c 100644 --- a/src/test/java/org/stellar/sdk/requests/TradesRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/TradesRequestBuilderTest.java @@ -3,6 +3,7 @@ import okhttp3.HttpUrl; import org.junit.Test; import org.stellar.sdk.Asset; +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.KeyPair; import org.stellar.sdk.Network; import org.stellar.sdk.Server; @@ -47,6 +48,14 @@ public void testTradesForAccount() { "cursor=13537736921089&" + "limit=200&" + "order=asc", uri.toString()); - } + + @Test + public void testForLiquidityPool() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.trades() + .forLiquidityPool(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9")) + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/trades", uri.toString()); + } } diff --git a/src/test/java/org/stellar/sdk/requests/TransactionsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/TransactionsRequestBuilderTest.java index b32487f35..429805ce8 100644 --- a/src/test/java/org/stellar/sdk/requests/TransactionsRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/TransactionsRequestBuilderTest.java @@ -3,6 +3,7 @@ import okhttp3.HttpUrl; import org.junit.Test; import org.stellar.sdk.KeyPair; +import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.Network; import org.stellar.sdk.Server; @@ -52,6 +53,15 @@ public void testForLedger() { assertEquals("https://horizon-testnet.stellar.org/ledgers/200000000000/transactions?limit=50&order=asc", uri.toString()); } + @Test + public void testForLiquidityPool() { + Server server = new Server("https://horizon-testnet.stellar.org"); + HttpUrl uri = server.transactions() + .forLiquidityPool(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9")) + .buildUri(); + assertEquals("https://horizon-testnet.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/transactions", uri.toString()); + } + @Test public void testIncludeFailed() { Server server = new Server("https://horizon-testnet.stellar.org"); diff --git a/src/test/java/org/stellar/sdk/responses/AssetDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/AssetDeserializerTest.java index fd41cf84d..686e4abe8 100644 --- a/src/test/java/org/stellar/sdk/responses/AssetDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/AssetDeserializerTest.java @@ -26,4 +26,21 @@ public void testDeserializeCredit() { assertEquals(creditAsset.getCode(), "CNY"); assertEquals(creditAsset.getIssuer(), "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX"); } + + @Test + public void testDeserializeCanonicalStringNative() { + String json = "\"native\""; + Asset asset = GsonSingleton.getInstance().fromJson(json, Asset.class); + assertEquals(asset.getType(), "native"); + } + + @Test + public void testDeserializeCanonicalStringCredit() { + String json = "\"CNY:GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX\""; + Asset asset = GsonSingleton.getInstance().fromJson(json, Asset.class); + assertEquals(asset.getType(), "credit_alphanum4"); + AssetTypeCreditAlphaNum creditAsset = (AssetTypeCreditAlphaNum) asset; + assertEquals(creditAsset.getCode(), "CNY"); + assertEquals(creditAsset.getIssuer(), "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX"); + } } diff --git a/src/test/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializerTest.java new file mode 100644 index 000000000..898a39011 --- /dev/null +++ b/src/test/java/org/stellar/sdk/responses/LiquidityPoolIDDeserializerTest.java @@ -0,0 +1,16 @@ +package org.stellar.sdk.responses; + +import junit.framework.TestCase; + +import org.junit.Test; +import org.stellar.sdk.LiquidityPoolID; + +public class LiquidityPoolIDDeserializerTest extends TestCase { + @Test + public void testDeserialize() { + String json = "67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9"; + + LiquidityPoolID liquidityPoolID = GsonSingleton.getInstance().fromJson(json, LiquidityPoolID.class); + assertEquals(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9"), liquidityPoolID); + } +} diff --git a/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java b/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java new file mode 100644 index 000000000..32f8aa6f8 --- /dev/null +++ b/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java @@ -0,0 +1,81 @@ +package org.stellar.sdk.responses; + +import junit.framework.TestCase; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; +import org.stellar.sdk.Asset; +import org.stellar.sdk.LiquidityPoolID; +import org.stellar.sdk.xdr.LiquidityPoolType; + +public class LiquidityPoolResponseTest extends TestCase { + @Test + public void testDeserialize() { + String json = "{\n" + + " \"_links\": {\n" + + " \"effects\": {\n" + + " \"href\": \"/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/effects{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " },\n" + + " \"operations\": {\n" + + " \"href\": \"/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/operations{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " },\n" + + " \"self\": {\n" + + " \"href\": \"/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9\"\n" + + " },\n" + + " \"transactions\": {\n" + + " \"href\": \"/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/transactions{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " }\n" + + " },\n" + + " \"fee_bp\": 30,\n" + + " \"id\": \"67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9\",\n" + + " \"paging_token\": \"113725249324879873\",\n" + + " \"reserves\": [\n" + + " {\n" + + " \"amount\": \"1000.0000005\",\n" + + " \"asset\": \"EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S\"\n" + + " },\n" + + " {\n" + + " \"amount\": \"2000.0000000\",\n" + + " \"asset\": \"PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S\"\n" + + " }\n" + + " ],\n" + + " \"total_shares\": \"5000\",\n" + + " \"total_trustlines\": \"300\",\n" + + " \"type\": \"constant_product\"\n" + + "}"; + + LiquidityPoolResponse liquidityPool = GsonSingleton.getInstance().fromJson(json, LiquidityPoolResponse.class); + assertEquals(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9"), liquidityPool.getLiquidityPoolID()); + assertEquals("113725249324879873", liquidityPool.getPagingToken()); + assertEquals(Integer.valueOf(30), liquidityPool.getFeeBP()); + assertEquals(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, liquidityPool.getType()); + assertEquals("300", liquidityPool.getTotalTrustlines()); + assertEquals("5000", liquidityPool.getTotalShares()); + assertArrayEquals(new LiquidityPoolResponse.Reserve[]{ + new LiquidityPoolResponse.Reserve("1000.0000005", "EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S"), + new LiquidityPoolResponse.Reserve("2000.0000000", "PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S") + }, liquidityPool.getReserves()); + assertEquals("/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/effects{?cursor,limit,order}", liquidityPool.getLinks().getEffects().getHref()); + assertEquals("/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/operations{?cursor,limit,order}", liquidityPool.getLinks().getOperations().getHref()); + assertEquals("/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9", liquidityPool.getLinks().getSelf().getHref()); + assertEquals("/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/transactions{?cursor,limit,order}", liquidityPool.getLinks().getTransactions().getHref()); + } + + @Test + public void testReserveEquality() { + LiquidityPoolResponse.Reserve a = new LiquidityPoolResponse.Reserve("2000.0000000", Asset.create("PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")); + LiquidityPoolResponse.Reserve b = new LiquidityPoolResponse.Reserve("2000.0000000", Asset.create("PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")); + LiquidityPoolResponse.Reserve c = new LiquidityPoolResponse.Reserve("1000.0000005", "PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S"); + LiquidityPoolResponse.Reserve d = new LiquidityPoolResponse.Reserve("2000.0000000", Asset.create("EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")); + + assertEquals(a, b); + assertNotEquals(a, c); + assertNotEquals(a, d); + assertNotEquals(c, d); + } +} From 94cc7bda86c4c195907b95cded696d9066fbe731 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 17 Sep 2021 08:51:54 +0100 Subject: [PATCH 15/21] Add effects --- .../sdk/responses/effects/LiquidityPool.java | 55 +++++++++++++++++++ ...oolClaimableAssetAmountEffectResponse.java | 39 +++++++++++++ .../LiquidityPoolCreatedEffectResponse.java | 23 ++++++++ .../LiquidityPoolDepositedEffectReponse.java | 39 +++++++++++++ .../LiquidityPoolRemovedEffectReponse.java | 26 +++++++++ .../LiquidityPoolRevokedEffectResponse.java | 39 +++++++++++++ .../LiquidityPoolTradeEffectReponse.java | 40 ++++++++++++++ .../LiquidityPoolWithdrewEffectReponse.java | 39 +++++++++++++ 8 files changed, 300 insertions(+) create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmountEffectResponse.java create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectReponse.java create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectReponse.java create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectReponse.java create mode 100644 src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectReponse.java diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java new file mode 100644 index 000000000..cc5ef57f0 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java @@ -0,0 +1,55 @@ +package org.stellar.sdk.responses.effects; + +import org.stellar.sdk.AssetAmount; +import org.stellar.sdk.LiquidityPoolID; +import org.stellar.sdk.xdr.LiquidityPoolType; + +import com.google.gson.annotations.SerializedName; + +public class LiquidityPool { + @SerializedName("id") + protected final LiquidityPoolID id; + @SerializedName("fee_bp") + protected final Integer feeBP; + @SerializedName("type") + protected final LiquidityPoolType type; + @SerializedName("total_trustlines") + protected final Integer totalTrustlines; + @SerializedName("total_shares") + protected final String totalShares; + @SerializedName("reserves") + protected final AssetAmount[] reserves; + + public LiquidityPool(LiquidityPoolID id, Integer feeBP, LiquidityPoolType type, Integer totalTrustlines, String totalShares, AssetAmount[] reserves) { + this.id = id; + this.feeBP = feeBP; + this.type = type; + this.totalTrustlines = totalTrustlines; + this.totalShares = totalShares; + this.reserves = reserves; + } + + public LiquidityPoolID getID() { + return id; + } + + public Integer getFeeBP() { + return feeBP; + } + + public LiquidityPoolType getType() { + return type; + } + + public Integer getTotalTrustlines() { + return totalTrustlines; + } + + public String getTotalShares() { + return totalShares; + } + + public AssetAmount[] getReserves() { + return reserves; + } +} diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmountEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmountEffectResponse.java new file mode 100644 index 000000000..ea21b2002 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmountEffectResponse.java @@ -0,0 +1,39 @@ +package org.stellar.sdk.responses.effects; + +import org.stellar.sdk.Asset; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents liquidity_pool_claimable_asset_amount effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +public class LiquidityPoolClaimableAssetAmountEffectResponse extends EffectResponse { + @SerializedName("asset") + protected final Asset asset; + @SerializedName("amount") + protected final String amount; + @SerializedName("claimable_balance_id") + protected final String claimableBalanceID; + + public LiquidityPoolClaimableAssetAmountEffectResponse(Asset asset, String amount, String claimableBalanceID) { + this.asset = asset; + this.amount = amount; + this.claimableBalanceID = claimableBalanceID; + } + + public Asset getAsset() { + return asset; + } + + public String getAmount() { + return amount; + } + + public String getClaimableBalanceID() { + return claimableBalanceID; + } +} diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java new file mode 100644 index 000000000..32d633c31 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java @@ -0,0 +1,23 @@ +package org.stellar.sdk.responses.effects; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents liquidity_pool_created effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +public class LiquidityPoolCreatedEffectResponse extends EffectResponse { + @SerializedName("liquidity_pool") + protected final LiquidityPool liquidityPool; + + public LiquidityPoolCreatedEffectResponse(LiquidityPool liquidityPool) { + this.liquidityPool = liquidityPool; + } + + public LiquidityPoolID getLiquidityPoolID() { + return liquidityPool; + } +} diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectReponse.java new file mode 100644 index 000000000..86f44ad99 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectReponse.java @@ -0,0 +1,39 @@ +package org.stellar.sdk.responses.effects; + +import org.stellar.sdk.AssetAmount; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents liquidity_pool_deposited effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +public class LiquidityPoolDepositedEffectReponse extends EffectResponse { + @SerializedName("liquidity_pool") + protected final LiquidityPool liquidityPool; + @SerializedName("reserves_deposited") + protected final AssetAmount[] reservesDeposited; + @SerializedName("shares_received") + protected final String sharesReceived; + + public LiquidityPoolDepositedEffectReponse(LiquidityPool liquidityPool, AssetAmount[] reservesDeposited, String sharesReceived) { + this.liquidityPool = liquidityPool; + this.reservesDeposited = reservesDeposited; + this.sharesReceived = sharesReceived; + } + + public LiquidityPool getLiquidityPool() { + return liquidityPool; + } + + public AssetAmount[] getReservesDeposited() { + return reservesDeposited; + } + + public String getSharesReceived() { + return sharesReceived; + } +} diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectReponse.java new file mode 100644 index 000000000..8a719dfad --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectReponse.java @@ -0,0 +1,26 @@ +package org.stellar.sdk.responses.effects; + +import org.stellar.sdk.AssetAmount; +import org.stellar.sdk.LiquidityPoolID; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents liquidity_pool_removed effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +public class LiquidityPoolRemovedEffectReponse extends EffectResponse { + @SerializedName("liquidity_pool_id") + protected final LiquidityPoolID liquidityPoolID; + + public LiquidityPoolRemovedEffectReponse(LiquidityPoolID liquidityPoolID) { + this.liquidityPoolID = liquidityPoolID; + } + + public LiquidityPoolID getLiquidityPoolID() { + return liquidityPoolID; + } +} diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java new file mode 100644 index 000000000..b1d52233e --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java @@ -0,0 +1,39 @@ +package org.stellar.sdk.responses.effects; + +import org.stellar.sdk.Asset; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents liquidity_pool_revoked effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +public class LiquidityPoolRevokedEffectResponse extends EffectResponse { + @SerializedName("liquidity_pool") + protected final LiquidityPool liquidityPool; + @SerializedName("reserves_revoked") + protected final LiquidityPoolClaimableAssetAmount reservesRevoked; + @SerializedName("shares_revoked") + protected final String sharesRevoked; + + public LiquidityPoolRevokedEffectResponse(LiquidityPool liquidityPool, LiquidityPoolClaimableAssetAmount reservesRevoked, String sharesRevoked) { + this.liquidityPool = liquidityPool; + this.reservesRevoked = reservesRevoked; + this.sharesRevoked = sharesRevoked; + } + + public LiquidityPool getLiquidityPool() { + return liquidityPool; + } + + public LiquidityPoolClaimableAssetAmount getReservesRevoked() { + return reservesRevoked; + } + + public String getSharesRevoked() { + return sharesRevoked; + } +} diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectReponse.java new file mode 100644 index 000000000..fe5b044e5 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectReponse.java @@ -0,0 +1,40 @@ +package org.stellar.sdk.responses.effects; + +import org.stellar.sdk.AssetAmount; +import org.stellar.sdk.LiquidityPoolID; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents liquidity_pool_trade effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +public class LiquidityPoolTradeEffectReponse extends EffectResponse { + @SerializedName("liquidity_pool") + protected final LiquidityPoolID liquidityPoolID; + @SerializedName("sold") + protected final AssetAmount sold; + @SerializedName("bought") + protected final AssetAmount bought; + + public LiquidityPoolTradeEffectReponse(LiquidityPoolID liquidityPoolID, AssetAmount sold, AssetAmount bought) { + this.liquidityPoolID = liquidityPoolID; + this.sold = sold; + this.bought = bought; + } + + public LiquidityPoolID getLiquidityPoolID() { + return liquidityPoolID; + } + + public AssetAmount getSold() { + return sold; + } + + public AssetAmount getBought() { + return bought; + } +} diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectReponse.java new file mode 100644 index 000000000..f29a0ed8b --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectReponse.java @@ -0,0 +1,39 @@ +package org.stellar.sdk.responses.effects; + +import org.stellar.sdk.AssetAmount; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents liquidity_pool_withdrew effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +public class LiquidityPoolWithdrewEffectReponse extends EffectResponse { + @SerializedName("liquidity_pool") + protected final LiquidityPool liquidityPool; + @SerializedName("reserves_received") + protected final AssetAmount[] reservesReceived; + @SerializedName("shares_redeemed") + protected final String sharesRedeemed; + + public LiquidityPoolWithdrewEffectReponse(LiquidityPool liquidityPool, AssetAmount[] reservesReceived, String sharesRedeemed) { + this.liquidityPool = liquidityPool; + this.reservesReceived = reservesReceived; + this.sharesRedeemed = sharesRedeemed; + } + + public LiquidityPool getLiquidityPool() { + return liquidityPool; + } + + public AssetAmount[] getReservesReceived() { + return reservesReceived; + } + + public String getSharesRedeemed() { + return sharesRedeemed; + } +} From 4be5e624e9f1904d3e484fc6a12a28326b0c3797 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 17 Sep 2021 08:53:25 +0100 Subject: [PATCH 16/21] comment --- .../org/stellar/sdk/LiquidityPoolConstantProductParameters.java | 2 +- src/main/java/org/stellar/sdk/LiquidityPoolParameters.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java index 515e7cbf5..ec25df871 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java @@ -14,7 +14,7 @@ public final class LiquidityPoolConstantProductParameters extends LiquidityPoolP protected final int fee; /** - * TODO: Write something here + * LiquidityPoolConstantProductParameters represents the parameters specifying a constant-product liquidity pool. * * @param a First asset in the liquidity pool * @param b Second asset in the liquidity pool diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java index 2ca3e8646..a0317228f 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolParameters.java @@ -12,7 +12,7 @@ public abstract class LiquidityPoolParameters { public static Integer Fee = 30; /** - * TODO: Write something here + * LiquidityPoolParameters represents the parameters specifying a liquidity pool. * * @param type Type of the liquidity pool * @param a First asset in the liquidity pool From 2c48284017446b5ebbd48c0e1514ba34152b3a33 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 17 Sep 2021 09:48:35 +0100 Subject: [PATCH 17/21] Fix type and add effect deserializers --- .../sdk/responses/EffectDeserializer.java | 12 ++ .../responses/LiquidityPoolDeserializer.java | 28 ++++ .../sdk/responses/LiquidityPoolResponse.java | 10 +- .../sdk/responses/PageDeserializer.java | 1 + ...=> LiquidityPoolClaimableAssetAmount.java} | 6 +- .../LiquidityPoolCreatedEffectResponse.java | 2 +- ...LiquidityPoolDepositedEffectResponse.java} | 4 +- ...> LiquidityPoolRemovedEffectResponse.java} | 4 +- ... => LiquidityPoolTradeEffectResponse.java} | 4 +- ... LiquidityPoolWithdrewEffectResponse.java} | 4 +- .../responses/LiquidityPoolResponseTest.java | 2 +- .../LiquidityPoolsPageDeserializerTest.java | 127 ++++++++++++++++++ .../responses/TradesPageDeserializerTest.java | 4 +- 13 files changed, 188 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/stellar/sdk/responses/LiquidityPoolDeserializer.java rename src/main/java/org/stellar/sdk/responses/effects/{LiquidityPoolClaimableAssetAmountEffectResponse.java => LiquidityPoolClaimableAssetAmount.java} (76%) rename src/main/java/org/stellar/sdk/responses/effects/{LiquidityPoolDepositedEffectReponse.java => LiquidityPoolDepositedEffectResponse.java} (83%) rename src/main/java/org/stellar/sdk/responses/effects/{LiquidityPoolRemovedEffectReponse.java => LiquidityPoolRemovedEffectResponse.java} (81%) rename src/main/java/org/stellar/sdk/responses/effects/{LiquidityPoolTradeEffectReponse.java => LiquidityPoolTradeEffectResponse.java} (83%) rename src/main/java/org/stellar/sdk/responses/effects/{LiquidityPoolWithdrewEffectReponse.java => LiquidityPoolWithdrewEffectResponse.java} (83%) create mode 100644 src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java diff --git a/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java b/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java index 4c9b4437a..0589ad33b 100644 --- a/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java @@ -123,6 +123,18 @@ public EffectResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializ return gson.fromJson(json, SignerSponsorshipRemovedEffectResponse.class); case 80: return gson.fromJson(json, ClaimableBalanceClawedBackEffectResponse.class); + case 90: + return gson.fromJson(json, LiquidityPoolDepositedEffectResponse.class); + case 91: + return gson.fromJson(json, LiquidityPoolWithdrewEffectResponse.class); + case 92: + return gson.fromJson(json, LiquidityPoolTradeEffectResponse.class); + case 93: + return gson.fromJson(json, LiquidityPoolCreatedEffectResponse.class); + case 94: + return gson.fromJson(json, LiquidityPoolRemovedEffectResponse.class); + case 95: + return gson.fromJson(json, LiquidityPoolRevokedEffectResponse.class); default: throw new RuntimeException("Invalid effect type"); } diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolDeserializer.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolDeserializer.java new file mode 100644 index 000000000..224baac76 --- /dev/null +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolDeserializer.java @@ -0,0 +1,28 @@ +package org.stellar.sdk.responses; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; + +import org.stellar.sdk.Asset; +import org.stellar.sdk.LiquidityPoolID; +import org.stellar.sdk.xdr.LiquidityPoolType; + +import java.lang.reflect.Type; + +class LiquidityPoolDeserializer implements JsonDeserializer { + @Override + public LiquidityPoolResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + // Create new Gson object with adapters needed in Operation + Gson gson = new GsonBuilder() + .registerTypeAdapter(Asset.class, new AssetDeserializer()) + .registerTypeAdapter(LiquidityPoolID.class, new LiquidityPoolIDDeserializer()) + .registerTypeAdapter(LiquidityPoolType.class, new LiquidityPoolTypeDeserializer()) + .create(); + + return gson.fromJson(json, LiquidityPoolResponse.class); + } +} \ No newline at end of file diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java index 666d720fd..1916a85ab 100644 --- a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java @@ -19,7 +19,7 @@ */ public class LiquidityPoolResponse extends Response { @SerializedName("id") - private LiquidityPoolID liquidityPoolID; + private LiquidityPoolID id; @SerializedName("paging_token") private String pagingToken; @SerializedName("fee_bp") @@ -35,12 +35,12 @@ public class LiquidityPoolResponse extends Response { @SerializedName("_links") private Links links; - LiquidityPoolResponse(LiquidityPoolID liquidityPoolID) { - this.liquidityPoolID = liquidityPoolID; + LiquidityPoolResponse(LiquidityPoolID id) { + this.id = id; } - public LiquidityPoolID getLiquidityPoolID() { - return liquidityPoolID; + public LiquidityPoolID getID() { + return id; } public String getPagingToken() { diff --git a/src/main/java/org/stellar/sdk/responses/PageDeserializer.java b/src/main/java/org/stellar/sdk/responses/PageDeserializer.java index ec269a640..deff00b30 100644 --- a/src/main/java/org/stellar/sdk/responses/PageDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/PageDeserializer.java @@ -43,6 +43,7 @@ public Page deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo .registerTypeAdapter(Predicate.class, new PredicateDeserializer()) .registerTypeAdapter(OperationResponse.class, new OperationDeserializer()) .registerTypeAdapter(EffectResponse.class, new EffectDeserializer()) + .registerTypeAdapter(LiquidityPoolResponse.class, new LiquidityPoolDeserializer()) .registerTypeAdapter(TransactionResponse.class, new TransactionDeserializer()) .create(); diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmountEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmount.java similarity index 76% rename from src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmountEffectResponse.java rename to src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmount.java index ea21b2002..eb3a1c4b0 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmountEffectResponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolClaimableAssetAmount.java @@ -5,13 +5,13 @@ import com.google.gson.annotations.SerializedName; /** - * Represents liquidity_pool_claimable_asset_amount effect response. + * Represents liquidity_pool_claimable_asset_amount used in effect responses. * * @see Effect documentation * @see org.stellar.sdk.requests.EffectsRequestBuilder * @see org.stellar.sdk.Server#effects() */ -public class LiquidityPoolClaimableAssetAmountEffectResponse extends EffectResponse { +public class LiquidityPoolClaimableAssetAmount { @SerializedName("asset") protected final Asset asset; @SerializedName("amount") @@ -19,7 +19,7 @@ public class LiquidityPoolClaimableAssetAmountEffectResponse extends EffectRespo @SerializedName("claimable_balance_id") protected final String claimableBalanceID; - public LiquidityPoolClaimableAssetAmountEffectResponse(Asset asset, String amount, String claimableBalanceID) { + public LiquidityPoolClaimableAssetAmount(Asset asset, String amount, String claimableBalanceID) { this.asset = asset; this.amount = amount; this.claimableBalanceID = claimableBalanceID; diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java index 32d633c31..54dff6eb7 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolCreatedEffectResponse.java @@ -17,7 +17,7 @@ public LiquidityPoolCreatedEffectResponse(LiquidityPool liquidityPool) { this.liquidityPool = liquidityPool; } - public LiquidityPoolID getLiquidityPoolID() { + public LiquidityPool getLiquidityPool() { return liquidityPool; } } diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectResponse.java similarity index 83% rename from src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectReponse.java rename to src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectResponse.java index 86f44ad99..69d49eaad 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectReponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolDepositedEffectResponse.java @@ -11,7 +11,7 @@ * @see org.stellar.sdk.requests.EffectsRequestBuilder * @see org.stellar.sdk.Server#effects() */ -public class LiquidityPoolDepositedEffectReponse extends EffectResponse { +public class LiquidityPoolDepositedEffectResponse extends EffectResponse { @SerializedName("liquidity_pool") protected final LiquidityPool liquidityPool; @SerializedName("reserves_deposited") @@ -19,7 +19,7 @@ public class LiquidityPoolDepositedEffectReponse extends EffectResponse { @SerializedName("shares_received") protected final String sharesReceived; - public LiquidityPoolDepositedEffectReponse(LiquidityPool liquidityPool, AssetAmount[] reservesDeposited, String sharesReceived) { + public LiquidityPoolDepositedEffectResponse(LiquidityPool liquidityPool, AssetAmount[] reservesDeposited, String sharesReceived) { this.liquidityPool = liquidityPool; this.reservesDeposited = reservesDeposited; this.sharesReceived = sharesReceived; diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectResponse.java similarity index 81% rename from src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectReponse.java rename to src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectResponse.java index 8a719dfad..ec0d7ff0d 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectReponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRemovedEffectResponse.java @@ -12,11 +12,11 @@ * @see org.stellar.sdk.requests.EffectsRequestBuilder * @see org.stellar.sdk.Server#effects() */ -public class LiquidityPoolRemovedEffectReponse extends EffectResponse { +public class LiquidityPoolRemovedEffectResponse extends EffectResponse { @SerializedName("liquidity_pool_id") protected final LiquidityPoolID liquidityPoolID; - public LiquidityPoolRemovedEffectReponse(LiquidityPoolID liquidityPoolID) { + public LiquidityPoolRemovedEffectResponse(LiquidityPoolID liquidityPoolID) { this.liquidityPoolID = liquidityPoolID; } diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectResponse.java similarity index 83% rename from src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectReponse.java rename to src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectResponse.java index fe5b044e5..08dcef124 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectReponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolTradeEffectResponse.java @@ -12,7 +12,7 @@ * @see org.stellar.sdk.requests.EffectsRequestBuilder * @see org.stellar.sdk.Server#effects() */ -public class LiquidityPoolTradeEffectReponse extends EffectResponse { +public class LiquidityPoolTradeEffectResponse extends EffectResponse { @SerializedName("liquidity_pool") protected final LiquidityPoolID liquidityPoolID; @SerializedName("sold") @@ -20,7 +20,7 @@ public class LiquidityPoolTradeEffectReponse extends EffectResponse { @SerializedName("bought") protected final AssetAmount bought; - public LiquidityPoolTradeEffectReponse(LiquidityPoolID liquidityPoolID, AssetAmount sold, AssetAmount bought) { + public LiquidityPoolTradeEffectResponse(LiquidityPoolID liquidityPoolID, AssetAmount sold, AssetAmount bought) { this.liquidityPoolID = liquidityPoolID; this.sold = sold; this.bought = bought; diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectReponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectResponse.java similarity index 83% rename from src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectReponse.java rename to src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectResponse.java index f29a0ed8b..e91791734 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectReponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolWithdrewEffectResponse.java @@ -11,7 +11,7 @@ * @see org.stellar.sdk.requests.EffectsRequestBuilder * @see org.stellar.sdk.Server#effects() */ -public class LiquidityPoolWithdrewEffectReponse extends EffectResponse { +public class LiquidityPoolWithdrewEffectResponse extends EffectResponse { @SerializedName("liquidity_pool") protected final LiquidityPool liquidityPool; @SerializedName("reserves_received") @@ -19,7 +19,7 @@ public class LiquidityPoolWithdrewEffectReponse extends EffectResponse { @SerializedName("shares_redeemed") protected final String sharesRedeemed; - public LiquidityPoolWithdrewEffectReponse(LiquidityPool liquidityPool, AssetAmount[] reservesReceived, String sharesRedeemed) { + public LiquidityPoolWithdrewEffectResponse(LiquidityPool liquidityPool, AssetAmount[] reservesReceived, String sharesRedeemed) { this.liquidityPool = liquidityPool; this.reservesReceived = reservesReceived; this.sharesRedeemed = sharesRedeemed; diff --git a/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java b/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java index 32f8aa6f8..55ed32215 100644 --- a/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java +++ b/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java @@ -50,7 +50,7 @@ public void testDeserialize() { "}"; LiquidityPoolResponse liquidityPool = GsonSingleton.getInstance().fromJson(json, LiquidityPoolResponse.class); - assertEquals(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9"), liquidityPool.getLiquidityPoolID()); + assertEquals(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9"), liquidityPool.getID()); assertEquals("113725249324879873", liquidityPool.getPagingToken()); assertEquals(Integer.valueOf(30), liquidityPool.getFeeBP()); assertEquals(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, liquidityPool.getType()); diff --git a/src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java new file mode 100644 index 000000000..7e1445196 --- /dev/null +++ b/src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java @@ -0,0 +1,127 @@ +package org.stellar.sdk.responses; + +import com.google.common.base.Optional; +import com.google.gson.reflect.TypeToken; +import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNotEquals; +import org.junit.Test; +import org.stellar.sdk.LiquidityPoolID; +import org.stellar.sdk.xdr.LiquidityPoolType; + +public class LiquidityPoolsPageDeserializerTest extends TestCase { + @Test + public void testDeserialize() { + Page liquidityPoolsPage = GsonSingleton.getInstance().fromJson(json, new TypeToken>() {}.getType()); + + assertEquals("https://horizon.stellar.org/liquidity_pools?cursor=3748308153536513-0\\u0026limit=10\\u0026order=asc", liquidityPoolsPage.getLinks().getNext().getHref()); + assertEquals("https://horizon.stellar.org/liquidity_pools?cursor=3697472920621057-0\\u0026limit=10\\u0026order=desc", liquidityPoolsPage.getLinks().getPrev().getHref()); + assertEquals("https://horizon.stellar.org/liquidity_pools?cursor=\\u0026limit=10\\u0026order=asc", liquidityPoolsPage.getLinks().getSelf().getHref()); + + LiquidityPoolResponse liquidityPool = liquidityPoolsPage.getRecords().get(0); + assertEquals(new LiquidityPoolID("67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9"), liquidityPool.getID()); + assertEquals("113725249324879873", liquidityPool.getPagingToken()); + assertEquals(Integer.valueOf(30), liquidityPool.getFeeBP()); + assertEquals(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, liquidityPool.getType()); + assertEquals("300", liquidityPool.getTotalTrustlines()); + assertEquals("5000", liquidityPool.getTotalShares()); + assertArrayEquals(new LiquidityPoolResponse.Reserve[]{ + new LiquidityPoolResponse.Reserve("1000.0000005", "EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S"), + new LiquidityPoolResponse.Reserve("2000.0000000", "PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S") + }, liquidityPool.getReserves()); + assertEquals("https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/effects{?cursor,limit,order}", liquidityPool.getLinks().getEffects().getHref()); + assertEquals("https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/operations{?cursor,limit,order}", liquidityPool.getLinks().getOperations().getHref()); + assertEquals("https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9", liquidityPool.getLinks().getSelf().getHref()); + assertEquals("https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/transactions{?cursor,limit,order}", liquidityPool.getLinks().getTransactions().getHref()); + + assertEquals(new LiquidityPoolID("14be5a5b3d3f5e1e74380ab0a3bf9c172b7246fdf7753b172cbacd4d66143c08"), liquidityPoolsPage.getRecords().get(1).getID()); + } + + String json = "{\n" + + " \"_links\": {\n" + + " \"next\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools?cursor=3748308153536513-0\\\\u0026limit=10\\\\u0026order=asc\"\n" + + " },\n" + + " \"prev\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools?cursor=3697472920621057-0\\\\u0026limit=10\\\\u0026order=desc\"\n" + + " },\n" + + " \"self\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools?cursor=\\\\u0026limit=10\\\\u0026order=asc\"\n" + + " }\n" + + " },\n" + + " \"_embedded\": {\n" + + " \"records\": [\n" + + " {\n" + + " \"_links\": {\n" + + " \"effects\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/effects{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " },\n" + + " \"operations\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/operations{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " },\n" + + " \"self\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9\"\n" + + " },\n" + + " \"transactions\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/transactions{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " }\n" + + " },\n" + + " \"fee_bp\": 30,\n" + + " \"id\": \"67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9\",\n" + + " \"paging_token\": \"113725249324879873\",\n" + + " \"reserves\": [\n" + + " {\n" + + " \"amount\": \"1000.0000005\",\n" + + " \"asset\": \"EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S\"\n" + + " },\n" + + " {\n" + + " \"amount\": \"2000.0000000\",\n" + + " \"asset\": \"PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S\"\n" + + " }\n" + + " ],\n" + + " \"total_shares\": \"5000\",\n" + + " \"total_trustlines\": \"300\",\n" + + " \"type\": \"constant_product\"\n" + + " },\n" + + " {\n" + + " \"_links\": {\n" + + " \"effects\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/14be5a5b3d3f5e1e74380ab0a3bf9c172b7246fdf7753b172cbacd4d66143c08/effects{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " },\n" + + " \"operations\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/14be5a5b3d3f5e1e74380ab0a3bf9c172b7246fdf7753b172cbacd4d66143c08/operations{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " },\n" + + " \"self\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/14be5a5b3d3f5e1e74380ab0a3bf9c172b7246fdf7753b172cbacd4d66143c08\"\n" + + " },\n" + + " \"transactions\": {\n" + + " \"href\": \"https://horizon.stellar.org/liquidity_pools/14be5a5b3d3f5e1e74380ab0a3bf9c172b7246fdf7753b172cbacd4d66143c08/transactions{?cursor,limit,order}\",\n" + + " \"templated\": true\n" + + " }\n" + + " },\n" + + " \"fee_bp\": 30,\n" + + " \"id\": \"14be5a5b3d3f5e1e74380ab0a3bf9c172b7246fdf7753b172cbacd4d66143c08\",\n" + + " \"paging_token\": \"113725249324879874\",\n" + + " \"reserves\": [\n" + + " {\n" + + " \"amount\": \"1000.0000005\",\n" + + " \"asset\": \"EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S\"\n" + + " },\n" + + " {\n" + + " \"amount\": \"1200.0000000\",\n" + + " \"asset\": \"USDC:GC5W3BH2MQRQK2H4A6LP3SXDSAAY2W2W64OWKKVNQIAOVWSAHFDEUSDC\"\n" + + " }\n" + + " ],\n" + + " \"total_shares\": \"3500\",\n" + + " \"total_trustlines\": \"200\",\n" + + " \"type\": \"constant_product\"\n" + + " }\n" + + " ]\n" + + " }\n" + + "}\n"; +} diff --git a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java index 6092b65bd..86735e5ec 100644 --- a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java @@ -24,8 +24,8 @@ public void testDeserialize() { assertEquals(tradesPage.getRecords().get(0).getCounterOfferId(), Optional.of("11")); assertEquals(tradesPage.getRecords().get(0).getBaseAsset(), new AssetTypeNative()); assertEquals(tradesPage.getRecords().get(0).getCounterAsset(), Asset.createNonNativeAsset("JPY", "GBVAOIACNSB7OVUXJYC5UE2D4YK2F7A24T7EE5YOMN4CE6GCHUTOUQXM")); - assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), 267); - assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), 1000); + assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), "267"); + assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), "1000"); assertEquals(tradesPage.getRecords().get(1).getBaseAccount(), Optional.of("GAVH5JM5OKXGMQDS7YPRJ4MQCPXJUGH26LYQPQJ4SOMOJ4SXY472ZM7G")); } From 25b3f006160ed3525ca270a17268d31e2e1682fb Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 17 Sep 2021 17:48:51 +0100 Subject: [PATCH 18/21] review feedback --- .../sdk/LiquidityPoolConstantProductParameters.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java index ec25df871..4903f4330 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java @@ -2,6 +2,8 @@ import com.google.common.base.Objects; +import org.stellar.sdk.xdr.LiquidityPoolType; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -59,7 +61,7 @@ public final boolean equals(Object object) { @Override public final org.stellar.sdk.xdr.LiquidityPoolParameters toXdr() { org.stellar.sdk.xdr.LiquidityPoolParameters xdr = new org.stellar.sdk.xdr.LiquidityPoolParameters(); - xdr.setDiscriminant(org.stellar.sdk.xdr.LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT); + xdr.setDiscriminant(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT); org.stellar.sdk.xdr.LiquidityPoolConstantProductParameters params = new org.stellar.sdk.xdr.LiquidityPoolConstantProductParameters(); params.setAssetA(assetA.toXdr()); @@ -85,9 +87,9 @@ public static LiquidityPoolConstantProductParameters fromXdr(org.stellar.sdk.xdr @Override - public final org.stellar.sdk.LiquidityPoolID getId() { + public final LiquidityPoolID getId() { return new LiquidityPoolID( - org.stellar.sdk.xdr.LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, + LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, assetA, assetB, fee From a16488ad1748da89699037093c28b47bd0c6b871 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 20 Sep 2021 14:22:05 +0100 Subject: [PATCH 19/21] Review feedback - remove builders --- .../sdk/LiquidityPoolDepositOperation.java | 149 +++--------------- .../sdk/LiquidityPoolWithdrawOperation.java | 97 ++---------- src/main/java/org/stellar/sdk/Operation.java | 4 +- .../LiquidityPoolDepositOperationTest.java | 18 +-- .../LiquidityPoolWithdrawOperationTest.java | 18 +-- 5 files changed, 55 insertions(+), 231 deletions(-) diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index 5a8b62f75..a6ec016fc 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -21,7 +21,7 @@ public class LiquidityPoolDepositOperation extends Operation { private final Price minPrice; private final Price maxPrice; - private LiquidityPoolDepositOperation(LiquidityPoolID liquidityPoolID, String maxAmountA, String maxAmountB, Price minPrice, Price maxPrice) { + public LiquidityPoolDepositOperation(LiquidityPoolID liquidityPoolID, String maxAmountA, String maxAmountB, Price minPrice, Price maxPrice) { this.liquidityPoolID = checkNotNull(liquidityPoolID, "liquidityPoolID cannot be null"); this.maxAmountA = checkNotNull(maxAmountA, "amountA cannot be null"); this.maxAmountB = checkNotNull(maxAmountB, "amountB cannot be null"); @@ -29,6 +29,25 @@ private LiquidityPoolDepositOperation(LiquidityPoolID liquidityPoolID, String ma this.maxPrice = checkNotNull(maxPrice, "maxPrice cannot be null"); } + public LiquidityPoolDepositOperation(LiquidityPoolDepositOp op) { + this.liquidityPoolID = LiquidityPoolID.fromXdr(op.getLiquidityPoolID()); + this.maxAmountA = Operation.fromXdrAmount(op.getMaxAmountA().getInt64().longValue()); + this.maxAmountB = Operation.fromXdrAmount(op.getMaxAmountB().getInt64().longValue()); + this.minPrice = Price.fromXdr(op.getMinPrice()); + this.maxPrice = Price.fromXdr(op.getMaxPrice()); + } + + public LiquidityPoolDepositOperation(AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { + if (a.getAsset().compareTo(b.getAsset()) >= 0) { + throw new RuntimeException("AssetA must be < AssetB"); + } + this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee); + this.maxAmountA = a.getAmount(); + this.maxAmountB = b.getAmount(); + this.minPrice = checkNotNull(minPrice, "minPrice cannot be null"); + this.maxPrice = checkNotNull(maxPrice, "maxPrice cannot be null"); + } + public LiquidityPoolID getLiquidityPoolID() { return liquidityPoolID; } @@ -64,134 +83,6 @@ OperationBody toOperationBody(AccountConverter accountConverter) { return body; } - /** - * Builds LiquidityPoolDeposit operation. - * @see LiquidityPoolDepositOperation - */ - public static class Builder { - private Optional liquidityPoolID = Optional.absent(); - private Optional a = Optional.absent(); - private Optional b = Optional.absent(); - private String maxAmountA; - private String maxAmountB; - private Price minPrice; - private Price maxPrice; - - private String mSourceAccount; - - Builder(LiquidityPoolDepositOp op) { - this.liquidityPoolID = Optional.fromNullable(LiquidityPoolID.fromXdr(op.getLiquidityPoolID())); - this.maxAmountA = Operation.fromXdrAmount(op.getMaxAmountA().getInt64().longValue()); - this.maxAmountB = Operation.fromXdrAmount(op.getMaxAmountB().getInt64().longValue()); - this.minPrice = Price.fromXdr(op.getMinPrice()); - this.maxPrice = Price.fromXdr(op.getMaxPrice()); - } - - /** - * Creates a new LiquidityPoolDeposit builder. - */ - public Builder(AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { - if (a.getAsset().compareTo(b.getAsset()) >= 0) { - throw new RuntimeException("AssetA must be < AssetB"); - } - this.liquidityPoolID = Optional.of(new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee)); - this.a = Optional.of(a.getAsset()); - this.b = Optional.of(b.getAsset()); - this.maxAmountA = a.getAmount(); - this.maxAmountB = b.getAmount(); - this.minPrice = minPrice; - this.maxPrice = maxPrice; - } - - /** - * Creates a new LiquidityPoolDeposit builder. - */ - public Builder(LiquidityPoolID liquidityPoolID, String amountA, String amountB, Price minPrice, Price maxPrice) { - this.liquidityPoolID = Optional.fromNullable(liquidityPoolID); - this.maxAmountA = amountA; - this.maxAmountB = amountB; - this.minPrice = minPrice; - this.maxPrice = maxPrice; - } - - /** - * Set asset and amount A of this operation - * @param asset Asset A - * @param maxAmount Max amount of asset A to deposit - * @return Builder object so you can chain methods. - */ - public Builder setA(Asset asset, String maxAmount) { - this.liquidityPoolID = Optional.absent(); - this.a = Optional.of(asset); - this.maxAmountA = maxAmount; - return this; - } - - /** - * Set asset and amount B of this operation - * @param asset Asset B - * @param maxAmount Max amount of asset B to deposit - * @return Builder object so you can chain methods. - */ - public Builder setB(Asset asset, String maxAmount) { - this.liquidityPoolID = Optional.absent(); - this.b = Optional.of(asset); - this.maxAmountB = maxAmount; - return this; - } - - /** - * Set minimum price for this deposit. - * @param value Min price for this operation - * @return Builder object so you can chain methods. - */ - public Builder setMinPrice(Price value) { - this.minPrice = value; - return this; - } - - /** - * Set maximum price for this deposit. - * @param value Max price for this operation - * @return Builder object so you can chain methods. - */ - public Builder setMaxPrice(Price value) { - this.maxPrice = value; - return this; - } - - /** - * Set source account of this operation - * @param sourceAccount Source account - * @return Builder object so you can chain methods. - */ - public Builder setSourceAccount(String sourceAccount) { - mSourceAccount = sourceAccount; - return this; - } - - /** - * Builds an operation - */ - public LiquidityPoolDepositOperation build() { - if (a.isPresent() && b.isPresent()) { - if (a.get().compareTo(b.get()) >= 0) { - throw new RuntimeException("AssetA must be < AssetB"); - } - - if (!liquidityPoolID.isPresent()) { - liquidityPoolID = Optional.of(new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.get(), b.get(), LiquidityPoolParameters.Fee)); - } - } - - LiquidityPoolDepositOperation op = new LiquidityPoolDepositOperation(liquidityPoolID.get(), maxAmountA, maxAmountB, minPrice, maxPrice); - if (mSourceAccount != null) { - op.setSourceAccount(mSourceAccount); - } - return op; - } - } - public int hashCode() { return Objects.hashCode(liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice); } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java index f1da62820..e1b9f927b 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java @@ -18,13 +18,27 @@ public class LiquidityPoolWithdrawOperation extends Operation { private final String minAmountA; private final String minAmountB; - private LiquidityPoolWithdrawOperation(LiquidityPoolID liquidityPoolID, String amount, String minAmountA, String minAmountB) { + public LiquidityPoolWithdrawOperation(LiquidityPoolID liquidityPoolID, String amount, String minAmountA, String minAmountB) { this.liquidityPoolID = checkNotNull(liquidityPoolID, "liquidityPoolID cannot be null"); this.amount = checkNotNull(amount, "amount cannot be null"); this.minAmountA = checkNotNull(minAmountA, "minAmountA cannot be null"); this.minAmountB = checkNotNull(minAmountB, "minAmountB cannot be null"); } + public LiquidityPoolWithdrawOperation(LiquidityPoolWithdrawOp op) { + this.liquidityPoolID = LiquidityPoolID.fromXdr(op.getLiquidityPoolID()); + this.amount = Operation.fromXdrAmount(op.getAmount().getInt64().longValue()); + this.minAmountA = Operation.fromXdrAmount(op.getMinAmountA().getInt64().longValue()); + this.minAmountB = Operation.fromXdrAmount(op.getMinAmountB().getInt64().longValue()); + } + + public LiquidityPoolWithdrawOperation(AssetAmount a, AssetAmount b, String amount) { + this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee); + this.amount = checkNotNull(amount, "amount cannot be null"); + this.minAmountA = a.getAmount(); + this.minAmountB = b.getAmount(); + } + public LiquidityPoolID getLiquidityPoolID() { return liquidityPoolID; } @@ -55,87 +69,6 @@ OperationBody toOperationBody(AccountConverter accountConverter) { return body; } - /** - * Builds LiquidityPoolWithdraw operation. - * @see LiquidityPoolWithdrawOperation - */ - public static class Builder { - private LiquidityPoolID liquidityPoolID; - private String amount; - private String minAmountA; - private String minAmountB; - - private String mSourceAccount; - - Builder(LiquidityPoolWithdrawOp op) { - this.liquidityPoolID = LiquidityPoolID.fromXdr(op.getLiquidityPoolID()); - this.amount = Operation.fromXdrAmount(op.getAmount().getInt64().longValue()); - this.minAmountA = Operation.fromXdrAmount(op.getMinAmountA().getInt64().longValue()); - this.minAmountB = Operation.fromXdrAmount(op.getMinAmountB().getInt64().longValue()); - } - - /** - * Creates a new LiquidityPoolDeposit builder. - */ - public Builder(LiquidityPoolID liquidityPoolID, String amount, String minAmountA, String minAmountB) { - this.liquidityPoolID = liquidityPoolID; - this.amount = amount; - this.minAmountA = minAmountA; - this.minAmountB = minAmountB; - } - - /** - * Creates a new LiquidityPoolDeposit builder. - */ - public Builder(AssetAmount a, AssetAmount b, String amount) { - this.liquidityPoolID = new LiquidityPoolID(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, a.getAsset(), b.getAsset(), LiquidityPoolParameters.Fee); - this.amount = amount; - this.minAmountA = a.getAmount(); - this.minAmountB = b.getAmount(); - } - - public Builder setLiquidityPoolID(LiquidityPoolID liquidityPoolID) { - this.liquidityPoolID = liquidityPoolID; - return this; - } - - public Builder setAmount(String amount) { - this.amount = amount; - return this; - } - - public Builder setMinAmountA(String minAmountA) { - this.minAmountA = minAmountA; - return this; - } - - public Builder setMinAmountB(String minAmountB) { - this.minAmountB = minAmountB; - return this; - } - - /** - * Set source account of this operation - * @param sourceAccount Source account - * @return Builder object so you can chain methods. - */ - public Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); - return this; - } - - /** - * Builds an operation - */ - public LiquidityPoolWithdrawOperation build() { - LiquidityPoolWithdrawOperation op = new LiquidityPoolWithdrawOperation(liquidityPoolID, amount, minAmountA, minAmountB); - if (mSourceAccount != null) { - op.setSourceAccount(mSourceAccount); - } - return op; - } - } - public int hashCode() { return Objects.hashCode(liquidityPoolID, amount, minAmountA, minAmountB); } diff --git a/src/main/java/org/stellar/sdk/Operation.java b/src/main/java/org/stellar/sdk/Operation.java index 7edd9837e..dcf1e1e0c 100644 --- a/src/main/java/org/stellar/sdk/Operation.java +++ b/src/main/java/org/stellar/sdk/Operation.java @@ -177,10 +177,10 @@ public static Operation fromXdr(AccountConverter accountConverter, org.stellar.s operation = new SetTrustlineFlagsOperation.Builder(body.getSetTrustLineFlagsOp()).build(); break; case LIQUIDITY_POOL_DEPOSIT: - operation = new LiquidityPoolDepositOperation.Builder(body.getLiquidityPoolDepositOp()).build(); + operation = new LiquidityPoolDepositOperation(body.getLiquidityPoolDepositOp()); break; case LIQUIDITY_POOL_WITHDRAW: - operation = new LiquidityPoolWithdrawOperation.Builder(body.getLiquidityPoolWithdrawOp()).build(); + operation = new LiquidityPoolWithdrawOperation(body.getLiquidityPoolWithdrawOp()); break; default: throw new RuntimeException("Unknown operation body " + body.getDiscriminant()); diff --git a/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java b/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java index ae7af44ab..951608092 100644 --- a/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java +++ b/src/test/java/org/stellar/sdk/LiquidityPoolDepositOperationTest.java @@ -24,9 +24,8 @@ public void testLiquidityPoolDepositOperationValid() { String maxAmountB = "2000"; Price minPrice = Price.fromString("0.01"); Price maxPrice = Price.fromString("0.02"); - LiquidityPoolDepositOperation operation = new LiquidityPoolDepositOperation.Builder(liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice) - .setSourceAccount(source.getAccountId()) - .build(); + LiquidityPoolDepositOperation operation = new LiquidityPoolDepositOperation(liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice); + operation.setSourceAccount(source.getAccountId()); org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); LiquidityPoolDepositOperation parsedOperation = (LiquidityPoolDepositOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); @@ -44,17 +43,18 @@ public void testLiquidityPoolDepositOperationValid() { } @Test - public void testBuilderPairs() { + public void testConstructorPairs() { String maxAmountA = "1000"; String maxAmountB = "2000"; Price minPrice = Price.fromString("0.01"); Price maxPrice = Price.fromString("0.02"); - LiquidityPoolDepositOperation operation = new LiquidityPoolDepositOperation.Builder( + LiquidityPoolDepositOperation operation = new LiquidityPoolDepositOperation( new AssetAmount(nativeAsset, maxAmountA), new AssetAmount(creditAsset, maxAmountB), minPrice, maxPrice - ).setSourceAccount(source.getAccountId()).build(); + ); + operation.setSourceAccount(source.getAccountId()); org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); LiquidityPoolDepositOperation parsedOperation = (LiquidityPoolDepositOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); @@ -72,18 +72,18 @@ public void testBuilderPairs() { } @Test - public void testBuilderPairsMisorderedAssets() { + public void testConstructorPairsMisorderedAssets() { String maxAmountA = "1000"; String maxAmountB = "2000"; Price minPrice = Price.fromString("0.01"); Price maxPrice = Price.fromString("0.02"); try { - new LiquidityPoolDepositOperation.Builder( + new LiquidityPoolDepositOperation( new AssetAmount(creditAsset, maxAmountB), new AssetAmount(nativeAsset, maxAmountA), minPrice, maxPrice - ).setSourceAccount(source.getAccountId()).build(); + ).setSourceAccount(source.getAccountId()); fail(); } catch (RuntimeException e) { assertEquals("AssetA must be < AssetB", e.getMessage()); diff --git a/src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java b/src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java index c8707561b..20139e82a 100644 --- a/src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java +++ b/src/test/java/org/stellar/sdk/LiquidityPoolWithdrawOperationTest.java @@ -23,9 +23,8 @@ public void testLiquidityPoolWithdrawOperationValid() { String amount = "5"; String minAmountA = "1000"; String minAmountB = "2000"; - LiquidityPoolWithdrawOperation operation = new LiquidityPoolWithdrawOperation.Builder(liquidityPoolID, amount, minAmountA, minAmountB) - .setSourceAccount(source.getAccountId()) - .build(); + LiquidityPoolWithdrawOperation operation = new LiquidityPoolWithdrawOperation(liquidityPoolID, amount, minAmountA, minAmountB); + operation.setSourceAccount(source.getAccountId()); org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); LiquidityPoolWithdrawOperation parsedOperation = (LiquidityPoolWithdrawOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); @@ -42,15 +41,16 @@ public void testLiquidityPoolWithdrawOperationValid() { } @Test - public void testBuilderPairs() { + public void testConstructorPairs() { String amount = "5"; String minAmountA = "1000"; String minAmountB = "2000"; - LiquidityPoolWithdrawOperation operation = new LiquidityPoolWithdrawOperation.Builder( + LiquidityPoolWithdrawOperation operation = new LiquidityPoolWithdrawOperation( new AssetAmount(nativeAsset, minAmountA), new AssetAmount(creditAsset, minAmountB), amount - ).setSourceAccount(source.getAccountId()).build(); + ); + operation.setSourceAccount(source.getAccountId()); org.stellar.sdk.xdr.Operation xdr = operation.toXdr(AccountConverter.enableMuxed()); LiquidityPoolWithdrawOperation parsedOperation = (LiquidityPoolWithdrawOperation) Operation.fromXdr(AccountConverter.enableMuxed(), xdr); @@ -67,16 +67,16 @@ public void testBuilderPairs() { } @Test - public void testBuilderPairsMisorderedAssets() { + public void testConstructorPairsMisorderedAssets() { String amount = "5"; String minAmountA = "1000"; String minAmountB = "2000"; try { - new LiquidityPoolWithdrawOperation.Builder( + new LiquidityPoolWithdrawOperation( new AssetAmount(creditAsset, minAmountA), new AssetAmount(nativeAsset, minAmountB), amount - ).setSourceAccount(source.getAccountId()).build(); + ).setSourceAccount(source.getAccountId()); fail(); } catch (RuntimeException e) { assertEquals("AssetA must be < AssetB", e.getMessage()); From 41a416ecce60a11b96a977daa49c2f3e6a72d3ef Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 20 Sep 2021 16:10:01 +0100 Subject: [PATCH 20/21] use Longs for some stuff --- .../stellar/sdk/responses/LiquidityPoolResponse.java | 8 ++++---- .../stellar/sdk/responses/effects/LiquidityPool.java | 10 +++++----- .../sdk/responses/LiquidityPoolResponseTest.java | 4 ++-- .../responses/LiquidityPoolsPageDeserializerTest.java | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java index 1916a85ab..3c2821718 100644 --- a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java @@ -27,9 +27,9 @@ public class LiquidityPoolResponse extends Response { @SerializedName("type") private LiquidityPoolType type; @SerializedName("total_trustlines") - private String totalTrustlines; + private Long totalTrustlines; @SerializedName("total_shares") - private String totalShares; + private Long totalShares; @SerializedName("reserves") private Reserve[] reserves; @SerializedName("_links") @@ -55,11 +55,11 @@ public LiquidityPoolType getType() { return type; } - public String getTotalTrustlines() { + public Long getTotalTrustlines() { return totalTrustlines; } - public String getTotalShares() { + public Long getTotalShares() { return totalShares; } diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java index cc5ef57f0..f9083d7bb 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPool.java @@ -14,13 +14,13 @@ public class LiquidityPool { @SerializedName("type") protected final LiquidityPoolType type; @SerializedName("total_trustlines") - protected final Integer totalTrustlines; + protected final Long totalTrustlines; @SerializedName("total_shares") - protected final String totalShares; + protected final Long totalShares; @SerializedName("reserves") protected final AssetAmount[] reserves; - public LiquidityPool(LiquidityPoolID id, Integer feeBP, LiquidityPoolType type, Integer totalTrustlines, String totalShares, AssetAmount[] reserves) { + public LiquidityPool(LiquidityPoolID id, Integer feeBP, LiquidityPoolType type, Long totalTrustlines, Long totalShares, AssetAmount[] reserves) { this.id = id; this.feeBP = feeBP; this.type = type; @@ -41,11 +41,11 @@ public LiquidityPoolType getType() { return type; } - public Integer getTotalTrustlines() { + public Long getTotalTrustlines() { return totalTrustlines; } - public String getTotalShares() { + public Long getTotalShares() { return totalShares; } diff --git a/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java b/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java index 55ed32215..f04bbbaf7 100644 --- a/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java +++ b/src/test/java/org/stellar/sdk/responses/LiquidityPoolResponseTest.java @@ -54,8 +54,8 @@ public void testDeserialize() { assertEquals("113725249324879873", liquidityPool.getPagingToken()); assertEquals(Integer.valueOf(30), liquidityPool.getFeeBP()); assertEquals(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, liquidityPool.getType()); - assertEquals("300", liquidityPool.getTotalTrustlines()); - assertEquals("5000", liquidityPool.getTotalShares()); + assertEquals(Long.valueOf(300), liquidityPool.getTotalTrustlines()); + assertEquals(Long.valueOf(5000), liquidityPool.getTotalShares()); assertArrayEquals(new LiquidityPoolResponse.Reserve[]{ new LiquidityPoolResponse.Reserve("1000.0000005", "EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S"), new LiquidityPoolResponse.Reserve("2000.0000000", "PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S") diff --git a/src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java index 7e1445196..d044f7866 100644 --- a/src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/LiquidityPoolsPageDeserializerTest.java @@ -23,8 +23,8 @@ public void testDeserialize() { assertEquals("113725249324879873", liquidityPool.getPagingToken()); assertEquals(Integer.valueOf(30), liquidityPool.getFeeBP()); assertEquals(LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT, liquidityPool.getType()); - assertEquals("300", liquidityPool.getTotalTrustlines()); - assertEquals("5000", liquidityPool.getTotalShares()); + assertEquals(Long.valueOf(300), liquidityPool.getTotalTrustlines()); + assertEquals(Long.valueOf(5000), liquidityPool.getTotalShares()); assertArrayEquals(new LiquidityPoolResponse.Reserve[]{ new LiquidityPoolResponse.Reserve("1000.0000005", "EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S"), new LiquidityPoolResponse.Reserve("2000.0000000", "PHP:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S") From 38e2d63ea5bc20357d4a8ec7988fdb2f5bf41ec0 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 20 Sep 2021 17:52:05 +0100 Subject: [PATCH 21/21] Use longs for TradePrice --- .../java/org/stellar/sdk/responses/TradePrice.java | 10 +++++----- .../sdk/responses/TradesPageDeserializerTest.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/stellar/sdk/responses/TradePrice.java b/src/main/java/org/stellar/sdk/responses/TradePrice.java index 3d3d270e6..c24194fcb 100644 --- a/src/main/java/org/stellar/sdk/responses/TradePrice.java +++ b/src/main/java/org/stellar/sdk/responses/TradePrice.java @@ -11,16 +11,16 @@ */ public class TradePrice { @SerializedName("n") - private final String n; + private final Long n; @SerializedName("d") - private final String d; + private final Long d; /** * Create a new price. Price in Stellar is represented as a fraction. * @param n numerator * @param d denominator */ - public TradePrice(String n, String d) { + public TradePrice(Long n, Long d) { this.n = n; this.d = d; } @@ -28,14 +28,14 @@ public TradePrice(String n, String d) { /** * Returns numerator. */ - public String getNumerator() { + public Long getNumerator() { return n; } /** * Returns denominator */ - public String getDenominator() { + public Long getDenominator() { return d; } diff --git a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java index 86735e5ec..ee199388b 100644 --- a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java @@ -24,8 +24,8 @@ public void testDeserialize() { assertEquals(tradesPage.getRecords().get(0).getCounterOfferId(), Optional.of("11")); assertEquals(tradesPage.getRecords().get(0).getBaseAsset(), new AssetTypeNative()); assertEquals(tradesPage.getRecords().get(0).getCounterAsset(), Asset.createNonNativeAsset("JPY", "GBVAOIACNSB7OVUXJYC5UE2D4YK2F7A24T7EE5YOMN4CE6GCHUTOUQXM")); - assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), "267"); - assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), "1000"); + assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), Long.valueOf(267)); + assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), Long.valueOf(1000)); assertEquals(tradesPage.getRecords().get(1).getBaseAccount(), Optional.of("GAVH5JM5OKXGMQDS7YPRJ4MQCPXJUGH26LYQPQJ4SOMOJ4SXY472ZM7G")); }