Skip to content

Commit 63e55f9

Browse files
authored
refactor: hip-1261 (#2722)
Signed-off-by: Mustafa Uzun <mustafa.uzun@limechain.tech>
1 parent 81a2895 commit 63e55f9

8 files changed

Lines changed: 214 additions & 147 deletions

File tree

examples/src/main/java/com/hedera/hashgraph/sdk/examples/FeeEstimateQueryExample.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,26 @@ private static FeeEstimateResponse estimateWithStateMode(Client client, Transfer
105105
.setTransaction(tx)
106106
.execute(client);
107107

108-
System.out.println("Mode: " + stateEstimate.getMode());
109108
printNetworkFee(stateEstimate);
110109
printNodeFee(stateEstimate);
111110
printServiceFee(stateEstimate);
112111
printTotalFee(stateEstimate);
113-
printNotes(stateEstimate);
112+
System.out.println("\nHigh Volume Multiplier: " + stateEstimate.getHighVolumeMultiplier());
114113

115114
return stateEstimate;
116115
}
117116

118117
private static void printNetworkFee(FeeEstimateResponse estimate) {
119118
System.out.println("\nNetwork Fee:");
120-
System.out.println(" Multiplier: " + estimate.getNetworkFee().getMultiplier());
121-
System.out.println(" Subtotal: " + estimate.getNetworkFee().getSubtotal() + " tinycents");
119+
System.out.println(" Multiplier: " + estimate.getNetwork().getMultiplier());
120+
System.out.println(" Subtotal: " + estimate.getNetwork().getSubtotal() + " tinycents");
122121
}
123122

124123
private static void printNodeFee(FeeEstimateResponse estimate) {
125124
System.out.println("\nNode Fee:");
126-
System.out.println(" Base: " + estimate.getNodeFee().getBase() + " tinycents");
127-
long nodeTotal = estimate.getNodeFee().getBase();
128-
for (FeeExtra extra : estimate.getNodeFee().getExtras()) {
125+
System.out.println(" Base: " + estimate.getNode().getBase() + " tinycents");
126+
long nodeTotal = estimate.getNode().getBase();
127+
for (FeeExtra extra : estimate.getNode().getExtras()) {
129128
System.out.println(" Extra - " + extra.getName() + ": " + extra.getSubtotal() + " tinycents");
130129
nodeTotal += extra.getSubtotal();
131130
}
@@ -134,9 +133,9 @@ private static void printNodeFee(FeeEstimateResponse estimate) {
134133

135134
private static void printServiceFee(FeeEstimateResponse estimate) {
136135
System.out.println("\nService Fee:");
137-
System.out.println(" Base: " + estimate.getServiceFee().getBase() + " tinycents");
138-
long serviceTotal = estimate.getServiceFee().getBase();
139-
for (FeeExtra extra : estimate.getServiceFee().getExtras()) {
136+
System.out.println(" Base: " + estimate.getService().getBase() + " tinycents");
137+
long serviceTotal = estimate.getService().getBase();
138+
for (FeeExtra extra : estimate.getService().getExtras()) {
140139
System.out.println(" Extra - " + extra.getName() + ": " + extra.getSubtotal() + " tinycents");
141140
serviceTotal += extra.getSubtotal();
142141
}
@@ -148,15 +147,6 @@ private static void printTotalFee(FeeEstimateResponse estimate) {
148147
System.out.println("Total Estimated Fee: " + Hbar.fromTinybars(estimate.getTotal() / 100));
149148
}
150149

151-
private static void printNotes(FeeEstimateResponse estimate) {
152-
if (!estimate.getNotes().isEmpty()) {
153-
System.out.println("\nNotes:");
154-
for (String note : estimate.getNotes()) {
155-
System.out.println(" - " + note);
156-
}
157-
}
158-
}
159-
160150
private static FeeEstimateResponse estimateWithIntrinsicMode(Client client, TransferTransaction tx)
161151
throws Exception {
162152
System.out.println("\n=== Estimating Fees with INTRINSIC Mode ===");
@@ -166,12 +156,10 @@ private static FeeEstimateResponse estimateWithIntrinsicMode(Client client, Tran
166156
.setTransaction(tx)
167157
.execute(client);
168158

169-
System.out.println("Mode: " + intrinsicEstimate.getMode());
170-
System.out.println(
171-
"Network Fee Subtotal: " + intrinsicEstimate.getNetworkFee().getSubtotal() + " tinycents");
172-
System.out.println("Node Fee Base: " + intrinsicEstimate.getNodeFee().getBase() + " tinycents");
173159
System.out.println(
174-
"Service Fee Base: " + intrinsicEstimate.getServiceFee().getBase() + " tinycents");
160+
"Network Fee Subtotal: " + intrinsicEstimate.getNetwork().getSubtotal() + " tinycents");
161+
System.out.println("Node Fee Base: " + intrinsicEstimate.getNode().getBase() + " tinycents");
162+
System.out.println("Service Fee Base: " + intrinsicEstimate.getService().getBase() + " tinycents");
175163
System.out.println("Total Estimated Fee: " + intrinsicEstimate.getTotal() + " tinycents");
176164
System.out.println("Total Estimated Fee: " + Hbar.fromTinybars(intrinsicEstimate.getTotal() / 100));
177165

sdk/src/main/java/com/hedera/hashgraph/sdk/FeeEstimateMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
public enum FeeEstimateMode {
1010
/**
11-
* Default mode: uses latest known state.
11+
* Uses latest known state.
1212
* <p>
1313
* This mode calculates fees based on the current state of the network,
1414
* taking into account all state-dependent factors such as current
@@ -17,7 +17,7 @@ public enum FeeEstimateMode {
1717
STATE(0),
1818

1919
/**
20-
* Intrinsic mode: ignores state-dependent factors.
20+
* Default mode: ignores state-dependent factors.
2121
* <p>
2222
* This mode calculates fees based only on the intrinsic properties of
2323
* the transaction itself, ignoring dynamic network conditions. This

sdk/src/main/java/com/hedera/hashgraph/sdk/FeeEstimateQuery.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class FeeEstimateQuery {
3030
@Nullable
3131
private com.hedera.hashgraph.sdk.proto.Transaction transaction = null;
3232

33+
private int highVolumeThrottle = 0;
3334
private int maxAttempts = 10;
3435
private Duration maxBackoff = Duration.ofSeconds(8L);
3536

@@ -64,7 +65,7 @@ public FeeEstimateMode getMode() {
6465
/**
6566
* Set the mode for fee estimation.
6667
* <p>
67-
* Defaults to {@link FeeEstimateMode#STATE} if not set.
68+
* Defaults to {@link FeeEstimateMode#INTRINSIC} if not set.
6869
*
6970
* @param mode the fee estimate mode
7071
* @return {@code this}
@@ -75,6 +76,32 @@ public FeeEstimateQuery setMode(FeeEstimateMode mode) {
7576
return this;
7677
}
7778

79+
/**
80+
* Extract the high-volume throttle utilization in basis points.
81+
*
82+
* @return the high-volume throttle value (0–10000)
83+
*/
84+
public int getHighVolumeThrottle() {
85+
return highVolumeThrottle;
86+
}
87+
88+
/**
89+
* Set the high-volume throttle utilization in basis points (0–10000, where 10000 = 100%).
90+
* <p>
91+
* When non-zero, the mirror node returns a high-volume pricing multiplier
92+
* in the response.
93+
*
94+
* @param highVolumeThrottle the throttle utilization in basis points
95+
* @return {@code this}
96+
*/
97+
public FeeEstimateQuery setHighVolumeThrottle(int highVolumeThrottle) {
98+
if (highVolumeThrottle < 0 || highVolumeThrottle > 10000) {
99+
throw new IllegalArgumentException("highVolumeThrottle must be between 0 and 10000");
100+
}
101+
this.highVolumeThrottle = highVolumeThrottle;
102+
return this;
103+
}
104+
78105
/**
79106
* Extract the transaction to estimate fees for.
80107
*
@@ -178,7 +205,7 @@ public FeeEstimateResponse execute(Client client) throws IOException, Interrupte
178205
* @throws InterruptedException if the operation is interrupted
179206
*/
180207
public FeeEstimateResponse execute(Client client, Duration timeout) throws IOException, InterruptedException {
181-
var resolvedMode = mode != null ? mode : FeeEstimateMode.STATE;
208+
var resolvedMode = mode != null ? mode : FeeEstimateMode.INTRINSIC;
182209
var requestPayload = getRequestPayload();
183210
var url = buildUrl(client, resolvedMode);
184211

@@ -187,7 +214,7 @@ public FeeEstimateResponse execute(Client client, Duration timeout) throws IOExc
187214
var response = HTTP_CLIENT.send(
188215
buildHttpRequest(url, timeout, requestPayload), HttpResponse.BodyHandlers.ofString());
189216

190-
var result = handleResponse(response, resolvedMode, attempt);
217+
var result = handleResponse(response, attempt);
191218
if (result != null) {
192219
return result;
193220
}
@@ -203,10 +230,9 @@ public FeeEstimateResponse execute(Client client, Duration timeout) throws IOExc
203230
/**
204231
* Handle the HTTP response and return the result or null if retry is needed.
205232
*/
206-
private FeeEstimateResponse handleResponse(
207-
HttpResponse<String> response, FeeEstimateMode resolvedMode, int attempt) {
233+
private FeeEstimateResponse handleResponse(HttpResponse<String> response, int attempt) {
208234
if (isSuccessfulResponse(response.statusCode())) {
209-
return FeeEstimateResponse.fromJson(response.body(), resolvedMode);
235+
return FeeEstimateResponse.fromJson(response.body());
210236
}
211237

212238
if (!shouldRetry(response.statusCode()) || attempt >= maxAttempts) {
@@ -253,7 +279,7 @@ public CompletableFuture<FeeEstimateResponse> executeAsync(Client client) {
253279
* @return the fee estimate response
254280
*/
255281
public CompletableFuture<FeeEstimateResponse> executeAsync(Client client, Duration timeout) {
256-
var resolvedMode = mode != null ? mode : FeeEstimateMode.STATE;
282+
var resolvedMode = mode != null ? mode : FeeEstimateMode.INTRINSIC;
257283
CompletableFuture<FeeEstimateResponse> returnFuture = new CompletableFuture<>();
258284
executeAsync(client, timeout, resolvedMode, returnFuture, 1);
259285
return returnFuture;
@@ -316,7 +342,7 @@ private void handleAsyncResponse(
316342
int attempt,
317343
HttpResponse<String> response) {
318344
if (isSuccessfulResponse(response.statusCode())) {
319-
returnFuture.complete(FeeEstimateResponse.fromJson(response.body(), resolvedMode));
345+
returnFuture.complete(FeeEstimateResponse.fromJson(response.body()));
320346
return;
321347
}
322348

@@ -352,7 +378,11 @@ private byte[] getRequestPayload() {
352378

353379
private String buildUrl(Client client, FeeEstimateMode resolvedMode) {
354380
// Keep mode casing consistent with JS SDK (uppercase)
355-
return client.getMirrorRestBaseUrl() + "/network/fees?mode=" + resolvedMode.toString();
381+
String url = client.getMirrorRestBaseUrl() + "/network/fees?mode=" + resolvedMode.toString();
382+
if (highVolumeThrottle > 0) {
383+
url += "&high_volume_throttle=" + highVolumeThrottle;
384+
}
385+
return url;
356386
}
357387

358388
private HttpRequest buildHttpRequest(String url, Duration timeout, byte[] payload) {

0 commit comments

Comments
 (0)