Skip to content

Commit 3759cb1

Browse files
committed
chore: added ruff formating to examples
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 927b5f0 commit 3759cb1

134 files changed

Lines changed: 698 additions & 1602 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/account/account_allowance_approve_transaction_hbar.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Hedera allowance documentation. This example focuses solely on HBAR
3131
allowances and does not demonstrate revoking allowances or token/NFT usage.
3232
"""
33+
3334
import os
3435
import sys
3536

@@ -75,10 +76,7 @@ def create_account(client: Client):
7576
)
7677

7778
if account_receipt.status != ResponseCode.SUCCESS:
78-
print(
79-
"Account creation failed with status: "
80-
f"{ResponseCode(account_receipt.status).name}"
81-
)
79+
print(f"Account creation failed with status: {ResponseCode(account_receipt.status).name}")
8280
sys.exit(1)
8381

8482
account_account_id = account_receipt.account_id
@@ -100,10 +98,7 @@ def approve_hbar_allowance(
10098
)
10199

102100
if receipt.status != ResponseCode.SUCCESS:
103-
print(
104-
"Hbar allowance approval failed with status: "
105-
f"{ResponseCode(receipt.status).name}"
106-
)
101+
print(f"Hbar allowance approval failed with status: {ResponseCode(receipt.status).name}")
107102
sys.exit(1)
108103

109104
print(f"Hbar allowance of {amount} approved for spender {spender_account_id}")
@@ -134,10 +129,7 @@ def transfer_hbar_with_allowance(
134129
print(f"Hbar transfer failed with status: {ResponseCode(receipt.status).name}")
135130
sys.exit(1)
136131

137-
print(
138-
f"Successfully transferred {amount} from {owner_account_id} "
139-
f"to {receiver_account_id} using allowance"
140-
)
132+
print(f"Successfully transferred {amount} from {owner_account_id} to {receiver_account_id} using allowance")
141133

142134
return receipt
143135

examples/account/account_allowance_approve_transaction_nft.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Usage:
2929
uv run examples/account/account_allowance_approve_transaction_nft.py
3030
"""
31+
3132
import os
3233
import sys
3334

@@ -129,21 +130,14 @@ def create_nft_token(client, owner_id, owner_key):
129130

130131
def mint_nft(client, token_id, metadata_list):
131132
"""Mint NFT(s) with metadata."""
132-
tx = (
133-
TokenMintTransaction()
134-
.set_token_id(token_id)
135-
.set_metadata(metadata_list)
136-
.execute(client)
137-
)
133+
tx = TokenMintTransaction().set_token_id(token_id).set_metadata(metadata_list).execute(client)
138134

139135
if tx.status != ResponseCode.SUCCESS:
140136
print(f"Mint failed: {ResponseCode(tx.status).name}")
141137
sys.exit(1)
142138

143139
serials = tx.serial_numbers
144-
print(
145-
f"NFT Owner ({client.operator_account_id}) minted {len(serials)} NFT(s) for Token {token_id}: {serials}"
146-
)
140+
print(f"NFT Owner ({client.operator_account_id}) minted {len(serials)} NFT(s) for Token {token_id}: {serials}")
147141
return [NftId(token_id, s) for s in serials]
148142

149143

@@ -179,22 +173,14 @@ def approve_nft_allowance(client, nft_id, owner_id, spender_id, owner_key):
179173
print(f"Approval failed: {ResponseCode(tx.status).name}")
180174
sys.exit(1)
181175

182-
print(
183-
f"NFT Owner ({owner_id}) approved Spender ({spender_id}) for NFT {nft_id.token_id} (all serials)"
184-
)
176+
print(f"NFT Owner ({owner_id}) approved Spender ({spender_id}) for NFT {nft_id.token_id} (all serials)")
185177

186178

187179
def transfer_nft_using_allowance(spender_client, nft_id, owner_id, receiver_id):
188180
"""Transfer an NFT using approved allowance via the spender client."""
189-
print(
190-
f"Spender ({spender_client.operator_account_id}) transferring NFT {nft_id} from Owner ({owner_id})..."
191-
)
181+
print(f"Spender ({spender_client.operator_account_id}) transferring NFT {nft_id} from Owner ({owner_id})...")
192182

193-
tx = (
194-
TransferTransaction()
195-
.add_approved_nft_transfer(nft_id, owner_id, receiver_id)
196-
.execute(spender_client)
197-
)
183+
tx = TransferTransaction().add_approved_nft_transfer(nft_id, owner_id, receiver_id).execute(spender_client)
198184

