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

Update address book *.pb files #508

Merged
merged 6 commits into from
Oct 3, 2023
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
234 changes: 125 additions & 109 deletions addressbook/mainnet.pb

Large diffs are not rendered by default.

174 changes: 17 additions & 157 deletions addressbook/previewnet.pb

Large diffs are not rendered by default.

123 changes: 26 additions & 97 deletions addressbook/testnet.pb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions sdk/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(EXEMPT_CUSTOM_FEES_EXAMPLE_NAME ${PROJECT_NAME}-exempt-custom-fees-example)
set(FILE_APPEND_CHUNKED_EXAMPLE_NAME ${PROJECT_NAME}-file-append-chunked-example)
set(GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME ${PROJECT_NAME}-generate-private-key-from-mnemonic-example)
set(GET_ACCOUNT_BALANCE_EXAMPLE_NAME ${PROJECT_NAME}-get-account-balance-example)
set(GET_ADDRESS_BOOK_EXAMPLE_NAME ${PROJECT_NAME}-get-address-book-example)
set(GET_FILE_CONTENTS_EXAMPLE_NAME ${PROJECT_NAME}-get-file-contents-example)
set(NFT_ADD_REMOVE_ALLOWANCES_EXAMPLE_NAME ${PROJECT_NAME}-nft-add-remove-allowances-example)
set(SCHEDULE_EXAMPLE_NAME ${PROJECT_NAME}-schedule-example)
Expand Down Expand Up @@ -46,6 +47,7 @@ add_executable(${EXEMPT_CUSTOM_FEES_EXAMPLE_NAME} ExemptCustomFeesExample.cc)
add_executable(${FILE_APPEND_CHUNKED_EXAMPLE_NAME} FileAppendChunkedExample.cc)
add_executable(${GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME} GeneratePrivateKeyFromMnemonic.cc)
add_executable(${GET_ACCOUNT_BALANCE_EXAMPLE_NAME} GetAccountBalanceExample.cc)
add_executable(${GET_ADDRESS_BOOK_EXAMPLE_NAME} GetAddressBookExample.cc)
add_executable(${GET_FILE_CONTENTS_EXAMPLE_NAME} GetFileContentsExample.cc)
add_executable(${NFT_ADD_REMOVE_ALLOWANCES_EXAMPLE_NAME} NftAddRemoveAllowancesExample.cc)
add_executable(${SCHEDULE_EXAMPLE_NAME} ScheduleExample.cc)
Expand Down Expand Up @@ -94,6 +96,7 @@ target_link_libraries(${EXEMPT_CUSTOM_FEES_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${FILE_APPEND_CHUNKED_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GET_ACCOUNT_BALANCE_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GET_ADDRESS_BOOK_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GET_FILE_CONTENTS_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${NFT_ADD_REMOVE_ALLOWANCES_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${SCHEDULE_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
Expand Down Expand Up @@ -127,6 +130,7 @@ install(TARGETS
${FILE_APPEND_CHUNKED_EXAMPLE_NAME}
${GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME}
${GET_ACCOUNT_BALANCE_EXAMPLE_NAME}
${GET_ADDRESS_BOOK_EXAMPLE_NAME}
${GET_FILE_CONTENTS_EXAMPLE_NAME}
${NFT_ADD_REMOVE_ALLOWANCES_EXAMPLE_NAME}
${SCHEDULE_EXAMPLE_NAME}
Expand Down
44 changes: 44 additions & 0 deletions sdk/examples/GetAddressBookExample.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*-
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "AddressBookQuery.h"
#include "Client.h"
#include "FileId.h"
#include "NodeAddressBook.h"

#include <iostream>

using namespace Hedera;

int main(int argc, char** argv)
{
// Create a client for the Hedera network of which to get the address book.
Client client = Client::forTestnet();

// Query for the address book using the client.
const NodeAddressBook nodeAddressBook = AddressBookQuery().setFileId(FileId::ADDRESS_BOOK).execute(client);

// Print off the received addresses contained in the address book.
for (const auto& nodeAddress : nodeAddressBook.getNodeAddresses())
{
std::cout << nodeAddress.toString() << std::endl;
}

return 0;
}
9 changes: 5 additions & 4 deletions sdk/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_library(${PROJECT_NAME} STATIC
src/AccountRecordsQuery.cc
src/AccountStakersQuery.cc
src/AccountUpdateTransaction.cc
src/AddressBookQuery.cc
src/AssessedCustomFee.cc
src/ChunkedTransaction.cc
src/Client.cc
Expand Down Expand Up @@ -40,6 +41,7 @@ add_library(${PROJECT_NAME} STATIC
src/ECDSAsecp256k1PublicKey.cc
src/ED25519PrivateKey.cc
src/ED25519PublicKey.cc
src/Endpoint.cc
src/EthereumFlow.cc
src/EthereumTransaction.cc
src/EthereumTransactionData.cc
Expand All @@ -61,6 +63,7 @@ add_library(${PROJECT_NAME} STATIC
src/FreezeType.cc
src/HbarAllowance.cc
src/HbarTransfer.cc
src/IPv4Address.cc
src/Key.cc
src/KeyList.cc
src/LedgerId.cc
Expand All @@ -69,6 +72,8 @@ add_library(${PROJECT_NAME} STATIC
src/NetworkVersionInfo.cc
src/NetworkVersionInfoQuery.cc
src/NftId.cc
src/NodeAddress.cc
src/NodeAddressBook.cc
src/PrivateKey.cc
src/ProxyStaker.cc
src/PublicKey.cc
Expand Down Expand Up @@ -136,17 +141,13 @@ add_library(${PROJECT_NAME} STATIC
src/impl/BaseNode.cc
src/impl/BaseNodeAddress.cc
src/impl/DerivationPathUtils.cc
src/impl/Endpoint.cc
src/impl/DurationConverter.cc
src/impl/HederaCertificateVerifier.cc
src/impl/HexConverter.cc
src/impl/IPv4Address.cc
src/impl/MirrorNetwork.cc
src/impl/MirrorNode.cc
src/impl/Network.cc
src/impl/Node.cc
src/impl/NodeAddress.cc
src/impl/NodeAddressBook.cc
src/impl/OpenSSLUtils.cc
src/impl/RLPItem.cc
src/impl/TimestampConverter.cc
Expand Down
164 changes: 164 additions & 0 deletions sdk/main/include/AddressBookQuery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*-
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef HEDERA_SDK_CPP_ADDRESS_BOOK_QUERY_H_
#define HEDERA_SDK_CPP_ADDRESS_BOOK_QUERY_H_

#include "Defaults.h"
#include "FileId.h"

#include <chrono>

namespace Hedera
{
class Client;
class NodeAddressBook;
}

namespace com::hedera::mirror::api::proto
{
class AddressBookQuery;
}

namespace Hedera
{
/**
* A query that returns the current address book being used by the network's consensus nodes.
*/
class AddressBookQuery
{
public:
/**
* Submit this AddressBookQuery to a Hedera network.
*
* @param client The Client to use to submit this AddressBookQuery.
* @return The NodeAddressBook object sent from the Hedera network that contains the result of this AddressBookQuery.
* @throws MaxAttemptsExceededException If this AddressBookQuery attempts to execute past the number of allowable
* attempts.
* @throws PrecheckStatusException If this AddressBookQuery fails its pre-check.
* @throws UninitializedException If the input Client has not yet been initialized.
*/
NodeAddressBook execute(const Client& client);

/**
* Submit this AddressBookQuery to a Hedera network with a specific timeout.
*
* @param client The Client to use to submit this AddressBookQuery.
* @param timeout The desired timeout for the execution of this AddressBookQuery.
* @return The NodeAddressBook object sent from the Hedera network that contains the result of this AddressBookQuery.
* @throws MaxAttemptsExceededException If this AddressBookQuery attempts to execute past the number of allowable
* attempts.
* @throws PrecheckStatusException If this AddressBookQuery fails its pre-check.
* @throws UninitializedException If the input Client has not yet been initialized.
*/
NodeAddressBook execute(const Client& client, const std::chrono::duration<double>& timeout);

/**
* Set the ID of the file of which to request the address book.
*
* @param fileId The ID of the file of which to request the address book.
* @return A reference to this AddressBookQuery object with the newly-set file ID.
*/
AddressBookQuery& setFileId(const FileId& fileId);

/**
* Set the number of node addresses to retrieve. Set to 0 to retrieve all node addresses.
*
* @param limit The number of node addresses to retrieve.
* @return A reference to this AddressBookQuery object with the newly-set node address limit.
*/
AddressBookQuery& setLimit(unsigned int limit);

/**
* Set the maximum number of attempts to try and execute this AddressBookQuery.
*
* @param attempts The maximum number of attempts to try and execute this AddressBookQuery.
* @return A reference to this AddressBookQuery object with the newly-set maximum attempts.
*/
AddressBookQuery& setMaxAttempts(unsigned int attempts);

/**
* Set the maximum amount of time to wait before attempting to resubmit this AddressBookQuery.
*
* @param backoff The maximum amount of time to wait before attempting to resubmit this AddressBookQuery.
* @return A reference to this Client with the newly-set maximum backoff time.
* @throws std::invalid_argument If the desired maximum backoff duration is shorter than DEFAULT_MIN_BACKOFF.
*/
AddressBookQuery& setMaxBackoff(const std::chrono::duration<double>& backoff);

/**
* Get the ID of the file of which this query is currently configured to get the address book.
*
* @return The ID of the file for which this query is meant.
*/
[[nodiscard]] inline FileId getFileId() const { return mFileId; }

/**
* Get the number of node addresses to retrieve.
*
* @return The number of node addresses to retrieve.
*/
[[nodiscard]] inline unsigned int getLimit() const { return mLimit; }

/**
* Get the maximum number of attempts to try and execute this AddressBookQuery.
*
* @return The maximum number of attempts to try and execute this AddressBookQuery.
*/
[[nodiscard]] inline unsigned int getMaxAttempts() const { return mMaxAttempts; }

/**
* Get the maximum amount of time to wait before attempting to resubmit this AddressBookQuery.
*
* @return The the maximum amount of time to wait before attempting to resubmit this AddressBookQuery.
*/
[[nodiscard]] inline std::chrono::duration<double> getMaxBackoff() const { return mMaxBackoff; }

private:
/**
* Build an AddressBookQuery protobuf object from this AddressBookQuery.
*
* @return The AddressBookQuery protobuf object built from this AddressBookQuery.
*/
com::hedera::mirror::api::proto::AddressBookQuery build() const;

/**
* The ID of the file of which this query should get the address book.
*/
FileId mFileId;

/**
* The number of node addresses to retrieve. 0 retrieves all node addresses.
*/
unsigned int mLimit = 0U;

/**
* The maximum number of attempts to try and execute this AddressBookQuery.
*/
unsigned int mMaxAttempts = DEFAULT_MAX_ATTEMPTS;

/**
* The the maximum amount of time to wait before attempting to resubmit this AddressBookQuery.
*/
std::chrono::duration<double> mMaxBackoff = DEFAULT_MAX_BACKOFF;
};

} // namespace Hedera

#endif // HEDERA_SDK_CPP_ADDRESS_BOOK_QUERY_H_
45 changes: 44 additions & 1 deletion sdk/main/include/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Client
*
* After this method returns, this Client can be re-used. All network communication can be re-established as needed.
*/
void close() const;
void close();

/**
* Set the length of time a request sent by this Client can be processed before it times out.
Expand Down Expand Up @@ -198,6 +198,15 @@ class Client
*/
Client& setMaxBackoff(const std::chrono::duration<double>& backoff);

/**
* Set the period of time this Client wait between updating its network. This will immediately cancel any scheduled
* network updates and start a new waiting period.
*
* @param update The period of time this Client wait between updating its network.
* @return A reference to this Client with the newly-set network update period.
*/
Client& setNetworkUpdatePeriod(const std::chrono::duration<double>& update);

/**
* Get a pointer to the Network this Client is using to communicate with consensus nodes.
*
Expand Down Expand Up @@ -283,6 +292,13 @@ class Client
*/
[[nodiscard]] std::optional<std::chrono::duration<double>> getMaxBackoff() const;

/**
* Get the period of time this Client wait between updating its network.
*
* @return The period of time this Client wait between updating its network.
*/
[[nodiscard]] std::chrono::duration<double> getNetworkUpdatePeriod() const;

/**
* Get a pointer to the MirrorNetwork being used by this client.
*
Expand All @@ -291,6 +307,33 @@ class Client
[[nodiscard]] std::shared_ptr<internal::MirrorNetwork> getMirrorNetwork() const;

private:
/**
* Start the network update thread.
*
* @param period The period of time to wait before a network update is performed.
*/
void startNetworkUpdateThread(const std::chrono::duration<double>& period);

/**
* Schedule a network update a certain period of time from when this is called.
*
* @param period The period of time to wait before a network update is performed.
*/
void scheduleNetworkUpdate(const std::chrono::duration<double>& period);

/**
* Cancel any scheduled network updates.
*/
void cancelScheduledNetworkUpdate();

/**
* Helper function used for moving a Client implementation into this Client, as well as doing network update thread
* handling.
*
* @param other The Client to move into this Client.
*/
void moveClient(Client&& other);

/**
* Implementation object used to hide implementation details and internal headers.
*/
Expand Down
8 changes: 8 additions & 0 deletions sdk/main/include/Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ constexpr auto DEFAULT_CHUNK_SIZE = 1024U;
* The default number of chunks for a ChunkedTransaction.
*/
constexpr auto DEFAULT_MAX_CHUNKS = 20U;
/**
* The default amount of time to wait after a network update to update again.
*/
constexpr auto DEFAULT_NETWORK_UPDATE_PERIOD = std::chrono::hours(24);
/**
* The default amount of time to wait after Client creation to update the network for the first time.
*/
constexpr auto DEFAULT_NETWORK_UPDATE_INITIAL_DELAY = std::chrono::seconds(10);

}

Expand Down
Loading
Loading