From f1b645f7edc49d8f2827e35acfa3e0b6b4670d4f Mon Sep 17 00:00:00 2001 From: steffenboe Date: Wed, 16 Oct 2024 15:04:01 +0200 Subject: [PATCH] feat: set adressBook and remove overloaded method (#2024) Co-authored-by: Ivan Ivanov --- .../java/com/hedera/hashgraph/sdk/Client.java | 20 ++----------------- .../com/hedera/hashgraph/sdk/ClientTest.java | 6 +++--- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java index bfd1668fb..0ee362665 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java @@ -460,31 +460,15 @@ void untrackSubscription(SubscriptionHandle subscriptionHandle) { * and update the address book if necessary. * * @param addressBook A list of nodes and their metadata - * @param updateAddressBook whether to update the address book of the network * @return {@code this} */ - public synchronized Client setNetworkFromAddressBook(NodeAddressBook addressBook, boolean updateAddressBook) + public synchronized Client setNetworkFromAddressBook(NodeAddressBook addressBook) throws InterruptedException, TimeoutException { network.setNetwork(Network.addressBookToNetwork(addressBook.nodeAddresses)); - if (updateAddressBook) { - network.setAddressBook(addressBook); - } + network.setAddressBook(addressBook); return this; } - /** - * Replace all nodes in this Client with the nodes in the Address Book - * - * @param addressBook A list of nodes and their metadata - * @return {@code this} - * @throws InterruptedException when a thread is interrupted while it's waiting, sleeping, or otherwise occupied - * @throws TimeoutException when shutting down nodes - */ - public synchronized Client setNetworkFromAddressBook(NodeAddressBook addressBook) - throws InterruptedException, TimeoutException { - return setNetworkFromAddressBook(addressBook, false); - } - /** * Extract the network. * diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java index 58e155d97..f46e34e70 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java @@ -423,7 +423,7 @@ void setNetworkFromAddressBook() throws Exception { client.setNetworkFromAddressBook(NodeAddressBook.fromBytes(com.hedera.hashgraph.sdk.proto.NodeAddressBook.newBuilder() .addNodeAddress(nodeAddress(10001, "10001", new byte[] {1, 0, 1}, new byte[] {10, 0, 0, 1})) .addNodeAddress(nodeAddress(10002, "10002", new byte[] {1, 0, 2}, new byte[] {10, 0, 0, 2})) - .build().toByteString()), true); + .build().toByteString())); // verify security parameters in client assertThat(nodeAddress.apply(10001).certHash).isEqualTo(ByteString.copyFrom(new byte[]{1, 0, 1})); @@ -435,7 +435,7 @@ void setNetworkFromAddressBook() throws Exception { client.setNetworkFromAddressBook(NodeAddressBook.fromBytes(com.hedera.hashgraph.sdk.proto.NodeAddressBook.newBuilder() .addNodeAddress(nodeAddress(10001, "10001", null, new byte[] {10, 0, 0, 1})) .addNodeAddress(nodeAddress(10002, "10002", null, new byte[] {10, 0, 0, 2})) - .build().toByteString()), true); + .build().toByteString())); // verify security parameters in client (unchanged) assertThat(nodeAddress.apply(10001).certHash).isEqualTo(ByteString.copyFrom(new byte[]{1, 0, 1})); @@ -447,7 +447,7 @@ void setNetworkFromAddressBook() throws Exception { client.setNetworkFromAddressBook(NodeAddressBook.fromBytes(com.hedera.hashgraph.sdk.proto.NodeAddressBook.newBuilder() .addNodeAddress(nodeAddress(10001, "810001", new byte[] {8, 1, 0, 1}, new byte[] {10, 0, 0, 1})) .addNodeAddress(nodeAddress(10002, "810002", new byte[] {8, 1, 0, 2}, new byte[] {10, 0, 0, 2})) - .build().toByteString()), true); + .build().toByteString())); // verify security parameters in client assertThat(nodeAddress.apply(10001).certHash).isEqualTo(ByteString.copyFrom(new byte[]{8, 1, 0, 1}));