Skip to content

Commit

Permalink
feat: set adressBook and remove overloaded method (#2024)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Ivanov <ivanivanov.ii726@gmail.com>
  • Loading branch information
steffenboe and 0xivanov authored Oct 16, 2024
1 parent 214ed6e commit f1b645f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
20 changes: 2 additions & 18 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
Expand All @@ -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}));
Expand All @@ -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}));
Expand Down

0 comments on commit f1b645f

Please sign in to comment.