Skip to content

Commit cee7d2b

Browse files
docs: align Query examples with SDK implementation
Signed-off-by: undefinedIsMyLife <[email protected]>
1 parent d879703 commit cee7d2b

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

docs/sdk_developers/query.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,34 +271,46 @@ Below is a complete implementation of a simple query to retrieve an account bala
271271

272272
```python
273273
from hiero_sdk_python.query.query import Query
274-
from hiero_sdk_python.hapi.services import query_pb2, crypto_get_account_balance_pb2
274+
from hiero_sdk_python.hapi.services import (
275+
query_pb2,
276+
crypto_get_account_balance_pb2,
277+
)
278+
from hiero_sdk_python.executable import _Method
275279
from hiero_sdk_python.hbar import Hbar
276280

277-
class AccountBalanceQuery(Query):
281+
282+
class CryptoGetAccountBalanceQuery(Query):
283+
"""
284+
Example showing how a Query subclass is structured.
285+
"""
286+
278287
def __init__(self, account_id):
279288
super().__init__()
280289
self.account_id = account_id
281290

282-
# Required method: build the Protobuf request
283291
def _make_request(self):
292+
if not self.account_id:
293+
raise ValueError("Account ID must be set")
294+
284295
header = self._make_request_header()
285-
body = crypto_get_account_balance_pb2.CryptoGetAccountBalanceQuery(
286-
header=header,
287-
accountID=self.account_id._to_proto()
288-
)
289-
return query_pb2.Query(cryptoGetAccountBalance=body)
290296

291-
# Required method: extract the query response
297+
body = crypto_get_account_balance_pb2.CryptoGetAccountBalanceQuery()
298+
body.header.CopyFrom(header)
299+
body.accountID.CopyFrom(self.account_id._to_proto())
300+
301+
query = query_pb2.Query()
302+
query.cryptogetAccountBalance.CopyFrom(body)
303+
return query
304+
292305
def _get_query_response(self, response):
293-
return response.cryptoGetAccountBalance
306+
return response.cryptogetAccountBalance
294307

295-
# Required method: specify the gRPC method to call
296308
def _get_method(self, channel):
297-
return _Method(query_func=channel.crypto.get_account_balance)
309+
return _Method(
310+
transaction_func=None,
311+
query_func=channel.crypto.cryptoGetBalance,
312+
)
298313

299-
# Optional helper: set a custom query payment
300-
def set_custom_payment(self, amount: Hbar):
301-
self.set_query_payment(amount)
302314
```
303315

304316
### Usage Example
@@ -393,11 +405,10 @@ The SDK includes several production-ready query implementations that demonstrate
393405

394406
- `examples/query/account_balance_query.py` — Simple query with minimal configuration
395407
- `examples/query/account_info_query.py` — Paid query with structured response
396-
- `examples/query/token_info_query.py` — Token metadata query
397-
- `examples/query/token_nft_info_query.py` — NFT-specific token query
398-
- `examples/query/topic_info_query.py` — Consensus topic metadata
399-
- `examples/query/topic_message_query.py` — Streaming-style topic message retrieval
400-
- `examples/query/transaction_receipt_query.py` — Transaction receipt lookup
408+
- `examples/query/token_info_query.py` — Fungible token metadata
409+
- `examples/query/token_nft_info_query.py` — NFT token metadata
410+
- `examples/query/topic_info_query.py` — Streaming-style topic message retrieval
411+
- `examples/query/transaction_get_receipt_query.py` — Transaction receipt lookup
401412
- `examples/query/transaction_record_query.py` — Transaction record retrieval
402413

403414
These examples illustrate consistent usage of `_make_request()`, `_get_query_response()`, and `_get_method()` without duplicating execution or payment logic.

0 commit comments

Comments
 (0)