diff --git a/build.gradle b/build.gradle index ea6eb9cc9..40e74d935 100644 --- a/build.gradle +++ b/build.gradle @@ -50,17 +50,12 @@ shadowJar { exclude 'com.android.org.conscrypt' } relocate 'net.', 'shadow.net.' - relocate 'javax.annotation', 'shadow.javax.annotation' - relocate 'org.apache', 'shadow.org.apache' - relocate 'org.jvnet', 'shadow.org.jvnet' - relocate 'org.codehaus', 'shadow.org.codehaus' - relocate 'org.threeten', 'shadow.org.threeten' - relocate 'org.checkerframework', 'shadow.org.checkerframework' relocate 'okhttp3', 'shadow.okhttp3' relocate 'okio', 'shadow.okio' relocate 'kotlin', 'shadow.kotlin' relocate 'org.intellij', 'shadow.org.intellij' relocate 'org.jetbrains', 'shadow.org.jetbrains' + relocate 'org.apache', 'shadow.org.apache' } repositories { @@ -71,11 +66,9 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:${okhttpclientVersion}" implementation "com.squareup.okhttp3:okhttp-sse:${okhttpclientVersion}" implementation 'com.moandjiezana.toml:toml4j:0.7.2' - // use the android version because we don't want java 8 stuff - // TODO: Do we really need to introduce guava? - implementation 'com.google.guava:guava:32.1.2-android' implementation 'com.google.code.gson:gson:2.10.1' implementation 'net.i2p.crypto:eddsa:0.3.0' + implementation 'commons-codec:commons-codec:1.16.0' testImplementation 'org.mockito:mockito-core:5.5.0' testImplementation "com.squareup.okhttp3:mockwebserver:${okhttpclientVersion}" diff --git a/src/main/java/org/stellar/sdk/AbstractTransaction.java b/src/main/java/org/stellar/sdk/AbstractTransaction.java index 50e908122..b391e3347 100644 --- a/src/main/java/org/stellar/sdk/AbstractTransaction.java +++ b/src/main/java/org/stellar/sdk/AbstractTransaction.java @@ -1,13 +1,11 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.collect.ImmutableList; -import com.google.common.io.BaseEncoding; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import lombok.NonNull; import org.stellar.sdk.xdr.DecoratedSignature; import org.stellar.sdk.xdr.Hash; import org.stellar.sdk.xdr.SignatureHint; @@ -15,14 +13,15 @@ import org.stellar.sdk.xdr.TransactionSignaturePayload; public abstract class AbstractTransaction { + protected final Network mNetwork; protected final AccountConverter accountConverter; protected List mSignatures; public static final int MIN_BASE_FEE = 100; - AbstractTransaction(AccountConverter accountConverter, Network network) { - this.accountConverter = checkNotNull(accountConverter, "accountConverter cannot be null"); - this.mNetwork = checkNotNull(network, "network cannot be null"); + AbstractTransaction(@NonNull AccountConverter accountConverter, @NonNull Network network) { + this.accountConverter = accountConverter; + this.mNetwork = network; this.mSignatures = new ArrayList(); } @@ -31,8 +30,7 @@ public abstract class AbstractTransaction { * * @param signer {@link KeyPair} object representing a signer */ - public void sign(KeyPair signer) { - checkNotNull(signer, "signer cannot be null"); + public void sign(@NonNull KeyPair signer) { byte[] txHash = this.hash(); mSignatures.add(signer.signDecorated(txHash)); } @@ -42,8 +40,7 @@ public void sign(KeyPair signer) { * * @param preimage the sha256 hash of preimage should be equal to signer hash */ - public void sign(byte[] preimage) { - checkNotNull(preimage, "preimage cannot be null"); + public void sign(byte @NonNull [] preimage) { org.stellar.sdk.xdr.Signature signature = new org.stellar.sdk.xdr.Signature(); signature.setSignature(preimage); @@ -66,7 +63,7 @@ public byte[] hash() { /** Returns transaction hash encoded as a hexadecimal string. */ public String hashHex() { - return BaseEncoding.base16().lowerCase().encode(this.hash()); + return Util.bytesToHex(this.hash()).toLowerCase(); } /** Returns signature base. */ @@ -96,7 +93,7 @@ public AccountConverter getAccountConverter() { * @return immutable list of signatures */ public List getSignatures() { - return ImmutableList.copyOf(mSignatures); + return Collections.unmodifiableList(mSignatures); } /** diff --git a/src/main/java/org/stellar/sdk/Account.java b/src/main/java/org/stellar/sdk/Account.java index 8d1f77bb7..85a945b92 100644 --- a/src/main/java/org/stellar/sdk/Account.java +++ b/src/main/java/org/stellar/sdk/Account.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; /** * Represents an account in Stellar network with it's sequence number. Account object is required to @@ -21,9 +20,9 @@ public class Account implements TransactionBuilderAccount { * @param sequenceNumber Current sequence number of the account (can be obtained using * java-stellar-sdk or horizon server) */ - public Account(String accountId, Long sequenceNumber) { - mAccountId = checkNotNull(accountId, "accountId cannot be null"); - mSequenceNumber = checkNotNull(sequenceNumber, "sequenceNumber cannot be null"); + public Account(@NonNull String accountId, @NonNull Long sequenceNumber) { + mAccountId = accountId; + mSequenceNumber = sequenceNumber; } @Override @@ -57,7 +56,7 @@ public void incrementSequenceNumber() { } public int hashCode() { - return Objects.hashCode(this.mAccountId, this.mSequenceNumber); + return Objects.hash(this.mAccountId, this.mSequenceNumber); } @Override @@ -67,7 +66,7 @@ public boolean equals(Object object) { } Account other = (Account) object; - return Objects.equal(this.mAccountId, other.mAccountId) - && Objects.equal(this.mSequenceNumber, other.mSequenceNumber); + return Objects.equals(this.mAccountId, other.mAccountId) + && Objects.equals(this.mSequenceNumber, other.mSequenceNumber); } } diff --git a/src/main/java/org/stellar/sdk/AccountMergeOperation.java b/src/main/java/org/stellar/sdk/AccountMergeOperation.java index 1f2a9b9a9..368500b70 100644 --- a/src/main/java/org/stellar/sdk/AccountMergeOperation.java +++ b/src/main/java/org/stellar/sdk/AccountMergeOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.Operation.OperationBody; import org.stellar.sdk.xdr.OperationType; @@ -17,8 +16,8 @@ public class AccountMergeOperation extends Operation { private final String destination; - private AccountMergeOperation(String destination) { - this.destination = checkNotNull(destination, "destination cannot be null"); + private AccountMergeOperation(@NonNull String destination) { + this.destination = destination; } /** The account that receives the remaining XLM balance of the source account. */ @@ -79,7 +78,7 @@ public AccountMergeOperation build() { } public int hashCode() { - return Objects.hashCode(this.destination, this.getSourceAccount()); + return Objects.hash(this.destination, this.getSourceAccount()); } @Override @@ -89,7 +88,7 @@ public boolean equals(Object object) { } AccountMergeOperation other = (AccountMergeOperation) object; - return Objects.equal(this.destination, other.destination) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.destination, other.destination) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/AllowTrustOperation.java b/src/main/java/org/stellar/sdk/AllowTrustOperation.java index 2ef0e823c..f84bf43ed 100644 --- a/src/main/java/org/stellar/sdk/AllowTrustOperation.java +++ b/src/main/java/org/stellar/sdk/AllowTrustOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; /** @@ -21,9 +20,12 @@ public class AllowTrustOperation extends Operation { private final boolean authorizeToMaintainLiabilities; private AllowTrustOperation( - String trustor, String assetCode, boolean authorize, boolean authorizeToMaintainLiabilities) { - this.trustor = checkNotNull(trustor, "trustor cannot be null"); - this.assetCode = checkNotNull(assetCode, "assetCode cannot be null"); + @NonNull String trustor, + @NonNull String assetCode, + boolean authorize, + boolean authorizeToMaintainLiabilities) { + this.trustor = trustor; + this.assetCode = assetCode; this.authorize = authorize; this.authorizeToMaintainLiabilities = authorizeToMaintainLiabilities; } @@ -165,7 +167,7 @@ public AllowTrustOperation build() { @Override public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), this.assetCode, this.authorize, @@ -180,10 +182,10 @@ public boolean equals(Object object) { } AllowTrustOperation other = (AllowTrustOperation) object; - return Objects.equal(this.assetCode, other.assetCode) - && Objects.equal(this.authorize, other.authorize) - && Objects.equal(this.authorizeToMaintainLiabilities, other.authorizeToMaintainLiabilities) - && Objects.equal(this.trustor, other.trustor) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.assetCode, other.assetCode) + && Objects.equals(this.authorize, other.authorize) + && Objects.equals(this.authorizeToMaintainLiabilities, other.authorizeToMaintainLiabilities) + && Objects.equals(this.trustor, other.trustor) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/AssetAmount.java b/src/main/java/org/stellar/sdk/AssetAmount.java index cfa539632..9c735630a 100644 --- a/src/main/java/org/stellar/sdk/AssetAmount.java +++ b/src/main/java/org/stellar/sdk/AssetAmount.java @@ -1,7 +1,7 @@ package org.stellar.sdk; -import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; +import java.util.Objects; public final class AssetAmount { @SerializedName("asset") @@ -24,7 +24,7 @@ public String getAmount() { } public int hashCode() { - return Objects.hashCode(asset, amount); + return Objects.hash(asset, amount); } @Override @@ -34,7 +34,7 @@ public boolean equals(Object object) { } AssetAmount o = (AssetAmount) object; - return Objects.equal(this.getAsset(), o.getAsset()) - && Objects.equal(this.getAmount(), o.getAmount()); + return Objects.equals(this.getAsset(), o.getAsset()) + && Objects.equals(this.getAmount(), o.getAmount()); } } diff --git a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum.java b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum.java index a8b126586..aa4b799f0 100644 --- a/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum.java +++ b/src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; /** * Base class for AssetTypeCreditAlphaNum4 and AssetTypeCreditAlphaNum12 subclasses. @@ -13,9 +12,7 @@ public abstract class AssetTypeCreditAlphaNum extends Asset { protected final String mCode; protected final String mIssuer; - public AssetTypeCreditAlphaNum(String code, String issuer) { - checkNotNull(code, "code cannot be null"); - checkNotNull(issuer, "issuer cannot be null"); + public AssetTypeCreditAlphaNum(@NonNull String code, @NonNull String issuer) { mCode = code; mIssuer = issuer; } @@ -37,7 +34,7 @@ public String toString() { @Override public int hashCode() { - return Objects.hashCode(this.mCode, this.mIssuer); + return Objects.hash(this.mCode, this.mIssuer); } @Override diff --git a/src/main/java/org/stellar/sdk/AssetTypePoolShare.java b/src/main/java/org/stellar/sdk/AssetTypePoolShare.java index da9dd4436..d5293a512 100644 --- a/src/main/java/org/stellar/sdk/AssetTypePoolShare.java +++ b/src/main/java/org/stellar/sdk/AssetTypePoolShare.java @@ -1,6 +1,6 @@ package org.stellar.sdk; -import com.google.common.base.Objects; +import java.util.Objects; /** * Represents Stellar liquidity pool share asset - claimants; - private CreateClaimableBalanceOperation(String amount, Asset asset, List claimants) { - this.asset = checkNotNull(asset, "asset cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); - this.claimants = checkNotNull(claimants, "claimants cannot be null"); + private CreateClaimableBalanceOperation( + @NonNull String amount, @NonNull Asset asset, @NonNull List claimants) { + this.asset = asset; + this.amount = amount; + this.claimants = claimants; if (this.claimants.isEmpty()) { throw new IllegalArgumentException("claimants cannot be empty"); } @@ -80,7 +80,7 @@ public static class Builder { Builder(CreateClaimableBalanceOp op) { asset = Asset.fromXdr(op.getAsset()); amount = Operation.fromXdrAmount(op.getAmount().getInt64().longValue()); - claimants = Lists.newArrayList(); + claimants = new ArrayList<>(); for (org.stellar.sdk.xdr.Claimant c : op.getClaimants()) { claimants.add( new Claimant( @@ -108,8 +108,8 @@ public Builder(String amount, Asset asset, List claimants) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public CreateClaimableBalanceOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public CreateClaimableBalanceOperation.Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -126,7 +126,7 @@ public CreateClaimableBalanceOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.amount, this.asset, this.claimants, this.getSourceAccount()); + return Objects.hash(this.amount, this.asset, this.claimants, this.getSourceAccount()); } @Override @@ -136,9 +136,9 @@ public boolean equals(Object object) { } CreateClaimableBalanceOperation other = (CreateClaimableBalanceOperation) object; - return Objects.equal(this.amount, other.amount) - && Objects.equal(this.asset, other.asset) - && Objects.equal(this.claimants, other.claimants) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.amount, other.amount) + && Objects.equals(this.asset, other.asset) + && Objects.equals(this.claimants, other.claimants) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/CreatePassiveSellOfferOperation.java b/src/main/java/org/stellar/sdk/CreatePassiveSellOfferOperation.java index e9ae8031d..56b6acf4a 100644 --- a/src/main/java/org/stellar/sdk/CreatePassiveSellOfferOperation.java +++ b/src/main/java/org/stellar/sdk/CreatePassiveSellOfferOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.CreatePassiveSellOfferOp; import org.stellar.sdk.xdr.Int64; import org.stellar.sdk.xdr.OperationType; @@ -22,11 +21,14 @@ public class CreatePassiveSellOfferOperation extends Operation { private final String price; private CreatePassiveSellOfferOperation( - Asset selling, Asset buying, String amount, String price) { - this.selling = checkNotNull(selling, "selling cannot be null"); - this.buying = checkNotNull(buying, "buying cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); - this.price = checkNotNull(price, "price cannot be null"); + @NonNull Asset selling, + @NonNull Asset buying, + @NonNull String amount, + @NonNull String price) { + this.selling = selling; + this.buying = buying; + this.amount = amount; + this.price = price; } /** The asset being sold in this operation */ @@ -103,11 +105,15 @@ public static class Builder { * @param price Price of 1 unit of selling in terms of buying. * @throws ArithmeticException when amount has more than 7 decimal places. */ - public Builder(Asset selling, Asset buying, String amount, String price) { - this.selling = checkNotNull(selling, "selling cannot be null"); - this.buying = checkNotNull(buying, "buying cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); - this.price = checkNotNull(price, "price cannot be null"); + public Builder( + @NonNull Asset selling, + @NonNull Asset buying, + @NonNull String amount, + @NonNull String price) { + this.selling = selling; + this.buying = buying; + this.amount = amount; + this.price = price; } /** @@ -116,8 +122,8 @@ public Builder(Asset selling, Asset buying, String amount, String price) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public CreatePassiveSellOfferOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public CreatePassiveSellOfferOperation.Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -134,7 +140,7 @@ public CreatePassiveSellOfferOperation build() { @Override public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.amount, this.buying, this.price, this.selling, this.getSourceAccount()); } @@ -145,10 +151,10 @@ public boolean equals(Object object) { } CreatePassiveSellOfferOperation other = (CreatePassiveSellOfferOperation) object; - return Objects.equal(this.amount, other.amount) - && Objects.equal(this.buying, other.buying) - && Objects.equal(this.price, other.price) - && Objects.equal(this.selling, other.selling) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.amount, other.amount) + && Objects.equals(this.buying, other.buying) + && Objects.equals(this.price, other.price) + && Objects.equals(this.selling, other.selling) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/EndSponsoringFutureReservesOperation.java b/src/main/java/org/stellar/sdk/EndSponsoringFutureReservesOperation.java index 3c6a2c7f4..271e60f12 100644 --- a/src/main/java/org/stellar/sdk/EndSponsoringFutureReservesOperation.java +++ b/src/main/java/org/stellar/sdk/EndSponsoringFutureReservesOperation.java @@ -1,15 +1,14 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.OperationType; public class EndSponsoringFutureReservesOperation extends Operation { public EndSponsoringFutureReservesOperation() {} - public EndSponsoringFutureReservesOperation(String sourceAccount) { - setSourceAccount(checkNotNull(sourceAccount, "sourceAccount cannot be null")); + public EndSponsoringFutureReservesOperation(@NonNull String sourceAccount) { + setSourceAccount(sourceAccount); } @Override @@ -33,6 +32,6 @@ public boolean equals(Object object) { } EndSponsoringFutureReservesOperation other = (EndSponsoringFutureReservesOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/FeeBumpTransaction.java b/src/main/java/org/stellar/sdk/FeeBumpTransaction.java index 410a6df34..28f4cd38b 100644 --- a/src/main/java/org/stellar/sdk/FeeBumpTransaction.java +++ b/src/main/java/org/stellar/sdk/FeeBumpTransaction.java @@ -1,10 +1,9 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.DecoratedSignature; import org.stellar.sdk.xdr.EnvelopeType; import org.stellar.sdk.xdr.FeeBumpTransactionEnvelope; @@ -23,12 +22,12 @@ public class FeeBumpTransaction extends AbstractTransaction { FeeBumpTransaction( AccountConverter accountConverter, - String feeAccount, + @NonNull String feeAccount, long fee, - Transaction innerTransaction) { + @NonNull Transaction innerTransaction) { super(accountConverter, innerTransaction.getNetwork()); - this.mFeeAccount = checkNotNull(feeAccount, "feeAccount cannot be null"); - this.mInner = checkNotNull(innerTransaction, "innerTransaction cannot be null"); + this.mFeeAccount = feeAccount; + this.mInner = innerTransaction; this.mFee = fee; } @@ -122,10 +121,9 @@ public static class Builder { * @param accountConverter The AccountConverter which will be used to encode the fee account. * @param inner The inner transaction which will be fee bumped. read-only, the */ - public Builder(AccountConverter accountConverter, final Transaction inner) { - checkNotNull(inner, "inner cannot be null"); + public Builder(@NonNull AccountConverter accountConverter, @NonNull final Transaction inner) { EnvelopeType txType = inner.toEnvelopeXdr().getDiscriminant(); - this.mAccountConverter = checkNotNull(accountConverter, "accountConverter cannot be null"); + this.mAccountConverter = accountConverter; if (inner.toEnvelopeXdr().getDiscriminant() == EnvelopeType.ENVELOPE_TYPE_TX_V0) { this.mInner = new TransactionBuilder( @@ -140,8 +138,7 @@ public Builder(AccountConverter accountConverter, final Transaction inner) { .timeBounds(inner.getTimeBounds()) .build()) .build(); - - this.mInner.mSignatures = Lists.newArrayList(inner.mSignatures); + this.mInner.mSignatures = new ArrayList<>(inner.mSignatures); } else { this.mInner = inner; } @@ -186,29 +183,30 @@ public FeeBumpTransaction.Builder setBaseFee(long baseFee) { return this; } - public FeeBumpTransaction.Builder setFeeAccount(String feeAccount) { + public FeeBumpTransaction.Builder setFeeAccount(@NonNull String feeAccount) { if (this.mFeeAccount != null) { throw new RuntimeException("fee account has been already been set."); } - this.mFeeAccount = checkNotNull(feeAccount, "feeAccount cannot be null"); + this.mFeeAccount = feeAccount; return this; } public FeeBumpTransaction build() { + if (this.mFeeAccount == null) { + throw new NullPointerException("fee account has to be set. you must call setFeeAccount()."); + } + if (this.mBaseFee == null) { + throw new NullPointerException("base fee has to be set. you must call setBaseFee()."); + } return new FeeBumpTransaction( - this.mAccountConverter, - checkNotNull( - this.mFeeAccount, "fee account has to be set. you must call setFeeAccount()."), - checkNotNull(this.mBaseFee, "base fee has to be set. you must call setBaseFee()."), - this.mInner); + this.mAccountConverter, this.mFeeAccount, this.mBaseFee, this.mInner); } } @Override public int hashCode() { - return Objects.hashCode( - this.mFee, this.mInner, this.mNetwork, this.mFeeAccount, this.mSignatures); + return Objects.hash(this.mFee, this.mInner, this.mNetwork, this.mFeeAccount, this.mSignatures); } @Override @@ -218,10 +216,10 @@ public boolean equals(Object object) { } FeeBumpTransaction other = (FeeBumpTransaction) object; - return Objects.equal(this.mFee, other.mFee) - && Objects.equal(this.mFeeAccount, other.mFeeAccount) - && Objects.equal(this.mInner, other.mInner) - && Objects.equal(this.mNetwork, other.mNetwork) - && Objects.equal(this.mSignatures, other.mSignatures); + return Objects.equals(this.mFee, other.mFee) + && Objects.equals(this.mFeeAccount, other.mFeeAccount) + && Objects.equals(this.mInner, other.mInner) + && Objects.equals(this.mNetwork, other.mNetwork) + && Objects.equals(this.mSignatures, other.mSignatures); } } diff --git a/src/main/java/org/stellar/sdk/InflationOperation.java b/src/main/java/org/stellar/sdk/InflationOperation.java index 97a0e1ce0..fbeaf9b3c 100644 --- a/src/main/java/org/stellar/sdk/InflationOperation.java +++ b/src/main/java/org/stellar/sdk/InflationOperation.java @@ -1,6 +1,6 @@ package org.stellar.sdk; -import com.google.common.base.Objects; +import java.util.Objects; import org.stellar.sdk.xdr.OperationType; /** @@ -21,7 +21,7 @@ org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter acc @Override public int hashCode() { - return Objects.hashCode(this.getSourceAccount()); + return Objects.hash(this.getSourceAccount()); } @Override @@ -31,6 +31,6 @@ public boolean equals(Object object) { } InflationOperation other = (InflationOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/InvokeHostFunctionOperation.java b/src/main/java/org/stellar/sdk/InvokeHostFunctionOperation.java index 20c7728f5..69d8c7b41 100644 --- a/src/main/java/org/stellar/sdk/InvokeHostFunctionOperation.java +++ b/src/main/java/org/stellar/sdk/InvokeHostFunctionOperation.java @@ -5,12 +5,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import javax.annotation.Nullable; import lombok.EqualsAndHashCode; import lombok.NonNull; import lombok.Singular; import lombok.Value; import lombok.experimental.SuperBuilder; +import org.jetbrains.annotations.Nullable; import org.stellar.sdk.xdr.ContractExecutable; import org.stellar.sdk.xdr.ContractExecutableType; import org.stellar.sdk.xdr.ContractIDPreimage; diff --git a/src/main/java/org/stellar/sdk/KeyPair.java b/src/main/java/org/stellar/sdk/KeyPair.java index 55533db5a..50da9d00e 100644 --- a/src/main/java/org/stellar/sdk/KeyPair.java +++ b/src/main/java/org/stellar/sdk/KeyPair.java @@ -1,9 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.System.arraycopy; -import com.google.common.base.Objects; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.security.GeneralSecurityException; @@ -11,6 +9,8 @@ import java.security.Signature; import java.security.SignatureException; import java.util.Arrays; +import java.util.Objects; +import lombok.NonNull; import net.i2p.crypto.eddsa.EdDSAEngine; import net.i2p.crypto.eddsa.EdDSAPrivateKey; import net.i2p.crypto.eddsa.EdDSAPublicKey; @@ -53,8 +53,8 @@ public KeyPair(EdDSAPublicKey publicKey) { * @param publicKey * @param privateKey */ - public KeyPair(EdDSAPublicKey publicKey, EdDSAPrivateKey privateKey) { - mPublicKey = checkNotNull(publicKey, "publicKey cannot be null"); + public KeyPair(@NonNull EdDSAPublicKey publicKey, EdDSAPrivateKey privateKey) { + mPublicKey = publicKey; mPrivateKey = privateKey; } @@ -314,7 +314,7 @@ public boolean verify(byte[] data, byte[] signature) { } public int hashCode() { - return Objects.hashCode(this.mPrivateKey, this.mPublicKey); + return Objects.hash(this.mPrivateKey, this.mPublicKey); } @Override @@ -324,7 +324,7 @@ public boolean equals(Object object) { } KeyPair other = (KeyPair) object; - return Objects.equal(this.mPrivateKey, other.mPrivateKey) + return Objects.equals(this.mPrivateKey, other.mPrivateKey) && this.mPublicKey.equals(other.mPublicKey); } } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java index a79977c2a..007751f48 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolConstantProductParameters.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.LiquidityPoolType; /** @@ -24,10 +23,7 @@ public final class LiquidityPoolConstantProductParameters extends LiquidityPoolP * @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"); + public LiquidityPoolConstantProductParameters(@NonNull Asset a, @NonNull Asset b, int feeBP) { assetA = a; assetB = b; fee = feeBP; @@ -52,9 +48,9 @@ public final boolean equals(Object object) { } LiquidityPoolConstantProductParameters o = (LiquidityPoolConstantProductParameters) object; - return Objects.equal(this.getAssetA(), o.getAssetA()) - && Objects.equal(this.getAssetB(), o.getAssetB()) - && Objects.equal(this.getFee(), o.getFee()); + return Objects.equals(this.getAssetA(), o.getAssetA()) + && Objects.equals(this.getAssetB(), o.getAssetB()) + && Objects.equals(this.getFee(), o.getFee()); } /** Generates XDR object from a given LiquidityPoolParameters object */ diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java index b9d45b954..11e2637cb 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolDepositOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.LiquidityPoolDepositOp; import org.stellar.sdk.xdr.LiquidityPoolType; import org.stellar.sdk.xdr.Operation.OperationBody; @@ -24,16 +23,16 @@ public class LiquidityPoolDepositOperation extends Operation { private final 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"); - this.minPrice = checkNotNull(minPrice, "minPrice cannot be null"); - this.maxPrice = checkNotNull(maxPrice, "maxPrice cannot be null"); + @NonNull LiquidityPoolID liquidityPoolID, + @NonNull String maxAmountA, + @NonNull String maxAmountB, + @NonNull Price minPrice, + @NonNull Price maxPrice) { + this.liquidityPoolID = liquidityPoolID; + this.maxAmountA = maxAmountA; + this.maxAmountB = maxAmountB; + this.minPrice = minPrice; + this.maxPrice = maxPrice; } public LiquidityPoolDepositOperation(LiquidityPoolDepositOp op) { @@ -45,7 +44,7 @@ public LiquidityPoolDepositOperation(LiquidityPoolDepositOp op) { } public LiquidityPoolDepositOperation( - AssetAmount a, AssetAmount b, Price minPrice, Price maxPrice) { + AssetAmount a, AssetAmount b, @NonNull Price minPrice, @NonNull Price maxPrice) { if (a.getAsset().compareTo(b.getAsset()) >= 0) { throw new RuntimeException("AssetA must be < AssetB"); } @@ -57,8 +56,8 @@ public LiquidityPoolDepositOperation( 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"); + this.minPrice = minPrice; + this.maxPrice = maxPrice; } public LiquidityPoolID getLiquidityPoolID() { @@ -97,7 +96,7 @@ OperationBody toOperationBody(AccountConverter accountConverter) { } public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), liquidityPoolID, maxAmountA, maxAmountB, minPrice, maxPrice); } @@ -108,11 +107,11 @@ public boolean equals(Object object) { } LiquidityPoolDepositOperation o = (LiquidityPoolDepositOperation) object; - 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()) - && Objects.equal(this.getSourceAccount(), o.getSourceAccount()); + return Objects.equals(this.getLiquidityPoolID(), o.getLiquidityPoolID()) + && Objects.equals(this.getMaxAmountA(), o.getMaxAmountA()) + && Objects.equals(this.getMaxAmountB(), o.getMaxAmountB()) + && Objects.equals(this.getMinPrice(), o.getMinPrice()) + && Objects.equals(this.getMaxPrice(), o.getMaxPrice()) + && Objects.equals(this.getSourceAccount(), o.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolID.java b/src/main/java/org/stellar/sdk/LiquidityPoolID.java index 75de896e0..c08a8b14d 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolID.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolID.java @@ -1,8 +1,8 @@ package org.stellar.sdk; -import com.google.common.base.Objects; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.Objects; import org.stellar.sdk.xdr.*; /** @@ -59,7 +59,7 @@ public boolean equals(Object object) { LiquidityPoolID o = (LiquidityPoolID) object; - return Objects.equal(this.toString(), o.toString()); + return Objects.equals(this.toString(), o.toString()); } /** Generates XDR object from a given LiquidityPoolID object */ diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java index 0bd7c9247..93da9e4f3 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolShareChangeTrustAsset.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.AssetType; /** @@ -19,8 +18,7 @@ public final class LiquidityPoolShareChangeTrustAsset extends ChangeTrustAsset { * * @param params the liquidity pool parameters */ - public LiquidityPoolShareChangeTrustAsset(LiquidityPoolParameters params) { - checkNotNull(params, "params cannot be null"); + public LiquidityPoolShareChangeTrustAsset(@NonNull LiquidityPoolParameters params) { mParams = params; } @@ -70,7 +68,7 @@ public boolean equals(Object object) { @Override public int compareTo(ChangeTrustAsset other) { - if (other.getType() != "pool_share") { + if (!Objects.equals(other.getType(), "pool_share")) { return 1; } return this.toString().compareTo(((LiquidityPoolShareChangeTrustAsset) other).toString()); diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java b/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java index 0dcee17f3..b6664c40a 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolShareTrustLineAsset.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.AssetType; /** @@ -19,8 +18,7 @@ public final class LiquidityPoolShareTrustLineAsset extends TrustLineAsset { * * @param params the LiquidityPoolParameters */ - public LiquidityPoolShareTrustLineAsset(LiquidityPoolParameters params) { - checkNotNull(params, "params cannot be null"); + public LiquidityPoolShareTrustLineAsset(@NonNull LiquidityPoolParameters params) { mId = params.getId(); } @@ -29,8 +27,7 @@ public LiquidityPoolShareTrustLineAsset(LiquidityPoolParameters params) { * * @param id the LiquidityPoolID */ - public LiquidityPoolShareTrustLineAsset(LiquidityPoolID id) { - checkNotNull(id, "id cannot be null"); + public LiquidityPoolShareTrustLineAsset(@NonNull LiquidityPoolID id) { mId = id; } @@ -71,7 +68,7 @@ public boolean equals(Object object) { @Override public int compareTo(TrustLineAsset other) { - if (other.getType() != "pool_share") { + if (!Objects.equals(other.getType(), "pool_share")) { return 1; } return this.toString().compareTo(((LiquidityPoolShareTrustLineAsset) other).toString()); diff --git a/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java index c6c8a0931..dd9c91d69 100644 --- a/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java +++ b/src/main/java/org/stellar/sdk/LiquidityPoolWithdrawOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.LiquidityPoolType; import org.stellar.sdk.xdr.LiquidityPoolWithdrawOp; import org.stellar.sdk.xdr.Operation.OperationBody; @@ -23,11 +22,14 @@ public class LiquidityPoolWithdrawOperation extends Operation { private final 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"); + @NonNull LiquidityPoolID liquidityPoolID, + @NonNull String amount, + @NonNull String minAmountA, + @NonNull String minAmountB) { + this.liquidityPoolID = liquidityPoolID; + this.amount = amount; + this.minAmountA = minAmountA; + this.minAmountB = minAmountB; } public LiquidityPoolWithdrawOperation(LiquidityPoolWithdrawOp op) { @@ -37,14 +39,14 @@ public LiquidityPoolWithdrawOperation(LiquidityPoolWithdrawOp op) { this.minAmountB = Operation.fromXdrAmount(op.getMinAmountB().getInt64().longValue()); } - public LiquidityPoolWithdrawOperation(AssetAmount a, AssetAmount b, String amount) { + public LiquidityPoolWithdrawOperation(AssetAmount a, AssetAmount b, @NonNull 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.amount = amount; this.minAmountA = a.getAmount(); this.minAmountB = b.getAmount(); } @@ -80,8 +82,7 @@ OperationBody toOperationBody(AccountConverter accountConverter) { } public int hashCode() { - return Objects.hashCode( - this.getSourceAccount(), liquidityPoolID, amount, minAmountA, minAmountB); + return Objects.hash(this.getSourceAccount(), liquidityPoolID, amount, minAmountA, minAmountB); } @Override @@ -91,10 +92,10 @@ public boolean equals(Object object) { } 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()) - && Objects.equal(this.getSourceAccount(), o.getSourceAccount()); + return Objects.equals(this.getLiquidityPoolID(), o.getLiquidityPoolID()) + && Objects.equals(this.getAmount(), o.getAmount()) + && Objects.equals(this.getMinAmountA(), o.getMinAmountA()) + && Objects.equals(this.getMinAmountB(), o.getMinAmountB()) + && Objects.equals(this.getSourceAccount(), o.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/ManageBuyOfferOperation.java b/src/main/java/org/stellar/sdk/ManageBuyOfferOperation.java index 66c9f768d..94c09e2f1 100644 --- a/src/main/java/org/stellar/sdk/ManageBuyOfferOperation.java +++ b/src/main/java/org/stellar/sdk/ManageBuyOfferOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; /** @@ -22,11 +21,15 @@ public class ManageBuyOfferOperation extends Operation { private final long offerId; private ManageBuyOfferOperation( - Asset selling, Asset buying, String amount, String price, long offerId) { - this.selling = checkNotNull(selling, "selling cannot be null"); - this.buying = checkNotNull(buying, "buying cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); - this.price = checkNotNull(price, "price cannot be null"); + @NonNull Asset selling, + @NonNull Asset buying, + @NonNull String amount, + @NonNull String price, + long offerId) { + this.selling = selling; + this.buying = buying; + this.amount = amount; + this.price = price; // offerId can be null this.offerId = offerId; } @@ -117,11 +120,15 @@ public static class Builder { * @param price Price of thing being bought in terms of what you are selling. * @throws ArithmeticException when amount has more than 7 decimal places. */ - public Builder(Asset selling, Asset buying, String amount, String price) { - this.selling = checkNotNull(selling, "selling cannot be null"); - this.buying = checkNotNull(buying, "buying cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); - this.price = checkNotNull(price, "price cannot be null"); + public Builder( + @NonNull Asset selling, + @NonNull Asset buying, + @NonNull String amount, + @NonNull String price) { + this.selling = selling; + this.buying = buying; + this.amount = amount; + this.price = price; } /** @@ -140,8 +147,8 @@ public Builder setOfferId(long offerId) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -158,7 +165,7 @@ public ManageBuyOfferOperation build() { @Override public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), this.amount, this.buying, this.offerId, this.price, this.selling); } @@ -169,11 +176,11 @@ public boolean equals(Object object) { } ManageBuyOfferOperation other = (ManageBuyOfferOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()) - && Objects.equal(this.amount, other.amount) - && Objects.equal(this.buying, other.buying) - && Objects.equal(this.offerId, other.offerId) - && Objects.equal(this.price, other.price) - && Objects.equal(this.selling, other.selling); + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()) + && Objects.equals(this.amount, other.amount) + && Objects.equals(this.buying, other.buying) + && Objects.equals(this.offerId, other.offerId) + && Objects.equals(this.price, other.price) + && Objects.equals(this.selling, other.selling); } } diff --git a/src/main/java/org/stellar/sdk/ManageDataOperation.java b/src/main/java/org/stellar/sdk/ManageDataOperation.java index 3d4a488f1..c216a69c9 100644 --- a/src/main/java/org/stellar/sdk/ManageDataOperation.java +++ b/src/main/java/org/stellar/sdk/ManageDataOperation.java @@ -1,9 +1,8 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; import java.util.Arrays; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; /** @@ -17,8 +16,8 @@ public class ManageDataOperation extends Operation { private final String name; private final byte[] value; - private ManageDataOperation(String name, byte[] value) { - this.name = checkNotNull(name, "name cannot be null"); + private ManageDataOperation(@NonNull String name, byte[] value) { + this.name = name; this.value = value; if (new XdrString(this.name).getBytes().length > 64) { @@ -84,8 +83,8 @@ public static class Builder { * @param name The name of data entry * @param value The value of data entry. nullnull will delete data entry. */ - public Builder(String name, byte[] value) { - this.name = checkNotNull(name, "name cannot be null"); + public Builder(@NonNull String name, byte[] value) { + this.name = name; this.value = value; } @@ -95,8 +94,8 @@ public Builder(String name, byte[] value) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -112,7 +111,7 @@ public ManageDataOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.getSourceAccount(), this.name, Arrays.hashCode(this.value)); + return Objects.hash(this.getSourceAccount(), this.name, Arrays.hashCode(this.value)); } @Override @@ -122,8 +121,8 @@ public boolean equals(Object object) { } ManageDataOperation other = (ManageDataOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()) - && Objects.equal(this.name, other.name) + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()) + && Objects.equals(this.name, other.name) && Arrays.equals(this.value, other.value); } } diff --git a/src/main/java/org/stellar/sdk/ManageSellOfferOperation.java b/src/main/java/org/stellar/sdk/ManageSellOfferOperation.java index 1594cd1aa..282008c3c 100644 --- a/src/main/java/org/stellar/sdk/ManageSellOfferOperation.java +++ b/src/main/java/org/stellar/sdk/ManageSellOfferOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; /** @@ -22,11 +21,15 @@ public class ManageSellOfferOperation extends Operation { private final long offerId; private ManageSellOfferOperation( - Asset selling, Asset buying, String amount, String price, long offerId) { - this.selling = checkNotNull(selling, "selling cannot be null"); - this.buying = checkNotNull(buying, "buying cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); - this.price = checkNotNull(price, "price cannot be null"); + @NonNull Asset selling, + @NonNull Asset buying, + @NonNull String amount, + @NonNull String price, + long offerId) { + this.selling = selling; + this.buying = buying; + this.amount = amount; + this.price = price; // offerId can be null this.offerId = offerId; } @@ -117,11 +120,15 @@ public static class Builder { * @param price Price of 1 unit of selling in terms of buying. * @throws ArithmeticException when amount has more than 7 decimal places. */ - public Builder(Asset selling, Asset buying, String amount, String price) { - this.selling = checkNotNull(selling, "selling cannot be null"); - this.buying = checkNotNull(buying, "buying cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); - this.price = checkNotNull(price, "price cannot be null"); + public Builder( + @NonNull Asset selling, + @NonNull Asset buying, + @NonNull String amount, + @NonNull String price) { + this.selling = selling; + this.buying = buying; + this.amount = amount; + this.price = price; } /** @@ -140,8 +147,8 @@ public Builder setOfferId(long offerId) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -158,7 +165,7 @@ public ManageSellOfferOperation build() { @Override public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), this.amount, this.buying, this.offerId, this.price, this.selling); } @@ -169,11 +176,11 @@ public boolean equals(Object object) { } ManageSellOfferOperation other = (ManageSellOfferOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()) - && Objects.equal(this.amount, other.amount) - && Objects.equal(this.buying, other.buying) - && Objects.equal(this.offerId, other.offerId) - && Objects.equal(this.price, other.price) - && Objects.equal(this.selling, other.selling); + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()) + && Objects.equals(this.amount, other.amount) + && Objects.equals(this.buying, other.buying) + && Objects.equals(this.offerId, other.offerId) + && Objects.equals(this.price, other.price) + && Objects.equals(this.selling, other.selling); } } diff --git a/src/main/java/org/stellar/sdk/MemoHashAbstract.java b/src/main/java/org/stellar/sdk/MemoHashAbstract.java index 1c664ae4d..bb9752b84 100644 --- a/src/main/java/org/stellar/sdk/MemoHashAbstract.java +++ b/src/main/java/org/stellar/sdk/MemoHashAbstract.java @@ -1,23 +1,21 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.io.BaseEncoding; import java.util.Arrays; +import lombok.NonNull; abstract class MemoHashAbstract extends Memo { protected byte[] bytes; - public MemoHashAbstract(byte[] bytes) { - checkNotNull(bytes, "bytes cannot be null"); - checkArgument(bytes.length == 32, "bytes must be 32-bytes long."); + public MemoHashAbstract(byte @NonNull [] bytes) { + if (bytes.length != 32) { + throw new IllegalArgumentException("bytes must be 32-bytes long."); + } this.bytes = bytes; } public MemoHashAbstract(String hexString) { // We change to lowercase because we want to decode both: upper cased and lower cased alphabets. - this(BaseEncoding.base16().lowerCase().decode(hexString.toLowerCase())); + this(Util.hexToBytes(hexString.toLowerCase())); } /** Returns 32 bytes long array contained in this memo. */ @@ -34,7 +32,7 @@ public byte[] getBytes() { * */ public String getHexValue() { - return BaseEncoding.base16().lowerCase().encode(this.bytes); + return Util.bytesToHex(this.bytes).toLowerCase(); } @Override diff --git a/src/main/java/org/stellar/sdk/MemoId.java b/src/main/java/org/stellar/sdk/MemoId.java index f702f2029..996230404 100644 --- a/src/main/java/org/stellar/sdk/MemoId.java +++ b/src/main/java/org/stellar/sdk/MemoId.java @@ -1,7 +1,7 @@ package org.stellar.sdk; -import com.google.common.base.Objects; import java.math.BigInteger; +import java.util.Objects; import org.stellar.sdk.xdr.MemoType; import org.stellar.sdk.xdr.Uint64; import org.stellar.sdk.xdr.XdrUnsignedHyperInteger; @@ -45,7 +45,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MemoId memoId = (MemoId) o; - return Objects.equal(id, memoId.id); + return Objects.equals(id, memoId.id); } @Override diff --git a/src/main/java/org/stellar/sdk/MemoText.java b/src/main/java/org/stellar/sdk/MemoText.java index 8d85aa4d1..5575f0ff0 100644 --- a/src/main/java/org/stellar/sdk/MemoText.java +++ b/src/main/java/org/stellar/sdk/MemoText.java @@ -1,8 +1,6 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - +import lombok.NonNull; import org.stellar.sdk.xdr.MemoType; import org.stellar.sdk.xdr.XdrString; @@ -10,17 +8,18 @@ public class MemoText extends Memo { private XdrString text; - public MemoText(String text) { - this(new XdrString(checkNotNull(text, "text cannot be null"))); + public MemoText(@NonNull String text) { + this(new XdrString(text)); } - public MemoText(byte[] text) { - this(new XdrString(checkNotNull(text, "text cannot be null"))); + public MemoText(byte @NonNull [] text) { + this(new XdrString(text)); } - public MemoText(XdrString text) { - checkNotNull(text, "text cannot be null"); - checkArgument(text.getBytes().length <= 28, "text cannot be more than 28-bytes long."); + public MemoText(@NonNull XdrString text) { + if (text.getBytes().length > 28) { + throw new IllegalArgumentException("text cannot be more than 28-bytes long."); + } this.text = text; } diff --git a/src/main/java/org/stellar/sdk/Network.java b/src/main/java/org/stellar/sdk/Network.java index d82eaad71..4723d718a 100644 --- a/src/main/java/org/stellar/sdk/Network.java +++ b/src/main/java/org/stellar/sdk/Network.java @@ -1,9 +1,8 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; import java.nio.charset.Charset; +import java.util.Objects; +import lombok.NonNull; /** * Network class is used to specify which Stellar network you want to use. Each network has a @@ -25,8 +24,8 @@ public class Network { * * @param networkPassphrase */ - public Network(String networkPassphrase) { - this.networkPassphrase = checkNotNull(networkPassphrase, "networkPassphrase cannot be null"); + public Network(@NonNull String networkPassphrase) { + this.networkPassphrase = networkPassphrase; } /** Returns network passphrase */ @@ -51,7 +50,7 @@ public boolean equals(Object object) { } Network other = (Network) object; - return Objects.equal(this.networkPassphrase, other.networkPassphrase); + return Objects.equals(this.networkPassphrase, other.networkPassphrase); } @Override diff --git a/src/main/java/org/stellar/sdk/Operation.java b/src/main/java/org/stellar/sdk/Operation.java index f9af93cb3..840c7a25d 100644 --- a/src/main/java/org/stellar/sdk/Operation.java +++ b/src/main/java/org/stellar/sdk/Operation.java @@ -1,11 +1,10 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - import java.io.IOException; import java.math.BigDecimal; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.experimental.SuperBuilder; @@ -19,8 +18,7 @@ public abstract class Operation { private static final BigDecimal ONE = new BigDecimal(10).pow(7); - protected static long toXdrAmount(String value) { - value = checkNotNull(value, "value cannot be null"); + protected static long toXdrAmount(@NonNull String value) { BigDecimal amount = new BigDecimal(value).multiply(Operation.ONE); return amount.longValueExact(); } diff --git a/src/main/java/org/stellar/sdk/PathPaymentStrictReceiveOperation.java b/src/main/java/org/stellar/sdk/PathPaymentStrictReceiveOperation.java index 7588b17e2..49c4f2203 100644 --- a/src/main/java/org/stellar/sdk/PathPaymentStrictReceiveOperation.java +++ b/src/main/java/org/stellar/sdk/PathPaymentStrictReceiveOperation.java @@ -1,10 +1,8 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; import java.util.Arrays; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.Int64; import org.stellar.sdk.xdr.OperationType; import org.stellar.sdk.xdr.PathPaymentStrictReceiveOp; @@ -27,21 +25,23 @@ public class PathPaymentStrictReceiveOperation extends Operation { private final Asset[] path; private PathPaymentStrictReceiveOperation( - Asset sendAsset, - String sendMax, - String destination, - Asset destAsset, - String destAmount, + @NonNull Asset sendAsset, + @NonNull String sendMax, + @NonNull String destination, + @NonNull Asset destAsset, + @NonNull String destAmount, Asset[] path) { - this.sendAsset = checkNotNull(sendAsset, "sendAsset cannot be null"); - this.sendMax = checkNotNull(sendMax, "sendMax cannot be null"); - this.destination = checkNotNull(destination, "destination cannot be null"); - this.destAsset = checkNotNull(destAsset, "destAsset cannot be null"); - this.destAmount = checkNotNull(destAmount, "destAmount cannot be null"); + this.sendAsset = sendAsset; + this.sendMax = sendMax; + this.destination = destination; + this.destAsset = destAsset; + this.destAmount = destAmount; if (path == null) { this.path = new Asset[0]; } else { - checkArgument(path.length <= 5, "The maximum number of assets in the path is 5"); + if (path.length > 5) { + throw new IllegalArgumentException("The maximum number of assets in the path is 5"); + } this.path = path; } } @@ -150,12 +150,16 @@ public static class Builder { * @throws ArithmeticException when sendMax or destAmount has more than 7 decimal places. */ public Builder( - Asset sendAsset, String sendMax, String destination, Asset destAsset, String destAmount) { - this.sendAsset = checkNotNull(sendAsset, "sendAsset cannot be null"); - this.sendMax = checkNotNull(sendMax, "sendMax cannot be null"); - this.destination = checkNotNull(destination, "destination cannot be null"); - this.destAsset = checkNotNull(destAsset, "destAsset cannot be null"); - this.destAmount = checkNotNull(destAmount, "destAmount cannot be null"); + @NonNull Asset sendAsset, + @NonNull String sendMax, + @NonNull String destination, + @NonNull Asset destAsset, + @NonNull String destAmount) { + this.sendAsset = sendAsset; + this.sendMax = sendMax; + this.destination = destination; + this.destAsset = destAsset; + this.destAmount = destAmount; } /** @@ -167,9 +171,10 @@ public Builder( * would contain XLM and BTC. * @return Builder object so you can chain methods. */ - public PathPaymentStrictReceiveOperation.Builder setPath(Asset[] path) { - checkNotNull(path, "path cannot be null"); - checkArgument(path.length <= 5, "The maximum number of assets in the path is 5"); + public PathPaymentStrictReceiveOperation.Builder setPath(@NonNull Asset[] path) { + if (path.length > 5) { + throw new IllegalArgumentException("The maximum number of assets in the path is 5"); + } this.path = path; return this; } @@ -180,8 +185,9 @@ public PathPaymentStrictReceiveOperation.Builder setPath(Asset[] path) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public PathPaymentStrictReceiveOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public PathPaymentStrictReceiveOperation.Builder setSourceAccount( + @NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -198,7 +204,7 @@ public PathPaymentStrictReceiveOperation build() { } public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), this.destAmount, this.destAsset, @@ -215,12 +221,12 @@ public boolean equals(Object object) { } PathPaymentStrictReceiveOperation other = (PathPaymentStrictReceiveOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()) - && Objects.equal(this.destAmount, other.destAmount) - && Objects.equal(this.destAsset, other.destAsset) - && Objects.equal(this.destination, other.destination) + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()) + && Objects.equals(this.destAmount, other.destAmount) + && Objects.equals(this.destAsset, other.destAsset) + && Objects.equals(this.destination, other.destination) && Arrays.equals(this.path, other.path) - && Objects.equal(this.sendAsset, other.sendAsset) - && Objects.equal(this.sendMax, other.sendMax); + && Objects.equals(this.sendAsset, other.sendAsset) + && Objects.equals(this.sendMax, other.sendMax); } } diff --git a/src/main/java/org/stellar/sdk/PathPaymentStrictSendOperation.java b/src/main/java/org/stellar/sdk/PathPaymentStrictSendOperation.java index 37363f958..85e92c499 100644 --- a/src/main/java/org/stellar/sdk/PathPaymentStrictSendOperation.java +++ b/src/main/java/org/stellar/sdk/PathPaymentStrictSendOperation.java @@ -1,10 +1,8 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; import java.util.Arrays; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.Int64; import org.stellar.sdk.xdr.OperationType; import org.stellar.sdk.xdr.PathPaymentStrictSendOp; @@ -27,21 +25,23 @@ public class PathPaymentStrictSendOperation extends Operation { private final Asset[] path; private PathPaymentStrictSendOperation( - Asset sendAsset, - String sendAmount, - String destination, - Asset destAsset, - String destMin, + @NonNull Asset sendAsset, + @NonNull String sendAmount, + @NonNull String destination, + @NonNull Asset destAsset, + @NonNull String destMin, Asset[] path) { - this.sendAsset = checkNotNull(sendAsset, "sendAsset cannot be null"); - this.sendAmount = checkNotNull(sendAmount, "sendAmount cannot be null"); - this.destination = checkNotNull(destination, "destination cannot be null"); - this.destAsset = checkNotNull(destAsset, "destAsset cannot be null"); - this.destMin = checkNotNull(destMin, "destMin cannot be null"); + this.sendAsset = sendAsset; + this.sendAmount = sendAmount; + this.destination = destination; + this.destAsset = destAsset; + this.destMin = destMin; if (path == null) { this.path = new Asset[0]; } else { - checkArgument(path.length <= 5, "The maximum number of assets in the path is 5"); + if (path.length > 5) { + throw new IllegalArgumentException("The maximum number of assets in the path is 5"); + } this.path = path; } } @@ -150,12 +150,16 @@ public static class Builder { * @throws ArithmeticException when sendAmount or destMin has more than 7 decimal places. */ public Builder( - Asset sendAsset, String sendAmount, String destination, Asset destAsset, String destMin) { - this.sendAsset = checkNotNull(sendAsset, "sendAsset cannot be null"); - this.sendAmount = checkNotNull(sendAmount, "sendAmount cannot be null"); - this.destination = checkNotNull(destination, "destination cannot be null"); - this.destAsset = checkNotNull(destAsset, "destAsset cannot be null"); - this.destMin = checkNotNull(destMin, "destMin cannot be null"); + @NonNull Asset sendAsset, + @NonNull String sendAmount, + @NonNull String destination, + @NonNull Asset destAsset, + @NonNull String destMin) { + this.sendAsset = sendAsset; + this.sendAmount = sendAmount; + this.destination = destination; + this.destAsset = destAsset; + this.destMin = destMin; } /** @@ -167,9 +171,10 @@ public Builder( * would contain XLM and BTC. * @return Builder object so you can chain methods. */ - public PathPaymentStrictSendOperation.Builder setPath(Asset[] path) { - checkNotNull(path, "path cannot be null"); - checkArgument(path.length <= 5, "The maximum number of assets in the path is 5"); + public PathPaymentStrictSendOperation.Builder setPath(@NonNull Asset[] path) { + if (path.length > 5) { + throw new IllegalArgumentException("The maximum number of assets in the path is 5"); + } this.path = path; return this; } @@ -180,8 +185,8 @@ public PathPaymentStrictSendOperation.Builder setPath(Asset[] path) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public PathPaymentStrictSendOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public PathPaymentStrictSendOperation.Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -198,7 +203,7 @@ public PathPaymentStrictSendOperation build() { } public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), this.destMin, this.destAsset, @@ -215,12 +220,12 @@ public boolean equals(Object object) { } PathPaymentStrictSendOperation other = (PathPaymentStrictSendOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()) - && Objects.equal(this.destMin, other.destMin) - && Objects.equal(this.destAsset, other.destAsset) - && Objects.equal(this.destination, other.destination) + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()) + && Objects.equals(this.destMin, other.destMin) + && Objects.equals(this.destAsset, other.destAsset) + && Objects.equals(this.destination, other.destination) && Arrays.equals(this.path, other.path) - && Objects.equal(this.sendAsset, other.sendAsset) - && Objects.equal(this.sendAmount, other.sendAmount); + && Objects.equals(this.sendAsset, other.sendAsset) + && Objects.equals(this.sendAmount, other.sendAmount); } } diff --git a/src/main/java/org/stellar/sdk/PaymentOperation.java b/src/main/java/org/stellar/sdk/PaymentOperation.java index c0d284781..7cd823bc1 100644 --- a/src/main/java/org/stellar/sdk/PaymentOperation.java +++ b/src/main/java/org/stellar/sdk/PaymentOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.Int64; import org.stellar.sdk.xdr.OperationType; import org.stellar.sdk.xdr.PaymentOp; @@ -20,10 +19,11 @@ public class PaymentOperation extends Operation { private final Asset asset; private final String amount; - private PaymentOperation(String destination, Asset asset, String amount) { - this.destination = checkNotNull(destination, "destination cannot be null"); - this.asset = checkNotNull(asset, "asset cannot be null"); - this.amount = checkNotNull(amount, "amount cannot be null"); + private PaymentOperation( + @NonNull String destination, @NonNull Asset asset, @NonNull String amount) { + this.destination = destination; + this.asset = asset; + this.amount = amount; } /** Account that receives the payment. */ @@ -120,7 +120,7 @@ public PaymentOperation build() { } public int hashCode() { - return Objects.hashCode(this.getSourceAccount(), this.asset, this.amount, this.destination); + return Objects.hash(this.getSourceAccount(), this.asset, this.amount, this.destination); } @Override @@ -130,9 +130,9 @@ public boolean equals(Object object) { } PaymentOperation other = (PaymentOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()) - && Objects.equal(this.asset, other.asset) - && Objects.equal(this.amount, other.amount) - && Objects.equal(this.destination, other.destination); + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()) + && Objects.equals(this.asset, other.asset) + && Objects.equals(this.amount, other.amount) + && Objects.equals(this.destination, other.destination); } } diff --git a/src/main/java/org/stellar/sdk/Predicate.java b/src/main/java/org/stellar/sdk/Predicate.java index 12ce7c159..b646d66f2 100644 --- a/src/main/java/org/stellar/sdk/Predicate.java +++ b/src/main/java/org/stellar/sdk/Predicate.java @@ -1,10 +1,10 @@ package org.stellar.sdk; -import com.google.common.base.Objects; -import com.google.common.collect.Lists; import java.math.BigInteger; import java.time.Instant; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; import org.stellar.sdk.xdr.ClaimPredicate; import org.stellar.sdk.xdr.ClaimPredicateType; import org.stellar.sdk.xdr.Duration; @@ -16,7 +16,7 @@ public abstract class Predicate { private static List convertXDRPredicates(ClaimPredicate[] predicates) { - List list = Lists.newArrayList(); + List list = new ArrayList<>(); for (ClaimPredicate p : predicates) { list.add(fromXdr(p)); } @@ -88,7 +88,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - return (getClass() == o.getClass()) && Objects.equal(inner, ((Not) o).inner); + return (getClass() == o.getClass()) && Objects.equals(inner, ((Not) o).inner); } @Override @@ -121,7 +121,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - return (getClass() == o.getClass()) && Objects.equal(inner, ((Or) o).inner); + return (getClass() == o.getClass()) && Objects.equals(inner, ((Or) o).inner); } @Override @@ -158,7 +158,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - return (getClass() == o.getClass()) && Objects.equal(inner, ((And) o).inner); + return (getClass() == o.getClass()) && Objects.equals(inner, ((And) o).inner); } @Override @@ -227,7 +227,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - return (getClass() == o.getClass()) && Objects.equal(timePoint, ((AbsBefore) o).timePoint); + return (getClass() == o.getClass()) && Objects.equals(timePoint, ((AbsBefore) o).timePoint); } @Override @@ -265,7 +265,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - return (getClass() == o.getClass()) && Objects.equal(duration, ((RelBefore) o).duration); + return (getClass() == o.getClass()) && Objects.equals(duration, ((RelBefore) o).duration); } @Override diff --git a/src/main/java/org/stellar/sdk/Price.java b/src/main/java/org/stellar/sdk/Price.java index 6e1709530..8976abe71 100644 --- a/src/main/java/org/stellar/sdk/Price.java +++ b/src/main/java/org/stellar/sdk/Price.java @@ -1,13 +1,12 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; import java.math.BigDecimal; import java.math.MathContext; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.Int32; /** Represents Price. Price in Stellar is represented as a fraction. */ @@ -46,8 +45,7 @@ public int getDenominator() { * * @param price Ex. "1.25" */ - public static Price fromString(String price) { - checkNotNull(price, "price cannot be null"); + public static Price fromString(@NonNull String price) { BigDecimal maxInt = new BigDecimal(Integer.MAX_VALUE); BigDecimal number = new BigDecimal(price); BigDecimal a; @@ -106,7 +104,7 @@ public String toString() { @Override public int hashCode() { - return Objects.hashCode(this.getNumerator(), this.getDenominator()); + return Objects.hash(this.getNumerator(), this.getDenominator()); } @Override diff --git a/src/main/java/org/stellar/sdk/RevokeAccountSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeAccountSponsorshipOperation.java index fc0645a5c..2f737464f 100644 --- a/src/main/java/org/stellar/sdk/RevokeAccountSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeAccountSponsorshipOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; public class RevokeAccountSponsorshipOperation extends Operation { @@ -64,8 +63,9 @@ public Builder(String accountId) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public RevokeAccountSponsorshipOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public RevokeAccountSponsorshipOperation.Builder setSourceAccount( + @NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -82,7 +82,7 @@ public RevokeAccountSponsorshipOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.accountId, this.getSourceAccount()); + return Objects.hash(this.accountId, this.getSourceAccount()); } @Override @@ -92,7 +92,7 @@ public boolean equals(Object object) { } RevokeAccountSponsorshipOperation other = (RevokeAccountSponsorshipOperation) object; - return Objects.equal(this.accountId, other.accountId) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.accountId, other.accountId) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java index 763f47010..7c3fb0efc 100644 --- a/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java @@ -1,10 +1,8 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; -import com.google.common.io.BaseEncoding; import java.io.IOException; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; public class RevokeClaimableBalanceSponsorshipOperation extends Operation { @@ -20,7 +18,7 @@ public String getBalanceId() { @Override org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter accountConverter) { - byte[] balanceIdBytes = BaseEncoding.base16().lowerCase().decode(this.balanceId.toLowerCase()); + byte[] balanceIdBytes = Util.hexToBytes(this.balanceId); ClaimableBalanceID balanceId; try { balanceId = ClaimableBalanceID.fromXdrByteArray(balanceIdBytes); @@ -61,9 +59,8 @@ public static class Builder { Builder(RevokeSponsorshipOp op) { try { balanceId = - BaseEncoding.base16() - .lowerCase() - .encode(op.getLedgerKey().getClaimableBalance().getBalanceID().toXdrByteArray()); + Util.bytesToHex(op.getLedgerKey().getClaimableBalance().getBalanceID().toXdrByteArray()) + .toLowerCase(); } catch (IOException e) { throw new IllegalArgumentException("Invalid claimableBalance in the operation", e); } @@ -85,8 +82,8 @@ public Builder(String balanceId) { * @return Builder object so you can chain methods. */ public RevokeClaimableBalanceSponsorshipOperation.Builder setSourceAccount( - String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + @NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -103,7 +100,7 @@ public RevokeClaimableBalanceSponsorshipOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.balanceId, this.getSourceAccount()); + return Objects.hash(this.balanceId, this.getSourceAccount()); } @Override @@ -114,7 +111,7 @@ public boolean equals(Object object) { RevokeClaimableBalanceSponsorshipOperation other = (RevokeClaimableBalanceSponsorshipOperation) object; - return Objects.equal(this.balanceId, other.balanceId) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.balanceId, other.balanceId) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/RevokeDataSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeDataSponsorshipOperation.java index 001bfe79d..d90f68d5a 100644 --- a/src/main/java/org/stellar/sdk/RevokeDataSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeDataSponsorshipOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; public class RevokeDataSponsorshipOperation extends Operation { @@ -78,8 +77,8 @@ public Builder(String accountId, String dataName) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public RevokeDataSponsorshipOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public RevokeDataSponsorshipOperation.Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -96,7 +95,7 @@ public RevokeDataSponsorshipOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.accountId, this.dataName, this.getSourceAccount()); + return Objects.hash(this.accountId, this.dataName, this.getSourceAccount()); } @Override @@ -106,8 +105,8 @@ public boolean equals(Object object) { } RevokeDataSponsorshipOperation other = (RevokeDataSponsorshipOperation) object; - return Objects.equal(this.accountId, other.accountId) - && Objects.equal(this.dataName, other.dataName) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.accountId, other.accountId) + && Objects.equals(this.dataName, other.dataName) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/RevokeOfferSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeOfferSponsorshipOperation.java index 161b0a12d..f44463f16 100644 --- a/src/main/java/org/stellar/sdk/RevokeOfferSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeOfferSponsorshipOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; public class RevokeOfferSponsorshipOperation extends Operation { @@ -78,8 +77,8 @@ public Builder(String seller, Long offerId) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public RevokeOfferSponsorshipOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public RevokeOfferSponsorshipOperation.Builder setSourceAccount(@NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -96,7 +95,7 @@ public RevokeOfferSponsorshipOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.offerId, this.getSourceAccount()); + return Objects.hash(this.offerId, this.getSourceAccount()); } @Override @@ -106,8 +105,8 @@ public boolean equals(Object object) { } RevokeOfferSponsorshipOperation other = (RevokeOfferSponsorshipOperation) object; - return Objects.equal(this.seller, other.seller) - && Objects.equal(this.offerId, other.offerId) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.seller, other.seller) + && Objects.equals(this.offerId, other.offerId) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/RevokeSignerSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeSignerSponsorshipOperation.java index d3918bced..834db0e91 100644 --- a/src/main/java/org/stellar/sdk/RevokeSignerSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeSignerSponsorshipOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; public class RevokeSignerSponsorshipOperation extends Operation { @@ -74,8 +73,9 @@ public Builder(String accountId, SignerKey signer) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public RevokeSignerSponsorshipOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public RevokeSignerSponsorshipOperation.Builder setSourceAccount( + @NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -92,7 +92,7 @@ public RevokeSignerSponsorshipOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.accountId, this.signer, this.getSourceAccount()); + return Objects.hash(this.accountId, this.signer, this.getSourceAccount()); } @Override @@ -102,8 +102,8 @@ public boolean equals(Object object) { } RevokeSignerSponsorshipOperation other = (RevokeSignerSponsorshipOperation) object; - return Objects.equal(this.accountId, other.accountId) - && Objects.equal(this.signer, other.signer) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.accountId, other.accountId) + && Objects.equals(this.signer, other.signer) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java index bd91a5bd0..219240ff1 100644 --- a/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeTrustlineSponsorshipOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; public class RevokeTrustlineSponsorshipOperation extends Operation { @@ -76,8 +75,9 @@ public Builder(String accountId, TrustLineAsset asset) { * @param sourceAccount The operation's source account. * @return Builder object so you can chain methods. */ - public RevokeTrustlineSponsorshipOperation.Builder setSourceAccount(String sourceAccount) { - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + public RevokeTrustlineSponsorshipOperation.Builder setSourceAccount( + @NonNull String sourceAccount) { + mSourceAccount = sourceAccount; return this; } @@ -94,7 +94,7 @@ public RevokeTrustlineSponsorshipOperation build() { @Override public int hashCode() { - return Objects.hashCode(this.accountId, this.asset, this.getSourceAccount()); + return Objects.hash(this.accountId, this.asset, this.getSourceAccount()); } @Override @@ -104,8 +104,8 @@ public boolean equals(Object object) { } RevokeTrustlineSponsorshipOperation other = (RevokeTrustlineSponsorshipOperation) object; - return Objects.equal(this.accountId, other.accountId) - && Objects.equal(this.asset, other.asset) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.accountId, other.accountId) + && Objects.equals(this.asset, other.asset) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/Sep10Challenge.java b/src/main/java/org/stellar/sdk/Sep10Challenge.java index be86cd019..a47526b75 100644 --- a/src/main/java/org/stellar/sdk/Sep10Challenge.java +++ b/src/main/java/org/stellar/sdk/Sep10Challenge.java @@ -1,18 +1,18 @@ package org.stellar.sdk; -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.google.common.io.BaseEncoding; import java.io.IOException; import java.math.BigInteger; import java.security.SecureRandom; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import org.stellar.sdk.xdr.DecoratedSignature; import org.stellar.sdk.xdr.Signature; @@ -84,8 +84,7 @@ public static Transaction newChallenge( byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); if (clientDomain.isEmpty() != clientSigningKey.isEmpty()) { throw new InvalidSep10ChallengeException( @@ -309,10 +308,9 @@ public static ChallengeTransaction readChallengeTransaction( "Random nonce encoded as base64 should be 64 bytes long."); } - BaseEncoding base64Encoding = BaseEncoding.base64(); byte[] nonce; try { - nonce = base64Encoding.decode(new String(manageDataOperation.getValue())); + nonce = Base64.getDecoder().decode(new String(manageDataOperation.getValue())); } catch (IllegalArgumentException e) { throw new InvalidSep10ChallengeException( "Failed to decode random nonce provided in ManageData operation.", e); @@ -512,7 +510,7 @@ public static Set verifyChallengeTransactionSigners( // are consumed only once on the transaction. Set allSigners = new HashSet(clientSigners); allSigners.add(serverKeyPair.getAccountId()); - Optional clientDomainSigner = Optional.absent(); + Optional clientDomainSigner = Optional.empty(); for (Operation op : transaction.getOperations()) { if (!(op instanceof ManageDataOperation)) { @@ -681,10 +679,14 @@ private static Set verifyTransactionSignatures( byte[] txHash = transaction.hash(); // find and verify signatures - Set signersFound = new HashSet(); - Multimap signatures = HashMultimap.create(); + Set signersFound = new HashSet<>(); + Map> signatures = new HashMap<>(); + for (DecoratedSignature decoratedSignature : transaction.getSignatures()) { - signatures.put(decoratedSignature.getHint(), decoratedSignature.getSignature()); + SignatureHint hint = decoratedSignature.getHint(); + Signature signature = decoratedSignature.getSignature(); + List signatureList = signatures.computeIfAbsent(hint, k -> new ArrayList<>()); + signatureList.add(signature); } for (String signer : signers) { @@ -695,13 +697,13 @@ private static Set verifyTransactionSignatures( continue; } SignatureHint hint = keyPair.getSignatureHint(); - - for (Signature signature : signatures.get(hint)) { + List signatureList = signatures.getOrDefault(hint, Collections.emptyList()); + for (Signature signature : signatureList) { if (keyPair.verify(txHash, signature.getSignature())) { signersFound.add(signer); // explicitly ensure that a transaction signature cannot be // mapped to more than one signer - signatures.remove(hint, signature); + signatureList.remove(signature); break; } } @@ -745,7 +747,7 @@ public String getMatchedHomeDomain() { @Override public int hashCode() { - return Objects.hashCode(this.transaction.hashHex(), this.clientAccountId); + return Objects.hash(this.transaction.hashHex(), this.clientAccountId); } @Override @@ -759,9 +761,9 @@ public boolean equals(Object object) { } ChallengeTransaction other = (ChallengeTransaction) object; - return Objects.equal(this.transaction.hashHex(), other.transaction.hashHex()) - && Objects.equal(this.clientAccountId, other.clientAccountId) - && Objects.equal(this.matchedHomeDomain, other.matchedHomeDomain); + return Objects.equals(this.transaction.hashHex(), other.transaction.hashHex()) + && Objects.equals(this.clientAccountId, other.clientAccountId) + && Objects.equals(this.matchedHomeDomain, other.matchedHomeDomain); } } @@ -785,7 +787,7 @@ public int getWeight() { @Override public int hashCode() { - return Objects.hashCode(this.key, this.weight); + return Objects.hash(this.key, this.weight); } @Override @@ -799,7 +801,7 @@ public boolean equals(Object object) { } Signer other = (Signer) object; - return Objects.equal(this.key, other.key) && Objects.equal(this.weight, other.weight); + return Objects.equals(this.key, other.key) && Objects.equals(this.weight, other.weight); } } } diff --git a/src/main/java/org/stellar/sdk/Server.java b/src/main/java/org/stellar/sdk/Server.java index 77c5473fe..c331d01ff 100644 --- a/src/main/java/org/stellar/sdk/Server.java +++ b/src/main/java/org/stellar/sdk/Server.java @@ -1,11 +1,11 @@ package org.stellar.sdk; -import com.google.common.base.Optional; import com.google.gson.reflect.TypeToken; import java.io.Closeable; import java.io.IOException; import java.net.SocketTimeoutException; import java.util.HashSet; +import java.util.Optional; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; @@ -62,7 +62,7 @@ public Server(String serverURI, OkHttpClient httpClient, OkHttpClient submitHttp this.serverURI = HttpUrl.parse(serverURI); this.httpClient = httpClient; this.submitHttpClient = submitHttpClient; - this.network = Optional.absent(); + this.network = Optional.empty(); this.networkLock = new ReentrantReadWriteLock(); } diff --git a/src/main/java/org/stellar/sdk/SetOptionsOperation.java b/src/main/java/org/stellar/sdk/SetOptionsOperation.java index 0a3e94927..086ac4f3a 100644 --- a/src/main/java/org/stellar/sdk/SetOptionsOperation.java +++ b/src/main/java/org/stellar/sdk/SetOptionsOperation.java @@ -1,8 +1,7 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.*; /** @@ -340,9 +339,7 @@ public Builder setHomeDomain(String homeDomain) { * @param weight The weight to attach to the signer (0-255). * @return Builder object so you can chain methods. */ - public Builder setSigner(SignerKey signer, Integer weight) { - checkNotNull(signer, "signer cannot be null"); - checkNotNull(weight, "weight cannot be null"); + public Builder setSigner(@NonNull SignerKey signer, @NonNull Integer weight) { this.signer = signer; signerWeight = weight & 0xFF; return this; @@ -382,7 +379,7 @@ public SetOptionsOperation build() { @Override public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), this.inflationDestination, this.clearFlags, @@ -403,16 +400,16 @@ public boolean equals(Object object) { } SetOptionsOperation other = (SetOptionsOperation) object; - return Objects.equal(this.getSourceAccount(), other.getSourceAccount()) - && Objects.equal(this.inflationDestination, other.inflationDestination) - && Objects.equal(this.clearFlags, other.clearFlags) - && Objects.equal(this.setFlags, other.setFlags) - && Objects.equal(this.masterKeyWeight, other.masterKeyWeight) - && Objects.equal(this.lowThreshold, other.lowThreshold) - && Objects.equal(this.mediumThreshold, other.mediumThreshold) - && Objects.equal(this.highThreshold, other.highThreshold) - && Objects.equal(this.homeDomain, other.homeDomain) - && Objects.equal(this.signer, other.signer) - && Objects.equal(this.signerWeight, other.signerWeight); + return Objects.equals(this.getSourceAccount(), other.getSourceAccount()) + && Objects.equals(this.inflationDestination, other.inflationDestination) + && Objects.equals(this.clearFlags, other.clearFlags) + && Objects.equals(this.setFlags, other.setFlags) + && Objects.equals(this.masterKeyWeight, other.masterKeyWeight) + && Objects.equals(this.lowThreshold, other.lowThreshold) + && Objects.equals(this.mediumThreshold, other.mediumThreshold) + && Objects.equals(this.highThreshold, other.highThreshold) + && Objects.equals(this.homeDomain, other.homeDomain) + && Objects.equals(this.signer, other.signer) + && Objects.equals(this.signerWeight, other.signerWeight); } } diff --git a/src/main/java/org/stellar/sdk/SetTrustlineFlagsOperation.java b/src/main/java/org/stellar/sdk/SetTrustlineFlagsOperation.java index ba959f18e..2b5453335 100644 --- a/src/main/java/org/stellar/sdk/SetTrustlineFlagsOperation.java +++ b/src/main/java/org/stellar/sdk/SetTrustlineFlagsOperation.java @@ -1,7 +1,7 @@ package org.stellar.sdk; -import com.google.common.base.Objects; import java.util.EnumSet; +import java.util.Objects; import org.stellar.sdk.xdr.*; /** @@ -146,7 +146,7 @@ public SetTrustlineFlagsOperation build() { @Override public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.getSourceAccount(), this.trustor, this.asset, this.clearFlags, this.setFlags); } @@ -157,10 +157,10 @@ public boolean equals(Object object) { } SetTrustlineFlagsOperation other = (SetTrustlineFlagsOperation) object; - return Objects.equal(this.trustor, other.trustor) - && Objects.equal(this.asset, other.asset) - && Objects.equal(this.clearFlags, other.clearFlags) - && Objects.equal(this.setFlags, other.setFlags) - && Objects.equal(this.getSourceAccount(), other.getSourceAccount()); + return Objects.equals(this.trustor, other.trustor) + && Objects.equals(this.asset, other.asset) + && Objects.equals(this.clearFlags, other.clearFlags) + && Objects.equals(this.setFlags, other.setFlags) + && Objects.equals(this.getSourceAccount(), other.getSourceAccount()); } } diff --git a/src/main/java/org/stellar/sdk/SignedPayloadSigner.java b/src/main/java/org/stellar/sdk/SignedPayloadSigner.java index 0eb30b16b..15ae5ddcc 100644 --- a/src/main/java/org/stellar/sdk/SignedPayloadSigner.java +++ b/src/main/java/org/stellar/sdk/SignedPayloadSigner.java @@ -1,7 +1,6 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - +import lombok.NonNull; import org.stellar.sdk.xdr.AccountID; import org.stellar.sdk.xdr.PublicKey; import org.stellar.sdk.xdr.PublicKeyType; @@ -24,9 +23,7 @@ public class SignedPayloadSigner { * @param signerAccountId - the xdr AccountID * @param payload - the raw payload for a signed payload */ - public SignedPayloadSigner(AccountID signerAccountId, byte[] payload) { - checkNotNull(payload, "payload cannot be null"); - checkNotNull(signerAccountId, "accountId cannot be null"); + public SignedPayloadSigner(@NonNull AccountID signerAccountId, byte @NonNull [] payload) { if (payload.length > SIGNED_PAYLOAD_MAX_PAYLOAD_LENGTH) { throw new IllegalArgumentException( "invalid payload length, must be less than " + SIGNED_PAYLOAD_MAX_PAYLOAD_LENGTH); @@ -39,8 +36,8 @@ public SignedPayloadSigner(AccountID signerAccountId, byte[] payload) { throw new IllegalArgumentException( "invalid payload signer, only ED25519 public key accounts are supported currently"); } - this.signerAccountId = checkNotNull(signerAccountId); - this.payload = checkNotNull(payload); + this.signerAccountId = signerAccountId; + this.payload = payload; } /** diff --git a/src/main/java/org/stellar/sdk/Signer.java b/src/main/java/org/stellar/sdk/Signer.java index 9fa5e0af2..1f947bc8c 100644 --- a/src/main/java/org/stellar/sdk/Signer.java +++ b/src/main/java/org/stellar/sdk/Signer.java @@ -1,7 +1,6 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; - +import lombok.NonNull; import org.stellar.sdk.xdr.SignerKey; import org.stellar.sdk.xdr.SignerKeyType; import org.stellar.sdk.xdr.Uint256; @@ -15,8 +14,7 @@ public class Signer { * @param keyPair * @return org.stellar.sdk.xdr.SignerKey */ - public static SignerKey ed25519PublicKey(KeyPair keyPair) { - checkNotNull(keyPair, "keyPair cannot be null"); + public static SignerKey ed25519PublicKey(@NonNull KeyPair keyPair) { return keyPair.getXdrSignerKey(); } @@ -27,8 +25,7 @@ public static SignerKey ed25519PublicKey(KeyPair keyPair) { * @param hash * @return org.stellar.sdk.xdr.SignerKey */ - public static SignerKey sha256Hash(byte[] hash) { - checkNotNull(hash, "hash cannot be null"); + public static SignerKey sha256Hash(byte @NonNull [] hash) { SignerKey signerKey = new SignerKey(); Uint256 value = Signer.createUint256(hash); @@ -45,8 +42,7 @@ public static SignerKey sha256Hash(byte[] hash) { * @param tx * @return org.stellar.sdk.xdr.SignerKey */ - public static SignerKey preAuthTx(Transaction tx) { - checkNotNull(tx, "tx cannot be null"); + public static SignerKey preAuthTx(@NonNull Transaction tx) { SignerKey signerKey = new SignerKey(); Uint256 value = Signer.createUint256(tx.hash()); @@ -62,8 +58,7 @@ public static SignerKey preAuthTx(Transaction tx) { * @param hash * @return org.stellar.sdk.xdr.SignerKey */ - public static SignerKey preAuthTx(byte[] hash) { - checkNotNull(hash, "hash cannot be null"); + public static SignerKey preAuthTx(byte @NonNull [] hash) { SignerKey signerKey = new SignerKey(); Uint256 value = Signer.createUint256(hash); diff --git a/src/main/java/org/stellar/sdk/SorobanDataBuilder.java b/src/main/java/org/stellar/sdk/SorobanDataBuilder.java index 96de828fd..fea84ec2d 100644 --- a/src/main/java/org/stellar/sdk/SorobanDataBuilder.java +++ b/src/main/java/org/stellar/sdk/SorobanDataBuilder.java @@ -2,10 +2,10 @@ import java.io.IOException; import java.util.Collection; -import javax.annotation.Nullable; import lombok.Builder; import lombok.NonNull; import lombok.Value; +import org.jetbrains.annotations.Nullable; import org.stellar.sdk.xdr.ExtensionPoint; import org.stellar.sdk.xdr.Int64; import org.stellar.sdk.xdr.LedgerFootprint; diff --git a/src/main/java/org/stellar/sdk/SorobanServer.java b/src/main/java/org/stellar/sdk/SorobanServer.java index 3ac2fb33a..7eb9574f7 100644 --- a/src/main/java/org/stellar/sdk/SorobanServer.java +++ b/src/main/java/org/stellar/sdk/SorobanServer.java @@ -11,13 +11,13 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; import okhttp3.HttpUrl; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; +import org.jetbrains.annotations.Nullable; import org.stellar.sdk.requests.ClientIdentificationInterceptor; import org.stellar.sdk.requests.ResponseHandler; import org.stellar.sdk.requests.sorobanrpc.GetEventsRequest; diff --git a/src/main/java/org/stellar/sdk/StrKey.java b/src/main/java/org/stellar/sdk/StrKey.java index 26db710b3..7856fef90 100644 --- a/src/main/java/org/stellar/sdk/StrKey.java +++ b/src/main/java/org/stellar/sdk/StrKey.java @@ -1,14 +1,12 @@ package org.stellar.sdk; -import com.google.common.base.Optional; -import com.google.common.io.BaseEncoding; -import com.google.common.primitives.Bytes; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.CharArrayWriter; import java.io.IOException; -import java.io.OutputStream; import java.util.Arrays; +import java.util.Optional; +import org.apache.commons.codec.binary.Base32; +import org.apache.commons.codec.binary.Base32OutputStream; import org.stellar.sdk.xdr.AccountID; import org.stellar.sdk.xdr.CryptoKeyType; import org.stellar.sdk.xdr.MuxedAccount; @@ -25,8 +23,7 @@ class StrKey { public static final int ACCOUNT_ID_ADDRESS_LENGTH = 56; private static final byte[] b32Table = decodingTable(); - private static final BaseEncoding base32Encoding = - BaseEncoding.base32().upperCase().omitPadding(); + private static final Base32 base32Codec = new Base32(); public static String encodeContractId(byte[] data) { char[] encoded = encodeCheck(VersionByte.CONTRACT, data); @@ -109,7 +106,7 @@ public static AccountID encodeToXDRAccountId(String data) { public static MuxedAccount encodeToXDRMuxedAccount(String data) { MuxedAccount muxed = new MuxedAccount(); - if (data.length() == 0) { + if (data.isEmpty()) { throw new IllegalArgumentException("address is empty"); } switch (decodeVersionByte(data)) { @@ -142,7 +139,7 @@ public static MuxedAccount encodeToXDRMuxedAccount(String data) { } public static VersionByte decodeVersionByte(String data) { - byte[] decoded = StrKey.base32Encoding.decode(java.nio.CharBuffer.wrap(data.toCharArray())); + byte[] decoded = base32Codec.decode(data); byte decodedVersionByte = decoded[0]; Optional versionByteOptional = VersionByte.findByValue(decodedVersionByte); if (!versionByteOptional.isPresent()) { @@ -240,28 +237,33 @@ protected static char[] encodeCheck(VersionByte versionByte, byte[] data) { byte[] unencoded = outputStream.toByteArray(); if (VersionByte.SEED != versionByte) { - return base32Encoding.encode(unencoded).toCharArray(); + return bytesToChars(removeBase32Padding(base32Codec.encode(unencoded))); } - // Why not use base32Encoding.encode here? + // Why not use base32Codec.encode here? // We don't want secret seed to be stored as String in memory because of security reasons. // It's impossible // to erase it from memory when we want it to be erased (ASAP). - CharArrayWriter charArrayWriter = new CharArrayWriter(unencoded.length); - OutputStream charOutputStream = base32Encoding.encodingStream(charArrayWriter); - charOutputStream.write(unencoded); - char[] charsEncoded = charArrayWriter.toCharArray(); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(unencoded.length); + Base32OutputStream base32OutputStream = new Base32OutputStream(byteArrayOutputStream); + base32OutputStream.write(unencoded); + base32OutputStream.close(); + + byte[] encodedBytes = byteArrayOutputStream.toByteArray(); + byte[] unpaddedEncodedBytes = removeBase32Padding(encodedBytes); + char[] charsEncoded = bytesToChars(unpaddedEncodedBytes); Arrays.fill(unencoded, (byte) 0); Arrays.fill(payload, (byte) 0); Arrays.fill(checksum, (byte) 0); + Arrays.fill(encodedBytes, (byte) 0); + Arrays.fill(unpaddedEncodedBytes, (byte) 0); - // Clean charArrayWriter internal buffer - int bufferSize = charArrayWriter.size(); - char[] zeros = new char[bufferSize]; - Arrays.fill(zeros, '0'); - charArrayWriter.reset(); - charArrayWriter.write(zeros); + // Clean byteArrayOutputStream internal buffer + int size = byteArrayOutputStream.size(); + byteArrayOutputStream.reset(); + byteArrayOutputStream.write(new byte[size]); + byteArrayOutputStream.close(); return charsEncoded; } catch (IOException e) { @@ -298,7 +300,7 @@ protected static byte[] decodeCheck(VersionByte versionByte, char[] encoded) { } } - byte[] decoded = base32Encoding.decode(java.nio.CharBuffer.wrap(encoded)); + byte[] decoded = base32Codec.decode(bytes); byte decodedVersionByte = decoded[0]; byte[] payload = Arrays.copyOfRange(decoded, 0, decoded.length - 2); byte[] data = Arrays.copyOfRange(payload, 1, payload.length); @@ -382,7 +384,7 @@ public static Optional findByValue(byte value) { return Optional.of(versionByte); } } - return Optional.absent(); + return Optional.empty(); } public int getValue() { @@ -398,6 +400,28 @@ private static byte[] getMuxedEd25519AccountBytes(MuxedAccount muxedAccount) { int idCopyStartIndex = idBytes.length - idNumBytesToCopy; System.arraycopy( idBytes, idCopyStartIndex, idPaddedBytes, 8 - idNumBytesToCopy, idNumBytesToCopy); - return Bytes.concat(accountBytes, idPaddedBytes); + byte[] result = new byte[accountBytes.length + idPaddedBytes.length]; + System.arraycopy(accountBytes, 0, result, 0, accountBytes.length); + System.arraycopy(idPaddedBytes, 0, result, accountBytes.length, idPaddedBytes.length); + return result; + } + + private static byte[] removeBase32Padding(byte[] data) { + // Calculate the length of unpadded data + int unpaddedLength = data.length; + while (unpaddedLength > 0 && data[unpaddedLength - 1] == '=') { + unpaddedLength--; + } + + // Create a copy of the data without padding bytes + return Arrays.copyOf(data, unpaddedLength); + } + + private static char[] bytesToChars(byte[] data) { + char[] chars = new char[data.length]; + for (int i = 0; i < data.length; i++) { + chars[i] = (char) (data[i] & 0xFF); + } + return chars; } } diff --git a/src/main/java/org/stellar/sdk/TimeBounds.java b/src/main/java/org/stellar/sdk/TimeBounds.java index b797c7df6..797d565ab 100644 --- a/src/main/java/org/stellar/sdk/TimeBounds.java +++ b/src/main/java/org/stellar/sdk/TimeBounds.java @@ -1,7 +1,7 @@ package org.stellar.sdk; -import com.google.common.base.Objects; import java.math.BigInteger; +import java.util.Objects; import org.stellar.sdk.xdr.TimePoint; import org.stellar.sdk.xdr.Uint64; import org.stellar.sdk.xdr.XdrUnsignedHyperInteger; @@ -101,12 +101,12 @@ public boolean equals(Object o) { return false; } TimeBounds that = (TimeBounds) o; - return Objects.equal(this.mMaxTime, that.mMaxTime) - && Objects.equal(this.mMinTime, that.mMinTime); + return Objects.equals(this.mMaxTime, that.mMaxTime) + && Objects.equals(this.mMinTime, that.mMinTime); } @Override public int hashCode() { - return Objects.hashCode(this.mMaxTime, this.mMinTime); + return Objects.hash(this.mMaxTime, this.mMinTime); } } diff --git a/src/main/java/org/stellar/sdk/Transaction.java b/src/main/java/org/stellar/sdk/Transaction.java index 56beee7d7..2a63facc8 100644 --- a/src/main/java/org/stellar/sdk/Transaction.java +++ b/src/main/java/org/stellar/sdk/Transaction.java @@ -1,12 +1,10 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.xdr.AccountID; import org.stellar.sdk.xdr.ClaimableBalanceID; import org.stellar.sdk.xdr.ClaimableBalanceIDType; @@ -42,19 +40,21 @@ public class Transaction extends AbstractTransaction { Transaction( AccountConverter accountConverter, - String sourceAccount, + @NonNull String sourceAccount, long fee, long sequenceNumber, - Operation[] operations, + @NonNull Operation[] operations, Memo memo, TransactionPreconditions preconditions, SorobanTransactionData sorobanData, Network network) { super(accountConverter, network); - this.mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); + this.mSourceAccount = sourceAccount; this.mSequenceNumber = sequenceNumber; - this.mOperations = checkNotNull(operations, "operations cannot be null"); - checkArgument(operations.length > 0, "At least one operation required"); + this.mOperations = operations; + if (operations.length == 0) { + throw new IllegalArgumentException("At least one operation required"); + } this.mPreconditions = preconditions; this.mFee = fee; this.mMemo = memo != null ? memo : Memo.none(); @@ -339,7 +339,7 @@ public TransactionEnvelope toEnvelopeXdr() { @Override public int hashCode() { - return Objects.hashCode( + return Objects.hash( this.envelopeType, this.mFee, this.mSourceAccount, @@ -359,16 +359,16 @@ public boolean equals(Object object) { } Transaction other = (Transaction) object; - return Objects.equal(this.envelopeType, other.envelopeType) - && Objects.equal(this.mFee, other.mFee) - && Objects.equal(this.mSourceAccount, other.mSourceAccount) - && Objects.equal(this.mSequenceNumber, other.mSequenceNumber) + return Objects.equals(this.envelopeType, other.envelopeType) + && Objects.equals(this.mFee, other.mFee) + && Objects.equals(this.mSourceAccount, other.mSourceAccount) + && Objects.equals(this.mSequenceNumber, other.mSequenceNumber) && Arrays.equals(this.mOperations, other.mOperations) - && Objects.equal(this.mMemo, other.mMemo) - && Objects.equal(this.mPreconditions, other.mPreconditions) - && Objects.equal(this.mNetwork, other.mNetwork) - && Objects.equal(this.mSignatures, other.mSignatures) - && Objects.equal(this.mSorobanData, other.mSorobanData); + && Objects.equals(this.mMemo, other.mMemo) + && Objects.equals(this.mPreconditions, other.mPreconditions) + && Objects.equals(this.mNetwork, other.mNetwork) + && Objects.equals(this.mSignatures, other.mSignatures) + && Objects.equals(this.mSorobanData, other.mSorobanData); } /** diff --git a/src/main/java/org/stellar/sdk/TransactionBuilder.java b/src/main/java/org/stellar/sdk/TransactionBuilder.java index 44dcb4794..d31f56f83 100644 --- a/src/main/java/org/stellar/sdk/TransactionBuilder.java +++ b/src/main/java/org/stellar/sdk/TransactionBuilder.java @@ -1,13 +1,13 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Lists.newArrayList; import static org.stellar.sdk.TransactionPreconditions.TIMEOUT_INFINITE; -import com.google.common.base.Function; import java.math.BigInteger; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.function.Function; +import lombok.NonNull; import org.stellar.sdk.TransactionPreconditions.TransactionPreconditionsBuilder; import org.stellar.sdk.xdr.SorobanTransactionData; import org.stellar.sdk.xdr.TimePoint; @@ -35,11 +35,13 @@ public class TransactionBuilder { * @param network the testnet or pubnet network to use */ public TransactionBuilder( - AccountConverter accountConverter, TransactionBuilderAccount sourceAccount, Network network) { - mAccountConverter = checkNotNull(accountConverter, "accountConverter cannot be null"); - mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); - mNetwork = checkNotNull(network, "Network cannot be null"); - mOperations = newArrayList(); + @NonNull AccountConverter accountConverter, + @NonNull TransactionBuilderAccount sourceAccount, + @NonNull Network network) { + mAccountConverter = accountConverter; + mSourceAccount = sourceAccount; + mNetwork = network; + mOperations = new ArrayList<>(); mPreconditions = TransactionPreconditions.builder().build(); } @@ -67,8 +69,7 @@ public int getOperationsCount() { * @return Builder object so you can chain methods. * @see Operation */ - public TransactionBuilder addOperation(Operation operation) { - checkNotNull(operation, "operation cannot be null"); + public TransactionBuilder addOperation(@NonNull Operation operation) { mOperations.add(operation); return this; } @@ -81,8 +82,7 @@ public TransactionBuilder addOperation(Operation operation) { * @return Builder object so you can chain methods. * @see Operation */ - public TransactionBuilder addOperations(Collection operations) { - checkNotNull(operations, "operations cannot be null"); + public TransactionBuilder addOperations(@NonNull Collection operations) { mOperations.addAll(operations); return this; } @@ -94,8 +94,7 @@ public TransactionBuilder addOperations(Collection operations) { * @param preconditions the tx PreConditions * @return updated Builder object */ - public TransactionBuilder addPreconditions(TransactionPreconditions preconditions) { - checkNotNull(preconditions, "preconditions cannot be null"); + public TransactionBuilder addPreconditions(@NonNull TransactionPreconditions preconditions) { this.mPreconditions = preconditions; return this; } @@ -108,11 +107,10 @@ public TransactionBuilder addPreconditions(TransactionPreconditions precondition * @return Builder object so you can chain methods. * @see Memo */ - public TransactionBuilder addMemo(Memo memo) { + public TransactionBuilder addMemo(@NonNull Memo memo) { if (mMemo != null) { throw new RuntimeException("Memo has been already added."); } - checkNotNull(memo, "memo cannot be null"); mMemo = memo; return this; } @@ -127,8 +125,7 @@ public TransactionBuilder addMemo(Memo memo) { * @deprecated this method will be removed in upcoming releases, use addPreconditions() * instead for more control over preconditions. */ - public TransactionBuilder addTimeBounds(TimeBounds timeBounds) { - checkNotNull(timeBounds, "timeBounds cannot be null"); + public TransactionBuilder addTimeBounds(@NonNull TimeBounds timeBounds) { if (mPreconditions.getTimeBounds() != null) { throw new RuntimeException("TimeBounds already set."); } @@ -247,12 +244,7 @@ public Transaction build() { * based on sourceAccount's current sequence number + 1. */ public static Function IncrementedSequenceNumberFunc = - new Function() { - @Override - public Long apply(TransactionBuilderAccount sourceAccount) { - return sourceAccount.getIncrementedSequenceNumber(); - } - }; + TransactionBuilderAccount::getIncrementedSequenceNumber; @Deprecated public static org.stellar.sdk.xdr.TimeBounds buildTimeBounds(long minTime, long maxTime) { diff --git a/src/main/java/org/stellar/sdk/TrustLineAsset.java b/src/main/java/org/stellar/sdk/TrustLineAsset.java index 0bb5986f2..2d059a14e 100644 --- a/src/main/java/org/stellar/sdk/TrustLineAsset.java +++ b/src/main/java/org/stellar/sdk/TrustLineAsset.java @@ -1,6 +1,6 @@ package org.stellar.sdk; -import static com.google.common.base.Preconditions.checkNotNull; +import lombok.NonNull; /** * TrustLineAsset class. @@ -144,9 +144,8 @@ public static TrustLineAsset fromXdr(org.stellar.sdk.xdr.TrustLineAsset xdr) { public static final class Wrapper extends TrustLineAsset { private Asset asset; - public Wrapper(Asset baseAsset) { + public Wrapper(@NonNull Asset baseAsset) { super(); - checkNotNull(baseAsset, "asset cannot be null"); asset = baseAsset; } diff --git a/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java index 3730ebec6..fa1c19c22 100644 --- a/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/EffectsRequestBuilder.java @@ -1,9 +1,8 @@ package org.stellar.sdk.requests; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.gson.reflect.TypeToken; import java.io.IOException; +import lombok.NonNull; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -25,8 +24,7 @@ public EffectsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { * Account * @param account Account for which to get effects */ - public EffectsRequestBuilder forAccount(String account) { - account = checkNotNull(account, "account cannot be null"); + public EffectsRequestBuilder forAccount(@NonNull String account) { this.setSegments("accounts", account, "effects"); return this; } @@ -50,8 +48,7 @@ public EffectsRequestBuilder forLedger(long ledgerSeq) { * Transaction * @param transactionId Transaction ID for which to get effects */ - public EffectsRequestBuilder forTransaction(String transactionId) { - transactionId = checkNotNull(transactionId, "transactionId cannot be null"); + public EffectsRequestBuilder forTransaction(@NonNull String transactionId) { this.setSegments("transactions", transactionId, "effects"); return this; } diff --git a/src/main/java/org/stellar/sdk/requests/EventListener.java b/src/main/java/org/stellar/sdk/requests/EventListener.java index f95366787..75b36d32c 100644 --- a/src/main/java/org/stellar/sdk/requests/EventListener.java +++ b/src/main/java/org/stellar/sdk/requests/EventListener.java @@ -1,6 +1,6 @@ package org.stellar.sdk.requests; -import com.google.common.base.Optional; +import java.util.Optional; /** This interface is used in {@link RequestBuilder} classes stream method. */ public interface EventListener { diff --git a/src/main/java/org/stellar/sdk/requests/OffersRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/OffersRequestBuilder.java index d66671ad6..44475ce4d 100644 --- a/src/main/java/org/stellar/sdk/requests/OffersRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/OffersRequestBuilder.java @@ -1,9 +1,8 @@ package org.stellar.sdk.requests; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.gson.reflect.TypeToken; import java.io.IOException; +import lombok.NonNull; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -54,8 +53,7 @@ public OfferResponse offer(long offerId) throws IOException { * GET /accounts/{account}/offers */ @Deprecated - public OffersRequestBuilder forAccount(String account) { - account = checkNotNull(account, "account cannot be null"); + public OffersRequestBuilder forAccount(@NonNull String account) { this.setSegments("accounts", account, "offers"); 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 055deadd3..4128b4d80 100644 --- a/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/OperationsRequestBuilder.java @@ -1,12 +1,10 @@ package org.stellar.sdk.requests; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Joiner; -import com.google.common.collect.Sets; import com.google.gson.reflect.TypeToken; import java.io.IOException; +import java.util.HashSet; import java.util.Set; +import lombok.NonNull; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -21,7 +19,7 @@ public class OperationsRequestBuilder extends RequestBuilder { public OperationsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { super(httpClient, serverURI, "operations"); - toJoin = Sets.newHashSet(); + toJoin = new HashSet<>(); } /** @@ -61,8 +59,7 @@ public OperationResponse operation(long operationId) throws IOException { * Account * @param account Account for which to get operations */ - public OperationsRequestBuilder forAccount(String account) { - account = checkNotNull(account, "account cannot be null"); + public OperationsRequestBuilder forAccount(@NonNull String account) { this.setSegments("accounts", account, "operations"); return this; } @@ -75,8 +72,7 @@ public OperationsRequestBuilder forAccount(String account) { * for ClaimableBalance * @param claimableBalance Claimable Balance for which to get operations */ - public OperationsRequestBuilder forClaimableBalance(String claimableBalance) { - claimableBalance = checkNotNull(claimableBalance, "claimableBalance cannot be null"); + public OperationsRequestBuilder forClaimableBalance(@NonNull String claimableBalance) { this.setSegments("claimable_balances", claimableBalance, "operations"); return this; } @@ -100,8 +96,7 @@ public OperationsRequestBuilder forLedger(long ledgerSeq) { * for Transaction * @param transactionId Transaction ID for which to get operations */ - public OperationsRequestBuilder forTransaction(String transactionId) { - transactionId = checkNotNull(transactionId, "transactionId cannot be null"); + public OperationsRequestBuilder forTransaction(@NonNull String transactionId) { this.setSegments("transactions", transactionId, "operations"); return this; } @@ -162,7 +157,7 @@ protected void updateToJoin(String value, boolean include) { if (toJoin.isEmpty()) { uriBuilder.removeAllQueryParameters("join"); } else { - uriBuilder.setQueryParameter("join", Joiner.on(",").join(toJoin)); + uriBuilder.setQueryParameter("join", String.join(",", toJoin)); } } diff --git a/src/main/java/org/stellar/sdk/requests/PaymentsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/PaymentsRequestBuilder.java index 6feb001a3..a5dd26608 100644 --- a/src/main/java/org/stellar/sdk/requests/PaymentsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/PaymentsRequestBuilder.java @@ -1,12 +1,10 @@ package org.stellar.sdk.requests; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Joiner; -import com.google.common.collect.Sets; import com.google.gson.reflect.TypeToken; import java.io.IOException; +import java.util.HashSet; import java.util.Set; +import lombok.NonNull; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -20,7 +18,7 @@ public class PaymentsRequestBuilder extends RequestBuilder { public PaymentsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { super(httpClient, serverURI, "payments"); - toJoin = Sets.newHashSet(); + toJoin = new HashSet<>(); } /** @@ -30,8 +28,7 @@ public PaymentsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { * Account * @param account Account for which to get payments */ - public PaymentsRequestBuilder forAccount(String account) { - account = checkNotNull(account, "account cannot be null"); + public PaymentsRequestBuilder forAccount(@NonNull String account) { this.setSegments("accounts", account, "payments"); return this; } @@ -55,8 +52,7 @@ public PaymentsRequestBuilder forLedger(long ledgerSeq) { * Transaction * @param transactionId Transaction ID for which to get payments */ - public PaymentsRequestBuilder forTransaction(String transactionId) { - transactionId = checkNotNull(transactionId, "transactionId cannot be null"); + public PaymentsRequestBuilder forTransaction(@NonNull String transactionId) { this.setSegments("transactions", transactionId, "payments"); return this; } @@ -81,7 +77,7 @@ protected void updateToJoin(String value, boolean include) { if (toJoin.isEmpty()) { uriBuilder.removeAllQueryParameters("join"); } else { - uriBuilder.setQueryParameter("join", Joiner.on(",").join(toJoin)); + uriBuilder.setQueryParameter("join", String.join(",", toJoin)); } } diff --git a/src/main/java/org/stellar/sdk/requests/RequestBuilder.java b/src/main/java/org/stellar/sdk/requests/RequestBuilder.java index a935bef0d..0bfadc7ab 100644 --- a/src/main/java/org/stellar/sdk/requests/RequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/RequestBuilder.java @@ -1,7 +1,5 @@ package org.stellar.sdk.requests; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -83,11 +81,11 @@ public RequestBuilder order(Order direction) { * @param assets the list of assets to be serialized into the query parameter value */ public RequestBuilder setAssetsParameter(String name, List assets) { - List assetStrings = Lists.newArrayList(); + List assetStrings = new ArrayList<>(); for (Asset asset : assets) { assetStrings.add(encodeAsset(asset)); } - uriBuilder.setQueryParameter(name, Joiner.on(",").join(assetStrings)); + uriBuilder.setQueryParameter(name, String.join(",", assetStrings)); return this; } diff --git a/src/main/java/org/stellar/sdk/requests/SSEStream.java b/src/main/java/org/stellar/sdk/requests/SSEStream.java index 33a1f94f9..b6d86bd9a 100644 --- a/src/main/java/org/stellar/sdk/requests/SSEStream.java +++ b/src/main/java/org/stellar/sdk/requests/SSEStream.java @@ -1,8 +1,8 @@ package org.stellar.sdk.requests; -import com.google.common.base.Optional; import java.io.Closeable; import java.net.SocketException; +import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -10,7 +10,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import javax.annotation.Nullable; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -18,6 +17,7 @@ import okhttp3.internal.sse.RealEventSource; import okhttp3.sse.EventSource; import okhttp3.sse.EventSourceListener; +import org.jetbrains.annotations.Nullable; import org.stellar.sdk.Util; import org.stellar.sdk.responses.GsonSingleton; import org.stellar.sdk.responses.Pageable; @@ -199,7 +199,7 @@ public void onOpen(EventSource eventSource, Response response) {} @Override public void onFailure( EventSource eventSource, @Nullable Throwable t, @Nullable Response response) { - Optional code = Optional.absent(); + Optional code = Optional.empty(); if (response != null) { code = Optional.of(response.code()); } @@ -212,7 +212,7 @@ public void onFailure( listener.onFailure(Optional.of(t), code); } } else { - Optional absent = Optional.absent(); + Optional absent = Optional.empty(); listener.onFailure(absent, code); } } diff --git a/src/main/java/org/stellar/sdk/requests/TooManyRequestsException.java b/src/main/java/org/stellar/sdk/requests/TooManyRequestsException.java index 850f9d377..bb56ead87 100644 --- a/src/main/java/org/stellar/sdk/requests/TooManyRequestsException.java +++ b/src/main/java/org/stellar/sdk/requests/TooManyRequestsException.java @@ -1,6 +1,6 @@ package org.stellar.sdk.requests; -import com.google.common.base.Optional; +import java.util.Optional; /** * Exception thrown when too many requests were sent to the Horizon server. @@ -21,6 +21,6 @@ public TooManyRequestsException(Integer retryAfter) { * is unknown. */ public Optional getRetryAfter() { - return Optional.fromNullable(retryAfter); + return Optional.ofNullable(retryAfter); } } diff --git a/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java index 6139951cd..9115bba61 100644 --- a/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java @@ -1,9 +1,8 @@ package org.stellar.sdk.requests; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.gson.reflect.TypeToken; import java.io.IOException; +import lombok.NonNull; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -49,8 +48,7 @@ public TradesRequestBuilder counterAsset(Asset asset) { * Account * @param account Account for which to get trades */ - public TradesRequestBuilder forAccount(String account) { - account = checkNotNull(account, "account cannot be null"); + public TradesRequestBuilder forAccount(@NonNull String account) { this.setSegments("accounts", account, "trades"); return this; } @@ -85,8 +83,7 @@ public TradesRequestBuilder forLiquidityPool(String liquidityPoolID) { * @return current {@link TradesRequestBuilder} instance * @see List All Trades */ - public TradesRequestBuilder forTradeType(String tradeType) { - tradeType = checkNotNull(tradeType, "tradeType cannot be null"); + public TradesRequestBuilder forTradeType(@NonNull String tradeType) { uriBuilder.setQueryParameter(TRADE_TYPE_PARAMETER_NAME, tradeType); return this; } diff --git a/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java b/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java index fe2e8ebd9..fac6de464 100644 --- a/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java +++ b/src/main/java/org/stellar/sdk/requests/TransactionsRequestBuilder.java @@ -1,9 +1,8 @@ package org.stellar.sdk.requests; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.gson.reflect.TypeToken; import java.io.IOException; +import lombok.NonNull; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -55,8 +54,7 @@ public TransactionResponse transaction(String transactionId) throws IOException * for Account * @param account Account for which to get transactions */ - public TransactionsRequestBuilder forAccount(String account) { - account = checkNotNull(account, "account cannot be null"); + public TransactionsRequestBuilder forAccount(@NonNull String account) { this.setSegments("accounts", account, "transactions"); return this; } @@ -69,8 +67,7 @@ public TransactionsRequestBuilder forAccount(String account) { * for ClaimableBalance * @param claimableBalance Claimable Balance for which to get transactions */ - public TransactionsRequestBuilder forClaimableBalance(String claimableBalance) { - claimableBalance = checkNotNull(claimableBalance, "claimableBalance cannot be null"); + public TransactionsRequestBuilder forClaimableBalance(@NonNull String claimableBalance) { this.setSegments("claimable_balances", claimableBalance, "transactions"); return this; } diff --git a/src/main/java/org/stellar/sdk/responses/AccountResponse.java b/src/main/java/org/stellar/sdk/responses/AccountResponse.java index d537e732c..5d3390a1f 100644 --- a/src/main/java/org/stellar/sdk/responses/AccountResponse.java +++ b/src/main/java/org/stellar/sdk/responses/AccountResponse.java @@ -1,12 +1,12 @@ package org.stellar.sdk.responses; -import static com.google.common.base.Preconditions.checkNotNull; import static org.stellar.sdk.Asset.create; -import com.google.common.base.Optional; -import com.google.common.io.BaseEncoding; import com.google.gson.annotations.SerializedName; +import java.util.Base64; import java.util.HashMap; +import java.util.Optional; +import lombok.NonNull; import org.stellar.sdk.Asset; import org.stellar.sdk.KeyPair; import org.stellar.sdk.LiquidityPoolID; @@ -163,7 +163,7 @@ public Integer getNumSponsored() { } public Optional getSponsor() { - return Optional.fromNullable(this.sponsor); + return Optional.ofNullable(this.sponsor); } /** Represents account thresholds. */ @@ -281,27 +281,26 @@ public static class Balance { private String sponsor; public Balance( - String assetType, + @NonNull String assetType, String assetCode, String assetIssuer, LiquidityPoolID liquidityPoolID, - String balance, + @NonNull String balance, String limit, - String buyingLiabilities, - String sellingLiabilities, + @NonNull String buyingLiabilities, + @NonNull 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.assetType = assetType; + this.balance = balance; 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.buyingLiabilities = buyingLiabilities; + this.sellingLiabilities = sellingLiabilities; this.isAuthorized = isAuthorized; this.isAuthorizedToMaintainLiabilities = isAuthorizedToMaintainLiabilities; this.lastModifiedLedger = lastModifiedLedger; @@ -322,15 +321,15 @@ public String getAssetType() { } public Optional getAssetCode() { - return Optional.fromNullable(assetCode); + return Optional.ofNullable(assetCode); } public Optional getAssetIssuer() { - return Optional.fromNullable(assetIssuer); + return Optional.ofNullable(assetIssuer); } public Optional getLiquidityPoolID() { - return Optional.fromNullable(liquidityPoolID); + return Optional.ofNullable(liquidityPoolID); } public String getBalance() { @@ -338,11 +337,11 @@ public String getBalance() { } public Optional getBuyingLiabilities() { - return Optional.fromNullable(buyingLiabilities); + return Optional.ofNullable(buyingLiabilities); } public Optional getSellingLiabilities() { - return Optional.fromNullable(sellingLiabilities); + return Optional.ofNullable(sellingLiabilities); } public String getLimit() { @@ -362,7 +361,7 @@ public Integer getLastModifiedLedger() { } public Optional getSponsor() { - return Optional.fromNullable(this.sponsor); + return Optional.ofNullable(this.sponsor); } } @@ -380,10 +379,10 @@ public static class Signer { @SerializedName("sponsor") private String sponsor; - public Signer(String key, String type, int weight, String sponsor) { - this.key = checkNotNull(key, "key cannot be null"); - this.type = checkNotNull(type, "type cannot be null"); - this.weight = checkNotNull(weight, "weight cannot be null"); + public Signer(@NonNull String key, @NonNull String type, int weight, String sponsor) { + this.key = key; + this.type = type; + this.weight = weight; // sponsor is an optional field this.sponsor = sponsor; } @@ -409,7 +408,7 @@ public String getType() { } public Optional getSponsor() { - return Optional.fromNullable(this.sponsor); + return Optional.ofNullable(this.sponsor); } } @@ -441,8 +440,7 @@ public String get(String key) { * @return raw value */ public byte[] getDecoded(String key) { - BaseEncoding base64Encoding = BaseEncoding.base64(); - return base64Encoding.decode(this.get(key)); + return Base64.getDecoder().decode(this.get(key)); } } diff --git a/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java b/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java index 4b032f03e..9a450f191 100644 --- a/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/AssetDeserializer.java @@ -1,13 +1,11 @@ package org.stellar.sdk.responses; -import static com.google.common.base.Optional.fromNullable; - -import com.google.common.base.Function; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import java.lang.reflect.Type; +import java.util.Optional; import org.stellar.sdk.Asset; class AssetDeserializer implements JsonDeserializer { @@ -21,23 +19,12 @@ public Asset deserialize(JsonElement json, Type typeOfT, JsonDeserializationCont return Asset.create( json.getAsJsonObject().get("asset_type").getAsString(), - fromNullable(json.getAsJsonObject().get("asset_code")) - .transform(ToString.FUNCTION) - .orNull(), - fromNullable(json.getAsJsonObject().get("asset_issuer")) - .transform(ToString.FUNCTION) - .orNull(), - fromNullable(json.getAsJsonObject().get("liquidity_pool_id")) - .transform(ToString.FUNCTION) - .orNull()); + getValueAsString(json.getAsJsonObject().get("asset_code")), + getValueAsString(json.getAsJsonObject().get("asset_issuer")), + getValueAsString(json.getAsJsonObject().get("liquidity_pool_id"))); } - enum ToString implements Function { - FUNCTION; - - @Override - public String apply(JsonElement input) { - return input.getAsString(); - } + private String getValueAsString(JsonElement element) { + return Optional.ofNullable(element).map(JsonElement::getAsString).orElse(null); } } diff --git a/src/main/java/org/stellar/sdk/responses/ClaimableBalanceResponse.java b/src/main/java/org/stellar/sdk/responses/ClaimableBalanceResponse.java index 15be5b25c..98b6f5ad1 100644 --- a/src/main/java/org/stellar/sdk/responses/ClaimableBalanceResponse.java +++ b/src/main/java/org/stellar/sdk/responses/ClaimableBalanceResponse.java @@ -1,8 +1,8 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.util.List; +import java.util.Optional; import org.stellar.sdk.Asset; import org.stellar.sdk.Claimant; @@ -87,7 +87,7 @@ public String getLastModifiedTime() { } public Optional getSponsor() { - return Optional.fromNullable(this.sponsor); + return Optional.ofNullable(this.sponsor); } public String getPagingToken() { diff --git a/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java b/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java index cc841b201..abcc12840 100644 --- a/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/EffectDeserializer.java @@ -1,6 +1,5 @@ package org.stellar.sdk.responses; -import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -26,7 +25,6 @@ public EffectResponse deserialize( .registerTypeAdapter(LiquidityPoolID.class, new LiquidityPoolIDDeserializer()) .registerTypeAdapter(LiquidityPoolType.class, new LiquidityPoolTypeDeserializer()) .registerTypeAdapter(Predicate.class, new PredicateDeserializer()) - .registerTypeAdapter(ImmutableList.class, new ImmutableListDeserializer()) .create(); int type = json.getAsJsonObject().get("type_i").getAsInt(); diff --git a/src/main/java/org/stellar/sdk/responses/GsonSingleton.java b/src/main/java/org/stellar/sdk/responses/GsonSingleton.java index c357e0bab..2a717c2d3 100644 --- a/src/main/java/org/stellar/sdk/responses/GsonSingleton.java +++ b/src/main/java/org/stellar/sdk/responses/GsonSingleton.java @@ -1,6 +1,5 @@ package org.stellar.sdk.responses; -import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -69,7 +68,6 @@ public static Gson getInstance() { .registerTypeAdapter( claimableBalancePageType.getType(), new PageDeserializer(claimableBalancePageType)) - .registerTypeAdapter(ImmutableList.class, new ImmutableListDeserializer()) .create(); } return instance; diff --git a/src/main/java/org/stellar/sdk/responses/ImmutableListDeserializer.java b/src/main/java/org/stellar/sdk/responses/ImmutableListDeserializer.java deleted file mode 100644 index 00aee6d21..000000000 --- a/src/main/java/org/stellar/sdk/responses/ImmutableListDeserializer.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.stellar.sdk.responses; - -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.TypeToken; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import java.lang.reflect.Type; -import java.util.List; - -public class ImmutableListDeserializer implements JsonDeserializer> { - - @Override - public ImmutableList deserialize( - JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { - @SuppressWarnings("unchecked") - final TypeToken> immutableListToken = - (TypeToken>) TypeToken.of(type); - final TypeToken> listToken = - immutableListToken.getSupertype(List.class); - final List list = context.deserialize(json, listToken.getType()); - return ImmutableList.copyOf(list); - } -} diff --git a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java index 73ca48b48..5789c1d01 100644 --- a/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java +++ b/src/main/java/org/stellar/sdk/responses/LiquidityPoolResponse.java @@ -1,9 +1,8 @@ package org.stellar.sdk.responses; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; +import java.util.Objects; +import lombok.NonNull; import org.stellar.sdk.Asset; import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.xdr.LiquidityPoolType; @@ -81,14 +80,14 @@ public static class Reserve { @SerializedName("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")); + public Reserve(@NonNull String amount, @NonNull String asset) { + this.amount = amount; + this.asset = Asset.create(asset); } - public Reserve(String amount, Asset asset) { - this.amount = checkNotNull(amount, "amount cannot be null"); - this.asset = checkNotNull(asset, "asset cannot be null"); + public Reserve(@NonNull String amount, @NonNull Asset asset) { + this.amount = amount; + this.asset = asset; } public Asset getAsset() { @@ -106,8 +105,8 @@ public boolean equals(Object other) { } LiquidityPoolResponse.Reserve o = (LiquidityPoolResponse.Reserve) other; - return Objects.equal(this.getAsset(), o.getAsset()) - && Objects.equal(this.getAmount(), o.getAmount()); + return Objects.equals(this.getAsset(), o.getAsset()) + && Objects.equals(this.getAmount(), o.getAmount()); } } diff --git a/src/main/java/org/stellar/sdk/responses/MuxedAccount.java b/src/main/java/org/stellar/sdk/responses/MuxedAccount.java index fe405022a..e447e72da 100644 --- a/src/main/java/org/stellar/sdk/responses/MuxedAccount.java +++ b/src/main/java/org/stellar/sdk/responses/MuxedAccount.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses; -import com.google.common.base.Objects; import java.math.BigInteger; +import java.util.Objects; public class MuxedAccount { private final String muxedAddress; @@ -33,13 +33,13 @@ public boolean equals(Object o) { return true; } return (getClass() == o.getClass()) - && Objects.equal(muxedAddress, ((MuxedAccount) o).muxedAddress) - && Objects.equal(unmuxedAddress, ((MuxedAccount) o).unmuxedAddress) - && Objects.equal(id, ((MuxedAccount) o).id); + && Objects.equals(muxedAddress, ((MuxedAccount) o).muxedAddress) + && Objects.equals(unmuxedAddress, ((MuxedAccount) o).unmuxedAddress) + && Objects.equals(id, ((MuxedAccount) o).id); } @Override public int hashCode() { - return Objects.hashCode(muxedAddress, unmuxedAddress, id); + return Objects.hash(muxedAddress, unmuxedAddress, id); } } diff --git a/src/main/java/org/stellar/sdk/responses/OfferResponse.java b/src/main/java/org/stellar/sdk/responses/OfferResponse.java index 867db40ed..a2b9d5031 100644 --- a/src/main/java/org/stellar/sdk/responses/OfferResponse.java +++ b/src/main/java/org/stellar/sdk/responses/OfferResponse.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; +import java.util.Optional; import org.stellar.sdk.Asset; /** @@ -109,7 +109,7 @@ public String getLastModifiedTime() { } public Optional getSponsor() { - return Optional.fromNullable(this.sponsor); + return Optional.ofNullable(this.sponsor); } public Links getLinks() { diff --git a/src/main/java/org/stellar/sdk/responses/OperationDeserializer.java b/src/main/java/org/stellar/sdk/responses/OperationDeserializer.java index 550cad8ab..42e48c2bc 100644 --- a/src/main/java/org/stellar/sdk/responses/OperationDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/OperationDeserializer.java @@ -1,6 +1,5 @@ package org.stellar.sdk.responses; -import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -28,7 +27,6 @@ public OperationResponse deserialize( .registerTypeAdapter(Asset.class, new AssetDeserializer()) .registerTypeAdapter(Predicate.class, new PredicateDeserializer()) .registerTypeAdapter(TransactionResponse.class, new TransactionDeserializer()) - .registerTypeAdapter(ImmutableList.class, new ImmutableListDeserializer()) .registerTypeAdapter(LiquidityPoolID.class, new LiquidityPoolIDDeserializer()) .registerTypeAdapter(LiquidityPoolType.class, new LiquidityPoolTypeDeserializer()) .create(); diff --git a/src/main/java/org/stellar/sdk/responses/OrderBookResponse.java b/src/main/java/org/stellar/sdk/responses/OrderBookResponse.java index 0e89f2a08..5fef9ad0a 100644 --- a/src/main/java/org/stellar/sdk/responses/OrderBookResponse.java +++ b/src/main/java/org/stellar/sdk/responses/OrderBookResponse.java @@ -1,8 +1,7 @@ package org.stellar.sdk.responses; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.gson.annotations.SerializedName; +import lombok.NonNull; import org.stellar.sdk.Asset; import org.stellar.sdk.Price; @@ -61,10 +60,10 @@ public static class Row { @SerializedName("price_r") private final Price priceR; - Row(String amount, String price, Price priceR) { - this.amount = checkNotNull(amount, "amount cannot be null"); - this.price = checkNotNull(price, "price cannot be null"); - this.priceR = checkNotNull(priceR, "priceR cannot be null"); + Row(@NonNull String amount, @NonNull String price, @NonNull Price priceR) { + this.amount = amount; + this.price = price; + this.priceR = priceR; } public String getAmount() { diff --git a/src/main/java/org/stellar/sdk/responses/Page.java b/src/main/java/org/stellar/sdk/responses/Page.java index 916e5bf91..c2d766ae2 100644 --- a/src/main/java/org/stellar/sdk/responses/Page.java +++ b/src/main/java/org/stellar/sdk/responses/Page.java @@ -1,6 +1,5 @@ package org.stellar.sdk.responses; -import com.google.common.base.Preconditions; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; import java.io.IOException; @@ -45,13 +44,13 @@ public Page getNextPage(OkHttpClient httpClient) throws URISyntaxException, I if (this.getLinks().getNext() == null) { return null; } - TypeToken> type = - Preconditions.checkNotNull( - this.type, - "type cannot be null, is it being correctly set after the creation of this " - + getClass().getSimpleName() - + "?"); - ResponseHandler> responseHandler = new ResponseHandler>(type); + if (this.type == null) { + throw new NullPointerException( + "type cannot be null, is it being correctly set after the creation of this " + + getClass().getSimpleName() + + "?"); + } + ResponseHandler> responseHandler = new ResponseHandler>(this.type); String url = this.getLinks().getNext().getHref(); Request request = new Request.Builder().get().url(url).build(); diff --git a/src/main/java/org/stellar/sdk/responses/PredicateDeserializer.java b/src/main/java/org/stellar/sdk/responses/PredicateDeserializer.java index 688e5a26b..4d71385f5 100644 --- a/src/main/java/org/stellar/sdk/responses/PredicateDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/PredicateDeserializer.java @@ -1,9 +1,9 @@ package org.stellar.sdk.responses; -import com.google.common.collect.Lists; import com.google.gson.*; import java.lang.reflect.Type; import java.time.Instant; +import java.util.ArrayList; import java.util.List; import org.stellar.sdk.Predicate; import org.stellar.sdk.xdr.Duration; @@ -25,7 +25,7 @@ public Predicate deserialize(JsonElement json, Type typeOfT, JsonDeserialization } if (obj.has("and")) { - List inner = Lists.newArrayList(); + List inner = new ArrayList<>(); for (JsonElement elt : obj.get("and").getAsJsonArray()) { inner.add(deserialize(elt, typeOfT, context)); } @@ -33,7 +33,7 @@ public Predicate deserialize(JsonElement json, Type typeOfT, JsonDeserialization } if (obj.has("or")) { - List inner = Lists.newArrayList(); + List inner = new ArrayList<>(); for (JsonElement elt : obj.get("or").getAsJsonArray()) { inner.add(deserialize(elt, typeOfT, context)); } diff --git a/src/main/java/org/stellar/sdk/responses/SubmitTransactionResponse.java b/src/main/java/org/stellar/sdk/responses/SubmitTransactionResponse.java index aae843a81..9f977f214 100644 --- a/src/main/java/org/stellar/sdk/responses/SubmitTransactionResponse.java +++ b/src/main/java/org/stellar/sdk/responses/SubmitTransactionResponse.java @@ -1,11 +1,11 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; -import com.google.common.io.BaseEncoding; import com.google.gson.annotations.SerializedName; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Base64; +import java.util.Optional; import org.stellar.sdk.Server; import org.stellar.sdk.xdr.OperationResult; import org.stellar.sdk.xdr.OperationType; @@ -63,7 +63,7 @@ public Optional getEnvelopeXdr() { if (this.getExtras() != null) { return Optional.of(this.getExtras().getEnvelopeXdr()); } - return Optional.absent(); + return Optional.empty(); } } @@ -74,7 +74,7 @@ public Optional getResultXdr() { if (this.getExtras() != null) { return Optional.of(this.getExtras().getResultXdr()); } - return Optional.absent(); + return Optional.empty(); } } @@ -89,17 +89,17 @@ public Optional getResultXdr() { */ public Optional getOfferIdFromResult(int position) throws IOException { if (!this.isSuccess()) { - return Optional.absent(); + return Optional.empty(); } Optional optionalResult = getDecodedTransactionResult(); if (!optionalResult.isPresent()) { - return Optional.absent(); + return Optional.empty(); } TransactionResult result = optionalResult.get(); if (result.getResult().getResults()[position] == null) { - return Optional.absent(); + return Optional.empty(); } OperationResult operationResult = result.getResult().getResults()[position]; @@ -108,7 +108,7 @@ public Optional getOfferIdFromResult(int position) throws IOException { if (operationType == OperationType.MANAGE_SELL_OFFER) { if (operationResultTr.getManageSellOfferResult().getSuccess().getOffer().getOffer() == null) { - return Optional.absent(); + return Optional.empty(); } return Optional.of( operationResultTr @@ -122,7 +122,7 @@ public Optional getOfferIdFromResult(int position) throws IOException { if (operationType == OperationType.MANAGE_BUY_OFFER) { if (operationResultTr.getManageBuyOfferResult().getSuccess().getOffer().getOffer() == null) { - return Optional.absent(); + return Optional.empty(); } return Optional.of( operationResultTr @@ -134,25 +134,24 @@ public Optional getOfferIdFromResult(int position) throws IOException { .getInt64()); } - return Optional.absent(); + return Optional.empty(); } /** - * Decoding "TransactionResult" from "resultXdr". This will be Optional.absent() if + * Decoding "TransactionResult" from "resultXdr". This will be Optional.empty()() if * transaction has failed. */ public Optional getDecodedTransactionResult() throws IOException { if (!this.isSuccess()) { - return Optional.absent(); + return Optional.empty(); } if (this.transactionResult == null) { Optional resultXDR = this.getResultXdr(); if (!resultXDR.isPresent()) { - return Optional.absent(); + return Optional.empty(); } - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(resultXDR.get()); + byte[] bytes = Base64.getDecoder().decode(resultXDR.get()); ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); XdrDataInputStream xdrInputStream = new XdrDataInputStream(inputStream); this.transactionResult = TransactionResult.decode(xdrInputStream); diff --git a/src/main/java/org/stellar/sdk/responses/TradePrice.java b/src/main/java/org/stellar/sdk/responses/TradePrice.java index c8ae3f842..a1ff99a39 100644 --- a/src/main/java/org/stellar/sdk/responses/TradePrice.java +++ b/src/main/java/org/stellar/sdk/responses/TradePrice.java @@ -1,9 +1,9 @@ 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; +import java.util.Objects; /** Represents Price. Price in Stellar is represented as a fraction. */ public class TradePrice { @@ -44,7 +44,7 @@ public String toString() { @Override public int hashCode() { - return Objects.hashCode(this.getNumerator(), this.getDenominator()); + return Objects.hash(this.getNumerator(), this.getDenominator()); } @Override @@ -54,7 +54,7 @@ public boolean equals(Object object) { } TradePrice other = (TradePrice) object; - return this.getNumerator() == other.getNumerator() - && this.getDenominator() == other.getDenominator(); + return Objects.equals(this.getNumerator(), other.getNumerator()) + && Objects.equals(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 ec3daa363..671bd6b38 100644 --- a/src/main/java/org/stellar/sdk/responses/TradeResponse.java +++ b/src/main/java/org/stellar/sdk/responses/TradeResponse.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; +import java.util.Optional; import org.stellar.sdk.Asset; import org.stellar.sdk.LiquidityPoolID; @@ -141,15 +141,15 @@ public boolean isBaseSeller() { } public Optional getBaseOfferId() { - return Optional.fromNullable(baseOfferId); + return Optional.ofNullable(baseOfferId); } public Optional getBaseAccount() { - return Optional.fromNullable(baseAccount); + return Optional.ofNullable(baseAccount); } public Optional getBaseLiquidityPoolID() { - return Optional.fromNullable(baseLiquidityPoolID); + return Optional.ofNullable(baseLiquidityPoolID); } public String getBaseAmount() { @@ -173,15 +173,15 @@ public String getBaseAssetIssuer() { } public Optional getCounterAccount() { - return Optional.fromNullable(counterAccount); + return Optional.ofNullable(counterAccount); } public Optional getCounterLiquidityPoolID() { - return Optional.fromNullable(counterLiquidityPoolID); + return Optional.ofNullable(counterLiquidityPoolID); } public Optional getCounterOfferId() { - return Optional.fromNullable(counterOfferId); + return Optional.ofNullable(counterOfferId); } public Asset getCounterAsset() { diff --git a/src/main/java/org/stellar/sdk/responses/TransactionDeserializer.java b/src/main/java/org/stellar/sdk/responses/TransactionDeserializer.java index 01ceae628..9faf0d2df 100644 --- a/src/main/java/org/stellar/sdk/responses/TransactionDeserializer.java +++ b/src/main/java/org/stellar/sdk/responses/TransactionDeserializer.java @@ -1,11 +1,11 @@ package org.stellar.sdk.responses; -import com.google.common.io.BaseEncoding; import com.google.gson.*; import java.io.ByteArrayInputStream; import java.io.IOException; import java.lang.reflect.Type; import java.math.BigInteger; +import java.util.Base64; import org.stellar.sdk.Memo; import org.stellar.sdk.xdr.TransactionEnvelope; import org.stellar.sdk.xdr.XdrDataInputStream; @@ -54,19 +54,19 @@ public TransactionResponse deserialize( // representation of a transaction. That's why we need to handle a special case // here. if (memoType.equals("text")) { - BaseEncoding base64Encoding = BaseEncoding.base64(); + Base64.Decoder base64Decoder = Base64.getDecoder(); JsonObject jsonResponse = json.getAsJsonObject(); if (jsonResponse.has("memo_bytes")) { // we obtain the memo text from the "memo_bytes" field because the original byte sequence // may not be valid utf8 String memoBase64 = json.getAsJsonObject().get("memo_bytes").getAsString(); - memo = Memo.text(base64Encoding.decode(memoBase64)); + memo = Memo.text(base64Decoder.decode(memoBase64)); } else { // memo_bytes is not available because horizon is running a version older than 1.2.0 // so we will recover the bytes from the xdr String envelopeXdr = json.getAsJsonObject().get("envelope_xdr").getAsString(); - byte[] bytes = base64Encoding.decode(envelopeXdr); + byte[] bytes = base64Decoder.decode(envelopeXdr); TransactionEnvelope transactionEnvelope = null; try { transactionEnvelope = @@ -80,13 +80,13 @@ public TransactionResponse deserialize( } } else { String memoValue = json.getAsJsonObject().get("memo").getAsString(); - BaseEncoding base64Encoding = BaseEncoding.base64(); + Base64.Decoder base64Decoder = Base64.getDecoder(); if (memoType.equals("id")) { memo = Memo.id(new BigInteger(memoValue)); } else if (memoType.equals("hash")) { - memo = Memo.hash(base64Encoding.decode(memoValue)); + memo = Memo.hash(base64Decoder.decode(memoValue)); } else if (memoType.equals("return")) { - memo = Memo.returnHash(base64Encoding.decode(memoValue)); + memo = Memo.returnHash(base64Decoder.decode(memoValue)); } else { throw new JsonParseException("Unknown memo type."); } diff --git a/src/main/java/org/stellar/sdk/responses/TransactionResponse.java b/src/main/java/org/stellar/sdk/responses/TransactionResponse.java index a3912c4fb..1864c5899 100644 --- a/src/main/java/org/stellar/sdk/responses/TransactionResponse.java +++ b/src/main/java/org/stellar/sdk/responses/TransactionResponse.java @@ -1,11 +1,10 @@ package org.stellar.sdk.responses; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; import java.util.List; +import java.util.Optional; +import lombok.NonNull; import lombok.Value; import org.stellar.sdk.Memo; @@ -93,7 +92,7 @@ public class TransactionResponse extends Response implements Pageable { public Optional getSourceAccountMuxed() { if (this.accountMuxed == null || this.accountMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of( new MuxedAccount(this.accountMuxed, this.sourceAccount, this.accountMuxedId)); @@ -101,7 +100,7 @@ public Optional getSourceAccountMuxed() { public Optional getFeeAccountMuxed() { if (this.feeAccountMuxed == null || this.feeAccountMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of( new MuxedAccount(this.feeAccountMuxed, this.feeAccount, this.feeAccountMuxedId)); @@ -132,15 +131,15 @@ public List getSignatures() { } public Optional getFeeBump() { - return Optional.fromNullable(this.feeBumpTransaction); + return Optional.ofNullable(this.feeBumpTransaction); } public Optional getInner() { - return Optional.fromNullable(this.innerTransaction); + return Optional.ofNullable(this.innerTransaction); } public Optional getPreconditions() { - return Optional.fromNullable(this.preconditions); + return Optional.ofNullable(this.preconditions); } public String getPagingToken() { @@ -183,8 +182,7 @@ public Memo getMemo() { return memo; } - public void setMemo(Memo memo) { - memo = checkNotNull(memo, "memo cannot be null"); + public void setMemo(@NonNull Memo memo) { if (this.memo != null) { throw new RuntimeException("Memo has been already set."); } diff --git a/src/main/java/org/stellar/sdk/responses/effects/EffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/EffectResponse.java index ee8f9a027..78935ca87 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/EffectResponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/EffectResponse.java @@ -1,8 +1,8 @@ package org.stellar.sdk.responses.effects; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.responses.Link; import org.stellar.sdk.responses.MuxedAccount; import org.stellar.sdk.responses.Pageable; @@ -51,7 +51,7 @@ public String getAccount() { public Optional getAccountMuxed() { if (this.accountMuxed == null || this.accountMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.accountMuxed, this.account, this.accountMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java index 228afd871..7aa8265a9 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/LiquidityPoolRevokedEffectResponse.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses.effects; -import com.google.common.collect.ImmutableList; import com.google.gson.annotations.SerializedName; +import java.util.List; /** * Represents liquidity_pool_revoked effect response. @@ -16,14 +16,14 @@ public class LiquidityPoolRevokedEffectResponse extends EffectResponse { protected final LiquidityPool liquidityPool; @SerializedName("reserves_revoked") - protected final ImmutableList reservesRevoked; + protected final List reservesRevoked; @SerializedName("shares_revoked") protected final String sharesRevoked; public LiquidityPoolRevokedEffectResponse( LiquidityPool liquidityPool, - ImmutableList reservesRevoked, + List reservesRevoked, String sharesRevoked) { this.liquidityPool = liquidityPool; this.reservesRevoked = reservesRevoked; @@ -34,7 +34,7 @@ public LiquidityPool getLiquidityPool() { return liquidityPool; } - public ImmutableList getReservesRevoked() { + public List getReservesRevoked() { return reservesRevoked; } diff --git a/src/main/java/org/stellar/sdk/responses/effects/TradeEffectResponse.java b/src/main/java/org/stellar/sdk/responses/effects/TradeEffectResponse.java index aca772d6d..fd63272d3 100644 --- a/src/main/java/org/stellar/sdk/responses/effects/TradeEffectResponse.java +++ b/src/main/java/org/stellar/sdk/responses/effects/TradeEffectResponse.java @@ -2,9 +2,9 @@ import static org.stellar.sdk.Asset.create; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.Asset; import org.stellar.sdk.responses.MuxedAccount; @@ -55,7 +55,7 @@ public class TradeEffectResponse extends EffectResponse { public Optional getSellerMuxed() { if (this.sellerMuxed == null || this.sellerMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.sellerMuxed, this.seller, this.sellerMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/operations/AccountMergeOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/AccountMergeOperationResponse.java index f4a8e590e..591807069 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/AccountMergeOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/AccountMergeOperationResponse.java @@ -1,8 +1,8 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.responses.MuxedAccount; /** @@ -34,14 +34,14 @@ public class AccountMergeOperationResponse extends OperationResponse { public Optional getAccountMuxed() { if (this.accountMuxed == null || this.accountMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.accountMuxed, this.account, this.accountMuxedId)); } public Optional getIntoMuxed() { if (this.intoMuxed == null || this.intoMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.intoMuxed, this.into, this.intoMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/operations/AllowTrustOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/AllowTrustOperationResponse.java index d93fd9bd6..282937ccc 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/AllowTrustOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/AllowTrustOperationResponse.java @@ -2,9 +2,9 @@ import static org.stellar.sdk.Asset.create; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.Asset; import org.stellar.sdk.AssetTypeNative; import org.stellar.sdk.responses.MuxedAccount; @@ -51,7 +51,7 @@ public String getTrustor() { public Optional getTrusteeMuxed() { if (this.trusteeMuxed == null || this.trusteeMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.trusteeMuxed, this.trustee, this.trusteeMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/operations/ChangeTrustOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/ChangeTrustOperationResponse.java index 27ea39c61..1d3dd26c5 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/ChangeTrustOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/ChangeTrustOperationResponse.java @@ -2,9 +2,9 @@ import static org.stellar.sdk.Asset.create; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.Asset; import org.stellar.sdk.responses.MuxedAccount; @@ -46,7 +46,7 @@ public class ChangeTrustOperationResponse extends OperationResponse { public Optional getTrustorMuxed() { if (this.trustorMuxed == null || this.trustorMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.trustorMuxed, this.trustor, this.trustorMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/operations/ClaimClaimableBalanceOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/ClaimClaimableBalanceOperationResponse.java index 71948ba41..ee57a1d5e 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/ClaimClaimableBalanceOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/ClaimClaimableBalanceOperationResponse.java @@ -1,8 +1,8 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.responses.MuxedAccount; /** @@ -26,7 +26,7 @@ public class ClaimClaimableBalanceOperationResponse extends OperationResponse { public Optional getClaimantMuxed() { if (this.claimantMuxed == null || this.claimantMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.claimantMuxed, this.claimant, this.claimantMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/operations/ClawbackOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/ClawbackOperationResponse.java index a013662ce..aa55318f3 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/ClawbackOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/ClawbackOperationResponse.java @@ -2,9 +2,9 @@ import static org.stellar.sdk.Asset.create; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.Asset; import org.stellar.sdk.responses.MuxedAccount; @@ -62,7 +62,7 @@ public String getFrom() { public Optional getFromMuxed() { if (this.fromMuxed == null || this.fromMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.fromMuxed, this.from, this.fromMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/operations/CreateAccountOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/CreateAccountOperationResponse.java index 3360f5ba5..394de5282 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/CreateAccountOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/CreateAccountOperationResponse.java @@ -1,8 +1,8 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.responses.MuxedAccount; /** @@ -31,7 +31,7 @@ public class CreateAccountOperationResponse extends OperationResponse { public Optional getFunderMuxed() { if (this.funderAccountMuxed == null || this.funderAccountMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of( new MuxedAccount(this.funderAccountMuxed, this.funder, this.funderAccountMuxedId)); diff --git a/src/main/java/org/stellar/sdk/responses/operations/EndSponsoringFutureReservesOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/EndSponsoringFutureReservesOperationResponse.java index f4a85cce4..b03ff7ec9 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/EndSponsoringFutureReservesOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/EndSponsoringFutureReservesOperationResponse.java @@ -1,8 +1,8 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.responses.MuxedAccount; /** @@ -23,7 +23,7 @@ public class EndSponsoringFutureReservesOperationResponse extends OperationRespo public Optional getBeginSponsorMuxed() { if (this.beginSponsorMuxed == null || this.beginSponsorMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of( new MuxedAccount(this.beginSponsorMuxed, this.beginSponsor, this.beginSponsorMuxedId)); diff --git a/src/main/java/org/stellar/sdk/responses/operations/InvokeHostFunctionOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/InvokeHostFunctionOperationResponse.java index 45764b231..298bec1c3 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/InvokeHostFunctionOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/InvokeHostFunctionOperationResponse.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses.operations; -import com.google.common.collect.ImmutableList; import com.google.gson.annotations.SerializedName; +import java.util.List; import org.stellar.sdk.xdr.HostFunctionType; /** @@ -20,7 +20,7 @@ public class InvokeHostFunctionOperationResponse extends OperationResponse { private final String function; @SerializedName("parameters") - private final ImmutableList parameters; + private final List parameters; @SerializedName("address") private final String address; @@ -29,14 +29,14 @@ public class InvokeHostFunctionOperationResponse extends OperationResponse { private final String salt; @SerializedName("asset_balance_changes") - private final ImmutableList assetBalanceChanges; + private final List assetBalanceChanges; public InvokeHostFunctionOperationResponse( String function, - ImmutableList parameters, + List parameters, String address, String salt, - ImmutableList assetBalanceChanges) { + List assetBalanceChanges) { this.function = function; this.parameters = parameters; this.address = address; @@ -60,7 +60,7 @@ public String getFunction() { return function; } - public ImmutableList getParameters() { + public List getParameters() { return parameters; } @@ -72,7 +72,7 @@ public String getSalt() { return salt; } - public ImmutableList getAssetBalanceChanges() { + public List getAssetBalanceChanges() { return assetBalanceChanges; } diff --git a/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolDepositOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolDepositOperationResponse.java index 493298ad5..08118252b 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolDepositOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolDepositOperationResponse.java @@ -1,7 +1,8 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; +import java.util.Arrays; +import java.util.Objects; import org.stellar.sdk.AssetAmount; import org.stellar.sdk.LiquidityPoolID; import org.stellar.sdk.Price; @@ -83,14 +84,14 @@ public String getSharesReceived() { } public int hashCode() { - return Objects.hashCode( + return Objects.hash( liquidityPoolId, - reservesMax, + Arrays.hashCode(reservesMax), minPrice, minPriceR, maxPrice, maxPriceR, - reservesDeposited, + Arrays.hashCode(reservesDeposited), sharesReceived); } @@ -101,13 +102,13 @@ public boolean equals(Object object) { } LiquidityPoolDepositOperationResponse o = (LiquidityPoolDepositOperationResponse) object; - return Objects.equal(this.getLiquidityPoolId(), o.getLiquidityPoolId()) - && Objects.equal(this.getReservesMax(), o.getReservesMax()) - && Objects.equal(this.getMaxPrice(), o.getMaxPrice()) - && Objects.equal(this.getMinPrice(), o.getMinPrice()) - && Objects.equal(this.getMaxPriceR(), o.getMaxPriceR()) - && Objects.equal(this.getMinPriceR(), o.getMinPriceR()) - && Objects.equal(this.getReservesDeposited(), o.getReservesDeposited()) - && Objects.equal(this.getSharesReceived(), o.getSharesReceived()); + return Objects.equals(this.getLiquidityPoolId(), o.getLiquidityPoolId()) + && Arrays.equals(this.getReservesMax(), o.getReservesMax()) + && Objects.equals(this.getMaxPrice(), o.getMaxPrice()) + && Objects.equals(this.getMinPrice(), o.getMinPrice()) + && Objects.equals(this.getMaxPriceR(), o.getMaxPriceR()) + && Objects.equals(this.getMinPriceR(), o.getMinPriceR()) + && Arrays.equals(this.getReservesDeposited(), o.getReservesDeposited()) + && Objects.equals(this.getSharesReceived(), o.getSharesReceived()); } } diff --git a/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolWithdrawOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolWithdrawOperationResponse.java index 16227e38c..a140d0a8b 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolWithdrawOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/LiquidityPoolWithdrawOperationResponse.java @@ -1,7 +1,8 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; +import java.util.Arrays; +import java.util.Objects; import org.stellar.sdk.AssetAmount; import org.stellar.sdk.LiquidityPoolID; @@ -46,7 +47,8 @@ public String getShares() { } public int hashCode() { - return Objects.hashCode(liquidityPoolId, reservesMin, reservesReceived, shares); + return Objects.hash( + liquidityPoolId, Arrays.hashCode(reservesMin), Arrays.hashCode(reservesReceived), shares); } @Override @@ -56,9 +58,9 @@ public boolean equals(Object object) { } LiquidityPoolWithdrawOperationResponse o = (LiquidityPoolWithdrawOperationResponse) object; - return Objects.equal(this.getLiquidityPoolId(), o.getLiquidityPoolId()) - && Objects.equal(this.getReservesMin(), o.getReservesMin()) - && Objects.equal(this.getReservesReceived(), o.getReservesReceived()) - && Objects.equal(this.getShares(), o.getShares()); + return Objects.equals(this.getLiquidityPoolId(), o.getLiquidityPoolId()) + && Arrays.equals(this.getReservesMin(), o.getReservesMin()) + && Arrays.equals(this.getReservesReceived(), o.getReservesReceived()) + && Objects.equals(this.getShares(), o.getShares()); } } diff --git a/src/main/java/org/stellar/sdk/responses/operations/OperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/OperationResponse.java index a3a35c31e..0ae97046c 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/OperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/OperationResponse.java @@ -1,8 +1,8 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.Optional; import org.stellar.sdk.responses.*; /** @@ -49,7 +49,7 @@ public abstract class OperationResponse extends Response implements Pageable { public Optional getSourceAccountMuxed() { if (this.sourceAccountMuxed == null || this.sourceAccountMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of( new MuxedAccount(this.sourceAccountMuxed, this.sourceAccount, this.sourceAccountMuxedId)); @@ -106,7 +106,7 @@ public Links getLinks() { } public Optional getTransaction() { - return Optional.fromNullable(transaction); + return Optional.ofNullable(transaction); } /** Represents operation links. */ diff --git a/src/main/java/org/stellar/sdk/responses/operations/PathPaymentBaseOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/PathPaymentBaseOperationResponse.java index 78d1b6f49..e91e24563 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/PathPaymentBaseOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/PathPaymentBaseOperationResponse.java @@ -2,11 +2,10 @@ import static org.stellar.sdk.Asset.create; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; import java.util.List; +import java.util.Optional; import org.stellar.sdk.Asset; import org.stellar.sdk.AssetTypeNative; import org.stellar.sdk.responses.MuxedAccount; @@ -55,7 +54,7 @@ public abstract class PathPaymentBaseOperationResponse extends OperationResponse private String sourceAssetIssuer; @SerializedName("path") - private ImmutableList path; + private List path; public String getAmount() { return amount; @@ -71,14 +70,14 @@ public String getFrom() { public Optional getFromMuxed() { if (this.fromMuxed == null || this.fromMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.fromMuxed, this.from, this.fromMuxedId)); } public Optional getToMuxed() { if (this.toMuxed == null || this.toMuxed.isEmpty()) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(new MuxedAccount(this.toMuxed, this.to, this.toMuxedId)); } diff --git a/src/main/java/org/stellar/sdk/responses/operations/RevokeSponsorshipOperationResponse.java b/src/main/java/org/stellar/sdk/responses/operations/RevokeSponsorshipOperationResponse.java index f1f53c5e0..cada85534 100644 --- a/src/main/java/org/stellar/sdk/responses/operations/RevokeSponsorshipOperationResponse.java +++ b/src/main/java/org/stellar/sdk/responses/operations/RevokeSponsorshipOperationResponse.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses.operations; -import com.google.common.base.Optional; import com.google.gson.annotations.SerializedName; +import java.util.Optional; /** * Represents RevokeSponsorship operation response. @@ -59,38 +59,38 @@ public RevokeSponsorshipOperationResponse( } public Optional getAccountId() { - return Optional.fromNullable(accountId); + return Optional.ofNullable(accountId); } public Optional getClaimableBalanceId() { - return Optional.fromNullable(claimableBalanceId); + return Optional.ofNullable(claimableBalanceId); } public Optional getDataAccountId() { - return Optional.fromNullable(dataAccountId); + return Optional.ofNullable(dataAccountId); } public Optional getDataName() { - return Optional.fromNullable(dataName); + return Optional.ofNullable(dataName); } public Optional getOfferId() { - return Optional.fromNullable(offerId); + return Optional.ofNullable(offerId); } public Optional getTrustlineAccountId() { - return Optional.fromNullable(trustlineAccountId); + return Optional.ofNullable(trustlineAccountId); } public Optional getTrustlineAsset() { - return Optional.fromNullable(trustlineAsset); + return Optional.ofNullable(trustlineAsset); } public Optional getSignerAccountId() { - return Optional.fromNullable(signerAccountId); + return Optional.ofNullable(signerAccountId); } public Optional getSignerKey() { - return Optional.fromNullable(signerKey); + return Optional.ofNullable(signerKey); } } diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java index 890b94b65..0dbd2cbf4 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java @@ -1,6 +1,6 @@ package org.stellar.sdk.responses.sorobanrpc; -import com.google.common.collect.ImmutableList; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Value; import org.stellar.sdk.requests.sorobanrpc.EventFilterType; @@ -14,7 +14,7 @@ @AllArgsConstructor @Value public class GetEventsResponse { - ImmutableList events; + List events; Long latestLedger; @@ -33,7 +33,7 @@ public static class EventInfo { String pagingToken; - ImmutableList topic; + List topic; EventInfoValue value; diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java index 96015fdd5..4fc8dfbb3 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses.sorobanrpc; -import com.google.common.collect.ImmutableList; import com.google.gson.annotations.SerializedName; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Value; @@ -14,7 +14,7 @@ @AllArgsConstructor @Value public class GetLedgerEntriesResponse { - ImmutableList entries; + List entries; Long latestLedger; diff --git a/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java b/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java index 26776e709..b7d64850f 100644 --- a/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java +++ b/src/main/java/org/stellar/sdk/responses/sorobanrpc/SimulateTransactionResponse.java @@ -1,23 +1,16 @@ package org.stellar.sdk.responses.sorobanrpc; -import com.google.common.collect.ImmutableList; import com.google.gson.annotations.SerializedName; import java.math.BigInteger; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Value; /** * Response for JSON-RPC method simulateTransaction. * - *

Note - The simulation response will have different model representations with different - * members present or absent depending on type of response that it is conveying. For example, the - * simulation response for invoke host function, could be one of three types: error, success, or - * restore operation needed. - * - *

Please refer to the latest Soroban simulateTransaction documentation for details on which members of the - * simulation response model are keyed to each type of response. + * @see simulateTransaction documentation */ @AllArgsConstructor @Value @@ -26,26 +19,20 @@ public class SimulateTransactionResponse { String transactionData; - ImmutableList events; + List events; Long minResourceFee; - // An array of the individual host function call results. - // This will only contain a single element if present, because only a single - // invokeHostFunctionOperation - // is supported per transaction. - ImmutableList results; + List results; SimulateTransactionCost cost; - RestorePreamble restorePreamble; - Long latestLedger; @AllArgsConstructor @Value public static class SimulateHostFunctionResult { - ImmutableList auth; + List auth; String xdr; } @@ -59,12 +46,4 @@ public static class SimulateTransactionCost { @SerializedName("memBytes") BigInteger memoryBytes; } - - @AllArgsConstructor - @Value - public static class RestorePreamble { - String transactionData; - - Long minResourceFee; - } } diff --git a/src/main/java/org/stellar/sdk/scval/Longs.java b/src/main/java/org/stellar/sdk/scval/Longs.java new file mode 100644 index 000000000..3439e5d07 --- /dev/null +++ b/src/main/java/org/stellar/sdk/scval/Longs.java @@ -0,0 +1,36 @@ +package org.stellar.sdk.scval; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE) +final class Longs { + /** + * @return a big-endian representation of {@code value} in an 8-element byte array. + */ + static byte[] toByteArray(long value) { + byte[] result = new byte[8]; + for (int i = 7; i >= 0; i--) { + result[i] = (byte) (value & 0xffL); + value >>= 8; + } + return result; + } + + /** + * @return the {@code long} value whose byte representation is the given 8 bytes, in big-endian + * order. + */ + static long fromByteArray(byte[] bytes) { + if (bytes.length != 8) { + throw new IllegalArgumentException("array length is not 8"); + } + return (bytes[0] & 0xFFL) << 56 + | (bytes[1] & 0xFFL) << 48 + | (bytes[2] & 0xFFL) << 40 + | (bytes[3] & 0xFFL) << 32 + | (bytes[4] & 0xFFL) << 24 + | (bytes[5] & 0xFFL) << 16 + | (bytes[6] & 0xFFL) << 8 + | (bytes[7] & 0xFFL); + } +} diff --git a/src/main/java/org/stellar/sdk/scval/ScvInt128.java b/src/main/java/org/stellar/sdk/scval/ScvInt128.java index 8fed7cec2..2326483e1 100644 --- a/src/main/java/org/stellar/sdk/scval/ScvInt128.java +++ b/src/main/java/org/stellar/sdk/scval/ScvInt128.java @@ -2,7 +2,6 @@ import static org.stellar.sdk.Util.getBytes; -import com.google.common.primitives.Longs; import java.math.BigInteger; import java.util.Arrays; import org.stellar.sdk.xdr.Int128Parts; diff --git a/src/main/java/org/stellar/sdk/scval/ScvInt256.java b/src/main/java/org/stellar/sdk/scval/ScvInt256.java index 8a9540f3f..2eab891b1 100644 --- a/src/main/java/org/stellar/sdk/scval/ScvInt256.java +++ b/src/main/java/org/stellar/sdk/scval/ScvInt256.java @@ -2,7 +2,6 @@ import static org.stellar.sdk.Util.getBytes; -import com.google.common.primitives.Longs; import java.math.BigInteger; import java.util.Arrays; import org.stellar.sdk.xdr.Int256Parts; diff --git a/src/test/java/org/stellar/sdk/AddressTest.java b/src/test/java/org/stellar/sdk/AddressTest.java index 6a2000d90..e878fafbe 100644 --- a/src/test/java/org/stellar/sdk/AddressTest.java +++ b/src/test/java/org/stellar/sdk/AddressTest.java @@ -3,9 +3,9 @@ import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.fail; -import com.google.common.io.BaseEncoding; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.Base64; import org.junit.Assert; import org.junit.Test; import org.stellar.sdk.xdr.SCAddress; @@ -76,8 +76,7 @@ public void testToSCAddressAccount() throws IOException { SCAddress scAddress = address.toSCAddress(); String xdr = "AAAAAAAAAAA/DDS/k60NmXHQTMyQ9wVRHIOKrZc0pKL7DXoD/H/omg=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(xdr); + byte[] bytes = Base64.getDecoder().decode(xdr); SCAddress expectScAddress = SCAddress.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); assertEquals(scAddress, expectScAddress); @@ -90,8 +89,7 @@ public void testToSCAddressContract() throws IOException { SCAddress scAddress = address.toSCAddress(); String xdr = "AAAAAT8MNL+TrQ2ZcdBMzJD3BVEcg4qtlzSkovsNegP8f+ia"; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(xdr); + byte[] bytes = Base64.getDecoder().decode(xdr); SCAddress expectScAddress = SCAddress.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); assertEquals(scAddress, expectScAddress); @@ -100,8 +98,7 @@ public void testToSCAddressContract() throws IOException { @Test public void testFromSCAddressAccount() throws IOException { String xdr = "AAAAAAAAAAA/DDS/k60NmXHQTMyQ9wVRHIOKrZc0pKL7DXoD/H/omg=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(xdr); + byte[] bytes = Base64.getDecoder().decode(xdr); SCAddress scAddress = SCAddress.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); Address address = Address.fromSCAddress(scAddress); @@ -113,8 +110,7 @@ public void testFromSCAddressAccount() throws IOException { @Test public void testFromSCAddressContract() throws IOException { String xdr = "AAAAAT8MNL+TrQ2ZcdBMzJD3BVEcg4qtlzSkovsNegP8f+ia"; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(xdr); + byte[] bytes = Base64.getDecoder().decode(xdr); SCAddress scAddress = SCAddress.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); Address address = Address.fromSCAddress(scAddress); @@ -130,8 +126,7 @@ public void testToSCVal() throws IOException { SCVal scVal = address.toSCVal(); String xdr = "AAAAEgAAAAE/DDS/k60NmXHQTMyQ9wVRHIOKrZc0pKL7DXoD/H/omg=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(xdr); + byte[] bytes = Base64.getDecoder().decode(xdr); SCVal expectSCVal = SCVal.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); assertEquals(scVal, expectSCVal); } @@ -139,8 +134,7 @@ public void testToSCVal() throws IOException { @Test public void testFromSCVal() throws IOException { String xdr = "AAAAEgAAAAE/DDS/k60NmXHQTMyQ9wVRHIOKrZc0pKL7DXoD/H/omg=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(xdr); + byte[] bytes = Base64.getDecoder().decode(xdr); SCVal scVal = SCVal.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); Address address = Address.fromSCVal(scVal); diff --git a/src/test/java/org/stellar/sdk/ClaimableBalanceIdTest.java b/src/test/java/org/stellar/sdk/ClaimableBalanceIdTest.java index d9484965c..c8de442a8 100644 --- a/src/test/java/org/stellar/sdk/ClaimableBalanceIdTest.java +++ b/src/test/java/org/stellar/sdk/ClaimableBalanceIdTest.java @@ -3,8 +3,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.common.collect.Lists; import java.io.IOException; +import java.util.Collections; import org.junit.Test; import org.stellar.sdk.xdr.CryptoKeyType; import org.stellar.sdk.xdr.MuxedAccount; @@ -22,7 +22,7 @@ public void testClaimableBalanceIds() throws IOException { new CreateClaimableBalanceOperation.Builder( "420", new AssetTypeNative(), - Lists.newArrayList( + Collections.singletonList( new Claimant( "GCACCFMIWJAHUUASSE2WC7V6VVDLYRLSJYZ3DJEXCG523FSHTNII6KOG", new Predicate.Unconditional()))) @@ -52,7 +52,7 @@ public void testClaimableBalanceIds() throws IOException { new CreateClaimableBalanceOperation.Builder( "420", new AssetTypeNative(), - Lists.newArrayList( + Collections.singletonList( new Claimant( "GCACCFMIWJAHUUASSE2WC7V6VVDLYRLSJYZ3DJEXCG523FSHTNII6KOG", new Predicate.Unconditional()))) diff --git a/src/test/java/org/stellar/sdk/MemoTest.java b/src/test/java/org/stellar/sdk/MemoTest.java index 1e5b6ecf9..133c5aea6 100644 --- a/src/test/java/org/stellar/sdk/MemoTest.java +++ b/src/test/java/org/stellar/sdk/MemoTest.java @@ -5,8 +5,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.common.base.Strings; -import com.google.common.io.BaseEncoding; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import java.math.BigInteger; @@ -95,7 +93,7 @@ public void testMemoNullHexHashSuccess() { @Test public void testMemoHashSuccess() { - MemoHash memo = Memo.hash(Strings.padEnd("4142434445464748494a4b4c", 64, '0')); + MemoHash memo = Memo.hash("4142434445464748494a4b4c0000000000000000000000000000000000000000"); assertEquals(MemoType.MEMO_HASH, memo.toXdr().getDiscriminant()); String test = "ABCDEFGHIJKL"; assertEquals(test, Util.paddedByteArrayToString(memo.getBytes())); @@ -105,7 +103,8 @@ public void testMemoHashSuccess() { @Test public void testMemoHashSuccessUppercase() { - MemoHash memo = Memo.hash(Strings.padEnd("4142434445464748494a4b4c".toUpperCase(), 64, '0')); + MemoHash memo = + Memo.hash("4142434445464748494a4b4c0000000000000000000000000000000000000000".toUpperCase()); assertEquals(MemoType.MEMO_HASH, memo.toXdr().getDiscriminant()); String test = "ABCDEFGHIJKL"; assertEquals(test, Util.paddedByteArrayToString(memo.getBytes())); @@ -163,6 +162,6 @@ public void testMemoReturnHashSuccess() { assertNull(memoXdr.getHash()); assertEquals( "4142434445464748494a4b4c0000000000000000000000000000000000000000", - BaseEncoding.base16().lowerCase().encode(memoXdr.getRetHash().getHash())); + Util.bytesToHex(memoXdr.getRetHash().getHash()).toLowerCase()); } } diff --git a/src/test/java/org/stellar/sdk/OperationTest.java b/src/test/java/org/stellar/sdk/OperationTest.java index d34b684fb..55a61d1e0 100644 --- a/src/test/java/org/stellar/sdk/OperationTest.java +++ b/src/test/java/org/stellar/sdk/OperationTest.java @@ -1,20 +1,17 @@ package org.stellar.sdk; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.stellar.sdk.Asset.create; -import com.google.common.collect.Lists; -import com.google.common.io.BaseEncoding; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.Arrays; import java.util.EnumSet; import org.junit.Test; import org.stellar.sdk.xdr.SignerKey; import org.stellar.sdk.xdr.TrustLineFlags; -import org.stellar.sdk.xdr.XdrDataInputStream; public class OperationTest { @@ -161,8 +158,7 @@ public void testPathPaymentStrictReceiveOperation() assertEquals(sendMax, parsedOperation.getSendMax()); assertTrue(parsedOperation.getDestAsset() instanceof AssetTypeCreditAlphaNum4); assertEquals(destAmount, parsedOperation.getDestAmount()); - assertEquals(Lists.newArrayList(path), Lists.newArrayList(parsedOperation.getPath())); - + assertArrayEquals(path, parsedOperation.getPath()); assertEquals( "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==", operation.toXdrBase64(AccountConverter.enableMuxed())); @@ -302,7 +298,7 @@ public void testPathPaymentStrictSendOperation() assertEquals(sendAmount, parsedOperation.getSendAmount()); assertTrue(parsedOperation.getDestAsset() instanceof AssetTypeCreditAlphaNum4); assertEquals(destMin, parsedOperation.getDestMin()); - assertEquals(Lists.newArrayList(path), Lists.newArrayList(parsedOperation.getPath())); + assertArrayEquals(path, parsedOperation.getPath()); assertEquals( "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAACMoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==", @@ -751,12 +747,9 @@ public void testManageSellOfferOperation_BadArithmeticRegression() throws IOExce String transactionEnvelopeToDecode = "AAAAAButy5zasS3DLZ5uFpZHL25aiHUfKRwdv1+3Wp12Ce7XAAAAZAEyGwYAAAAOAAAAAAAAAAAAAAABAAAAAQAAAAAbrcuc2rEtwy2ebhaWRy9uWoh1HykcHb9ft1qddgnu1wAAAAMAAAAAAAAAAUtJTgAAAAAARkrT28ebM6YQyhVZi1ttlwq/dk6ijTpyTNuHIMgUp+EAAAAAAAARPSfDKZ0AAv7oAAAAAAAAAAAAAAAAAAAAAXYJ7tcAAABAbE8rEoFt0Hcv41iwVCl74C1Hyr+Lj8ZyaYn7zTJhezClbc+pTW1KgYFIZOJiGVth2xFnBT1pMXuQkVdTlB3FCw=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(transactionEnvelopeToDecode); org.stellar.sdk.xdr.TransactionEnvelope transactionEnvelope = - org.stellar.sdk.xdr.TransactionEnvelope.decode( - new XdrDataInputStream(new ByteArrayInputStream(bytes))); + org.stellar.sdk.xdr.TransactionEnvelope.fromXdrBase64(transactionEnvelopeToDecode); assertEquals(1, transactionEnvelope.getV0().getTx().getOperations().length); ManageSellOfferOperation op = @@ -774,12 +767,9 @@ public void testManageBuyOfferOperation_BadArithmeticRegression() throws IOExcep String transactionEnvelopeToDecode = "AAAAAButy5zasS3DLZ5uFpZHL25aiHUfKRwdv1+3Wp12Ce7XAAAAZAEyGwYAAAAxAAAAAAAAAAAAAAABAAAAAQAAAAAbrcuc2rEtwy2ebhaWRy9uWoh1HykcHb9ft1qddgnu1wAAAAwAAAABS0lOAAAAAABGStPbx5szphDKFVmLW22XCr92TqKNOnJM24cgyBSn4QAAAAAAAAAAACNyOCfDKZ0AAv7oAAAAAAABv1IAAAAAAAAAAA=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(transactionEnvelopeToDecode); org.stellar.sdk.xdr.TransactionEnvelope transactionEnvelope = - org.stellar.sdk.xdr.TransactionEnvelope.decode( - new XdrDataInputStream(new ByteArrayInputStream(bytes))); + org.stellar.sdk.xdr.TransactionEnvelope.fromXdrBase64(transactionEnvelopeToDecode); assertEquals(1, transactionEnvelope.getV0().getTx().getOperations().length); ManageBuyOfferOperation op = diff --git a/src/test/java/org/stellar/sdk/Sep10ChallengeTest.java b/src/test/java/org/stellar/sdk/Sep10ChallengeTest.java index 3e61df922..95ca1e0d9 100644 --- a/src/test/java/org/stellar/sdk/Sep10ChallengeTest.java +++ b/src/test/java/org/stellar/sdk/Sep10ChallengeTest.java @@ -5,11 +5,11 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.common.collect.ImmutableList; -import com.google.common.io.BaseEncoding; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import java.util.Arrays; +import java.util.Base64; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -47,8 +47,7 @@ public void testChallenge() throws InvalidSep10ChallengeException { assertEquals(domainName + " auth", homeDomainOp.getName()); assertEquals(64, homeDomainOp.getValue().length); - BaseEncoding base64Encoding = BaseEncoding.base64(); - assertTrue(base64Encoding.canDecode(new String(homeDomainOp.getValue()))); + Base64.getDecoder().decode(new String(homeDomainOp.getValue())); ManageDataOperation webAuthDomainOp = (ManageDataOperation) transaction.getOperations()[1]; assertEquals(server.getAccountId(), webAuthDomainOp.getSourceAccount()); @@ -151,7 +150,7 @@ public void testReadChallengeTransactionAcceptsBothV0AndV1() assertEquals(v0ChallengeTransaction, v1ChallengeTransaction); - for (String envelopeBase64 : ImmutableList.of(v0Base64, v1Base64)) { + for (String envelopeBase64 : Arrays.asList(v0Base64, v1Base64)) { Sep10Challenge.ChallengeTransaction challengeTransaction = Sep10Challenge.readChallengeTransaction( envelopeBase64, server.getAccountId(), Network.TESTNET, domainName, webAuthDomain); @@ -288,8 +287,7 @@ public void testReadChallengeTransactionInvalidNotSignedByServer() throws IOExce byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation manageDataOperation1 = @@ -397,8 +395,7 @@ public void testReadChallengeTransactionInvalidSeqNoNotZero() throws IOException byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), 100L); ManageDataOperation manageDataOperation1 = @@ -443,8 +440,7 @@ public void testReadChallengeTransactionInvalidTimeboundsInfinite() throws IOExc byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation = @@ -614,8 +610,7 @@ public void testReadChallengeTransactionInvalidOperationNoSourceAccount() throws byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation manageDataOperation1 = @@ -658,8 +653,7 @@ public void testReadChallengeTransactionInvalidDataValueWrongEncodedLength() thr byte[] nonce = new byte[32]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation manageDataOperation1 = @@ -701,7 +695,8 @@ public void testReadChallengeTransactionInvalidDataValueCorruptBase64() throws I TimeBounds timeBounds = new TimeBounds(now, end); byte[] encodedNonce = - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?AAAAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8"); + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?AAAAAAAAAAAAAAAAAAAAAAAAAA" + .getBytes(StandardCharsets.UTF_8); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation manageDataOperation1 = new ManageDataOperation.Builder(domainName + " auth", encodedNonce) @@ -726,9 +721,7 @@ public void testReadChallengeTransactionInvalidDataValueCorruptBase64() throws I } catch (InvalidSep10ChallengeException e) { assertEquals( "Failed to decode random nonce provided in ManageData operation.", e.getMessage()); - assertEquals( - "com.google.common.io.BaseEncoding$DecodingException: Unrecognized character: ?", - e.getCause().getMessage()); + assertEquals("Illegal base64 character 3f", e.getCause().getMessage()); } } @@ -748,8 +741,7 @@ public void testReadChallengeTransactionInvalidDataValueWrongByteLength() throws byte[] nonce = new byte[47]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation manageDataOperation1 = @@ -835,8 +827,7 @@ public void testReadChallengeTransactionInvalidDataValueIsNull() throws IOExcept byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = @@ -884,8 +875,7 @@ public void testReadChallengeTransactionInvalidDataValueIsNull() throws IOExcept byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = @@ -933,8 +923,7 @@ public void testReadChallengeTransactionInvalidAdditionalManageDataOpsWithSource byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = @@ -979,8 +968,7 @@ public void testReadChallengeTransactionInvalidAdditionalOpsOfOtherTypes() throw byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = @@ -1231,8 +1219,7 @@ public void testReadChallengeTransactionInvalidWebAuthDomainOperationValueIsNull byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation domainNameOperation = @@ -1281,8 +1268,7 @@ public void testReadChallengeTransactionInvalidWebAuthDomainOperationValueIsNull byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation domainNameOperation = @@ -1353,8 +1339,7 @@ public void testChallengeWithClientDomain() throws InvalidSep10ChallengeExceptio assertEquals(domainName + " auth", homeDomainOp.getName()); assertEquals(64, homeDomainOp.getValue().length); - BaseEncoding base64Encoding = BaseEncoding.base64(); - assertTrue(base64Encoding.canDecode(new String(homeDomainOp.getValue()))); + Base64.getDecoder().decode(new String(homeDomainOp.getValue())); ManageDataOperation webAuthDomainOp = (ManageDataOperation) transaction.getOperations()[1]; assertEquals(server.getAccountId(), webAuthDomainOp.getSourceAccount()); @@ -1445,7 +1430,7 @@ public void testVerifyChallengeWithClientDomain() transaction.sign(clientDomainSigner); // should pass if clientDomainSigner is omitted from signers set - Set signers = new HashSet(Arrays.asList(client.getAccountId())); + Set signers = new HashSet<>(Collections.singletonList(client.getAccountId())); Sep10Challenge.verifyChallengeTransactionSigners( transaction.toEnvelopeXdrBase64(), server.getAccountId(), @@ -1530,8 +1515,7 @@ public void testVerifyChallengeTransactionThresholdInvalidNotSignedByServer() th byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation manageDataOperation1 = @@ -2080,8 +2064,7 @@ public void testVerifyChallengeTransactionSignersInvalidServer() throws IOExcept byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation manageDataOperation1 = @@ -2677,8 +2660,7 @@ public void testVerifyChallengeTransactionSignersInvalidNoSignersEmptySet() byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = @@ -2731,8 +2713,7 @@ public void testVerifyChallengeTransactionSignersInvalidNoSignersEmptySet() byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = @@ -2788,8 +2769,7 @@ public void testVerifyChallengeTransactionSignersInvalidNoSignersEmptySet() byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = @@ -2841,8 +2821,7 @@ public void testVerifyChallengeTransactionInvalidAdditionalOpsOfOtherTypes() thr byte[] nonce = new byte[48]; SecureRandom random = new SecureRandom(); random.nextBytes(nonce); - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] encodedNonce = base64Encoding.encode(nonce).getBytes(); + byte[] encodedNonce = Base64.getEncoder().encode(nonce); Account sourceAccount = new Account(server.getAccountId(), -1L); ManageDataOperation operation1 = diff --git a/src/test/java/org/stellar/sdk/SetOptionsOperationTest.java b/src/test/java/org/stellar/sdk/SetOptionsOperationTest.java index ab61c79a5..092e4baa7 100644 --- a/src/test/java/org/stellar/sdk/SetOptionsOperationTest.java +++ b/src/test/java/org/stellar/sdk/SetOptionsOperationTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import com.google.common.io.BaseEncoding; import org.junit.Test; import org.stellar.sdk.xdr.SignerKey; @@ -17,9 +16,8 @@ public void testPaylodSignerKey() { String payloadSignerStrKey = "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"; byte[] payload = - BaseEncoding.base16() - .decode( - "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); + Util.hexToBytes( + "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); SignedPayloadSigner signedPayloadSigner = new SignedPayloadSigner(StrKey.decodeStellarAccountId(payloadSignerStrKey), payload); SignerKey signerKey = Signer.signedPayload(signedPayloadSigner); diff --git a/src/test/java/org/stellar/sdk/SignedPayloadSignerTest.java b/src/test/java/org/stellar/sdk/SignedPayloadSignerTest.java index 7b5666b35..787ee9759 100644 --- a/src/test/java/org/stellar/sdk/SignedPayloadSignerTest.java +++ b/src/test/java/org/stellar/sdk/SignedPayloadSignerTest.java @@ -2,7 +2,6 @@ import static org.junit.Assert.fail; -import com.google.common.io.BaseEncoding; import org.junit.Test; import org.stellar.sdk.xdr.AccountID; import org.stellar.sdk.xdr.PublicKey; @@ -22,10 +21,9 @@ public void itFailsWhenAccoutIDIsNull() { public void itFailsWhenPayloadLengthTooBig() { String accountStrKey = "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"; byte[] payload = - BaseEncoding.base16() - .decode( - "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2001" - .toUpperCase()); + Util.hexToBytes( + "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2001" + .toUpperCase()); try { new SignedPayloadSigner(StrKey.decodeStellarAccountId(accountStrKey), payload); fail("should not create a payload signer if payload > max length"); diff --git a/src/test/java/org/stellar/sdk/SignerTest.java b/src/test/java/org/stellar/sdk/SignerTest.java index 28e7ec6f0..5a3855982 100644 --- a/src/test/java/org/stellar/sdk/SignerTest.java +++ b/src/test/java/org/stellar/sdk/SignerTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import com.google.common.io.BaseEncoding; import org.junit.Test; import org.stellar.sdk.xdr.SignerKey; @@ -14,9 +13,8 @@ public void itCreatesSignedPayloadSigner() { String accountStrKey = "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"; byte[] payload = - BaseEncoding.base16() - .decode( - "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); + Util.hexToBytes( + "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); SignedPayloadSigner signedPayloadSigner = new SignedPayloadSigner(StrKey.decodeStellarAccountId(accountStrKey), payload); SignerKey signerKey = Signer.signedPayload(signedPayloadSigner); diff --git a/src/test/java/org/stellar/sdk/SorobanDataBuilderTest.java b/src/test/java/org/stellar/sdk/SorobanDataBuilderTest.java index b7c764f70..f85f51c3e 100644 --- a/src/test/java/org/stellar/sdk/SorobanDataBuilderTest.java +++ b/src/test/java/org/stellar/sdk/SorobanDataBuilderTest.java @@ -1,6 +1,6 @@ package org.stellar.sdk; -import static com.google.common.collect.ImmutableList.of; +import static java.util.Collections.singletonList; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; @@ -99,8 +99,8 @@ public void testConstructorFromSorobanTransactionData() { public void testSetProperties() { SorobanTransactionData actualData = new SorobanDataBuilder() - .setReadOnly(of(readOnly)) - .setReadWrite(of(readWrite)) + .setReadOnly(singletonList(readOnly)) + .setReadWrite(singletonList(readWrite)) .setRefundableFee(5) .setResources( new SorobanDataBuilder.Resources.ResourcesBuilder() diff --git a/src/test/java/org/stellar/sdk/SorobanServerTest.java b/src/test/java/org/stellar/sdk/SorobanServerTest.java index cc5331b35..a16740fe3 100644 --- a/src/test/java/org/stellar/sdk/SorobanServerTest.java +++ b/src/test/java/org/stellar/sdk/SorobanServerTest.java @@ -1,17 +1,14 @@ package org.stellar.sdk; -import static com.google.common.collect.ImmutableList.of; +import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.stellar.sdk.xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE; -import com.google.common.io.BaseEncoding; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -66,8 +63,6 @@ import org.stellar.sdk.xdr.SorobanTransactionData; import org.stellar.sdk.xdr.Uint256; import org.stellar.sdk.xdr.Uint32; -import org.stellar.sdk.xdr.XdrDataInputStream; -import org.stellar.sdk.xdr.XdrDataOutputStream; import org.stellar.sdk.xdr.XdrString; import org.stellar.sdk.xdr.XdrUnsignedInteger; @@ -103,7 +98,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) throws InterruptedException { GetLedgerEntriesRequest expectedRequest = new GetLedgerEntriesRequest( - of("AAAAAAAAAADBPp7TMinJylnn+6dQXJACNc15LF+aJ2Py1BaR4P10JA==")); + singletonList("AAAAAAAAAADBPp7TMinJylnn+6dQXJACNc15LF+aJ2Py1BaR4P10JA==")); SorobanRpcRequest sorobanRpcRequest = gson.fromJson( recordedRequest.getBody().readUtf8(), @@ -252,8 +247,12 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) .contractData(ledgerKeyContractData) .build(); - GetLedgerEntriesRequest expectedRequest = - new GetLedgerEntriesRequest(of(ledgerKeyToXdrBase64(ledgerKey))); + GetLedgerEntriesRequest expectedRequest = null; + try { + expectedRequest = new GetLedgerEntriesRequest(singletonList(ledgerKey.toXdrBase64())); + } catch (IOException e) { + throw new RuntimeException(e); + } SorobanRpcRequest sorobanRpcRequest = gson.fromJson( recordedRequest.getBody().readUtf8(), @@ -320,8 +319,12 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) .contractData(ledgerKeyContractData) .build(); - GetLedgerEntriesRequest expectedRequest = - new GetLedgerEntriesRequest(of(ledgerKeyToXdrBase64(ledgerKey))); + GetLedgerEntriesRequest expectedRequest = null; + try { + expectedRequest = new GetLedgerEntriesRequest(singletonList(ledgerKey.toXdrBase64())); + } catch (IOException e) { + throw new RuntimeException(e); + } SorobanRpcRequest sorobanRpcRequest = gson.fromJson( recordedRequest.getBody().readUtf8(), @@ -379,7 +382,7 @@ public void testGetLedgerEntries() throws IOException, SorobanRpcErrorResponse { .account(ledgerKeyAccount0) .discriminant(LedgerEntryType.ACCOUNT) .build(); - String ledgerKey0Xdr = ledgerKeyToXdrBase64(ledgerKey0); + String ledgerKey0Xdr = ledgerKey0.toXdrBase64(); String accountId1 = "GDAT5HWTGIU4TSSZ4752OUC4SABDLTLZFRPZUJ3D6LKBNEPA7V2CIG54"; LedgerKey.LedgerKeyAccount ledgerKeyAccount1 = @@ -391,7 +394,7 @@ public void testGetLedgerEntries() throws IOException, SorobanRpcErrorResponse { .account(ledgerKeyAccount1) .discriminant(LedgerEntryType.ACCOUNT) .build(); - String ledgerKey1Xdr = ledgerKeyToXdrBase64(ledgerKey1); + String ledgerKey1Xdr = ledgerKey1.toXdrBase64(); MockWebServer mockWebServer = new MockWebServer(); Dispatcher dispatcher = @@ -425,16 +428,16 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) assertEquals(resp.getLatestLedger().longValue(), 7943L); assertEquals(resp.getEntries().size(), 2); assertEquals( - resp.getEntries().asList().get(0).getKey(), + resp.getEntries().get(0).getKey(), "AAAAAAAAAACynni6I2ACEzWuORVM1b2y0k1ZDni0W6JlC/Ad/mfCSg=="); assertEquals( - resp.getEntries().asList().get(0).getXdr(), + resp.getEntries().get(0).getXdr(), "AAAAAAAAAACynni6I2ACEzWuORVM1b2y0k1ZDni0W6JlC/Ad/mfCSgAAABdIdugAAAAAnwAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAA"); assertEquals( - resp.getEntries().asList().get(1).getKey(), + resp.getEntries().get(1).getKey(), "AAAAAAAAAADBPp7TMinJylnn+6dQXJACNc15LF+aJ2Py1BaR4P10JA=="); assertEquals( - resp.getEntries().asList().get(1).getXdr(), + resp.getEntries().get(1).getXdr(), "AAAAAAAAAADBPp7TMinJylnn+6dQXJACNc15LF+aJ2Py1BaR4P10JAAAABdIcmH6AAAAoQAAAAgAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAADAAAAAAAAHAkAAAAAZMPQ0g=="); server.close(); mockWebServer.close(); @@ -540,7 +543,8 @@ public void testGetEvents() throws IOException, SorobanRpcErrorResponse { GetEventsRequest.EventFilter eventFilter = GetEventsRequest.EventFilter.builder() - .contractIds(of("607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0")) + .contractIds( + singletonList("607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0")) .type(EventFilterType.CONTRACT) .topic(Arrays.asList("AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA=")) .build(); @@ -837,8 +841,8 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) ((InvokeHostFunctionOperation) transaction.getOperations()[0]).getHostFunction()) .sourceAccount(transaction.getOperations()[0].getSourceAccount()) .auth( - of( - sorobanAuthorizationEntryFromXdrBase64( + singletonList( + SorobanAuthorizationEntry.fromXdrBase64( "AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA"))) .build(); Transaction expectedTx = @@ -952,8 +956,8 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) ((InvokeHostFunctionOperation) transaction.getOperations()[0]).getHostFunction()) .sourceAccount(transaction.getOperations()[0].getSourceAccount()) .auth( - of( - sorobanAuthorizationEntryFromXdrBase64( + singletonList( + SorobanAuthorizationEntry.fromXdrBase64( "AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA"))) .build(); Transaction expectedTx = @@ -1038,7 +1042,7 @@ public void testPrepareTransactionWithAuth() .build()) .build(); - Transaction transaction = buildSorobanTransaction(null, of(auth)); + Transaction transaction = buildSorobanTransaction(null, singletonList(auth)); MockWebServer mockWebServer = new MockWebServer(); Dispatcher dispatcher = @@ -1077,7 +1081,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) .hostFunction( ((InvokeHostFunctionOperation) transaction.getOperations()[0]).getHostFunction()) .sourceAccount(transaction.getOperations()[0].getSourceAccount()) - .auth(of(auth)) + .auth(singletonList(auth)) .build(); Transaction expectedTx = new Transaction( @@ -1357,30 +1361,4 @@ private Transaction buildSorobanTransaction( return transactionBuilder.build(); } - - private static SorobanAuthorizationEntry sorobanAuthorizationEntryFromXdrBase64( - String sorobanAuthorizationEntry) { - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(sorobanAuthorizationEntry); - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - XdrDataInputStream xdrInputStream = new XdrDataInputStream(inputStream); - try { - return SorobanAuthorizationEntry.decode(xdrInputStream); - } catch (IOException e) { - throw new IllegalArgumentException( - "invalid ledgerEntryData: " + sorobanAuthorizationEntry, e); - } - } - - private static String ledgerKeyToXdrBase64(LedgerKey ledgerKey) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); - try { - ledgerKey.encode(xdrDataOutputStream); - } catch (IOException e) { - throw new IllegalArgumentException("invalid ledgerKey.", e); - } - BaseEncoding base64Encoding = BaseEncoding.base64(); - return base64Encoding.encode(byteArrayOutputStream.toByteArray()); - } } diff --git a/src/test/java/org/stellar/sdk/StrKeyTest.java b/src/test/java/org/stellar/sdk/StrKeyTest.java index a91dd3e0c..7a8cff31c 100644 --- a/src/test/java/org/stellar/sdk/StrKeyTest.java +++ b/src/test/java/org/stellar/sdk/StrKeyTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.common.io.BaseEncoding; import java.io.IOException; import org.junit.Test; import org.stellar.sdk.xdr.AccountID; @@ -142,9 +141,8 @@ public void testRoundTripHashXFromBytes() { public void testValidSignedPayloadEncode() { // Valid signed payload with an ed25519 public key and a 32-byte payload. byte[] payload = - BaseEncoding.base16() - .decode( - "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); + Util.hexToBytes( + "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); SignedPayloadSigner signedPayloadSigner = new SignedPayloadSigner( StrKey.decodeStellarAccountId( @@ -157,8 +155,7 @@ public void testValidSignedPayloadEncode() { // Valid signed payload with an ed25519 public key and a 29-byte payload. payload = - BaseEncoding.base16() - .decode("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d".toUpperCase()); + Util.hexToBytes("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d".toUpperCase()); signedPayloadSigner = new SignedPayloadSigner( StrKey.decodeStellarAccountId( diff --git a/src/test/java/org/stellar/sdk/StreamingSmokeTest.java b/src/test/java/org/stellar/sdk/StreamingSmokeTest.java index 7f988aa17..068f2b7f6 100644 --- a/src/test/java/org/stellar/sdk/StreamingSmokeTest.java +++ b/src/test/java/org/stellar/sdk/StreamingSmokeTest.java @@ -1,6 +1,6 @@ package org.stellar.sdk; -import com.google.common.base.Optional; +import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Assert; import org.junit.Ignore; diff --git a/src/test/java/org/stellar/sdk/TransactionBuilderTest.java b/src/test/java/org/stellar/sdk/TransactionBuilderTest.java index 1694d2cac..081a16a30 100644 --- a/src/test/java/org/stellar/sdk/TransactionBuilderTest.java +++ b/src/test/java/org/stellar/sdk/TransactionBuilderTest.java @@ -1,12 +1,11 @@ package org.stellar.sdk; -import static com.google.common.collect.Lists.newArrayList; import static org.junit.Assert.*; -import com.google.common.io.BaseEncoding; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; import org.junit.Test; import org.stellar.sdk.xdr.*; @@ -461,10 +460,9 @@ public void testBuilderExtraSigners() throws IOException { Account account = new Account(source.getAccountId(), 2908908335136768L); String accountStrKey = "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"; - byte[] payload = - BaseEncoding.base16() - .decode( - "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); + + String encodedString = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"; + byte[] payload = Util.hexToBytes(encodedString); SignerKey signerKey = new SignerKey.Builder() @@ -484,7 +482,7 @@ public void testBuilderExtraSigners() throws IOException { TransactionPreconditions.builder() .timeBounds( new TimeBounds(BigInteger.ZERO, TransactionPreconditions.TIMEOUT_INFINITE)) - .extraSigners(newArrayList(signerKey)) + .extraSigners(Collections.singletonList(signerKey)) .minSeqLedgerGap(5) .build()) .setBaseFee(Transaction.MIN_BASE_FEE) @@ -492,10 +490,12 @@ public void testBuilderExtraSigners() throws IOException { assertEquals( SignerKeyType.SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD, - newArrayList(transaction.getPreconditions().getExtraSigners()).get(0).getDiscriminant()); + transaction.getPreconditions().getExtraSigners().get(0).getDiscriminant()); assertArrayEquals( payload, - newArrayList(transaction.getPreconditions().getExtraSigners()) + transaction + .getPreconditions() + .getExtraSigners() .get(0) .getEd25519SignedPayload() .getPayload()); @@ -527,7 +527,7 @@ public void testBuilderFailsWhenTooManyExtraSigners() throws IOException { .timeBounds( new TimeBounds(BigInteger.ZERO, TransactionPreconditions.TIMEOUT_INFINITE)) .extraSigners( - newArrayList( + Arrays.asList( new SignerKey.Builder().build(), new SignerKey.Builder().build(), new SignerKey.Builder().build())) @@ -660,12 +660,8 @@ public void testBuilderInfinteTimeoutOnly() throws IOException { // Convert transaction to binary XDR and back again to make sure timeout is correctly // de/serialized. - XdrDataInputStream is = - new XdrDataInputStream( - new ByteArrayInputStream( - BaseEncoding.base64().decode(transaction.toEnvelopeXdrBase64()))); org.stellar.sdk.xdr.TransactionEnvelope decodedTransaction = - org.stellar.sdk.xdr.TransactionEnvelope.decode(is); + org.stellar.sdk.xdr.TransactionEnvelope.fromXdrBase64(transaction.toEnvelopeXdrBase64()); assertEquals( decodedTransaction @@ -714,12 +710,8 @@ public void testBuilderTimeoutOnly() throws IOException { // Convert transaction to binary XDR and back again to make sure timeout is correctly // de/serialized. - XdrDataInputStream is = - new XdrDataInputStream( - new ByteArrayInputStream( - BaseEncoding.base64().decode(transaction.toEnvelopeXdrBase64()))); org.stellar.sdk.xdr.TransactionEnvelope decodedTransaction = - org.stellar.sdk.xdr.TransactionEnvelope.decode(is); + org.stellar.sdk.xdr.TransactionEnvelope.fromXdrBase64(transaction.toEnvelopeXdrBase64()); assertEquals( decodedTransaction @@ -770,12 +762,8 @@ public void testBuilderTimeoutAndMaxTimeNotSet() throws IOException { // Convert transaction to binary XDR and back again to make sure timeout is correctly // de/serialized. - XdrDataInputStream is = - new XdrDataInputStream( - new ByteArrayInputStream( - BaseEncoding.base64().decode(transaction.toEnvelopeXdrBase64()))); org.stellar.sdk.xdr.TransactionEnvelope decodedTransaction = - org.stellar.sdk.xdr.TransactionEnvelope.decode(is); + org.stellar.sdk.xdr.TransactionEnvelope.fromXdrBase64(transaction.toEnvelopeXdrBase64()); assertEquals( decodedTransaction @@ -827,12 +815,8 @@ public void testBuilderInfinteTimeoutAndMaxTimeNotSet() throws FormatException, // Convert transaction to binary XDR and back again to make sure timebounds are correctly // de/serialized. - XdrDataInputStream is = - new XdrDataInputStream( - new ByteArrayInputStream( - BaseEncoding.base64().decode(transaction.toEnvelopeXdrBase64()))); org.stellar.sdk.xdr.TransactionEnvelope decodedTransaction = - org.stellar.sdk.xdr.TransactionEnvelope.decode(is); + org.stellar.sdk.xdr.TransactionEnvelope.fromXdrBase64(transaction.toEnvelopeXdrBase64()); assertEquals( decodedTransaction @@ -952,7 +936,7 @@ public void testNoNetworkSet() throws FormatException { .build(); fail(); } catch (NullPointerException e) { - assertTrue(e.getMessage().contains("Network cannot be null")); + assertTrue(e.getMessage().contains("network is marked non-null but is null")); } } diff --git a/src/test/java/org/stellar/sdk/TransactionPreconditionsTest.java b/src/test/java/org/stellar/sdk/TransactionPreconditionsTest.java index 81940e1dc..af65395e0 100644 --- a/src/test/java/org/stellar/sdk/TransactionPreconditionsTest.java +++ b/src/test/java/org/stellar/sdk/TransactionPreconditionsTest.java @@ -1,15 +1,14 @@ package org.stellar.sdk; -import static com.google.common.collect.Lists.newArrayList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.common.io.BaseEncoding; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.Arrays; import org.junit.Test; import org.stellar.sdk.xdr.Duration; import org.stellar.sdk.xdr.Int64; @@ -104,9 +103,8 @@ public void itRoundTripsFromV2ToV1IfOnlyTimeboundsPresent() throws IOException { public void itConvertsToV2Xdr() throws IOException { byte[] payload = - BaseEncoding.base16() - .decode( - "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); + Util.hexToBytes( + "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20".toUpperCase()); SignerKey signerKey = new SignerKey.Builder() .discriminant(SignerKeyType.SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD) @@ -124,7 +122,7 @@ public void itConvertsToV2Xdr() throws IOException { TransactionPreconditions.builder() .timeBounds(new TimeBounds(1, 2)) .minSeqNumber(3L) - .extraSigners(newArrayList(signerKey, signerKey, signerKey)) + .extraSigners(Arrays.asList(signerKey, signerKey, signerKey)) .build(); Preconditions xdr = preconditions.toXdr(); @@ -215,7 +213,7 @@ public void itChecksNonValidityOfExtraSignersSize() { TransactionPreconditions.builder() .timeBounds(new TimeBounds(1, 2)) .extraSigners( - newArrayList( + Arrays.asList( new SignerKey.Builder().build(), new SignerKey.Builder().build(), new SignerKey.Builder().build())) diff --git a/src/test/java/org/stellar/sdk/TransactionTest.java b/src/test/java/org/stellar/sdk/TransactionTest.java index a44dae76f..164bc9cb4 100644 --- a/src/test/java/org/stellar/sdk/TransactionTest.java +++ b/src/test/java/org/stellar/sdk/TransactionTest.java @@ -6,8 +6,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.common.io.BaseEncoding; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.math.BigInteger; import java.security.SecureRandom; @@ -38,7 +36,6 @@ import org.stellar.sdk.xdr.SorobanTransactionData; import org.stellar.sdk.xdr.Uint256; import org.stellar.sdk.xdr.Uint32; -import org.stellar.sdk.xdr.XdrDataInputStream; import org.stellar.sdk.xdr.XdrUnsignedInteger; public class TransactionTest { @@ -72,12 +69,8 @@ public void testParseV0Transaction() throws FormatException, IOException { transaction.setEnvelopeType(EnvelopeType.ENVELOPE_TYPE_TX_V0); transaction.sign(source); - XdrDataInputStream is = - new XdrDataInputStream( - new ByteArrayInputStream( - BaseEncoding.base64().decode(transaction.toEnvelopeXdrBase64()))); org.stellar.sdk.xdr.TransactionEnvelope decodedTransaction = - org.stellar.sdk.xdr.TransactionEnvelope.decode(is); + org.stellar.sdk.xdr.TransactionEnvelope.fromXdrBase64(transaction.toEnvelopeXdrBase64()); assertEquals(EnvelopeType.ENVELOPE_TYPE_TX_V0, decodedTransaction.getDiscriminant()); Transaction parsed = diff --git a/src/test/java/org/stellar/sdk/requests/PathsRequestBuilderTest.java b/src/test/java/org/stellar/sdk/requests/PathsRequestBuilderTest.java index 94c4a766c..a2ad1408f 100644 --- a/src/test/java/org/stellar/sdk/requests/PathsRequestBuilderTest.java +++ b/src/test/java/org/stellar/sdk/requests/PathsRequestBuilderTest.java @@ -5,7 +5,7 @@ import static org.junit.Assert.fail; import static org.stellar.sdk.Asset.create; -import com.google.common.collect.Lists; +import java.util.Arrays; import java.util.List; import okhttp3.HttpUrl; import org.junit.Test; @@ -46,7 +46,7 @@ public void testStrictReceiveWithSourceAccount() { @Test public void testStrictReceiveWithSourceAssets() { List assets = - Lists.newArrayList( + Arrays.asList( create("native", "", ""), create( "credit_alphanum4", @@ -87,7 +87,7 @@ public void testStrictReceiveWithSourceAssets() { @Test public void testStrictReceiveWithSourceAccountAndSourceAssets() { List assets = - Lists.newArrayList( + Arrays.asList( create("native", "", ""), create( "credit_alphanum4", @@ -151,7 +151,7 @@ public void testStrictSendWithDestinationAccount() { @Test public void testStrictSendWithDestinationAssets() { List assets = - Lists.newArrayList( + Arrays.asList( create("native", "", ""), create( "credit_alphanum4", @@ -190,7 +190,7 @@ public void testStrictSendWithDestinationAssets() { @Test public void testStrictSendWithDestinationAccountAndDestinationAssets() { List assets = - Lists.newArrayList( + Arrays.asList( create("native", "", ""), create( "credit_alphanum4", diff --git a/src/test/java/org/stellar/sdk/requests/ResponseHandlerTest.java b/src/test/java/org/stellar/sdk/requests/ResponseHandlerTest.java index 620a17216..8cbea5d26 100644 --- a/src/test/java/org/stellar/sdk/requests/ResponseHandlerTest.java +++ b/src/test/java/org/stellar/sdk/requests/ResponseHandlerTest.java @@ -2,8 +2,8 @@ import static org.junit.Assert.assertEquals; -import com.google.common.base.Optional; import java.io.IOException; +import java.util.Optional; import okhttp3.OkHttpClient; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -54,7 +54,7 @@ public void testTooManyRequestsNoHeader() throws IOException, InterruptedExcepti AccountsRequestBuilder.execute(okHttpClient, mockWebServer.url("/")); Assert.fail(); } catch (TooManyRequestsException tmre) { - assertEquals(Optional.absent(), tmre.getRetryAfter()); + assertEquals(Optional.empty(), tmre.getRetryAfter()); } finally { mockWebServer.shutdown(); diff --git a/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java index f4f3fa96a..570c6e9ef 100644 --- a/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/AccountDeserializerTest.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; import java.util.Arrays; +import java.util.Optional; import junit.framework.TestCase; import org.junit.Test; import org.stellar.sdk.AssetTypeCreditAlphaNum4; @@ -155,14 +155,14 @@ public void testDeserializeV9() { "ABC", "GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU"))); assertEquals(account.getBalances()[0].getBalance(), "1001.0000000"); assertEquals(account.getBalances()[0].getLimit(), "12000.4775807"); - assertEquals(account.getBalances()[0].getBuyingLiabilities(), Optional.absent()); - assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.absent()); + assertEquals(account.getBalances()[0].getBuyingLiabilities(), Optional.empty()); + assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.empty()); assertEquals(account.getBalances()[1].getAssetType(), "native"); assertEquals(account.getBalances()[1].getAsset(), Optional.of(new AssetTypeNative())); assertEquals(account.getBalances()[1].getBalance(), "20.0000300"); - assertEquals(account.getBalances()[1].getBuyingLiabilities(), Optional.absent()); - assertEquals(account.getBalances()[1].getSellingLiabilities(), Optional.absent()); + assertEquals(account.getBalances()[1].getBuyingLiabilities(), Optional.empty()); + assertEquals(account.getBalances()[1].getSellingLiabilities(), Optional.empty()); assertEquals(account.getBalances()[1].getLimit(), null); } @@ -172,12 +172,12 @@ public void testDeserializeLiquidityPoolBalanc() { GsonSingleton.getInstance().fromJson(jsonLiquidityPoolBalance, AccountResponse.class); assertEquals(account.getBalances()[0].getAssetType(), "liquidity_pool_shares"); - assertEquals(account.getBalances()[0].getAssetCode(), Optional.absent()); - assertEquals(account.getBalances()[0].getAssetIssuer(), Optional.absent()); + assertEquals(account.getBalances()[0].getAssetCode(), Optional.empty()); + assertEquals(account.getBalances()[0].getAssetIssuer(), Optional.empty()); assertEquals(account.getBalances()[0].getBalance(), "223.6067977"); assertEquals(account.getBalances()[0].getLimit(), "10000.00000"); - assertEquals(account.getBalances()[0].getBuyingLiabilities(), Optional.absent()); - assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.absent()); + assertEquals(account.getBalances()[0].getBuyingLiabilities(), Optional.empty()); + assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.empty()); assertTrue(account.getBalances()[0].getLiquidityPoolID().isPresent()); assertEquals( account.getBalances()[0].getLiquidityPoolID().get().toString(), @@ -185,8 +185,8 @@ public void testDeserializeLiquidityPoolBalanc() { assertEquals(account.getBalances()[1].getAssetType(), "native"); assertEquals(account.getBalances()[1].getBalance(), "20.0000300"); - assertEquals(account.getBalances()[1].getBuyingLiabilities(), Optional.absent()); - assertEquals(account.getBalances()[1].getSellingLiabilities(), Optional.absent()); + assertEquals(account.getBalances()[1].getBuyingLiabilities(), Optional.empty()); + assertEquals(account.getBalances()[1].getSellingLiabilities(), Optional.empty()); assertEquals(account.getBalances()[1].getLimit(), null); } diff --git a/src/test/java/org/stellar/sdk/responses/AccountsPageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/AccountsPageDeserializerTest.java index f4bc259ca..fb9d220f0 100644 --- a/src/test/java/org/stellar/sdk/responses/AccountsPageDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/AccountsPageDeserializerTest.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; import com.google.gson.reflect.TypeToken; +import java.util.Optional; import junit.framework.TestCase; import org.junit.Test; import org.stellar.sdk.LiquidityPoolID; @@ -43,7 +43,7 @@ public void testDeserializeWithLiquidityPoolBalance() { new LiquidityPoolID( "a468d41d8e9b8f3c7209651608b74b7db7ac9952dcae0cdf24871d1d9c7b0088"))); assertEquals( - accountsPage.getRecords().get(0).getBalances()[1].getLiquidityPoolID(), Optional.absent()); + accountsPage.getRecords().get(0).getBalances()[1].getLiquidityPoolID(), Optional.empty()); } String json = diff --git a/src/test/java/org/stellar/sdk/responses/ClaimableBalancePageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/ClaimableBalancePageDeserializerTest.java index 56f189983..bdb50ee9f 100644 --- a/src/test/java/org/stellar/sdk/responses/ClaimableBalancePageDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/ClaimableBalancePageDeserializerTest.java @@ -1,7 +1,7 @@ package org.stellar.sdk.responses; -import com.google.common.base.Optional; import com.google.gson.reflect.TypeToken; +import java.util.Optional; import junit.framework.TestCase; import org.junit.Test; import org.stellar.sdk.Asset; diff --git a/src/test/java/org/stellar/sdk/responses/OperationDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/OperationDeserializerTest.java index 52723ab03..cd7c46274 100644 --- a/src/test/java/org/stellar/sdk/responses/OperationDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/OperationDeserializerTest.java @@ -3,13 +3,11 @@ import static java.math.BigInteger.valueOf; import static org.stellar.sdk.Asset.create; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import java.math.BigInteger; import java.util.Arrays; +import java.util.Collections; import junit.framework.TestCase; import org.junit.Test; -import org.stellar.sdk.Asset; import org.stellar.sdk.AssetAmount; import org.stellar.sdk.AssetTypeNative; import org.stellar.sdk.AssetTypePoolShare; @@ -871,7 +869,7 @@ public void testDeserializePathPaymentOperation() { assertEquals(operation.getAsset(), new AssetTypeNative()); assertEquals( operation.getPath(), - ImmutableList.of( + Arrays.asList( new AssetTypeNative(), create(null, "CNY", "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX"), create(null, "CNYMNL", "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX"))); @@ -935,7 +933,7 @@ public void testDeserializePathPaymentStrictSendOperation() { assertEquals(operation.getAsset(), new AssetTypeNative()); assertEquals( operation.getPath(), - ImmutableList.of( + Arrays.asList( new AssetTypeNative(), create(null, "CNY", "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX"), create(null, "CNYMNL", "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX"))); @@ -1058,7 +1056,7 @@ public void testDeserializePathPaymentOperationSourceAssetNative() { assertEquals(operation.getAmount(), "2.5000000"); assertEquals(operation.getSourceMax(), "1.1779523"); assertEquals(operation.getSourceAsset(), new AssetTypeNative()); - assertEquals(operation.getPath(), ImmutableList.of()); + assertEquals(operation.getPath(), Collections.emptyList()); assertEquals( operation.getAsset(), create(null, "XRP", "GBVOL67TMUQBGL4TZYNMY3ZQ5WGQYFPFD5VJRWXR72VA33VFNL225PL5")); @@ -1587,11 +1585,12 @@ public void testDeserializeSetTrustlineFlagsOperation() { operation.getAssetIssuer(), "GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS"); assertEquals(operation.getAssetCode(), "EUR"); assertEquals(operation.getAssetType(), "credit_alphanum4"); - assertEquals(operation.getSetFlags(), Lists.newArrayList(4)); - assertEquals(operation.getClearFlags(), Lists.newArrayList(2)); - assertEquals(operation.getSetFlagStrings(), Lists.newArrayList("clawback_enabled")); + assertEquals(operation.getSetFlags(), Collections.singletonList(4)); + assertEquals(operation.getClearFlags(), Collections.singletonList(2)); + assertEquals(operation.getSetFlagStrings(), Collections.singletonList("clawback_enabled")); assertEquals( - operation.getClearFlagStrings(), Lists.newArrayList("authorized_to_maintain_liabilites")); + operation.getClearFlagStrings(), + Collections.singletonList("authorized_to_maintain_liabilites")); } @Test diff --git a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java index 811f3deff..f6d697053 100644 --- a/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/TradesPageDeserializerTest.java @@ -3,8 +3,8 @@ import static java.lang.Long.valueOf; import static org.stellar.sdk.Asset.create; -import com.google.common.base.Optional; import com.google.gson.reflect.TypeToken; +import java.util.Optional; import junit.framework.TestCase; import org.junit.Test; import org.stellar.sdk.AssetTypeNative; @@ -39,8 +39,8 @@ public void testDeserialize() { create(null, "JPY", "GBVAOIACNSB7OVUXJYC5UE2D4YK2F7A24T7EE5YOMN4CE6GCHUTOUQXM")); assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), valueOf(267)); assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), valueOf(1000)); - assertEquals(tradesPage.getRecords().get(0).getCounterLiquidityPoolID(), Optional.absent()); - assertEquals(tradesPage.getRecords().get(0).getBaseLiquidityPoolID(), Optional.absent()); + assertEquals(tradesPage.getRecords().get(0).getCounterLiquidityPoolID(), Optional.empty()); + assertEquals(tradesPage.getRecords().get(0).getBaseLiquidityPoolID(), Optional.empty()); assertEquals( tradesPage.getRecords().get(1).getBaseAccount(), @@ -58,8 +58,8 @@ public void testDeserializeLiquidityPool() { Optional.of( new LiquidityPoolID( "a468d41d8e9b8f3c7209651608b74b7db7ac9952dcae0cdf24871d1d9c7bbase"))); - assertEquals(tradesPage.getRecords().get(0).getCounterLiquidityPoolID(), Optional.absent()); - assertEquals(tradesPage.getRecords().get(1).getBaseLiquidityPoolID(), Optional.absent()); + assertEquals(tradesPage.getRecords().get(0).getCounterLiquidityPoolID(), Optional.empty()); + assertEquals(tradesPage.getRecords().get(1).getBaseLiquidityPoolID(), Optional.empty()); assertEquals( tradesPage.getRecords().get(1).getCounterLiquidityPoolID(), Optional.of( diff --git a/src/test/java/org/stellar/sdk/responses/TransactionDeserializerTest.java b/src/test/java/org/stellar/sdk/responses/TransactionDeserializerTest.java index 94d4fe781..0dc88025a 100644 --- a/src/test/java/org/stellar/sdk/responses/TransactionDeserializerTest.java +++ b/src/test/java/org/stellar/sdk/responses/TransactionDeserializerTest.java @@ -1,11 +1,10 @@ package org.stellar.sdk.responses; import static java.math.BigInteger.valueOf; -import static org.junit.Assert.assertEquals; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; import java.util.Arrays; +import java.util.Collections; +import java.util.Optional; import junit.framework.TestCase; import org.junit.Test; import org.stellar.sdk.MemoHash; @@ -28,20 +27,20 @@ public void testDeserializeFeeBump() { assertEquals(transaction.getMaxFee(), Long.valueOf(776)); assertEquals(transaction.getFeeCharged(), Long.valueOf(123)); assertEquals(transaction.getOperationCount(), Integer.valueOf(1)); - assertEquals(transaction.getSignatures(), ImmutableList.of("Hh4e")); + assertEquals(transaction.getSignatures(), Collections.singletonList("Hh4e")); TransactionResponse.FeeBumpTransaction feeBumpTransaction = transaction.getFeeBump().get(); assertEquals( feeBumpTransaction.getHash(), "3dfef7d7226995b504f2827cc63d45ad41e9687bb0a8abcf08ba755fedca0352"); - assertEquals(feeBumpTransaction.getSignatures(), ImmutableList.of("Hh4e")); + assertEquals(feeBumpTransaction.getSignatures(), Collections.singletonList("Hh4e")); TransactionResponse.InnerTransaction innerTransaction = transaction.getInner().get(); assertEquals( innerTransaction.getHash(), "e98869bba8bce08c10b78406202127f3888c25454cd37b02600862452751f526"); assertEquals(innerTransaction.getMaxFee(), Long.valueOf(99)); - assertEquals(innerTransaction.getSignatures(), ImmutableList.of("FBQU")); + assertEquals(innerTransaction.getSignatures(), Collections.singletonList("FBQU")); assertFalse(transaction.getSourceAccountMuxed().isPresent()); assertFalse(transaction.getFeeAccountMuxed().isPresent()); @@ -74,11 +73,10 @@ public void testDeserialize() { "AAAAAAAAAAEAAAACAAAAAAAN+SAAAAAAAAAAAMDtGdqtLMLCPc5P4zZu0IwWlUF2rElL5KvTSoGO0W/uAAAAAEsKz9AADfkgAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAQAN+SAAAAAAAAAAAP1qe44j+i4uIT+arbD4QDQBt8ryEeJd7a0jskQ3nwDeAAHp6WMr55YACD1BAAAAHgAAAAoAAAAAAAAAAAAAAAABAAAAAAAACgAAAAARC07BokpLTOF+/vVKBwiAlop7hHGJTNeGGlY4MoPykwAAAAEAAAAAK+Lzfd3yDD+Ov0GbYu1g7SaIBrKZeBUxoCunkLuI7aoAAAABAAAAAERmsKL73CyLV/HvjyQCERDXXpWE70Xhyb6MR5qPO3yQAAAAAQAAAABSORGwAdyuanN3sNOHqNSpACyYdkUM3L8VafUu69EvEgAAAAEAAAAAeCzqJNkMM/jLvyuMIfyFHljBlLCtDyj17RMycPuNtRMAAAABAAAAAIEi4R7juq15ymL00DNlAddunyFT4FyUD4muC4t3bobdAAAAAQAAAACaNpLL5YMfjOTdXVEqrAh99LM12sN6He6pHgCRAa1f1QAAAAEAAAAAqB+lfAPV9ak+Zkv4aTNZwGaFFAfui4+yhM3dGhoYJ+sAAAABAAAAAMNJrEvdMg6M+M+n4BDIdzsVSj/ZI9SvAp7mOOsvAD/WAAAAAQAAAADbHA6xiKB1+G79mVqpsHMOleOqKa5mxDpP5KEp/Xdz9wAAAAEAAAAAAAAAAA=="); assertEquals( transaction.getSignatures(), - ImmutableList.of( + Collections.singletonList( "b/noKPYnxb8oJmv6gLixY0PUJMZZ9pxwc226JtAfyRkhv6oFINj3iDuGJoBeuUh6D1vujP9e4/fH0xZjDaO3Aw==")); - assertEquals( - transaction.getFeeBump(), Optional.absent()); - assertEquals(transaction.getInner(), Optional.absent()); + assertEquals(transaction.getFeeBump(), Optional.empty()); + assertEquals(transaction.getInner(), Optional.empty()); assertTrue(transaction.getMemo() instanceof MemoHash); MemoHash memo = (MemoHash) transaction.getMemo(); assertEquals( diff --git a/src/test/java/org/stellar/sdk/xdr/AccountEntryDecodeTest.java b/src/test/java/org/stellar/sdk/xdr/AccountEntryDecodeTest.java index f4004aef8..060cb74e7 100644 --- a/src/test/java/org/stellar/sdk/xdr/AccountEntryDecodeTest.java +++ b/src/test/java/org/stellar/sdk/xdr/AccountEntryDecodeTest.java @@ -3,16 +3,11 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import com.google.common.io.BaseEncoding; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import org.junit.Test; public class AccountEntryDecodeTest { - BaseEncoding base64Encoding = BaseEncoding.base64(); - @Test public void testDecodeSignerPayload() throws IOException { AccountEntry.Builder bldr = new AccountEntry.Builder(); @@ -80,15 +75,7 @@ public void testDecodeSignerPayload() throws IOException { AccountEntry xdr = bldr.build(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - XdrDataOutputStream outputStream = new XdrDataOutputStream(baos); - AccountEntry.encode(outputStream, xdr); - String encodedXdr = base64Encoding.encode(baos.toByteArray()); - - byte[] decodedbBytes = base64Encoding.decode(encodedXdr); - - AccountEntry accountEntry = - AccountEntry.decode(new XdrDataInputStream(new ByteArrayInputStream(decodedbBytes))); + AccountEntry accountEntry = AccountEntry.fromXdrBase64(xdr.toXdrBase64()); assertArrayEquals( new byte[32], accountEntry.getSigners()[0].getKey().getEd25519SignedPayload().getEd25519().getUint256()); diff --git a/src/test/java/org/stellar/sdk/xdr/TransactionDecodeTest.java b/src/test/java/org/stellar/sdk/xdr/TransactionDecodeTest.java index d4153e451..9951c2704 100644 --- a/src/test/java/org/stellar/sdk/xdr/TransactionDecodeTest.java +++ b/src/test/java/org/stellar/sdk/xdr/TransactionDecodeTest.java @@ -3,9 +3,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import com.google.common.io.BaseEncoding; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import org.junit.Test; @@ -19,11 +16,8 @@ public void testDecodeTxBody() throws IOException { String txBody = "AAAAAERmsKL73CyLV/HvjyQCERDXXpWE70Xhyb6MR5qPO3yQAAAAZAAIbkEAACD7AAAAAAAAAAN43bSwpXw8tSAhl7TBtQeOZTQAXwAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAP1qe44j+i4uIT+arbD4QDQBt8ryEeJd7a0jskQ3nwDeAAAAAAAAAADdVhDVFrUiS/jPrRpblXY4bAW9u4hbRI2Hhw+2ATsFpQAAAAAtPWvAAAAAAAAAAAGPO3yQAAAAQHGWVHCBsjTyap/OY9JjPHmzWtN2Y2sL98aMERc/xJ3hcWz6kdQAwjlEhilItCyokDHCrvALZy3v/1TlaDqprA0="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(txBody); - TransactionEnvelope transactionEnvelope = - TransactionEnvelope.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); + TransactionEnvelope transactionEnvelope = TransactionEnvelope.fromXdrBase64(txBody); assertEquals( new Long(2373025265623291L), transactionEnvelope.getV0().getTx().getSeqNum().getSequenceNumber().getInt64()); @@ -36,11 +30,7 @@ public void testDecodeTxResult() throws IOException { String txResult = "1exmRdhs3K6CEsvmD+rvuNaxqLfRGu6lkGCLCGOs5N4AAAAAAAAAZAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAA=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(txResult); - - TransactionResultPair transactionResult = - TransactionResultPair.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); + TransactionResultPair transactionResult = TransactionResultPair.fromXdrBase64(txResult); assertEquals( TransactionResultCode.txSUCCESS, transactionResult.getResult().getResult().getDiscriminant()); @@ -53,11 +43,8 @@ public void testDecodeTxMeta() throws IOException { String txMeta = "AAAAAAAAAAEAAAADAAAAAABZMEIAAAAAAAAAAN1WENUWtSJL+M+tGluVdjhsBb27iFtEjYeHD7YBOwWlAAAAAC09a8AAWTBCAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAwBZL8QAAAAAAAAAAP1qe44j+i4uIT+arbD4QDQBt8ryEeJd7a0jskQ3nwDeAALU1gZ4V7UACD1BAAAAHgAAAAoAAAAAAAAAAAAAAAABAAAAAAAACgAAAAARC07BokpLTOF+/vVKBwiAlop7hHGJTNeGGlY4MoPykwAAAAEAAAAAK+Lzfd3yDD+Ov0GbYu1g7SaIBrKZeBUxoCunkLuI7aoAAAABAAAAAERmsKL73CyLV/HvjyQCERDXXpWE70Xhyb6MR5qPO3yQAAAAAQAAAABSORGwAdyuanN3sNOHqNSpACyYdkUM3L8VafUu69EvEgAAAAEAAAAAeCzqJNkMM/jLvyuMIfyFHljBlLCtDyj17RMycPuNtRMAAAABAAAAAIEi4R7juq15ymL00DNlAddunyFT4FyUD4muC4t3bobdAAAAAQAAAACaNpLL5YMfjOTdXVEqrAh99LM12sN6He6pHgCRAa1f1QAAAAEAAAAAqB+lfAPV9ak+Zkv4aTNZwGaFFAfui4+yhM3dGhoYJ+sAAAABAAAAAMNJrEvdMg6M+M+n4BDIdzsVSj/ZI9SvAp7mOOsvAD/WAAAAAQAAAADbHA6xiKB1+G79mVqpsHMOleOqKa5mxDpP5KEp/Xdz9wAAAAEAAAAAAAAAAAAAAAEAWTBCAAAAAAAAAAD9anuOI/ouLiE/mq2w+EA0AbfK8hHiXe2tI7JEN58A3gAC1NXZOuv1AAg9QQAAAB4AAAAKAAAAAAAAAAAAAAAAAQAAAAAAAAoAAAAAEQtOwaJKS0zhfv71SgcIgJaKe4RxiUzXhhpWODKD8pMAAAABAAAAACvi833d8gw/jr9Bm2LtYO0miAaymXgVMaArp5C7iO2qAAAAAQAAAABEZrCi+9wsi1fx748kAhEQ116VhO9F4cm+jEeajzt8kAAAAAEAAAAAUjkRsAHcrmpzd7DTh6jUqQAsmHZFDNy/FWn1LuvRLxIAAAABAAAAAHgs6iTZDDP4y78rjCH8hR5YwZSwrQ8o9e0TMnD7jbUTAAAAAQAAAACBIuEe47qtecpi9NAzZQHXbp8hU+BclA+JrguLd26G3QAAAAEAAAAAmjaSy+WDH4zk3V1RKqwIffSzNdrDeh3uqR4AkQGtX9UAAAABAAAAAKgfpXwD1fWpPmZL+GkzWcBmhRQH7ouPsoTN3RoaGCfrAAAAAQAAAADDSaxL3TIOjPjPp+AQyHc7FUo/2SPUrwKe5jjrLwA/1gAAAAEAAAAA2xwOsYigdfhu/ZlaqbBzDpXjqimuZsQ6T+ShKf13c/cAAAABAAAAAAAAAAA="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(txMeta); - TransactionMeta transactionMeta = - TransactionMeta.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); + TransactionMeta transactionMeta = TransactionMeta.fromXdrBase64(txMeta); assertEquals(1, transactionMeta.getOperations().length); } @@ -65,11 +52,9 @@ public void testDecodeTxMeta() throws IOException { public void testTransactionEnvelopeWithMemo() throws IOException { String transactionEnvelopeToDecode = "AAAAACq1Ixcw1fchtF5aLTSw1zaYAYjb3WbBRd4jqYJKThB9AAAAZAA8tDoAAAALAAAAAAAAAAEAAAAZR29sZCBwYXltZW50IGZvciBzZXJ2aWNlcwAAAAAAAAEAAAAAAAAAAQAAAAARREGslec48mbJJygIwZoLvRtL6/gGL4ss2TOpnOUOhgAAAAFHT0xEAAAAACq1Ixcw1fchtF5aLTSw1zaYAYjb3WbBRd4jqYJKThB9AAAAADuaygAAAAAAAAAAAA=="; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(transactionEnvelopeToDecode); TransactionEnvelope transactionEnvelope = - TransactionEnvelope.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); + TransactionEnvelope.fromXdrBase64(transactionEnvelopeToDecode); assertEquals(1, transactionEnvelope.getV0().getTx().getOperations().length); assertTrue( Arrays.equals( @@ -90,15 +75,9 @@ public void testTransactionEnvelopeWithMemo() throws IOException { public void testRoundtrip() throws IOException { String txBody = "AAAAAM6jLgjKjuXxWkir4M7v0NqoOfODXcFnn6AGlP+d4RxAAAAAZAAIiE4AAAABAAAAAAAAAAEAAAAcyKMl+WDSzuttWkF2DvzKAkkEqeSZ4cZihjGJEAAAAAEAAAAAAAAAAQAAAAAgECmBaDwiRPE1z2vAE36J+45toU/ZxdvpR38tc0HvmgAAAAAAAAAAAJiWgAAAAAAAAAABneEcQAAAAECeXDKebJoAbST1T2AbDBui9K0TbSM8sfbhXUAZ2ROAoCRs5cG1pRvY+ityyPWFEKPd7+3qEupavkAZ/+L7/28G"; - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(txBody); - - TransactionEnvelope transactionEnvelope = - TransactionEnvelope.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); - ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); - transactionEnvelope.encode(new XdrDataOutputStream(byteOutputStream)); - String serialized = base64Encoding.encode(byteOutputStream.toByteArray()); + TransactionEnvelope transactionEnvelope = TransactionEnvelope.fromXdrBase64(txBody); + String serialized = transactionEnvelope.toXdrBase64(); assertEquals(serialized, txBody); } }