Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove the dependency on Guava. #524

Merged
merged 24 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6c6ae09
Use `lombok.NonNull` instead of `com.google.common.base.Preconditions…
overcat Sep 11, 2023
ec16bea
Use `java.util.Optional` instead of `com.google.common.base.Optional`.
overcat Sep 11, 2023
7ac9b03
Use `java.util.Objects` instead of `com.google.common.base.Objects`
overcat Sep 11, 2023
a4b25b5
Use `String.join` instead of `com.google.common.base.Joiner`
overcat Sep 11, 2023
e76c0ed
Remove the use of `com.google.common.collect.Lists`.
overcat Sep 11, 2023
6d34991
Remove the use of `com.google.common.collect.ImmutableList`.
overcat Sep 11, 2023
7932cc0
Remove the use of `com.google.common.collect.*`.
overcat Sep 11, 2023
ad5cb6e
Remove the use of `com.google.common.base.Function` and `com.google.c…
overcat Sep 11, 2023
e4b0a2a
Remove `com.google.common.primitives.Longs`, add our own implementation.
overcat Sep 11, 2023
91e3cc1
Use the self-implemented base16 and build-in base64 module instead of…
overcat Sep 12, 2023
936abfc
Merge branch 'soroban' into remove-guava
overcat Sep 12, 2023
e74fd1d
Introduce commons-codec and use its Base32 module.
overcat Sep 12, 2023
cef858d
fixup! Use `java.util.Objects` instead of `com.google.common.base.Obj…
overcat Sep 12, 2023
e9a3269
fixup! Introduce commons-codec and use its Base32 module.
overcat Sep 12, 2023
e474a46
fixup! Remove the use of `com.google.common.base.Function` and `com.g…
overcat Sep 12, 2023
89ac36d
Merge branch 'soroban' into remove-guava
overcat Sep 12, 2023
7592437
Remove the use of `com.google.common.collect.ImmutableList`.
overcat Sep 12, 2023
85654b0
Merge branch 'soroban' into remove-guava
overcat Sep 12, 2023
baf7b4c
remove com.google.guava:guava:32.1.2-android
overcat Sep 12, 2023
b2f0cb0
empty commit, trigger a pipeline
overcat Sep 13, 2023
cde613d
clean up shadowJar config
overcat Sep 13, 2023
cef2098
empty commit, trigger a pipeline
overcat Sep 13, 2023
8a17a35
fix import
overcat Sep 14, 2023
6c28a2e
Merge remote-tracking branch 'upstream/soroban' into remove-guava
sreuland Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}"
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/org/stellar/sdk/AbstractTransaction.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
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;
import org.stellar.sdk.xdr.TransactionEnvelope;
import org.stellar.sdk.xdr.TransactionSignaturePayload;

public abstract class AbstractTransaction {

protected final Network mNetwork;
protected final AccountConverter accountConverter;
protected List<DecoratedSignature> 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<DecoratedSignature>();
}

Expand All @@ -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));
}
Expand All @@ -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);

Expand All @@ -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. */
Expand Down Expand Up @@ -96,7 +93,7 @@ public AccountConverter getAccountConverter() {
* @return immutable list of signatures
*/
public List<DecoratedSignature> getSignatures() {
return ImmutableList.copyOf(mSignatures);
return Collections.unmodifiableList(mSignatures);
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/stellar/sdk/Account.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
15 changes: 7 additions & 8 deletions src/main/java/org/stellar/sdk/AccountMergeOperation.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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. */
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}
26 changes: 14 additions & 12 deletions src/main/java/org/stellar/sdk/AllowTrustOperation.java
Original file line number Diff line number Diff line change
@@ -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.*;

/**
Expand All @@ -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;
}
Expand Down Expand Up @@ -165,7 +167,7 @@ public AllowTrustOperation build() {

@Override
public int hashCode() {
return Objects.hashCode(
return Objects.hash(
this.getSourceAccount(),
this.assetCode,
this.authorize,
Expand All @@ -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());
}
}
8 changes: 4 additions & 4 deletions src/main/java/org/stellar/sdk/AssetAmount.java
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -24,7 +24,7 @@ public String getAmount() {
}

public int hashCode() {
return Objects.hashCode(asset, amount);
return Objects.hash(asset, amount);
}

@Override
Expand All @@ -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());
}
}
11 changes: 4 additions & 7 deletions src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/stellar/sdk/AssetTypePoolShare.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.stellar.sdk;

import com.google.common.base.Objects;
import java.util.Objects;

/**
* Represents Stellar liquidity pool share asset - <a
Expand Down Expand Up @@ -34,7 +34,7 @@ public boolean equals(Object object) {
return false;
}

return (Objects.equal(((AssetTypePoolShare) object).getPoolId(), poolId));
return (Objects.equals(((AssetTypePoolShare) object).getPoolId(), poolId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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 BeginSponsoringFutureReservesOperation extends Operation {
Expand Down Expand Up @@ -59,8 +58,9 @@ public Builder(String sponsoredId) {
* @param sourceAccount The operation's source account.
* @return Builder object so you can chain methods.
*/
public BeginSponsoringFutureReservesOperation.Builder setSourceAccount(String sourceAccount) {
mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null");
public BeginSponsoringFutureReservesOperation.Builder setSourceAccount(
@NonNull String sourceAccount) {
mSourceAccount = sourceAccount;
return this;
}

Expand All @@ -77,7 +77,7 @@ public BeginSponsoringFutureReservesOperation build() {

@Override
public int hashCode() {
return Objects.hashCode(this.sponsoredId, this.getSourceAccount());
return Objects.hash(this.sponsoredId, this.getSourceAccount());
}

@Override
Expand All @@ -87,7 +87,7 @@ public boolean equals(Object object) {
}

BeginSponsoringFutureReservesOperation other = (BeginSponsoringFutureReservesOperation) object;
return Objects.equal(this.sponsoredId, other.sponsoredId)
&& Objects.equal(this.getSourceAccount(), other.getSourceAccount());
return Objects.equals(this.sponsoredId, other.sponsoredId)
&& Objects.equals(this.getSourceAccount(), other.getSourceAccount());
}
}
15 changes: 7 additions & 8 deletions src/main/java/org/stellar/sdk/BumpSequenceOperation.java
Original file line number Diff line number Diff line change
@@ -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.BumpSequenceOp;
import org.stellar.sdk.xdr.Int64;
import org.stellar.sdk.xdr.OperationType;
Expand Down Expand Up @@ -65,8 +64,8 @@ public Builder(long bumpTo) {
* @param sourceAccount The operation's source account.
* @return Builder object so you can chain methods.
*/
public BumpSequenceOperation.Builder setSourceAccount(String sourceAccount) {
mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null");
public BumpSequenceOperation.Builder setSourceAccount(@NonNull String sourceAccount) {
mSourceAccount = sourceAccount;
return this;
}

Expand All @@ -82,7 +81,7 @@ public BumpSequenceOperation build() {

@Override
public int hashCode() {
return Objects.hashCode(this.bumpTo, this.getSourceAccount());
return Objects.hash(this.bumpTo, this.getSourceAccount());
}

@Override
Expand All @@ -92,7 +91,7 @@ public boolean equals(Object object) {
}

BumpSequenceOperation other = (BumpSequenceOperation) object;
return Objects.equal(this.bumpTo, other.bumpTo)
&& Objects.equal(this.getSourceAccount(), other.getSourceAccount());
return Objects.equals(this.bumpTo, other.bumpTo)
&& Objects.equals(this.getSourceAccount(), other.getSourceAccount());
}
}
Loading
Loading