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

fix(Android): Executing transaction fails at runtime #2100

Merged
merged 1 commit into from
Nov 28, 2024
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
12 changes: 1 addition & 11 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,8 @@ synchronized void close(Duration timeout) throws InterruptedException {
* @return the user agent string
*/
private String getUserAgent() {
var theModule = getClass().getModule();
var thePackage = getClass().getPackage();
String implementationVersion;
if (theModule.getName() == null) {
// running on classpath
implementationVersion =
thePackage != null ? thePackage.getImplementationVersion() : null;
} else {
// running on module path
implementationVersion =
theModule.getDescriptor().version().map(ModuleDescriptor.Version::toString).orElse(null);
}
var implementationVersion = thePackage != null ? thePackage.getImplementationVersion() : null;
return "hedera-sdk-java/" + ((implementationVersion != null) ? ("v" + implementationVersion) : "DEV");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -69,7 +70,6 @@ public final class TransactionId implements Comparable<TransactionId> {

private static final long NANOSECONDS_TO_REMOVE = 10000000000L;

private static final Random randomNanosecs = new Random();
private static final AtomicLong monotonicTime = new AtomicLong();


Expand Down Expand Up @@ -128,7 +128,8 @@ public static TransactionId generate(AccountId accountId) {
}
} while (!monotonicTime.compareAndSet(lastTime, currentTime));

return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + randomNanosecs.nextLong(1_000)));
// NOTE: using ThreadLocalRandom because it's compatible with Android SDK version 26
return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + ThreadLocalRandom.current().nextLong(1_000)));
}

/**
Expand Down