diff --git a/sdk-dependency-versions/build.gradle.kts b/sdk-dependency-versions/build.gradle.kts index ac383fd11..912ab6f47 100644 --- a/sdk-dependency-versions/build.gradle.kts +++ b/sdk-dependency-versions/build.gradle.kts @@ -29,27 +29,27 @@ dependencies.constraints { api("com.google.code.gson:gson:2.10.1") { because("com.google.gson") } - api("com.google.protobuf:protobuf-java:4.28.3") { + api("com.google.protobuf:protobuf-java:4.29.0") { // shouldn't be updated for now (breaking changes after 4.x.x) because("com.google.protobuf") } - api("com.google.protobuf:protobuf-javalite:4.28.3") { + api("com.google.protobuf:protobuf-javalite:4.29.0") { // shouldn't be updated for now (breaking changes after 4.x.x) because("com.google.protobuf") } - api("io.grpc:grpc-api:1.68.1") { + api("io.grpc:grpc-api:1.68.2") { because("io.grpc") } api("io.grpc:grpc-inprocess:1.67.1") { because("io.grpc.protobuf") } - api("io.grpc:grpc-protobuf:1.68.1") { + api("io.grpc:grpc-protobuf:1.68.2") { because("io.grpc.protobuf") } - api("io.grpc:grpc-protobuf-lite:1.68.1") { + api("io.grpc:grpc-protobuf-lite:1.68.2") { because("io.grpc.protobuf") } - api("io.grpc:grpc-stub:1.68.1") { + api("io.grpc:grpc-stub:1.68.2") { because("io.grpc.stub") } api("com.google.code.findbugs:jsr305:3.0.2") { @@ -69,7 +69,7 @@ dependencies.constraints { } // Testing - api("com.fasterxml.jackson.core:jackson-core:2.18.1") { + api("com.fasterxml.jackson.core:jackson-core:2.18.2") { because("com.fasterxml.jackson.core") } api("io.github.cdimascio:java-dotenv:5.3.1") { diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java index 5ee01304d..1b6ae177e 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java @@ -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"); } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java index f9f6642c0..fc542450e 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java @@ -53,10 +53,6 @@ public Endpoint() { static Endpoint fromProtobuf(ServiceEndpoint serviceEndpoint) { var port = (int) (serviceEndpoint.getPort() & 0x00000000ffffffffL); - if (port == 0 || port == 50111) { - port = 50211; - } - return new Endpoint() .setAddress(serviceEndpoint.getIpAddressV4().toByteArray()) .setPort(port) diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java index df5ab47b0..c4a7442ad 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java @@ -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; @@ -69,7 +70,6 @@ public final class TransactionId implements Comparable { private static final long NANOSECONDS_TO_REMOVE = 10000000000L; - private static final Random randomNanosecs = new Random(); private static final AtomicLong monotonicTime = new AtomicLong(); @@ -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))); } /** diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java index 9ee74d23c..b08f4f90b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java @@ -61,7 +61,7 @@ public class NodeCreateTransactionTest { private static final byte[] TEST_GRPC_CERTIFICATE_HASH = new byte[]{5, 6, 7, 8, 9}; private static final PublicKey TEST_ADMIN_KEY = PrivateKey.fromString( - "302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b") + "302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b") .getPublicKey(); final Instant TEST_VALID_START = Instant.ofEpochSecond(1554158542); @@ -83,7 +83,7 @@ void shouldSerialize() { private static Endpoint spawnTestEndpoint(byte offset) { return new Endpoint() - .setAddress(new byte[] {0x00, 0x01, 0x02, 0x03}) + .setAddress(new byte[]{0x00, 0x01, 0x02, 0x03}) .setDomainName(offset + "unit.test.com") .setPort(42 + offset); } @@ -131,7 +131,19 @@ void shouldBytesNoSetters() throws Exception { } @Test - void testSetNull() { + void testUnrecognizedServicePort() throws Exception { + var tx = new NodeCreateTransaction() + .setServiceEndpoints( + List.of(new Endpoint() + .setAddress(new byte[]{0x00, 0x01, 0x02, 0x03}) + .setDomainName("unit.test.com") + .setPort(50111))); + var tx2 = NodeCreateTransaction.fromBytes(tx.toBytes()); + assertThat(tx2.toString()).isEqualTo(tx.toString()); + } + + @Test + void testSetNull() { new NodeCreateTransaction() .setDescription(null) .setAccountId(null) diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java index a9de576c9..3ce37b29d 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java @@ -87,7 +87,7 @@ void shouldSerialize() { private static Endpoint spawnTestEndpoint(byte offset) { return new Endpoint() - .setAddress(new byte[] {0x00, 0x01, 0x02, 0x03}) + .setAddress(new byte[]{0x00, 0x01, 0x02, 0x03}) .setDomainName(offset + "unit.test.com") .setPort(42 + offset); } @@ -124,6 +124,18 @@ void shouldBytesNoSetters() throws Exception { assertThat(tx2.toString()).isEqualTo(tx.toString()); } + @Test + void testUnrecognizedServicePort() throws Exception { + var tx = new NodeUpdateTransaction() + .setServiceEndpoints( + List.of(new Endpoint() + .setAddress(new byte[]{0x00, 0x01, 0x02, 0x03}) + .setDomainName("unit.test.com") + .setPort(50111))); + var tx2 = NodeUpdateTransaction.fromBytes(tx.toBytes()); + assertThat(tx2.toString()).isEqualTo(tx.toString()); + } + @Test void testEmptyCertificates() throws Exception { var tx = new NodeUpdateTransaction() @@ -136,7 +148,7 @@ void testEmptyCertificates() throws Exception { } @Test - void testSetNull() { + void testSetNull() { new NodeUpdateTransaction() .setDescription(null) .setAccountId(null)