Skip to content
Draft
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
6 changes: 3 additions & 3 deletions HieroApi.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(HAPI_VERSION_TAG "v0.69.1" CACHE STRING "Use the configured version tag for the Hiero API protobufs")
set(HAPI_COMMIT_HASH "83fa1eb1446524aa695fa2c0d817361805afb979" CACHE STRING "Use the configured commit hash for the Hiero API protobufs (overrides version tag if provided)")
set(HAPI_VERSION_TAG "v0.72.0-alpha.1" CACHE STRING "Use the configured version tag for the Hiero API protobufs")
set(HAPI_COMMIT_HASH "df70b5b7f32f0dabf1f6883c5d255248a8f3aa03" CACHE STRING "Use the configured commit hash for the Hiero API protobufs (overrides version tag if provided)")

if (HAPI_VERSION_TAG STREQUAL "")
set(HAPI_VERSION_TAG "v0.69.1")
set(HAPI_VERSION_TAG "v0.72.0-alpha.1")
endif ()

# Use commit hash if provided, otherwise use version tag
Expand Down
2 changes: 1 addition & 1 deletion proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ set(PROTO_FILES
services/get_by_key.proto
services/get_by_solidity_id.proto
services/hook_dispatch.proto
services/hook_store.proto
services/hook_types.proto
services/lambda_sstore.proto
services/network_get_execution_time.proto
services/network_get_version_info.proto
services/network_service.proto
Expand Down
1 change: 1 addition & 0 deletions src/sdk/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ add_library(${PROJECT_NAME} STATIC
src/FeeComponents.cc
src/FeeData.cc
src/FeeDataType.cc
src/FeeEstimateQuery.cc
src/FeeSchedule.cc
src/FeeSchedules.cc
src/FileAppendTransaction.cc
Expand Down
36 changes: 36 additions & 0 deletions src/sdk/main/include/FeeEstimateMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_SDK_CPP_FEE_ESTIMATE_MODE_H_
#define HIERO_SDK_CPP_FEE_ESTIMATE_MODE_H_

#include <string>
#include <unordered_map>

namespace Hiero
{
/**
* Enum class representing the fee estimation mode.
*/
enum class FeeEstimateMode
{
/**
* STATE mode - Uses the current state of the network for fee estimation.
*/
STATE,

/**
* TRANSIENT mode - Uses a transient simulation for fee estimation.
*/
TRANSIENT
};

/**
* Map of FeeEstimateMode to its corresponding string representation.
*/
[[maybe_unused]] static const std::unordered_map<FeeEstimateMode, std::string> gFeeEstimateModeToString = {
{FeeEstimateMode::STATE, "STATE" },
{ FeeEstimateMode::TRANSIENT, "TRANSIENT"}
};

} // namespace Hiero

#endif // HIERO_SDK_CPP_FEE_ESTIMATE_MODE_H_
154 changes: 154 additions & 0 deletions src/sdk/main/include/FeeEstimateQuery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_SDK_CPP_FEE_ESTIMATE_QUERY_H_
#define HIERO_SDK_CPP_FEE_ESTIMATE_QUERY_H_

#include "Defaults.h"
#include "FeeEstimateMode.h"
#include "FeeEstimateResponse.h"
#include "WrappedTransaction.h"

#include <cstdint>
#include <memory>
#include <string>

namespace proto
{
class Transaction;
}

namespace Hiero
{
class Client;

/**
* FeeEstimateQuery allows users to query expected transaction fees without submitting transactions to the network.
*/
class FeeEstimateQuery
{
public:
/**
* Default constructor.
*/
FeeEstimateQuery() = default;

/**
* Execute the fee estimation query with the provided client.
*
* @param client The Client to use for the query.
* @return The FeeEstimateResponse containing the fee estimates.
* @throws std::invalid_argument If client is nullptr or no transaction is set.
* @throws IllegalStateException If the mirror node is not set or an error occurs during the query.
*/
[[nodiscard]] FeeEstimateResponse execute(const Client& client);

/**
* Set the estimation mode (optional, defaults to STATE).
*
* @param mode The FeeEstimateMode to use.
* @return A reference to this FeeEstimateQuery.
*/
FeeEstimateQuery& setMode(FeeEstimateMode mode);

/**
* Get the current estimation mode.
*
* @return The current FeeEstimateMode.
*/
[[nodiscard]] FeeEstimateMode getMode() const;

/**
* Set the transaction to estimate (required).
*
* @param transaction The WrappedTransaction to estimate.
* @return A reference to this FeeEstimateQuery.
*/
FeeEstimateQuery& setTransaction(const WrappedTransaction& transaction);

/**
* Get the current transaction.
*
* @return The current WrappedTransaction.
*/
[[nodiscard]] const WrappedTransaction& getTransaction() const;

/**
* Set the maximum number of retry attempts.
*
* @param maxAttempts The maximum number of retry attempts.
* @return A reference to this FeeEstimateQuery.
*/
FeeEstimateQuery& setMaxAttempts(uint64_t maxAttempts);

/**
* Get the maximum number of retry attempts.
*
* @return The maximum number of retry attempts.
*/
[[nodiscard]] uint64_t getMaxAttempts() const;

private:
/**
* Call the fee estimate REST API endpoint.
*
* @param client The Client to use.
* @param protoTx The protobuf Transaction object.
* @return The FeeEstimateResponse.
*/
[[nodiscard]] FeeEstimateResponse callGetFeeEstimate(const Client& client, const proto::Transaction& protoTx);

/**
* Estimate fees for a single transaction.
*
* @param client The Client to use.
* @return The FeeEstimateResponse.
*/
[[nodiscard]] FeeEstimateResponse estimateSingleTransaction(const Client& client);

/**
* Execute chunked transaction fee estimation (for FileAppend or TopicMessageSubmit).
*
* @param client The Client to use.
* @return The aggregated FeeEstimateResponse.
*/
[[nodiscard]] FeeEstimateResponse executeChunkedTransaction(const Client& client);

/**
* Determine if an error should trigger a retry.
*
* @param statusCode The HTTP status code.
* @return true if should retry, false otherwise.
*/
[[nodiscard]] bool shouldRetry(int statusCode) const;

/**
* Build the mirror node REST API URL.
*
* @param client The Client to use.
* @return The URL string.
*/
[[nodiscard]] std::string buildMirrorNodeUrl(const Client& client) const;

/**
* The estimation mode (defaults to STATE).
*/
FeeEstimateMode mMode = FeeEstimateMode::STATE;

/**
* The transaction to estimate.
*/
WrappedTransaction mTransaction;

/**
* The current retry attempt.
*/
uint64_t mAttempt = 0;

/**
* The maximum number of retry attempts.
*/
uint64_t mMaxAttempts = DEFAULT_MAX_ATTEMPTS;
};

} // namespace Hiero

#endif // HIERO_SDK_CPP_FEE_ESTIMATE_QUERY_H_
Loading
Loading