Skip to content

Commit

Permalink
Fix compilation warnings. (lightsail-network#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Mar 26, 2024
1 parent 035bb28 commit 7e4e8aa
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 74 deletions.
25 changes: 21 additions & 4 deletions src/main/java/org/stellar/sdk/AbstractTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,29 @@ public void sign(byte @NonNull [] preimage) {
signatures.add(decoratedSignature);
}

/** Returns transaction hash. */
/**
* Returns transaction hash.
*
* @return the transaction hash
*/
public byte[] hash() {
return Util.hash(this.signatureBase());
}

/** Returns transaction hash encoded as a hexadecimal string. */
/**
* Returns transaction hash encoded as a hexadecimal string.
*
* @return the transaction hash as a hexadecimal string
*/
public String hashHex() {
return Util.bytesToHex(this.hash()).toLowerCase();
}

/** Returns signature base. */
/**
* Returns signature base.
*
* @return the signature base
*/
public abstract byte[] signatureBase();

/**
Expand All @@ -99,6 +111,8 @@ public void addSignature(DecoratedSignature signature) {
/**
* Returns base64-encoded TransactionEnvelope XDR object. Transaction need to have at least one
* signature.
*
* @return the base64-encoded TransactionEnvelope XDR object.
*/
public String toEnvelopeXdrBase64() {
try {
Expand All @@ -112,7 +126,9 @@ public String toEnvelopeXdrBase64() {
* Creates a <code>AbstractTransaction</code> instance from previously build <code>
* TransactionEnvelope</code>
*
* @param accountConverter the {@link AccountConverter} to use for this transaction
* @param envelope the transaction envelope
* @param network the network that the transaction is to be submitted to
* @return the {@link Transaction} or {@link FeeBumpTransaction} instance
*/
public static AbstractTransaction fromEnvelopeXdr(
Expand All @@ -136,6 +152,7 @@ public static AbstractTransaction fromEnvelopeXdr(
* TransactionEnvelope</code>
*
* @param envelope the transaction envelope
* @param network the network that the transaction is to be submitted to
* @return the {@link Transaction} or {@link FeeBumpTransaction} instance
*/
public static AbstractTransaction fromEnvelopeXdr(TransactionEnvelope envelope, Network network) {
Expand Down Expand Up @@ -173,7 +190,7 @@ public static AbstractTransaction fromEnvelopeXdr(String envelope, Network netwo
* Get the signature base of this transaction envelope.
*
* @param taggedTransaction the tagged transaction for signing
* @param network the network to sign on
* @param network the network that the transaction is to be submitted to
* @return the signature base of this transaction envelope
*/
public static byte[] getTransactionSignatureBase(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/stellar/sdk/AllowTrustOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor(access = lombok.AccessLevel.PRIVATE)
@Deprecated
public class AllowTrustOperation extends Operation {

/** The account of the recipient of the trustline. */
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/stellar/sdk/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public String toXdrBase64() {
*
* @param xdr XDR object
*/
@SuppressWarnings("deprecation")
public static Operation fromXdr(
AccountConverter accountConverter, org.stellar.sdk.xdr.Operation xdr) {
org.stellar.sdk.xdr.Operation.OperationBody body = xdr.getBody();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/stellar/sdk/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.annotations.SerializedName;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -59,7 +60,7 @@ public static Price fromString(@NonNull String price) {
if (number.compareTo(maxInt) > 0) {
break;
}
a = number.setScale(0, BigDecimal.ROUND_FLOOR);
a = number.setScale(0, RoundingMode.FLOOR);
f = number.subtract(a);
BigDecimal h = a.multiply(fractions.get(i - 1)[0]).add(fractions.get(i - 2)[0]);
BigDecimal k = a.multiply(fractions.get(i - 1)[1]).add(fractions.get(i - 2)[1]);
Expand All @@ -70,7 +71,7 @@ public static Price fromString(@NonNull String price) {
if (f.compareTo(BigDecimal.ZERO) == 0) {
break;
}
number = new BigDecimal(1).divide(f, 20, BigDecimal.ROUND_HALF_UP);
number = new BigDecimal(1).divide(f, 20, RoundingMode.HALF_UP);
i = i + 1;
}
BigDecimal n = fractions.get(fractions.size() - 1)[0];
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/stellar/sdk/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ public TransactionEnvelope toEnvelopeXdr() {
* @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,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/stellar/sdk/requests/ResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import org.stellar.sdk.responses.GsonSingleton;
import org.stellar.sdk.responses.TypedResponse;

@SuppressWarnings("unchecked")
public class ResponseHandler<T> {

private TypeToken<T> type;
private final TypeToken<T> type;

/**
* "Generics on a type are typically erased at runtime, except when the type is compiled with the
Expand Down Expand Up @@ -50,7 +51,7 @@ public T handleResponse(final Response response) throws IOException, TooManyRequ
((org.stellar.sdk.responses.Response) object).setHeaders(response.headers());
}
if (object instanceof TypedResponse) {
((TypedResponse) object).setType(type);
((TypedResponse<T>) object).setType(type);
}
return object;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TooManyRequestsException extends RuntimeException {
private final Integer retryAfter;

public TooManyRequestsException(Integer retryAfter) {
super("The rate limit for the requesting IP address is over its alloted limit.");
super("The rate limit for the requesting IP address is over its allowed limit.");
this.retryAfter = retryAfter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class EffectDeserializer implements JsonDeserializer<EffectResponse> {
@Override
@SuppressWarnings("deprecation")
public EffectResponse deserialize(
JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class OperationDeserializer implements JsonDeserializer<OperationResponse> {
private static final OperationType[] AllOperationTypes = OperationType.values();

@Override
@SuppressWarnings("deprecation")
public OperationResponse deserialize(
JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
@Value
@EqualsAndHashCode(callSuper = true)
@Deprecated
public class TrustlineAuthorizedEffectResponse extends TrustlineAuthorizationResponse {
TrustlineAuthorizedEffectResponse(String trustor, String assetType, String assetCode) {
super(trustor, assetType, assetCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
@Value
@EqualsAndHashCode(callSuper = true)
@Deprecated
public class TrustlineAuthorizedToMaintainLiabilitiesEffectResponse
extends TrustlineAuthorizationResponse {
TrustlineAuthorizedToMaintainLiabilitiesEffectResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
@Value
@EqualsAndHashCode(callSuper = true)
@Deprecated
public class TrustlineDeauthorizedEffectResponse extends TrustlineAuthorizationResponse {
TrustlineDeauthorizedEffectResponse(String trustor, String assetType, String assetCode) {
super(trustor, assetType, assetCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
@Value
@EqualsAndHashCode(callSuper = true)
@Deprecated
public class AllowTrustOperationResponse extends OperationResponse {
@SerializedName("trustor")
String trustor;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/stellar/sdk/MemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testMemoId() {
public void testParseMemoId() {
String maxId = "18446744073709551615";
JsonElement element =
new JsonParser().parse(String.format("{ \"memo_type\": \"id\", \"memo\": \"%s\" }", maxId));
JsonParser.parseString(String.format("{ \"memo_type\": \"id\", \"memo\": \"%s\" }", maxId));
TransactionResponse transactionResponse =
new TransactionDeserializer().deserialize(element, null, null);
MemoId memoId = (MemoId) transactionResponse.getMemo();
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/stellar/sdk/OperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ public void testChangeTrustOperation() throws FormatException, IOException {
}

@Test
@SuppressWarnings("deprecation")
public void testAllowTrustOperation() throws IOException, FormatException {
// GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
KeyPair source =
Expand Down Expand Up @@ -456,6 +457,7 @@ public void testAllowTrustOperation() throws IOException, FormatException {
}

@Test
@SuppressWarnings("deprecation")
public void testAllowTrustOperationAssetCodeBuffer() throws IOException, FormatException {
// GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
KeyPair source =
Expand Down Expand Up @@ -603,7 +605,7 @@ public void testSetOptionsOperationSignerSha256() {
assertEquals(null, parsedOperation.getHighThreshold());
assertEquals(null, parsedOperation.getHomeDomain());
assertTrue(Arrays.equals(hash, parsedOperation.getSigner().getHashX().getUint256()));
assertEquals(new Integer(10), parsedOperation.getSignerWeight());
assertEquals(10, parsedOperation.getSignerWeight().intValue());
assertEquals(source.getAccountId(), parsedOperation.getSourceAccount());

assertEquals(
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/stellar/sdk/TransactionBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void testBuilderTimeoutNegative() throws IOException {
fail();
} catch (RuntimeException exception) {
assertTrue(exception.getMessage().contains("timeout cannot be negative"));
assertEquals(new Long(2908908335136768L), account.getSequenceNumber());
assertEquals(2908908335136768L, account.getSequenceNumber().longValue());
}
}

Expand Down Expand Up @@ -579,7 +579,7 @@ public void testBuilderFailsWhenNoTimeBoundsOrTimeoutSet() throws IOException {
fail();
} catch (RuntimeException exception) {
assertTrue(exception.getMessage().contains("Invalid preconditions, must define timebounds"));
assertEquals(new Long(2908908335136768L), account.getSequenceNumber());
assertEquals(2908908335136768L, account.getSequenceNumber().longValue());
}
}

Expand Down Expand Up @@ -831,7 +831,7 @@ public void testNoOperations() throws FormatException, IOException {
fail();
} catch (RuntimeException exception) {
assertTrue(exception.getMessage().contains("At least one operation required"));
assertEquals(new Long(2908908335136768L), account.getSequenceNumber());
assertEquals(2908908335136768L, account.getSequenceNumber().longValue());
}
}

Expand Down
23 changes: 13 additions & 10 deletions src/test/java/org/stellar/sdk/responses/EffectDeserializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ public void testDeserializeAccountThresholdsUpdatedEffect() {
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getAccount(), "GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO");
assertEquals(effect.getLowThreshold(), new Integer(2));
assertEquals(effect.getMedThreshold(), new Integer(3));
assertEquals(effect.getHighThreshold(), new Integer(4));
assertEquals(effect.getLowThreshold().intValue(), 2);
assertEquals(effect.getMedThreshold().intValue(), 3);
assertEquals(effect.getHighThreshold().intValue(), 4);

assertEquals(
effect.getLinks().getOperation().getHref(),
Expand Down Expand Up @@ -326,8 +326,8 @@ public void testDeserializeAccountFlagsUpdatedEffect() {
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getAccount(), "GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO");
assertEquals(effect.getAuthRequiredFlag(), new Boolean(false));
assertEquals(effect.getAuthRevokableFlag(), new Boolean(true));
assertEquals(effect.getAuthRequiredFlag(), Boolean.FALSE);
assertEquals(effect.getAuthRevokableFlag(), Boolean.TRUE);

assertEquals(
effect.getLinks().getOperation().getHref(),
Expand Down Expand Up @@ -491,7 +491,7 @@ public void testDeserializeSignerCreatedEffect() {
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getAccount(), "GB24LPGAHYTWRYOXIDKXLI55SBRWW42T3TZKDAAW3BOJX4ADVIATFTLU");
assertEquals(effect.getWeight(), new Integer(1));
assertEquals(effect.getWeight().intValue(), 1);
assertEquals(effect.getPublicKey(), "GB24LPGAHYTWRYOXIDKXLI55SBRWW42T3TZKDAAW3BOJX4ADVIATFTLU");

assertEquals(
Expand Down Expand Up @@ -534,7 +534,7 @@ public void testDeserializeSignerRemovedEffect() {
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getAccount(), "GCFKT6BN2FEASCEVDNHEC4LLFT2KLUUPEMKM4OJPEJ65H2AEZ7IH4RV6");
assertEquals(effect.getWeight(), new Integer(0));
assertEquals(effect.getWeight().intValue(), 0);
assertEquals(effect.getPublicKey(), "GCFKT6BN2FEASCEVDNHEC4LLFT2KLUUPEMKM4OJPEJ65H2AEZ7IH4RV6");

assertEquals(
Expand Down Expand Up @@ -577,7 +577,7 @@ public void testDeserializeSignerUpdatedEffect() {
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getAccount(), "GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO");
assertEquals(effect.getWeight(), new Integer(2));
assertEquals(effect.getWeight().intValue(), 2);
assertEquals(effect.getPublicKey(), "GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO");

assertEquals(
Expand Down Expand Up @@ -844,6 +844,7 @@ public void testDeserializeLiquidityPoolTrustlineUpdatedEffect() {
}

@Test
@SuppressWarnings("deprecation")
public void testDeserializeTrustlineAuthorizedEffect() {
String json =
"{\n"
Expand Down Expand Up @@ -889,6 +890,7 @@ public void testDeserializeTrustlineAuthorizedEffect() {
}

@Test
@SuppressWarnings("deprecation")
public void testDeserializeTrustlineAuthorizedToMaintainLiabilitiesEffect() {
String json =
"{\n"
Expand Down Expand Up @@ -934,6 +936,7 @@ public void testDeserializeTrustlineAuthorizedToMaintainLiabilitiesEffect() {
}

@Test
@SuppressWarnings("deprecation")
public void testDeserializeTrustlineDeauthorizedEffect() {
String json =
"{\n"
Expand Down Expand Up @@ -1015,7 +1018,7 @@ public void testDeserializeTradeEffect() {

assertEquals(effect.getAccount(), "GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO");
assertEquals(effect.getSeller(), "GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB");
assertEquals(effect.getOfferId(), new Long(1));
assertEquals(effect.getOfferId().longValue(), 1);
assertEquals(effect.getSoldAmount(), "1000.0");
assertEquals(
effect.getSoldAsset(),
Expand Down Expand Up @@ -1159,7 +1162,7 @@ public void testDeserializeSequenceBumpedEffect() {

assertEquals(effect.getAccount(), "GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF");
assertEquals(effect.getCreatedAt(), "2018-06-06T10:23:57Z");
assertEquals(effect.getNewSequence(), new Long(79473726952833048L));
assertEquals(effect.getNewSequence().longValue(), 79473726952833048L);
}

@Test
Expand Down
Loading

0 comments on commit 7e4e8aa

Please sign in to comment.