From b6448b348cfb0d916c3ec5901ebd50028f2df10d Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Mon, 14 Apr 2025 16:35:42 -0400 Subject: [PATCH] feat: add new file APIs Signed-off-by: Rob Walworth --- src/sdk/main/include/Client.h | 8 ++++++-- src/sdk/main/include/FileId.h | 28 ++++++++++++++++++++++++++++ src/sdk/main/src/Client.cc | 5 +++-- src/sdk/main/src/FileId.cc | 34 +++++++++++++++++++++++++++++++--- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/sdk/main/include/Client.h b/src/sdk/main/include/Client.h index 5038071ee..f87ea30f7 100644 --- a/src/sdk/main/include/Client.h +++ b/src/sdk/main/include/Client.h @@ -70,9 +70,13 @@ class Client * * @param mirrorNetwork The mirror node network from which to grab the address book and initialize the Client's * consensus network. - * @return A Client with the input mirror network and the corresponding address book consensus network + * @param realm The realm of the network from which to grab the address book. + * @param shard The shard of the network from which to grab the address book. + * @return A Client with the input mirror network and the corresponding address book consensus network. */ - [[nodiscard]] static Client forMirrorNetwork(const std::vector& mirrorNetwork); + [[nodiscard]] static Client forMirrorNetwork(const std::vector& mirrorNetwork, + int64_t realm = 0LL, + int64_t shard = 0LL); /** * Construct a Client by a name. The name must be one of "mainnet", "testnet", or "previewnet", otherwise this will diff --git a/src/sdk/main/include/FileId.h b/src/sdk/main/include/FileId.h index 83c2ab87d..94bbb39d1 100644 --- a/src/sdk/main/include/FileId.h +++ b/src/sdk/main/include/FileId.h @@ -3,6 +3,7 @@ #define HIERO_SDK_CPP_FILE_ID_H_ #include +#include #include #include #include @@ -43,6 +44,33 @@ class FileId */ [[maybe_unused]] static const FileId EXCHANGE_RATES; + /** + * Get the address book file ID for a particular realm and/or shard. + * + * @param realm The realm from which to get the address book file. + * @param shard The shard from which to get the address book file. + * @return The ID of the address book file from the input realm and/or shard. + */ + [[nodiscard]] static FileId getAddressBookFileIdFor(int64_t realm, int64_t shard); + + /** + * Get the fee schedule file ID for a particular realm and/or shard. + * + * @param realm The realm from which to get the fee schedule file. + * @param shard The shard from which to get the fee schedule file. + * @return The ID of the fee schedule file from the input realm and/or shard. + */ + [[nodiscard]] static FileId getFeeScheduleFileIdFor(int64_t realm, int64_t shard); + + /** + * Get the exchange rates file ID for a particular realm and/or shard. + * + * @param realm The realm from which to get the exchange rates file. + * @param shard The shard from which to get the exchange rates file. + * @return The ID of the exchange rates file from the input realm and/or shard. + */ + [[nodiscard]] static FileId getExchangeRatesFileIdFor(int64_t realm, int64_t shard); + /** * Construct with a file number. * diff --git a/src/sdk/main/src/Client.cc b/src/sdk/main/src/Client.cc index 8d173ff79..84326aaec 100644 --- a/src/sdk/main/src/Client.cc +++ b/src/sdk/main/src/Client.cc @@ -157,13 +157,14 @@ Client Client::forNetwork(const std::unordered_map& netw } //----- -Client Client::forMirrorNetwork(const std::vector& mirrorNetwork) +Client Client::forMirrorNetwork(const std::vector& mirrorNetwork, int64_t realm, int64_t shard) { Client client; client.setMirrorNetwork(mirrorNetwork); client.mImpl->mNetwork = std::make_shared(internal::Network::forNetwork(internal::Network::getNetworkFromAddressBook( - AddressBookQuery().setFileId(FileId::ADDRESS_BOOK).execute(client), internal::BaseNodeAddress::PORT_NODE_PLAIN))); + AddressBookQuery().setFileId(FileId::getAddressBookFileIdFor(realm, shard)).execute(client), + internal::BaseNodeAddress::PORT_NODE_PLAIN))); return client; } diff --git a/src/sdk/main/src/FileId.cc b/src/sdk/main/src/FileId.cc index f6cc005ea..ff9d77cfc 100644 --- a/src/sdk/main/src/FileId.cc +++ b/src/sdk/main/src/FileId.cc @@ -10,14 +10,42 @@ namespace Hiero { +namespace +{ +// The entity number of the address book file. +const uint64_t ADDRESS_BOOK_ENTITY_NUM = 102ULL; +// The entity number of the fee schedule file. +const uint64_t FEE_SCHEDULE_ENTITY_NUM = 111ULL; +// The entity number of the exchange rates file. +const uint64_t EXCHANGE_RATES_ENTITY_NUM = 112ULL; +} + +//----- +const FileId FileId::ADDRESS_BOOK = FileId(ADDRESS_BOOK_ENTITY_NUM); + //----- -const FileId FileId::ADDRESS_BOOK = FileId(0ULL, 0ULL, 102ULL); +const FileId FileId::FEE_SCHEDULE = FileId(FEE_SCHEDULE_ENTITY_NUM); //----- -const FileId FileId::FEE_SCHEDULE = FileId(0ULL, 0ULL, 111ULL); +const FileId FileId::EXCHANGE_RATES = FileId(EXCHANGE_RATES_ENTITY_NUM); //----- -const FileId FileId::EXCHANGE_RATES = FileId(0ULL, 0ULL, 112ULL); +FileId FileId::getAddressBookFileIdFor(int64_t realm, int64_t shard) +{ + return FileId(shard, realm, ADDRESS_BOOK_ENTITY_NUM); +} + +//----- +FileId FileId::getFeeScheduleFileIdFor(int64_t realm, int64_t shard) +{ + return FileId(shard, realm, FEE_SCHEDULE_ENTITY_NUM); +} + +//----- +FileId FileId::getExchangeRatesFileIdFor(int64_t realm, int64_t shard) +{ + return FileId(shard, realm, EXCHANGE_RATES_ENTITY_NUM); +} //----- FileId::FileId(uint64_t num)