From d88f7b4d04206f1bbf5b1fa250705e1c33e830b0 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 28 Nov 2024 17:19:23 +0200 Subject: [PATCH 1/8] fix(Android): Executing transaction fails at runtime (#2100) Signed-off-by: Ivan Ivanov --- .../main/java/com/hedera/hashgraph/sdk/BaseNode.java | 12 +----------- .../java/com/hedera/hashgraph/sdk/TransactionId.java | 5 +++-- 2 files changed, 4 insertions(+), 13 deletions(-) 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/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))); } /** From 914af7fbe2554b0b485d1dd52800d2dfab7435cd Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 29 Nov 2024 13:07:29 +0200 Subject: [PATCH 2/8] fix: Do not override service port (#2106) Signed-off-by: Ivan Ivanov --- .../com/hedera/hashgraph/sdk/Endpoint.java | 4 --- .../sdk/NodeCreateTransactionTest.java | 29 ++++++++++++------- .../sdk/NodeUpdateTransactionTest.java | 23 ++++++++++----- 3 files changed, 35 insertions(+), 21 deletions(-) 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/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java index 3c4577b2d..af814fb1f 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); } @@ -123,17 +123,26 @@ void fromScheduledTransaction() { } @Test - void testSerializeDeserialize() throws Exception { - var tx = new NodeCreateTransaction().setDescription(TEST_DESCRIPTION); - var tx2 = new NodeCreateTransaction().setDescription(TEST_DESCRIPTION); - var tx2Bytes = tx2.toBytes(); - NodeCreateTransaction deserializedTx2 = (NodeCreateTransaction) Transaction.fromBytes(tx2Bytes); - assertThat(tx.getGossipCaCertificate()).isEqualTo(deserializedTx2.getGossipCaCertificate()); - assertThat(tx.getGrpcCertificateHash()).isEqualTo(deserializedTx2.getGrpcCertificateHash()); + 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 testNullOptionalValues() throws Exception { + var tx = new NodeCreateTransaction(); + var tx2 = NodeCreateTransaction.fromBytes(tx.toBytes()); + assertThat(tx2.toString()).isEqualTo(tx.toString()); } @Test - void testSetNull() { + 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 f56474b57..e79f6e156 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); } @@ -120,11 +120,20 @@ void shouldBytes() throws Exception { @Test void testNullOptionalValues() throws Exception { var tx = new NodeUpdateTransaction(); - var tx2Bytes = tx.toBytes(); - NodeUpdateTransaction deserializedTx = (NodeUpdateTransaction) Transaction.fromBytes(tx2Bytes); - assertThat(deserializedTx.getGossipCaCertificate()).isNull(); - assertThat(deserializedTx.getGrpcCertificateHash()).isNull(); - assertThat(deserializedTx.getDescription()).isNull(); + var tx2 = NodeUpdateTransaction.fromBytes(tx.toBytes()); + 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 @@ -139,7 +148,7 @@ void testEmptyCertificates() throws Exception { } @Test - void testSetNull() { + void testSetNull() { new NodeUpdateTransaction() .setDescription(null) .setAccountId(null) From ac2cd752e5773e85220cfd05baec8cd6c0802d80 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:47:01 +0000 Subject: [PATCH 3/8] chore(deps): bump io.grpc:grpc-protobuf-lite from 1.68.1 to 1.68.2 in /sdk-dependency-versions (#2115) --- sdk-dependency-versions/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-dependency-versions/build.gradle.kts b/sdk-dependency-versions/build.gradle.kts index ac383fd11..464a593e1 100644 --- a/sdk-dependency-versions/build.gradle.kts +++ b/sdk-dependency-versions/build.gradle.kts @@ -46,7 +46,7 @@ dependencies.constraints { api("io.grpc:grpc-protobuf:1.68.1") { 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") { From c770efb15a9f0c5f5211b5debc005f71eaed773d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:48:00 +0000 Subject: [PATCH 4/8] chore(deps): bump io.grpc:grpc-api from 1.68.1 to 1.68.2 in /sdk-dependency-versions (#2113) --- sdk-dependency-versions/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-dependency-versions/build.gradle.kts b/sdk-dependency-versions/build.gradle.kts index 464a593e1..d162afea3 100644 --- a/sdk-dependency-versions/build.gradle.kts +++ b/sdk-dependency-versions/build.gradle.kts @@ -37,7 +37,7 @@ dependencies.constraints { // 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") { From 0a5a672bc30a0de9ff59d3c9ddf01ded4723d737 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:48:51 +0000 Subject: [PATCH 5/8] chore(deps): bump com.fasterxml.jackson.core:jackson-core from 2.18.1 to 2.18.2 in /sdk-dependency-versions (#2111) --- sdk-dependency-versions/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-dependency-versions/build.gradle.kts b/sdk-dependency-versions/build.gradle.kts index d162afea3..49677dc2b 100644 --- a/sdk-dependency-versions/build.gradle.kts +++ b/sdk-dependency-versions/build.gradle.kts @@ -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") { From 2446a175bc323e50e62cdccd3b01c437ec0a1465 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:49:19 +0000 Subject: [PATCH 6/8] chore(deps): bump com.google.protobuf:protobuf-java from 4.28.3 to 4.29.0 in /sdk-dependency-versions (#2110) --- sdk-dependency-versions/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk-dependency-versions/build.gradle.kts b/sdk-dependency-versions/build.gradle.kts index 49677dc2b..71ef383a5 100644 --- a/sdk-dependency-versions/build.gradle.kts +++ b/sdk-dependency-versions/build.gradle.kts @@ -29,11 +29,11 @@ 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") } From 8ca0e3e85e6c81b54e2253e94153da8a3056d309 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:02:25 +0000 Subject: [PATCH 7/8] chore(deps): bump io.grpc:grpc-stub from 1.68.1 to 1.68.2 in /sdk-dependency-versions (#2114) --- sdk-dependency-versions/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-dependency-versions/build.gradle.kts b/sdk-dependency-versions/build.gradle.kts index 71ef383a5..d42dcb31f 100644 --- a/sdk-dependency-versions/build.gradle.kts +++ b/sdk-dependency-versions/build.gradle.kts @@ -49,7 +49,7 @@ dependencies.constraints { 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") { From 18ac2a0c31dad6e02468dd1031d26188cd27b758 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:09:06 +0000 Subject: [PATCH 8/8] chore(deps): bump io.grpc:grpc-protobuf from 1.68.1 to 1.68.2 in /sdk-dependency-versions (#2112) --- sdk-dependency-versions/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-dependency-versions/build.gradle.kts b/sdk-dependency-versions/build.gradle.kts index d42dcb31f..912ab6f47 100644 --- a/sdk-dependency-versions/build.gradle.kts +++ b/sdk-dependency-versions/build.gradle.kts @@ -43,7 +43,7 @@ dependencies.constraints { 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.2") {