199185
if tx.status != ResponseCode.SUCCESS:
200186
print(f"Transfer failed: {ResponseCode(tx.status).name}")

examples/account/account_allowance_delete_transaction_hbar.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ def create_account(client: Client):
4545
)
4646

4747
if account_receipt.status != ResponseCode.SUCCESS:
48-
print(
49-
"Account creation failed with status: "
50-
f"{ResponseCode(account_receipt.status).name}"
51-
)
48+
print(f"Account creation failed with status: {ResponseCode(account_receipt.status).name}")
5249
sys.exit(1)
5350

5451
account_account_id = account_receipt.account_id
@@ -70,10 +67,7 @@ def approve_hbar_allowance(
7067
)
7168

7269
if receipt.status != ResponseCode.SUCCESS:
73-
print(
74-
"Hbar allowance approval failed with status: "
75-
f"{ResponseCode(receipt.status).name}"
76-
)
70+
print(f"Hbar allowance approval failed with status: {ResponseCode(receipt.status).name}")
7771
sys.exit(1)
7872

7973
print(f"Hbar allowance of {amount} approved for spender {spender_account_id}")
@@ -93,10 +87,7 @@ def delete_hbar_allowance(
9387
)
9488

9589
if receipt.status != ResponseCode.SUCCESS:
96-
print(
97-
"Hbar allowance deletion failed with status: "
98-
f"{ResponseCode(receipt.status).name}"
99-
)
90+
print(f"Hbar allowance deletion failed with status: {ResponseCode(receipt.status).name}")
10091
sys.exit(1)
10192

