Skip to content

Commit 478cd57

Browse files
authored
feat: add ScheduleInfoQuery (#354)
* feat: implement ScheduleInfo Signed-off-by: dosi <[email protected]> * feat: implement ScheduleInfoQuery Signed-off-by: dosi <[email protected]> * test: update schedule create integration tests Signed-off-by: dosi <[email protected]> * test: add ScheduleInfoQuery integration tests Signed-off-by: dosi <[email protected]> * test: add schedule info query unit tests Signed-off-by: dosi <[email protected]> * test: add schedule info unit tests Signed-off-by: dosi <[email protected]> * docs: add schedule info query example Signed-off-by: dosi <[email protected]> * docs: add ScheduleInfoQuery in running_examples Signed-off-by: dosi <[email protected]> * chore: add ScheduleInfo and ScheduleInfoQuery to __init__.py Signed-off-by: dosi <[email protected]> * chore: update changelog Signed-off-by: dosi <[email protected]> --------- Signed-off-by: dosi <[email protected]>
1 parent 68a6951 commit 478cd57

File tree

10 files changed

+1198
-1
lines changed

10 files changed

+1198
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
1010
- Convert camelCase to snake_case in integration tests (#318)
1111

1212
### Added
13+
- ScheduleInfoQuery class
14+
- ScheduleInfo class
1315
- Exposed node_id property in `TransactionReceipt`
1416
- NodeCreateTransaction class
1517
- ScheduleId() class

docs/sdk_users/running_examples.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ You can choose either syntax or even mix both styles in your projects.
6767
- [Executing Ethereum Transactions](#executing-ethereum-transactions)
6868
- [Schedule Transactions](#schedule-transactions)
6969
- [Creating a Schedule](#creating-a-schedule)
70+
- [Querying Schedule Info](#querying-schedule-info)
7071
- [Node Transactions](#node-transactions)
7172
- [Creating a Node](#creating-a-node)
7273
- [Miscellaneous Queries](#miscellaneous-queries)
@@ -1619,6 +1620,25 @@ receipt = (
16191620
)
16201621
```
16211622

1623+
### Querying Schedule Info
1624+
1625+
#### Pythonic Syntax:
1626+
```python
1627+
schedule_info_query = ScheduleInfoQuery(schedule_id=schedule_id)
1628+
schedule_info = schedule_info_query.execute(client)
1629+
print(schedule_info)
1630+
```
1631+
1632+
#### Method Chaining:
1633+
```python
1634+
schedule_info = (
1635+
ScheduleInfoQuery()
1636+
.set_schedule_id(schedule_id)
1637+
.execute(client)
1638+
)
1639+
print(schedule_info)
1640+
```
1641+
16221642
## Node Transactions
16231643

16241644
### Creating a Node

examples/query_schedule_info.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
"""
2+
Example demonstrating schedule info query on the network.
3+
"""
4+
5+
import datetime
6+
import os
7+
import sys
8+
9+
from dotenv import load_dotenv
10+
11+
from hiero_sdk_python import AccountId, Client, Hbar, Network, PrivateKey
12+
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
13+
from hiero_sdk_python.response_code import ResponseCode
14+
from hiero_sdk_python.schedule.schedule_info_query import ScheduleInfoQuery
15+
from hiero_sdk_python.timestamp import Timestamp
16+
from hiero_sdk_python.transaction.transfer_transaction import TransferTransaction
17+
18+
load_dotenv()
19+
20+
21+
def setup_client():
22+
"""Initialize and set up the client with operator account"""
23+
network = Network(network="testnet")
24+
client = Client(network)
25+
26+
operator_id = AccountId.from_string(os.getenv("OPERATOR_ID"))
27+
operator_key = PrivateKey.from_string(os.getenv("OPERATOR_KEY"))
28+
client.set_operator(operator_id, operator_key)
29+
30+
return client
31+
32+
33+
def create_account(client):
34+
"""Create a test account"""
35+
account_private_key = PrivateKey.generate_ed25519()
36+
account_public_key = account_private_key.public_key()
37+
38+
receipt = (
39+
AccountCreateTransaction()
40+
.set_key(account_public_key)
41+
.set_initial_balance(Hbar(2))
42+
.set_account_memo("Test account for schedule")
43+
.freeze_with(client)
44+
.sign(account_private_key)
45+
.execute(client)
46+
)
47+
48+
if receipt.status != ResponseCode.SUCCESS:
49+
print(f"Account creation failed with status: {ResponseCode(receipt.status).name}")
50+
sys.exit(1)
51+
52+
account_id = receipt.account_id
53+
print(f"\nAccount created with ID: {account_id}")
54+
55+
return account_id, account_private_key
56+
57+
58+
def create_schedule(client, account_id, account_private_key):
59+
"""Create a scheduled transaction"""
60+
# Amount to transfer in tinybars
61+
amount = Hbar(1).to_tinybars()
62+
63+
# Create a transfer transaction
64+
transfer_tx = (
65+
TransferTransaction()
66+
.add_hbar_transfer(account_id, -amount)
67+
.add_hbar_transfer(client.operator_account_id, amount)
68+
)
69+
70+
# Convert the transfer transaction into a scheduled transaction
71+
schedule_tx = transfer_tx.schedule()
72+
73+
# Set expiration time for the scheduled transaction (90 seconds from now)
74+
expiration_time = datetime.datetime.now() + datetime.timedelta(seconds=90)
75+
76+
receipt = (
77+
schedule_tx.set_payer_account_id(
78+
client.operator_account_id
79+
) # payer of the transaction fee
80+
.set_admin_key(
81+
client.operator_private_key.public_key()
82+
) # delete/modify the transaction
83+
.set_expiration_time(Timestamp.from_date(expiration_time))
84+
.freeze_with(client)
85+
.sign(
86+
account_private_key
87+
) # sign with the account private key as it transfers money
88+
.execute(client)
89+
)
90+
91+
if receipt.status != ResponseCode.SUCCESS:
92+
print(
93+
f"Schedule creation failed with status: {ResponseCode(receipt.status).name}"
94+
)
95+
sys.exit(1)
96+
97+
print(f"Schedule created with ID: {receipt.schedule_id}")
98+
99+
return receipt.schedule_id
100+
101+
102+
def query_schedule_info():
103+
"""
104+
Demonstrates querying a schedule info by:
105+
1. Setting up client with operator account
106+
2. Creating a test account
107+
3. Creating a scheduled transaction
108+
4. Querying the schedule info
109+
"""
110+
client = setup_client()
111+
112+
# Create an account first
113+
account_id, account_private_key = create_account(client)
114+
115+
# Create a schedule
116+
schedule_id = create_schedule(client, account_id, account_private_key)
117+
118+
# Query the schedule info
119+
info = ScheduleInfoQuery().set_schedule_id(schedule_id).execute(client)
120+
121+
print("\nSchedule Info:")
122+
print(f"Schedule ID: {info.schedule_id}")
123+
print(f"Creator Account ID: {info.creator_account_id}")
124+
print(f"Payer Account ID: {info.payer_account_id}")
125+
print(f"Deleted At: {info.deleted_at}")
126+
print(f"Executed At: {info.executed_at}")
127+
print(f"Expiration Time: {info.expiration_time}")
128+
print(f"Scheduled Transaction ID: {info.scheduled_transaction_id}")
129+
print(f"Schedule Memo: {info.schedule_memo}")
130+
print(f"Admin Key: {info.admin_key}")
131+
print(f"Signers: {len(info.signers)} signer(s)")
132+
for i, signer in enumerate(info.signers):
133+
print(f" Signer {i+1}: {signer}")
134+
print(f"Ledger ID: {info.ledger_id}")
135+
print(f"Wait For Expiry: {info.wait_for_expiry}")
136+
137+
# Alternative print
138+
# print("\nSchedule Info:")
139+
# print(info)
140+
141+
142+
if __name__ == "__main__":
143+
query_schedule_info()

src/hiero_sdk_python/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
# Schedule
111111
from .schedule.schedule_create_transaction import ScheduleCreateTransaction
112112
from .schedule.schedule_id import ScheduleId
113+
from .schedule.schedule_info import ScheduleInfo
114+
from .schedule.schedule_info_query import ScheduleInfoQuery
113115

114116
# Nodes
115117
from .nodes.node_create_transaction import NodeCreateTransaction
@@ -223,6 +225,8 @@
223225
# Schedule
224226
"ScheduleCreateTransaction",
225227
"ScheduleId",
228+
"ScheduleInfoQuery",
229+
"ScheduleInfo",
226230

227231
# Nodes
228232
"NodeCreateTransaction",

0 commit comments

Comments
 (0)