-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathaccount_info_query.py
More file actions
132 lines (97 loc) · 4.24 KB
/
Copy pathaccount_info_query.py
File metadata and controls
132 lines (97 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from __future__ import annotations
import logging
from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.account.account_info import AccountInfo
from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.executable import _Method
from hiero_sdk_python.hapi.services import crypto_get_info_pb2, query_pb2
from hiero_sdk_python.query.query import Query
logger = logging.getLogger(__name__)
class AccountInfoQuery(Query):
"""
A query to retrieve information about a specific Account.
This class constructs and executes a query to retrieve information
about an account on the network, including the account's properties
and settings.
"""
def __init__(self, account_id: AccountId | None = None):
"""
Initializes a new AccountInfoQuery instance with an optional account_id.
Args:
account_id (AccountId, optional): The ID of the account to query.
"""
super().__init__()
self.account_id: AccountId | None = account_id
def set_account_id(self, account_id: AccountId):
"""
Sets the ID of the account to query.
Args:
account_id (AccountId): The ID of the account.
Returns:
AccountInfoQuery: Returns self for method chaining.
"""
self.account_id = account_id
return self
def _make_request(self):
"""
Constructs the protobuf request for the query.
Builds a CryptoGetInfoQuery protobuf message with the
appropriate header and account ID.
Returns:
Query: The protobuf query message.
Raises:
Exception: If any other error occurs during request construction.
"""
try:
query_header = self._make_request_header()
crypto_info_query = crypto_get_info_pb2.CryptoGetInfoQuery()
crypto_info_query.header.CopyFrom(query_header)
if self.account_id is not None:
crypto_info_query.accountID.CopyFrom(self.account_id._to_proto())
query = query_pb2.Query()
query.cryptoGetInfo.CopyFrom(crypto_info_query)
return query
except Exception as e:
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise
def _get_method(self, channel: _Channel) -> _Method:
"""
Returns the appropriate gRPC method for the account info query.
Implements the abstract method from Query to provide the specific
gRPC method for getting account information.
Args:
channel (_Channel): The channel containing service stubs
Returns:
_Method: The method wrapper containing the query function
"""
return _Method(transaction_func=None, query_func=channel.crypto.getAccountInfo)
def execute(self, client, timeout: int | float | None = None):
"""
Executes the account info query.
Sends the query to the Hedera network and processes the response
to return an AccountInfo object.
This function delegates the core logic to `_execute()`, and may propagate exceptions raised by it.
Args:
client (Client): The client instance to use for execution
timeout (int | float, optional): The total execution timeout (in seconds) for this execution.
Returns:
AccountInfo: The account info from the network
Raises:
PrecheckError: If the query fails with a non-retryable error
MaxAttemptsError: If the query fails after the maximum number of attempts
ReceiptStatusError: If the query fails with a receipt status error
"""
self._before_execute(client)
response = self._execute(client, timeout)
return AccountInfo._from_proto(response.cryptoGetInfo.accountInfo)
def _get_query_response(self, response):
"""
Extracts the account info response from the full response.
Implements the abstract method from Query to extract the
specific account info response object.
Args:
response: The full response from the network
Returns:
The crypto get info response object
"""
return response.cryptoGetInfo