10293
print(f"Hbar allowance deleted for spender {spender_account_id}")
@@ -126,10 +117,7 @@ def transfer_hbar_with_allowance(
126117
print(f"Hbar transfer failed with status: {ResponseCode(receipt.status).name}")
127118
sys.exit(1)
128119

129-
print(
130-
f"Successfully transferred {amount} from {owner_account_id} "
131-
f"to {receiver_account_id} using allowance"
132-
)
120+
print(f"Successfully transferred {amount} from {owner_account_id} to {receiver_account_id} using allowance")
133121

134122
return receipt
135123

@@ -165,10 +153,7 @@ def transfer_hbar_without_allowance(
165153
f"{ResponseCode(receipt.status).name}"
166154
)
167155
else:
168-
print(
169-
"Hbar transfer successfully failed with "
170-
f"{ResponseCode(receipt.status).name} status"
171-
)
156+
print(f"Hbar transfer successfully failed with {ResponseCode(receipt.status).name} status")
172157

173158

174159
def main():

examples/account/account_allowance_delete_transaction_nft.py

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
python examples/account/account_allowance_delete_transaction_nft.py
1414
uv run examples/account/account_allowance_delete_transaction_nft.py
1515
"""
16+
1617
import os
1718
import sys
1819

@@ -81,9 +82,7 @@ def create_account(client, memo="Test Account"):
8182
try:
8283
receipt = tx
8384
if receipt.status != ResponseCode.SUCCESS:
84-
print(
85-
f"Account creation failed ({memo}): {ResponseCode(receipt.status).name}"
86-
)
85+
print(f"Account creation failed ({memo}): {ResponseCode(receipt.status).name}")
8786
sys.exit(1)
8887

8988
account_id = receipt.account_id
@@ -128,22 +127,15 @@ def create_nft_token(client, owner_id, owner_key):
128127
def mint_nft(client, token_id, metadata_list):
129128
"""Mint NFT(s)."""
130129
try:
131-
tx = (
132-
TokenMintTransaction()
133-
.set_token_id(token_id)
134-
.set_metadata(metadata_list)
135-
.execute(client)
136-
)
130+
tx = TokenMintTransaction().set_token_id(token_id).set_metadata(metadata_list).execute(client)
137131

138132
receipt = tx
139133
if receipt.status != ResponseCode.SUCCESS:
140134
print(f"NFT minting failed: {ResponseCode(receipt.status).name}")
141135
sys.exit(1)
142136

143137
serials = receipt.serial_numbers
144-
print(
145-
f"NFT Owner ({client.operator_account_id}) minted {len(serials)} NFT(s) for Token {token_id}: {serials}"
146-
)
138+
print(f"NFT Owner ({client.operator_account_id}) minted {len(serials)} NFT(s) for Token {token_id}: {serials}")
147139
return [NftId(token_id, s) for s in serials]
148140
except Exception as e:
149141
print(f"NFT minting exception: {e}")
@@ -164,9 +156,7 @@ def associate_token_with_account(client, account_id, private_key, token_id):
164156

165157
receipt = tx
166158
if receipt.status != ResponseCode.SUCCESS:
167-
print(
168-
f"Token association failed for {account_id}: {ResponseCode(receipt.status).name}"
169-
)
159+
print(f"Token association failed for {account_id}: {ResponseCode(receipt.status).name}")
170160
sys.exit(1)
171161

172162
print(f"Associated token {token_id} with Receiver account {account_id}")
@@ -197,9 +187,7 @@ def approve_nft_allowance_all_serials(
197187
print(f"Allowance approval failed: {ResponseCode(receipt.status).name}")
198188
sys.exit(1)
199189

200-
print(
201-
f"NFT Owner ({owner_id}) approved Spender ({spender_id}) for ALL serials of token {token_id}"
202-
)
190+
print(f"NFT Owner ({owner_id}) approved Spender ({spender_id}) for ALL serials of token {token_id}")
203191
except Exception as e:
204192
print(f"Allowance approval exception: {e}")
205193
sys.exit(1)
@@ -213,9 +201,7 @@ def delete_nft_allowance_all_serials(
213201
owner_key: PrivateKey,
214202
):
215203
"""Revokes an "approve for all serials" NFT allowance from a spender."""
216-
print(
217-
f"NFT Owner ({owner_id}) deleting 'approve for all' allowance for {token_id} from Spender ({spender_id})..."
218-
)
204+
print(f"NFT Owner ({owner_id}) deleting 'approve for all' allowance for {token_id} from Spender ({spender_id})...")
219205

220206
try:
221207
tx = (
@@ -237,29 +223,19 @@ def delete_nft_allowance_all_serials(
237223
sys.exit(1)
238224

239225

240-
def verify_allowance_removed(
241-
spender_client, nft_id: NftId, owner_id: AccountId, receiver_id: AccountId
242-
):
226+
def verify_allowance_removed(spender_client, nft_id: NftId, owner_id: AccountId, receiver_id: AccountId):
243227
"""
244228
Try to transfer NFT after allowance removal (should fail).
245229
246230
This transaction is paid for and signed by the SPENDER.
247231
"""
248-
print(
249-
f"\nVerifying allowance removal by Spender ({spender_client.operator_account_id}) attempting transfer..."
250-
)
232+
print(f"\nVerifying allowance removal by Spender ({spender_client.operator_account_id}) attempting transfer...")
251233

252234
try:
253-
receipt = (
254-
TransferTransaction()
255-
.add_approved_nft_transfer(nft_id, owner_id, receiver_id)
256-
.execute(spender_client)
257-
)
235+
receipt = TransferTransaction().add_approved_nft_transfer(nft_id, owner_id, receiver_id).execute(spender_client)
258236

259237
if receipt.status == ResponseCode.SPENDER_DOES_NOT_HAVE_ALLOWANCE:
260-
print(
261-
"Verification SUCCEEDED: Transfer failed with SPENDER_DOES_NOT_HAVE_ALLOWANCE as expected."
262-
)
238+
print("Verification SUCCEEDED: Transfer failed with SPENDER_DOES_NOT_HAVE_ALLOWANCE as expected.")
263239
elif receipt.status == ResponseCode.SUCCESS:
264240
print("Verification FAILED: Transfer succeeded unexpectedly!")
265241
sys.exit(1)
@@ -291,14 +267,10 @@ def main():
291267
associate_token_with_account(owner_client, receiver_id, receiver_key, token_id)
292268

293269
# 4. Approve allowance (for all serials)
294-
approve_nft_allowance_all_serials(
295-
owner_client, token_id, owner_id, spender_id, owner_key
296-
)
270+
approve_nft_allowance_all_serials(owner_client, token_id, owner_id, spender_id, owner_key)
297271

298272
# 5. Delete the "all serials" allowance
299-
delete_nft_allowance_all_serials(
300-
owner_client, token_id, owner_id, spender_id, owner_key
301-
)
273+
delete_nft_allowance_all_serials(owner_client, token_id, owner_id, spender_id, owner_key)
302274

303275
# 6. Verify deletion
304276
print("\nSetting up client for the Spender...")

examples/account/account_create_transaction.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def create_new_account(client: Client) -> None:
9696
print(f" New Account Private Key: {new_account_private_key.to_string()}")
9797
print(f" New Account Public Key: {new_account_public_key.to_string()}")
9898
else:
99-
raise Exception(
100-
"AccountID not found in receipt. Account may not have been created."
101-
)
99+
raise Exception("AccountID not found in receipt. Account may not have been created.")
102100

103101
except Exception as e:
104102
print(f"❌ Account creation failed: {str(e)}")

examples/account/account_create_transaction_evm_alias.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
uv run examples/account/account_create_transaction_evm_alias.py
1313
python examples/account/account_create_transaction_evm_alias.py
1414
"""
15+
1516
import sys
1617

1718
from dotenv import load_dotenv

examples/account/account_create_transaction_with_fallback_alias.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
uv run examples/account/account_create_transaction_with_fallback_alias.py
1111
python examples/account/account_create_transaction_with_fallback_alias.py
1212
"""
13+
1314
import sys
1415

1516
from dotenv import load_dotenv

examples/account/account_create_transaction_without_alias.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- uv run python examples/account/account_create_transaction_without_alias.py
1212
- python examples/account/account_create_transaction_without_alias.py
1313
"""
14+
1415
import sys
1516

1617
from hiero_sdk_python import (
@@ -33,6 +34,7 @@ def setup_client() -> Client:
3334
print(f"Client set up with operator id {client.operator_account_id}")
3435
return client
3536

37+
3638
def generate_account_key() -> tuple[PrivateKey, PublicKey]:
3739
"""Generate a key pair for the account."""
3840
print("\nSTEP 1: Generating a key pair for the account (no alias)...")
@@ -41,10 +43,13 @@ def generate_account_key() -> tuple[PrivateKey, PublicKey]:
4143
print(f"✅ Account public key (no alias): {account_public_key}")
4244
return account_private_key, account_public_key
4345

44-
def create_account_without_alias(client: Client, account_public_key: PublicKey, account_private_key: PrivateKey) -> AccountId:
46+
47+
def create_account_without_alias(
48+
client: Client, account_public_key: PublicKey, account_private_key: PrivateKey
49+
) -> AccountId:
4550
"""Create an account without setting any alias."""
4651
print("\nSTEP 2: Creating the account without setting any alias...")
47-
52+
4853
transaction = (
4954
AccountCreateTransaction(
5055
initial_balance=Hbar(5),
@@ -58,27 +63,21 @@ def create_account_without_alias(client: Client, account_public_key: PublicKey,
5863
response = transaction.execute(client)
5964

6065
if response.status != ResponseCode.SUCCESS:
61-
raise RuntimeError(
62-
f"Transaction failed with status: {response.status.name}"
63-
)
66+
raise RuntimeError(f"Transaction failed with status: {response.status.name}")
6467

6568
new_account_id = response.account_id
6669

6770
if new_account_id is None:
68-
raise RuntimeError(
69-
"AccountID not found in receipt. Account may not have been created."
70-
)
71+
raise RuntimeError("AccountID not found in receipt. Account may not have been created.")
7172

7273
print(f"✅ Account created with ID: {new_account_id}\n")
7374
return new_account_id
7475

76+
7577
def fetch_account_info(client: Client, account_id: AccountId) -> AccountInfo:
7678
"""Fetch account information."""
77-
return (
78-
AccountInfoQuery()
79-
.set_account_id(account_id)
80-
.execute(client)
81-
)
79+
return AccountInfoQuery().set_account_id(account_id).execute(client)
80+
8281

8382
def main() -> None:
8483
"""Main entry point."""
@@ -89,13 +88,11 @@ def main() -> None:
8988
account_info = fetch_account_info(client, new_account_id)
9089
print("\nAccount Info:")
9190
print(account_info)
92-
print(
93-
"\n✅ contract_account_id (no alias, zero-padded): "
94-
f"{account_info.contract_account_id}"
95-
)
91+
print(f"\n✅ contract_account_id (no alias, zero-padded): {account_info.contract_account_id}")
9692
except Exception as error:
9793
print(f"❌ Error: {error}")
9894
sys.exit(1)
9995

96+
10097
if __name__ == "__main__":
10198
main()

0 commit comments

Comments
 (0)