Skip to content

Commit

Permalink
refactor!: remove outdated code (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Jul 2, 2024
1 parent 2ae2a5f commit 2ff44ea
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.
.sourceAccount(source)
.build();
```
- refactor!: `TransactionBuilder.IncrementedSequenceNumberFunc` has been removed.
- refactor!: `Transaction.Builder` has been removed, use `TransactionBuilder` instead.

## 0.44.0
### Update
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/stellar/sdk/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
@AllArgsConstructor
public class Account implements TransactionBuilderAccount {

/** The account ID. */
@NonNull private final String accountId;

/** The sequence number of the account. */
@NonNull private Long sequenceNumber;

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/stellar/sdk/AccountFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Getter;
import org.stellar.sdk.xdr.AccountFlags;

// TODO: move to operations?
/**
* AccountFlag is the <code>enum</code> that can be used in {@link
* org.stellar.sdk.operations.SetOptionsOperation}.
Expand All @@ -26,8 +27,7 @@ public enum AccountFlag {
* Authorization immutable (0x4): If this is set then none of the authorization flags can be set
* and the account can never be deleted.
*/
AUTH_IMMUTABLE_FLAG(AccountFlags.AUTH_IMMUTABLE_FLAG.getValue()),
;
AUTH_IMMUTABLE_FLAG(AccountFlags.AUTH_IMMUTABLE_FLAG.getValue());

private final int value;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/stellar/sdk/AssetAmount.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.annotations.SerializedName;
import lombok.Value;

// TODO: move to resp?
/** Represents an amount of asset. */
@Value
public class AssetAmount {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/stellar/sdk/KeyPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public char[] getSecretSeed() {
return StrKey.encodeEd25519SecretSeed(privateKey.getSeed());
}

/** Returns the raw 32 byte public key. */
public byte[] getPublicKey() {
return publicKey.getAbyte();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/stellar/sdk/LedgerBounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* href="https://github.com/stellar/stellar-protocol/blob/master/core/cap-0021.md#specification">CAP-21</a>
*
* @see <a
* href="https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/operations-and-transactions#ledger-bounds"
* href="https://developers.stellar.org/docs/learn/fundamentals/transactions/operations-and-transactions#ledger-bounds"
* target="_blank">LedgerBounds</a>
*/
@Value
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/stellar/sdk/MemoNone.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ org.stellar.sdk.xdr.Memo toXdr() {
return memo;
}

// TODO: return a more meaningful value?
@Override
public String toString() {
return "";
Expand Down
37 changes: 9 additions & 28 deletions src/main/java/org/stellar/sdk/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,20 @@
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.Value;
import org.stellar.sdk.xdr.Int32;

/** Represents Price. Price in Stellar is represented as a fraction. */
@EqualsAndHashCode
@Value
public class Price {
/** numerator */
@SerializedName("n")
private final int n;
int numerator;

/** denominator */
@SerializedName("d")
private final int d;

/**
* Create a new price. Price in Stellar is represented as a fraction.
*
* @param n numerator
* @param d denominator
*/
public Price(int n, int d) {
this.n = n;
this.d = d;
}

/** Returns numerator. */
public int getNumerator() {
return n;
}

/** Returns denominator */
public int getDenominator() {
return d;
}
int denominator;

/**
* Approximates <code>price</code> to a fraction. Please remember that this function can give
Expand Down Expand Up @@ -89,8 +70,8 @@ public org.stellar.sdk.xdr.Price toXdr() {
org.stellar.sdk.xdr.Price xdr = new org.stellar.sdk.xdr.Price();
Int32 n = new Int32();
Int32 d = new Int32();
n.setInt32(this.n);
d.setInt32(this.d);
n.setInt32(this.numerator);
d.setInt32(this.denominator);
xdr.setN(n);
xdr.setD(d);
return xdr;
Expand All @@ -99,7 +80,7 @@ public org.stellar.sdk.xdr.Price toXdr() {
/** Returns price as a string. */
public String toString() {
MathContext mc = MathContext.DECIMAL64;
BigDecimal result = new BigDecimal(this.n).divide(new BigDecimal(this.d), mc);
BigDecimal result = new BigDecimal(this.numerator).divide(new BigDecimal(this.denominator), mc);

return result.toString();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/stellar/sdk/SignedPayloadSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;
import org.stellar.sdk.xdr.AccountID;
import org.stellar.sdk.xdr.PublicKey;
import org.stellar.sdk.xdr.PublicKeyType;
Expand All @@ -14,8 +15,10 @@
* target="_blank">signed payload signer</a>
*/
@Getter
@ToString
@EqualsAndHashCode
public class SignedPayloadSigner {
/** The maximum length of a signed payload */
public static final int SIGNED_PAYLOAD_MAX_PAYLOAD_LENGTH = 64;

/** The account that represents the signed payload signer */
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/stellar/sdk/StrKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ static AccountID muxedAccountToAccountId(MuxedAccount account) {
return aid;
}

/**
* Encodes strkey Stellar account ID (G...) to {@link AccountID}.
*
* @param data the data to encode
* @return {@link AccountID} representation of the key
*/
public static AccountID encodeToXDRAccountId(String data) {
AccountID accountID = new AccountID();
PublicKey publicKey = new PublicKey();
Expand All @@ -247,6 +253,12 @@ public static AccountID encodeToXDRAccountId(String data) {
return accountID;
}

/**
* Encodes strkey Stellar account ID (G...) or muxed account ID (M...) to {@link MuxedAccount}.
*
* @param data the data to encode
* @return {@link MuxedAccount} representation of the key
*/
public static MuxedAccount encodeToXDRMuxedAccount(String data) {
MuxedAccount muxed = new MuxedAccount();

Expand Down
24 changes: 16 additions & 8 deletions src/main/java/org/stellar/sdk/TimeBounds.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.stellar.sdk;

import java.math.BigInteger;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Value;
import org.stellar.sdk.xdr.TimePoint;
import org.stellar.sdk.xdr.Uint64;
import org.stellar.sdk.xdr.XdrUnsignedHyperInteger;
Expand All @@ -15,18 +14,17 @@
* to make it into the transaction set.
*
* @see <a
* href="https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/operations-and-transactions#time-bounds"
* href="https://developers.stellar.org/docs/learn/fundamentals/transactions/operations-and-transactions#time-bounds"
* target="_blank">Time Bounds</a>
* @see Transaction
*/
@Getter
@EqualsAndHashCode
public final class TimeBounds {
@Value
public class TimeBounds {
/** the UNIX timestamp (in seconds) */
private final BigInteger minTime;
BigInteger minTime;

/** the UNIX timestamp (in seconds) */
private final BigInteger maxTime;
BigInteger maxTime;

/**
* @param minTime 64bit Unix timestamp
Expand Down Expand Up @@ -72,6 +70,13 @@ public static TimeBounds expiresAfter(long timeout) {
return new TimeBounds(0, endTime);
}

/**
* Construct a new {@link TimeBounds} object from a {@link org.stellar.sdk.xdr.TimeBounds} XDR
* object.
*
* @param timeBounds {@link org.stellar.sdk.xdr.TimeBounds} XDR object
* @return {@link TimeBounds} object
*/
public static TimeBounds fromXdr(org.stellar.sdk.xdr.TimeBounds timeBounds) {
if (timeBounds == null) {
return null;
Expand All @@ -82,6 +87,9 @@ public static TimeBounds fromXdr(org.stellar.sdk.xdr.TimeBounds timeBounds) {
timeBounds.getMaxTime().getTimePoint().getUint64().getNumber());
}

/**
* @return {@link org.stellar.sdk.xdr.TimeBounds} XDR object
*/
public org.stellar.sdk.xdr.TimeBounds toXdr() {
org.stellar.sdk.xdr.TimeBounds timeBounds = new org.stellar.sdk.xdr.TimeBounds();
TimePoint minTime = new TimePoint();
Expand Down
44 changes: 21 additions & 23 deletions src/main/java/org/stellar/sdk/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import org.stellar.sdk.xdr.XdrUnsignedInteger;

/**
* Represents <a href="https://developers.stellar.org/docs/glossary/transactions/"
* Represents <a
* href="https://developers.stellar.org/docs/learn/fundamentals/transactions/operations-and-transactions#transactions"
* target="_blank">Transaction</a> in Stellar network.
*/
public class Transaction extends AbstractTransaction {
Expand All @@ -56,6 +57,21 @@ public class Transaction extends AbstractTransaction {

private EnvelopeType envelopeType = EnvelopeType.ENVELOPE_TYPE_TX;

/**
* Creates a new transaction.
*
* <p>In general, we suggest you use {@link TransactionBuilder} to build transactions.
*
* @param accountConverter the account converter
* @param sourceAccount The source account for the transaction.
* @param fee The fee paid for the transaction in stroops (1 stroop = 0.0000001 XLM).
* @param sequenceNumber The sequence number of the account creating this transaction.
* @param operations The operations to include in the transaction.
* @param memo The memo for the transaction.
* @param preconditions The preconditions for the transaction.
* @param sorobanData The Soroban data for the transaction.
* @param network The network that the transaction is to be submitted to.
*/
Transaction(
AccountConverter accountConverter,
@NonNull String sourceAccount,
Expand Down Expand Up @@ -106,6 +122,10 @@ public TimeBounds getTimeBounds() {
/**
* Returns the claimable balance ID for the CreateClaimableBalanceOperation at the given index
* within the transaction.
*
* @param index The index of the CreateClaimableBalanceOperation within the transaction, starting
* at 0
* @return The claimable balance ID for the CreateClaimableBalanceOperation at the given index
*/
public String getClaimableBalanceId(int index) {
if (index < 0 || index >= operations.length) {
Expand Down Expand Up @@ -186,7 +206,6 @@ private TransactionV0 toXdr() {
}

private org.stellar.sdk.xdr.Transaction toV1Xdr(AccountConverter accountConverter) {

// fee
Uint32 fee = new Uint32();
fee.setUint32((new XdrUnsignedInteger(this.fee)));
Expand Down Expand Up @@ -317,27 +336,6 @@ public TransactionEnvelope toEnvelopeXdr() {
return xdr;
}

/**
* Maintain backwards compatibility references to Transaction.Builder
*
* @see org.stellar.sdk.TransactionBuilder
* @deprecated will be removed in upcoming releases. Use <code>TransactionBuilder</code> instead.
*/
@Deprecated
public static class Builder extends TransactionBuilder {
// TODO: remove this class in the next release
public Builder(
AccountConverter accountConverter,
TransactionBuilderAccount sourceAccount,
Network network) {
super(accountConverter, sourceAccount, network);
}

public Builder(TransactionBuilderAccount sourceAccount, Network network) {
super(sourceAccount, network);
}
}

/**
* Returns true if this transaction is a Soroban transaction.
*
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/org/stellar/sdk/TransactionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import lombok.NonNull;
import org.stellar.sdk.operations.Operation;
import org.stellar.sdk.xdr.SorobanTransactionData;
Expand Down Expand Up @@ -241,13 +240,6 @@ public Transaction build() {
return transaction;
}

/**
* A default implementation of sequence number generation which will derive a sequence number
* based on sourceAccount's current sequence number + 1.
*/
public static Function<TransactionBuilderAccount, Long> IncrementedSequenceNumberFunc =
TransactionBuilderAccount::getIncrementedSequenceNumber;

/**
* Sets the transaction's internal Soroban transaction data (resources, footprint, etc.).
*
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/stellar/sdk/TransactionPreconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public class TransactionPreconditions {
/** The time bounds for the transaction. */
TimeBounds timeBounds;

/**
* Validates the preconditions.
*
* @throws IllegalArgumentException if the preconditions are invalid
*/
public void isValid() {
if (timeBounds == null) {
throw new IllegalArgumentException("Invalid preconditions, must define timebounds");
Expand All @@ -70,6 +75,9 @@ public void isValid() {
}
}

/**
* @return <code>true</code> if the preconditions are v2.
*/
public boolean hasV2() {
return (ledgerBounds != null
|| (minSeqLedgerGap > 0)
Expand All @@ -78,6 +86,12 @@ public boolean hasV2() {
|| !extraSigners.isEmpty());
}

/**
* Creates a new {@link TransactionPreconditions} object from a {@link Preconditions} XDR object.
*
* @param preconditions the {@link Preconditions} object to convert
* @return a new {@link TransactionPreconditions} object from the given XDR object
*/
public static TransactionPreconditions fromXdr(Preconditions preconditions) {
TransactionPreconditionsBuilder builder = new TransactionPreconditionsBuilder();

Expand Down Expand Up @@ -130,6 +144,9 @@ public static TransactionPreconditions fromXdr(Preconditions preconditions) {
return builder.build();
}

/**
* @return the XDR object of this {@link TransactionPreconditions}
*/
public Preconditions toXdr() {
Preconditions.PreconditionsBuilder preconditionsBuilder = Preconditions.builder();

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/stellar/sdk/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static String getSdkVersion() {
*
* @param asset The asset to check
*/
// TODO: remove the func
public static AssetTypeCreditAlphaNum assertNonNativeAsset(Asset asset) {
if (asset instanceof AssetTypeCreditAlphaNum) {
return (AssetTypeCreditAlphaNum) asset;
Expand Down

0 comments on commit 2ff44ea

Please sign in to comment.