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

Fixed some Android compatibility issues #1638

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ dependencies {
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'com.esaulpaugh:headlong:10.0.0'

// NOTE: This is to support Android API <= 30.
// https://github.com/stefan-zobel/streamsupport
// https://developer.android.com/about/dashboards/index.html
api "net.sourceforge.streamsupport:streamsupport-cfuture:1.7.4"

testImplementation "org.assertj:assertj-core:3.24.2"
testImplementation "io.github.json-snapshot:json-snapshot:1.0.17"
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.10.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.hedera.hashgraph.sdk;

import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.hedera.hashgraph.sdk.proto.Response;
import com.hedera.hashgraph.sdk.proto.ResponseHeader;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnegative;
import javax.annotation.Nullable;
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.time.Duration;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import com.hedera.hashgraph.sdk.proto.SignedTransaction;
import com.hedera.hashgraph.sdk.proto.TransactionBody;
import com.hedera.hashgraph.sdk.proto.TransactionID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java8.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletionStage;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;
import java8.util.function.Function;
import java.time.Duration;

import javax.annotation.Nullable;
Expand Down
13 changes: 8 additions & 5 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@
import java.nio.file.Files;
import java.time.Duration;
import java.time.Instant;
import java8.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletionStage;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;
import java8.util.function.Function;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -735,7 +738,7 @@ public synchronized Client setOperator(AccountId accountId, PrivateKey privateKe
* @return {@code this}
*/
public synchronized Client setOperatorWith(AccountId accountId, PublicKey publicKey,
UnaryOperator<byte[]> transactionSigner) {
Function<byte[], byte[]> transactionSigner) {
if (getNetworkName() != null) {
try {
accountId.validateChecksum(this);
Expand Down Expand Up @@ -1385,9 +1388,9 @@ public synchronized void close(Duration timeout) throws TimeoutException {
static class Operator {
final AccountId accountId;
final PublicKey publicKey;
final UnaryOperator<byte[]> transactionSigner;
final Function<byte[], byte[]> transactionSigner;

Operator(AccountId accountId, PublicKey publicKey, UnaryOperator<byte[]> transactionSigner) {
Operator(AccountId accountId, PublicKey publicKey, Function<byte[], byte[]> transactionSigner) {
this.accountId = accountId;
this.publicKey = publicKey;
this.transactionSigner = transactionSigner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.hedera.hashgraph.sdk;


import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java8.util.concurrent.CompletableFuture;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;


class ConsumerHelper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hedera.hashgraph.sdk.proto.ResponseHeader;
import com.hedera.hashgraph.sdk.proto.SmartContractServiceGrpc;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;
import java8.util.function.Function;
import javax.annotation.Nullable;
import org.bouncycastle.util.encoders.Hex;

Expand Down Expand Up @@ -120,7 +120,7 @@ public class ContractCreateFlow {
private PublicKey signPublicKey = null;

@Nullable
private UnaryOperator<byte[]> transactionSigner = null;
private Function<byte[], byte[]> transactionSigner = null;

/**
* Constructor
Expand Down Expand Up @@ -544,7 +544,7 @@ public ContractCreateFlow sign(PrivateKey privateKey) {
* @param transactionSigner the key list
* @return {@code this}
*/
public ContractCreateFlow signWith(PublicKey publicKey, UnaryOperator<byte[]> transactionSigner) {
public ContractCreateFlow signWith(PublicKey publicKey, Function<byte[], byte[]> transactionSigner) {
this.signPublicKey = publicKey;
this.transactionSigner = transactionSigner;
this.signPrivateKey = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.hedera.hashgraph.sdk.proto.ResponseHeader;
import com.hedera.hashgraph.sdk.proto.SmartContractServiceGrpc;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down
16 changes: 2 additions & 14 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Delayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
*/
package com.hedera.hashgraph.sdk;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java8.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
Expand All @@ -35,12 +33,6 @@
final class Delayer {
private static final Logger logger = LoggerFactory.getLogger(Delayer.class);

private static final ScheduledExecutorService SCHEDULER = Executors.newSingleThreadScheduledExecutor(r -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
});

private static final Duration MIN_DELAY = Duration.ofMillis(500);

/**
Expand Down Expand Up @@ -75,10 +67,6 @@ static CompletableFuture<Void> delayFor(long milliseconds, Executor executor) {
return CompletableFuture.runAsync(
() -> {
},
delayedExecutor(milliseconds, TimeUnit.MILLISECONDS, executor));
}

private static Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) {
return r -> SCHEDULER.schedule(() -> executor.execute(r), delay, unit);
CompletableFuture.delayedExecutor(milliseconds, TimeUnit.MILLISECONDS, executor));
}
}
6 changes: 3 additions & 3 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/EthereumFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import javax.annotation.Nullable;
import java.time.Duration;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;

/**
* Execute an Ethereum transaction on Hedera
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hedera.hashgraph.sdk.proto.Response;
import com.hedera.hashgraph.sdk.proto.ResponseHeader;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.hedera.hashgraph.sdk.proto.Response;
import com.hedera.hashgraph.sdk.proto.ResponseHeader;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.hedera.hashgraph.sdk.proto.Transaction;
import com.hedera.hashgraph.sdk.proto.TransactionBody;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java8.util.concurrent.CompletableFuture;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;
import java.time.Duration;
import java.time.Instant;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hedera.hashgraph.sdk.proto.ScheduleGetInfoQuery;
import com.hedera.hashgraph.sdk.proto.ScheduleServiceGrpc;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.hedera.hashgraph.sdk.proto.TransactionResponse;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.time.Instant;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.hedera.hashgraph.sdk.proto.TransactionBody;
import com.hedera.hashgraph.sdk.proto.TransactionResponse;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.LinkedHashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hedera.hashgraph.sdk.proto.TokenGetInfoQuery;
import com.hedera.hashgraph.sdk.proto.TokenServiceGrpc;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hedera.hashgraph.sdk.proto.TokenGetNftInfoQuery;
import com.hedera.hashgraph.sdk.proto.TokenServiceGrpc;
import io.grpc.MethodDescriptor;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

import javax.annotation.Nonnegative;
import javax.annotation.Nullable;
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java8.util.concurrent.CompletableFuture;
import java8.util.function.Function;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;
import org.bouncycastle.crypto.digests.SHA384Digest;
Expand Down Expand Up @@ -834,7 +834,7 @@ public final T sign(PrivateKey privateKey) {
* @param transactionSigner the key list
* @return {@code this}
*/
public T signWith(PublicKey publicKey, UnaryOperator<byte[]> transactionSigner) {
public T signWith(PublicKey publicKey, Function<byte[], byte[]> transactionSigner) {
if (!isFrozen()) {
throw new IllegalStateException("Signing requires transaction to be frozen");
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
*/
package com.hedera.hashgraph.sdk;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
import static java8.util.concurrent.CompletableFuture.completedFuture;
import static java8.util.concurrent.CompletableFuture.failedFuture;

import com.google.errorprone.annotations.Var;
import com.google.protobuf.InvalidProtocolBufferException;
import com.hedera.hashgraph.sdk.proto.TransactionID;
import java.time.Duration;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;
import javax.annotation.Nullable;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
package com.hedera.hashgraph.sdk;

import com.google.common.base.MoreObjects;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java8.util.concurrent.CompletableFuture;
import java8.util.function.BiConsumer;
import java8.util.function.Consumer;
import org.bouncycastle.util.encoders.Hex;
import java.time.Duration;

Expand Down
Loading
Loading