-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TokenDeleteTransaction token_delete.py token_delete_transaction.py test_token_delete_transaction.py test.py account_id naming in unit test readme delete token typo successful hardcoding to env file token_id string token_id readme admin_key integration admin_key token_create_transaction admin_key signing example admin_key test.py creating token readme/example with admin key test enable solo key basic types bytes defining bytes in private key sign admin as is set typo admin_key generate distinct public key test call admin_public_key_bytes test admin_key signing admin_key private public user-friendly and docs transaction body layer Documentation admin key paths uv lock path admin key sign client
- Loading branch information
1 parent
d172e1a
commit 150dd26
Showing
11 changed files
with
400 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import sys | ||
from dotenv import load_dotenv | ||
|
||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | ||
sys.path.insert(0, project_root) | ||
|
||
from hedera_sdk_python.client.client import Client | ||
from hedera_sdk_python.account.account_id import AccountId | ||
from hedera_sdk_python.crypto.private_key import PrivateKey | ||
from hedera_sdk_python.tokens.token_delete_transaction import TokenDeleteTransaction | ||
from hedera_sdk_python.client.network import Network | ||
from hedera_sdk_python.tokens.token_id import TokenId | ||
|
||
load_dotenv() | ||
|
||
def delete_token(): | ||
network = Network(network='testnet') | ||
client = Client(network) | ||
|
||
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID')) | ||
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY')) | ||
admin_key = PrivateKey.from_string(os.getenv('ADMIN_KEY')) | ||
token_id = TokenId.from_string(os.getenv('TOKEN_ID')) | ||
|
||
client.set_operator(operator_id, operator_key) | ||
|
||
transaction = ( | ||
TokenDeleteTransaction() | ||
.set_token_id(token_id) | ||
.freeze_with(client) | ||
.sign(operator_key) | ||
.sign(admin_key) | ||
) | ||
|
||
try: | ||
receipt = transaction.execute(client) | ||
if receipt is not None and receipt.status == 'SUCCESS': | ||
print(f"Token deletion successful") | ||
else: | ||
print(f"Token deletion failed.") | ||
sys.exit(1) | ||
except Exception as e: | ||
print(f"Token deletion failed: {str(e)}") | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
delete_token() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from hedera_sdk_python.transaction.transaction import Transaction | ||
from hedera_sdk_python.hapi import token_delete_pb2 | ||
from hedera_sdk_python.response_code import ResponseCode | ||
|
||
class TokenDeleteTransaction(Transaction): | ||
""" | ||
Represents a token deletion transaction on the Hedera network. | ||
This transaction deletes a specified token, rendering it inactive. | ||
Inherits from the base Transaction class and implements the required methods | ||
to build and execute a token deletion transaction. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Initializes a new TokenDeleteTransaction instance with default values. | ||
""" | ||
super().__init__() | ||
self.token_id = None | ||
self._default_transaction_fee = 3_000_000_000 | ||
|
||
def set_token_id(self, token_id): | ||
self._require_not_frozen() | ||
self.token_id = token_id | ||
return self | ||
|
||
def build_transaction_body(self): | ||
""" | ||
Builds and returns the protobuf transaction body for token deletion. | ||
Returns: | ||
TransactionBody: The protobuf transaction body containing the token deletion details. | ||
Raises: | ||
ValueError: If the token ID is missing. | ||
""" | ||
if not self.token_id: | ||
raise ValueError("Missing required TokenID.") | ||
|
||
token_delete_body = token_delete_pb2.TokenDeleteTransactionBody( | ||
token=self.token_id.to_proto() | ||
) | ||
|
||
transaction_body = self.build_base_transaction_body() | ||
transaction_body.tokenDeletion.CopyFrom(token_delete_body) | ||
|
||
return transaction_body | ||
|
||
def _execute_transaction(self, client, transaction_proto): | ||
""" | ||
Executes the token deletion transaction using the provided client. | ||
Args: | ||
client (Client): The client instance to use for execution. | ||
transaction_proto (Transaction): The protobuf Transaction message. | ||
Returns: | ||
TransactionReceipt: The receipt from the network after transaction execution. | ||
Raises: | ||
Exception: If the transaction submission fails or receives an error response. | ||
""" | ||
response = client.token_stub.deleteToken(transaction_proto) | ||
|
||
if response.nodeTransactionPrecheckCode != ResponseCode.OK: | ||
error_code = response.nodeTransactionPrecheckCode | ||
error_message = ResponseCode.get_name(error_code) | ||
raise Exception(f"Error during transaction submission: {error_code} ({error_message})") | ||
|
||
receipt = self.get_receipt(client) | ||
return receipt | ||
|
||
def get_receipt(self, client, timeout=60): | ||
""" | ||
Retrieves the receipt for the transaction. | ||
Args: | ||
client (Client): The client instance. | ||
timeout (int): Maximum time in seconds to wait for the receipt. | ||
Returns: | ||
TransactionReceipt: The transaction receipt from the network. | ||
Raises: | ||
Exception: If the transaction ID is not set or if receipt retrieval fails. | ||
""" | ||
if self.transaction_id is None: | ||
raise Exception("Transaction ID is not set.") | ||
|
||
receipt = client.get_transaction_receipt(self.transaction_id, timeout) | ||
return receipt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.