Skip to content

Commit b6448b3

Browse files
committed
feat: add new file APIs
Signed-off-by: Rob Walworth <robert.walworth@swirldslabs.com>
1 parent a19622d commit b6448b3

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

src/sdk/main/include/Client.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ class Client
7070
*
7171
* @param mirrorNetwork The mirror node network from which to grab the address book and initialize the Client's
7272
* consensus network.
73-
* @return A Client with the input mirror network and the corresponding address book consensus network
73+
* @param realm The realm of the network from which to grab the address book.
74+
* @param shard The shard of the network from which to grab the address book.
75+
* @return A Client with the input mirror network and the corresponding address book consensus network.
7476
*/
75-
[[nodiscard]] static Client forMirrorNetwork(const std::vector<std::string>& mirrorNetwork);
77+
[[nodiscard]] static Client forMirrorNetwork(const std::vector<std::string>& mirrorNetwork,
78+
int64_t realm = 0LL,
79+
int64_t shard = 0LL);
7680

7781
/**
7882
* Construct a Client by a name. The name must be one of "mainnet", "testnet", or "previewnet", otherwise this will

src/sdk/main/include/FileId.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define HIERO_SDK_CPP_FILE_ID_H_
44

55
#include <cstddef>
6+
#include <cstdint>
67
#include <memory>
78
#include <string>
89
#include <string_view>
@@ -43,6 +44,33 @@ class FileId
4344
*/
4445
[[maybe_unused]] static const FileId EXCHANGE_RATES;
4546

47+
/**
48+
* Get the address book file ID for a particular realm and/or shard.
49+
*
50+
* @param realm The realm from which to get the address book file.
51+
* @param shard The shard from which to get the address book file.
52+
* @return The ID of the address book file from the input realm and/or shard.
53+
*/
54+
[[nodiscard]] static FileId getAddressBookFileIdFor(int64_t realm, int64_t shard);
55+
56+
/**
57+
* Get the fee schedule file ID for a particular realm and/or shard.
58+
*
59+
* @param realm The realm from which to get the fee schedule file.
60+
* @param shard The shard from which to get the fee schedule file.
61+
* @return The ID of the fee schedule file from the input realm and/or shard.
62+
*/
63+
[[nodiscard]] static FileId getFeeScheduleFileIdFor(int64_t realm, int64_t shard);
64+
65+
/**
66+
* Get the exchange rates file ID for a particular realm and/or shard.
67+
*
68+
* @param realm The realm from which to get the exchange rates file.
69+
* @param shard The shard from which to get the exchange rates file.
70+
* @return The ID of the exchange rates file from the input realm and/or shard.
71+
*/
72+
[[nodiscard]] static FileId getExchangeRatesFileIdFor(int64_t realm, int64_t shard);
73+
4674
/**
4775
* Construct with a file number.
4876
*

src/sdk/main/src/Client.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,14 @@ Client Client::forNetwork(const std::unordered_map<std::string, AccountId>& netw
157157
}
158158

159159
//-----
160-
Client Client::forMirrorNetwork(const std::vector<std::string>& mirrorNetwork)
160+
Client Client::forMirrorNetwork(const std::vector<std::string>& mirrorNetwork, int64_t realm, int64_t shard)
161161
{
162162
Client client;
163163
client.setMirrorNetwork(mirrorNetwork);
164164
client.mImpl->mNetwork =
165165
std::make_shared<internal::Network>(internal::Network::forNetwork(internal::Network::getNetworkFromAddressBook(
166-
AddressBookQuery().setFileId(FileId::ADDRESS_BOOK).execute(client), internal::BaseNodeAddress::PORT_NODE_PLAIN)));
166+
AddressBookQuery().setFileId(FileId::getAddressBookFileIdFor(realm, shard)).execute(client),
167+
internal::BaseNodeAddress::PORT_NODE_PLAIN)));
167168

168169
return client;
169170
}

src/sdk/main/src/FileId.cc

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,42 @@
1010

1111
namespace Hiero
1212
{
13+
namespace
14+
{
15+
// The entity number of the address book file.
16+
const uint64_t ADDRESS_BOOK_ENTITY_NUM = 102ULL;
17+
// The entity number of the fee schedule file.
18+
const uint64_t FEE_SCHEDULE_ENTITY_NUM = 111ULL;
19+
// The entity number of the exchange rates file.
20+
const uint64_t EXCHANGE_RATES_ENTITY_NUM = 112ULL;
21+
}
22+
23+
//-----
24+
const FileId FileId::ADDRESS_BOOK = FileId(ADDRESS_BOOK_ENTITY_NUM);
25+
1326
//-----
14-
const FileId FileId::ADDRESS_BOOK = FileId(0ULL, 0ULL, 102ULL);
27+
const FileId FileId::FEE_SCHEDULE = FileId(FEE_SCHEDULE_ENTITY_NUM);
1528

1629
//-----
17-
const FileId FileId::FEE_SCHEDULE = FileId(0ULL, 0ULL, 111ULL);
30+
const FileId FileId::EXCHANGE_RATES = FileId(EXCHANGE_RATES_ENTITY_NUM);
1831

1932
//-----
20-
const FileId FileId::EXCHANGE_RATES = FileId(0ULL, 0ULL, 112ULL);
33+
FileId FileId::getAddressBookFileIdFor(int64_t realm, int64_t shard)
34+
{
35+
return FileId(shard, realm, ADDRESS_BOOK_ENTITY_NUM);
36+
}
37+
38+
//-----
39+
FileId FileId::getFeeScheduleFileIdFor(int64_t realm, int64_t shard)
40+
{
41+
return FileId(shard, realm, FEE_SCHEDULE_ENTITY_NUM);
42+
}
43+
44+
//-----
45+
FileId FileId::getExchangeRatesFileIdFor(int64_t realm, int64_t shard)
46+
{
47+
return FileId(shard, realm, EXCHANGE_RATES_ENTITY_NUM);
48+
}
2149

2250
//-----
2351
FileId::FileId(uint64_t num)

0 commit comments

Comments
 (0)