Skip to content

Commit 71df1cd

Browse files
authored
chore: Created examples/account_info.py (#804)
Signed-off-by: nikhil-nari <[email protected]>
1 parent 67973bf commit 71df1cd

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
1313
- Added missing validation logic `fee_schedule_key` in integration `token_create_transaction_e2e_test.py` and ``token_update_transaction_e2e_test.py`.
1414
- Add `account_balance_query.py` example to demonstrate how to use the CryptoGetAccountBalanceQuery class.
1515
- Add `examples/token_create_transaction_admin_key.py` demonstrating admin key privileges for token management including token updates, key changes, and deletion (#798)
16-
16+
- Add `examples/account_info.py` to demonstrate `AccountInfo` opeartions
1717

1818
### Changed
1919
- Refactored token-related example scripts (`token_delete.py`, `token_dissociate.py`, etc.) for improved readability and modularity. [#370]

examples/account_info.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from hiero_sdk_python.account.account_id import AccountId
2+
from hiero_sdk_python.crypto.private_key import PrivateKey
3+
from hiero_sdk_python.crypto.public_key import PublicKey
4+
from hiero_sdk_python.hbar import Hbar
5+
from hiero_sdk_python.timestamp import Timestamp
6+
from hiero_sdk_python.Duration import Duration
7+
from hiero_sdk_python.tokens.token_id import TokenId
8+
from hiero_sdk_python.tokens.token_relationship import TokenRelationship
9+
from hiero_sdk_python.account.account_info import AccountInfo
10+
11+
def create_mock_account_id() -> AccountId:
12+
"""Create a mock AccountId."""
13+
return AccountId.from_string("0.0.1234")
14+
15+
def create_mock_public_key() -> PublicKey:
16+
"""Generate a random ED25519 public key for demonstration."""
17+
private_key_demo = PrivateKey.generate_ecdsa()
18+
public_key_demo = private_key_demo.public_key()
19+
return public_key_demo
20+
21+
def create_mock_balance() -> Hbar:
22+
"""Return a mock account balance."""
23+
return Hbar(100)
24+
25+
def create_mock_expiration_time() -> Timestamp:
26+
"""Return a sample expiration timestamp (arbitrary future date)."""
27+
return Timestamp(seconds=1736539200,nanos=100)
28+
29+
def create_mock_auto_renew_period() -> Duration:
30+
"""Return a 90-day auto-renew period."""
31+
return Duration(seconds=7776000)
32+
33+
def create_mock_token_relationship() -> TokenRelationship:
34+
"""Create a sample token relationship with a mock token."""
35+
token_id = TokenId.from_string("0.0.9999")
36+
return TokenRelationship(token_id=token_id, balance=50)
37+
38+
def build_mock_account_info() -> AccountInfo:
39+
"""Construct a complete AccountInfo instance manually (no network calls)."""
40+
info = AccountInfo()
41+
info.account_id = create_mock_account_id()
42+
info.key = create_mock_public_key()
43+
info.balance = create_mock_balance()
44+
info.expiration_time = create_mock_expiration_time()
45+
info.auto_renew_period = create_mock_auto_renew_period()
46+
info.token_relationships = [create_mock_token_relationship()]
47+
info.account_memo = "Mock Account for Example"
48+
return info
49+
50+
def print_account_info(info: AccountInfo) -> None:
51+
"""Pretty-print key AccountInfo fields."""
52+
print("📜 AccountInfo Example (Mock Data)")
53+
print(f"Account ID: {info.account_id}")
54+
print(f"Key: {info.key}")
55+
print(f"Balance: {info.balance}")
56+
print(f"Expiration Time: {info.expiration_time}")
57+
print(f"Auto Renew Period: {info.auto_renew_period}")
58+
print(f"Token Relationships: {info.token_relationships}")
59+
print(f"Memo: {info.account_memo}")
60+
61+
def main():
62+
"""Run the AccountInfo example."""
63+
info = build_mock_account_info()
64+
print_account_info(info)
65+
66+
if __name__ == "__main__":
67+
main()

0 commit comments

Comments
 (0)