Skip to content

Commit 25cdd52

Browse files
wip: feeestimatequery
Signed-off-by: Ivaylo Nikolov <[email protected]>
1 parent f9e9189 commit 25cdd52

File tree

16 files changed

+1474
-0
lines changed

16 files changed

+1474
-0
lines changed

hiero-sdk-rust

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit f45e3cdd1dd0a531f7f23dae89eaaee289a26808

protobufs/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ fn main() -> anyhow::Result<()> {
145145
.extern_path(".proto.TopicID", "crate::services::TopicId")
146146
.extern_path(".proto.FileID", "crate::services::FileId")
147147
.extern_path(".proto.NodeAddress", "crate::services::NodeAddress")
148+
.extern_path(".proto.Transaction", "crate::services::Transaction")
148149
.extern_path(
149150
".proto.ConsensusMessageChunkInfo",
150151
"crate::services::ConsensusMessageChunkInfo",

protobufs/mirror/fee.proto

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
syntax = "proto3";
4+
5+
package com.hedera.mirror.api.proto;
6+
option java_package = "com.hedera.mirror.api.proto";
7+
8+
// Transaction type is available via the services proto compilation
9+
10+
/**
11+
* Determines whether the fee estimation depends on network state (e.g., whether an account exists or requires creation
12+
* during a transfer).
13+
*/
14+
enum EstimateMode {
15+
/*
16+
* Estimate based on intrinsic properties plus the latest known state (e.g., check if accounts
17+
* exist, load token associations). This is the default if no mode is specified.
18+
*/
19+
STATE = 0;
20+
21+
/*
22+
* Estimate based solely on the transaction's inherent properties (e.g., size, signatures, keys). Ignores
23+
* state-dependent factors.
24+
*/
25+
INTRINSIC = 1;
26+
}
27+
28+
/**
29+
* Request object for users, SDKs, and tools to query expected fees without
30+
* submitting transactions to the network.
31+
*/
32+
message FeeEstimateQuery {
33+
/**
34+
* The mode of fee estimation. Defaults to `STATE` if omitted.
35+
*/
36+
EstimateMode mode = 1;
37+
38+
/**
39+
* The raw HAPI transaction that should be estimated.
40+
*/
41+
.proto.Transaction transaction = 2;
42+
}
43+
44+
/**
45+
* The response containing the estimated transaction fees.
46+
*/
47+
message FeeEstimateResponse {
48+
/**
49+
* The mode that was used to calculate the fees.
50+
*/
51+
EstimateMode mode = 1;
52+
53+
/**
54+
* The network fee component which covers the cost of gossip, consensus,
55+
* signature verifications, fee payment, and storage.
56+
*/
57+
NetworkFee network = 2;
58+
59+
/**
60+
* The node fee component which is to be paid to the node that submitted the
61+
* transaction to the network. This fee exists to compensate the node for the
62+
* work it performed to pre-check the transaction before submitting it, and
63+
* incentivizes the node to accept new transactions from users.
64+
*/
65+
FeeEstimate node = 3;
66+
67+
/**
68+
* An array of strings for any caveats (e.g., ["Fallback to worst-case due to missing state"]).
69+
*/
70+
repeated string notes = 4;
71+
72+
/**
73+
* The service fee component which covers execution costs, state saved in the
74+
* Merkle tree, and additional costs to the blockchain storage.
75+
*/
76+
FeeEstimate service = 5;
77+
78+
/**
79+
* The sum of the network, node, and service subtotals in tinycents.
80+
*/
81+
uint64 total = 6;
82+
}
83+
84+
/**
85+
* The fee estimate for the network component. Includes the base fee and any
86+
* extras associated with it.
87+
*/
88+
message FeeEstimate {
89+
/**
90+
* The base fee price, in tinycents.
91+
*/
92+
uint64 base = 1;
93+
94+
/**
95+
* The extra fees that apply for this fee component.
96+
*/
97+
repeated FeeExtra extras = 2;
98+
}
99+
100+
/**
101+
* The extra fee charged for the transaction.
102+
*/
103+
message FeeExtra {
104+
/**
105+
* The charged count of items as calculated by `max(0, count - included)`.
106+
*/
107+
uint32 charged = 1;
108+
109+
/**
110+
* The actual count of items received.
111+
*/
112+
uint32 count = 2;
113+
114+
/**
115+
* The fee price per unit in tinycents.
116+
*/
117+
uint64 fee_per_unit = 3;
118+
119+
/**
120+
* The count of this "extra" that is included for free.
121+
*/
122+
uint32 included = 4;
123+
124+
/**
125+
* The unique name of this extra fee as defined in the fee schedule.
126+
*/
127+
string name = 5;
128+
129+
/**
130+
* The subtotal in tinycents for this extra fee. Calculated by multiplying the
131+
* charged count by the fee_per_unit.
132+
*/
133+
uint64 subtotal = 6;
134+
}
135+
136+
/**
137+
* The network fee component which covers the cost of gossip, consensus,
138+
* signature verifications, fee payment, and storage.
139+
*/
140+
message NetworkFee {
141+
/**
142+
* Multiplied by the node fee to determine the total network fee.
143+
*/
144+
uint32 multiplier = 1;
145+
146+
/**
147+
* The subtotal in tinycents for the network fee component which is calculated by
148+
* multiplying the node subtotal by the network multiplier.
149+
*/
150+
uint64 subtotal = 2;
151+
}

protobufs/mirror/mirror_network_service.proto

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ option java_package = "com.hedera.mirror.api.proto";
2727

2828
import "services/basic_types.proto";
2929
import "services/timestamp.proto";
30+
import "services/transaction.proto";
3031

3132
/**
3233
* Request object to query an address book for its list of nodes
@@ -43,6 +44,149 @@ message AddressBookQuery {
4344
int32 limit = 2;
4445
}
4546

47+
/**
48+
* Determines whether the fee estimation depends on network state (e.g., whether an account exists or requires creation
49+
* during a transfer).
50+
*/
51+
enum EstimateMode {
52+
/*
53+
* Estimate based on intrinsic properties plus the latest known state (e.g., check if accounts
54+
* exist, load token associations). This is the default if no mode is specified.
55+
*/
56+
STATE = 0;
57+
58+
/*
59+
* Estimate based solely on the transaction's inherent properties (e.g., size, signatures, keys). Ignores
60+
* state-dependent factors.
61+
*/
62+
INTRINSIC = 1;
63+
}
64+
65+
/**
66+
* Request object for users, SDKs, and tools to query expected fees without
67+
* submitting transactions to the network.
68+
*/
69+
message FeeEstimateQuery {
70+
/**
71+
* The mode of fee estimation. Defaults to `STATE` if omitted.
72+
*/
73+
EstimateMode mode = 1;
74+
75+
/**
76+
* The raw HAPI transaction that should be estimated.
77+
*/
78+
.proto.Transaction transaction = 2;
79+
}
80+
81+
/**
82+
* The response containing the estimated transaction fees.
83+
*/
84+
message FeeEstimateResponse {
85+
/**
86+
* The mode that was used to calculate the fees.
87+
*/
88+
EstimateMode mode = 1;
89+
90+
/**
91+
* The network fee component which covers the cost of gossip, consensus,
92+
* signature verifications, fee payment, and storage.
93+
*/
94+
NetworkFee network = 2;
95+
96+
/**
97+
* The node fee component which is to be paid to the node that submitted the
98+
* transaction to the network. This fee exists to compensate the node for the
99+
* work it performed to pre-check the transaction before submitting it, and
100+
* incentivizes the node to accept new transactions from users.
101+
*/
102+
FeeEstimate node = 3;
103+
104+
/**
105+
* An array of strings for any caveats (e.g., ["Fallback to worst-case due to missing state"]).
106+
*/
107+
repeated string notes = 4;
108+
109+
/**
110+
* The service fee component which covers execution costs, state saved in the
111+
* Merkle tree, and additional costs to the blockchain storage.
112+
*/
113+
FeeEstimate service = 5;
114+
115+
/**
116+
* The sum of the network, node, and service subtotals in tinycents.
117+
*/
118+
uint64 total = 6;
119+
}
120+
121+
/**
122+
* The fee estimate for the network component. Includes the base fee and any
123+
* extras associated with it.
124+
*/
125+
message FeeEstimate {
126+
/**
127+
* The base fee price, in tinycents.
128+
*/
129+
uint64 base = 1;
130+
131+
/**
132+
* The extra fees that apply for this fee component.
133+
*/
134+
repeated FeeExtra extras = 2;
135+
}
136+
137+
/**
138+
* The extra fee charged for the transaction.
139+
*/
140+
message FeeExtra {
141+
/**
142+
* The charged count of items as calculated by `max(0, count - included)`.
143+
*/
144+
uint32 charged = 1;
145+
146+
/**
147+
* The actual count of items received.
148+
*/
149+
uint32 count = 2;
150+
151+
/**
152+
* The fee price per unit in tinycents.
153+
*/
154+
uint64 fee_per_unit = 3;
155+
156+
/**
157+
* The count of this "extra" that is included for free.
158+
*/
159+
uint32 included = 4;
160+
161+
/**
162+
* The unique name of this extra fee as defined in the fee schedule.
163+
*/
164+
string name = 5;
165+
166+
/**
167+
* The subtotal in tinycents for this extra fee. Calculated by multiplying the
168+
* charged count by the fee_per_unit.
169+
*/
170+
uint64 subtotal = 6;
171+
}
172+
173+
/**
174+
* The network fee component which covers the cost of gossip, consensus,
175+
* signature verifications, fee payment, and storage.
176+
*/
177+
message NetworkFee {
178+
/**
179+
* Multiplied by the node fee to determine the total network fee.
180+
*/
181+
uint32 multiplier = 1;
182+
183+
/**
184+
* The subtotal in tinycents for the network fee component which is calculated by
185+
* multiplying the node subtotal by the network multiplier.
186+
*/
187+
uint64 subtotal = 2;
188+
}
189+
46190
/**
47191
* Provides cross network APIs like address book queries
48192
*/
@@ -53,5 +197,11 @@ service NetworkService {
53197
* the network since it is reconstructed from a normalized database table.
54198
*/
55199
rpc getNodes (AddressBookQuery) returns (stream .proto.NodeAddress);
200+
201+
/*
202+
* Query for fee estimates without submitting transactions to the network.
203+
* Returns a stream with a single FeeEstimateResponse.
204+
*/
205+
rpc getFeeEstimate (FeeEstimateQuery) returns (stream FeeEstimateResponse);
56206
}
57207

src/fee_estimate/fee_estimate.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
use crate::fee_estimate::fee_extra::FeeExtra;
4+
5+
/// The fee estimate for a specific component (node or service).
6+
#[derive(Debug, Clone, PartialEq, Eq)]
7+
pub struct FeeEstimate {
8+
/// The base fee price, in tinycents.
9+
pub base: u64,
10+
/// The extra fees that apply for this fee component.
11+
pub extras: Vec<FeeExtra>,
12+
}
13+
14+
impl FeeEstimate {
15+
/// Create a new `FeeEstimate`.
16+
pub fn new(base: u64, extras: Vec<FeeExtra>) -> Self {
17+
Self { base, extras }
18+
}
19+
}
20+

0 commit comments

Comments
 (0)