Skip to content

Commit 2bb8f80

Browse files
committed
Feat: implemented GetAccInfo, TCK endpt.
Signed-off-by: Adityarya11 <arya050411@gmail.com>
1 parent c0d2625 commit 2bb8f80

3 files changed

Lines changed: 122 additions & 6 deletions

File tree

tck/handlers/account.py

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
22
from hiero_sdk_python.account.account_id import AccountId
3+
from hiero_sdk_python.query.account_info_query import AccountInfoQuery
34
from hiero_sdk_python.hbar import Hbar
45
from hiero_sdk_python.response_code import ResponseCode
56
from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt
67
from tck.handlers.registry import rpc_method
7-
from tck.param.account import CreateAccountParams
8-
from tck.response.account import CreateAccountResponse
8+
from tck.param.account import CreateAccountParams, GetAccountInfoParams
9+
from tck.response.account import (
10+
CreateAccountResponse,
11+
GetAccountInfoResponse,
12+
StakingInfoResponse,
13+
TokenRelationshipResponse,
14+
)
915
from tck.util.client_utils import get_client
1016
from tck.util.constants import DEFAULT_GRPC_TIMEOUT
1117
from tck.util.key_utils import get_key_from_string
@@ -24,9 +30,7 @@ def _build_create_account_transaction(params: CreateAccountParams) -> AccountCre
2430
transaction.set_receiver_signature_required(params.receiverSignatureRequired)
2531

2632
if params.maxAutoTokenAssociations is not None:
27-
transaction.set_max_automatic_token_associations(
28-
params.maxAutoTokenAssociations
29-
)
33+
transaction.set_max_automatic_token_associations(params.maxAutoTokenAssociations)
3034

3135
if params.stakedAccountId is not None:
3236
transaction.set_staked_account_id(AccountId.from_string(params.stakedAccountId))
@@ -66,3 +70,66 @@ def create_account(params: CreateAccountParams) -> CreateAccountResponse:
6670
account_id = str(receipt.account_id)
6771

6872
return CreateAccountResponse(account_id, ResponseCode(receipt.status).name)
73+
74+
75+
def _build_account_info_response(info) -> GetAccountInfoResponse:
76+
staking_info_response = None
77+
if info.staking_info:
78+
staking_info_response = StakingInfoResponse(
79+
declineStakingReward=info.staking_info.decline_staking_reward,
80+
stakePeriodStart=str(info.staking_info.stake_period_start)
81+
if info.staking_info.stake_period_start
82+
else None,
83+
pendingReward=str(info.staking_info.pending_reward.to_tinybars())
84+
if info.staking_info.pending_reward
85+
else None,
86+
stakedToMe=str(info.staking_info.staked_to_me.to_tinybars()) if info.staking_info.staked_to_me else None,
87+
stakedAccountId=str(info.staking_info.staked_account_id) if info.staking_info.staked_account_id else None,
88+
stakedNodeId=str(info.staking_info.staked_node_id) if info.staking_info.staked_node_id else None,
89+
)
90+
91+
token_relationships_response = []
92+
if info.token_relationships:
93+
for rel in info.token_relationships:
94+
token_relationships_response.append(
95+
TokenRelationshipResponse(
96+
tokenId=str(rel.token_id) if rel.token_id else None,
97+
symbol=rel.symbol,
98+
balance=str(rel.balance) if rel.balance is not None else None,
99+
kycStatus=str(rel.kyc_status) if rel.kyc_status is not None else None,
100+
freezeStatus=str(rel.freeze_status) if rel.freeze_status is not None else None,
101+
decimals=str(rel.decimals) if rel.decimals is not None else None,
102+
automaticAssociation=rel.automatic_association,
103+
)
104+
)
105+
106+
return GetAccountInfoResponse(
107+
accountId=str(info.account_id) if info.account_id else None,
108+
contractAccountId=info.contract_account_id,
109+
isDeleted=info.is_deleted,
110+
proxyReceived=str(info.proxy_received.to_tinybars()) if info.proxy_received else None,
111+
key=info.key.to_bytes().hex() if info.key else None,
112+
balance=str(info.balance.to_tinybars()) if info.balance else None,
113+
isReceiverSignatureRequired=info.receiver_signature_required,
114+
expirationTime=str(info.expiration_time) if info.expiration_time else None,
115+
autoRenewPeriod=str(info.auto_renew_period.seconds) if info.auto_renew_period else None,
116+
tokenRelationships=token_relationships_response if token_relationships_response else None,
117+
accountMemo=info.account_memo,
118+
ownedNfts=str(info.owned_nfts) if info.owned_nfts is not None else None,
119+
maxAutomaticTokenAssociations=str(info.max_automatic_token_associations)
120+
if info.max_automatic_token_associations is not None
121+
else None,
122+
stakingInfo=staking_info_response,
123+
)
124+
125+
126+
@rpc_method("getAccountInfo")
127+
def get_account_info(params: GetAccountInfoParams) -> GetAccountInfoResponse:
128+
client = get_client(params.sessionId)
129+
130+
query = AccountInfoQuery()
131+
if params.accountId:
132+
query.set_account_id(AccountId.from_string(params.accountId))
133+
134+
info = query.execute(client)
135+
return _build_account_info_response(info)

tck/param/account.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22

3-
from tck.param.base import BaseTransactionParams
3+
from tck.param.base import BaseParams, BaseTransactionParams
44
from tck.util.param_utils import (
55
parse_common_transaction_params,
66
parse_session_id,
@@ -38,3 +38,12 @@ def parse_json_params(cls, params: dict) -> "CreateAccountParams":
3838
sessionId=parse_session_id(params),
3939
commonTransactionParams=parse_common_transaction_params(params),
4040
)
41+
42+
43+
@dataclass
44+
class GetAccountInfoParams(BaseParams):
45+
accountId: str | None = None
46+
47+
@classmethod
48+
def parse_json_params(cls, params: dict) -> "GetAccountInfoParams":
49+
return cls(accountId=params.get("accountId"), sessionId=parse_session_id(params))

tck/response/account.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
11
from dataclasses import dataclass
2+
from typing import List, Optional
23

34

45
@dataclass
56
class CreateAccountResponse:
67
accountId: str | None = None
78
status: str | None = None
9+
10+
11+
@dataclass
12+
class StakingInfoResponse:
13+
declineStakingReward: bool | None = None
14+
stakePeriodStart: str | None = None
15+
pendingReward: str | None = None
16+
stakedToMe: str | None = None
17+
stakedAccountId: str | None = None
18+
stakedNodeId: str | None = None
19+
20+
21+
@dataclass
22+
class TokenRelationshipResponse:
23+
tokenId: str | None = None
24+
symbol: str | None = None
25+
balance: str | None = None
26+
kycStatus: str | None = None
27+
freezeStatus: str | None = None
28+
decimals: str | None = None
29+
automaticAssociation: bool | None = None
30+
31+
32+
@dataclass
33+
class GetAccountInfoResponse:
34+
accountId: str | None = None
35+
contractAccountId: str | None = None
36+
isDeleted: bool | None = None
37+
proxyReceived: str | None = None
38+
key: str | None = None
39+
balance: str | None = None
40+
isReceiverSignatureRequired: bool | None = None
41+
expirationTime: str | None = None
42+
autoRenewPeriod: str | None = None
43+
tokenRelationships: List[TokenRelationshipResponse] | None = None
44+
accountMemo: str | None = None
45+
ownedNfts: str | None = None
46+
maxAutomaticTokenAssociations: str | None = None
47+
stakingInfo: StakingInfoResponse | None = None

0 commit comments

Comments
 (0)