Skip to content

Commit

Permalink
Revert "Merge pull request hiero-ledger#32 from exploreriii/TokenDiss…
Browse files Browse the repository at this point in the history
…ociateTransaction"

This reverts commit 8c61874, reversing
changes made to d2f2ce3.
  • Loading branch information
LukeBair committed Jan 29, 2025
1 parent 8c61874 commit fa8e920
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 348 deletions.
29 changes: 1 addition & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a Python SDK for interacting with the Hedera Hashgraph platform. It allows developers to:

- Manage Token Transactions like Create, Associate, Dissociate, Transfer & Delete
- Manage Token Transactions like Create, Associate, Transfer & Delete
- Manage Consensus Transactions like Topic Create, Update, Delete
- Submit Topic Messages
- Query Account Balance, Transaction Receipts, Topic Infos and Messages
Expand All @@ -17,7 +17,6 @@ This is a Python SDK for interacting with the Hedera Hashgraph platform. It allo
- [Querying Account Balance](#querying-account-balance)
- [Creating a Token](#creating-a-token)
- [Associating a Token](#associating-a-token)
- [Dissociating a Token](#dissociating-a-token)
- [Transferring Tokens](#transferring-tokens)
- [Deleting a Token](#deleting-a-token)
- [Transferring HBAR](#transferring-hbar)
Expand Down Expand Up @@ -108,7 +107,6 @@ New Account Private Key: 228a06c363b0eb328434d51xxx...
New Account Public Key: 8f444e36e8926def492adxxx...
Token creation successful. Token ID: 0.0.5025xxx
Token association successful.
Token dissociation successful.
Token transfer successful.
Token deletion successful.
Topic creation successful.
Expand Down Expand Up @@ -231,31 +229,6 @@ transaction = (
transaction.execute(client)
```

### Dissociating a Token

#### Pythonic Syntax:
```
transaction = TokenDissociateTransaction(
account_id=recipient_id,
token_ids=[token_id]
).freeze_with(client)
transaction.sign(recipient_key)
transaction.execute(client)
```
#### Method Chaining:
```
transaction = (
TokenDissociateTransaction()
.set_account_id(recipient_id)
.add_token_id(token_id)
.freeze_with(client)
.sign(recipient_key)
)
transaction.execute(client)
```

### Transferring Tokens

#### Pythonic Syntax:
Expand Down
72 changes: 0 additions & 72 deletions examples/token_dissociate.py

This file was deleted.

101 changes: 0 additions & 101 deletions src/hedera_sdk_python/tokens/token_dissociate_transaction.py

This file was deleted.

55 changes: 17 additions & 38 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from hedera_sdk_python.crypto.private_key import PrivateKey
from hedera_sdk_python.tokens.token_create_transaction import TokenCreateTransaction
from hedera_sdk_python.tokens.token_associate_transaction import TokenAssociateTransaction
from hedera_sdk_python.tokens.token_dissociate_transaction import TokenDissociateTransaction
from hedera_sdk_python.transaction.transfer_transaction import TransferTransaction
from hedera_sdk_python.tokens.token_delete_transaction import TokenDeleteTransaction
from hedera_sdk_python.response_code import ResponseCode
Expand All @@ -19,6 +18,7 @@
from hedera_sdk_python.consensus.topic_id import TopicId
from hedera_sdk_python.query.topic_info_query import TopicInfoQuery
from hedera_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery

load_dotenv()

def load_operator_credentials():
Expand Down Expand Up @@ -90,10 +90,10 @@ def create_token(client, operator_id, admin_key):
print(f"Token creation successful. Token ID: {token_id}")
return token_id

def associate_token(client, recipient_id, recipient_private_key, token_ids):
def associate_token(client, recipient_id, recipient_private_key, token_id):
transaction = TokenAssociateTransaction(
account_id=recipient_id,
token_ids=token_ids
token_ids=[token_id]
)
transaction.freeze_with(client)
transaction.sign(client.operator_private_key)
Expand All @@ -109,34 +109,16 @@ def associate_token(client, recipient_id, recipient_private_key, token_ids):
print(f"Token association failed: {str(e)}")
sys.exit(1)

def dissociate_token(client, recipient_id, recipient_private_key, token_id):
"""Dissociate the specified token with the recipient account."""
transaction = TokenDissociateTransaction(
account_id = recipient_id,
token_ids = token_id)
transaction.freeze_with(client)
transaction.sign(client.operator_private_key)
transaction.sign(recipient_private_key)

try:
receipt = transaction.execute(client)
if receipt.status != ResponseCode.SUCCESS:
status_message = ResponseCode.get_name(receipt.status)
raise Exception(f"Token dissociation failed with status: {status_message}")
print("Token dissociation successful.")
except Exception as e:
print(f"Token dissociation failed: {str(e)}")
sys.exit(1)

def transfer_token(client, source_id, source_private_key, recipient_id, token_id):
"""Transfer the specified token to the recipient account."""
transaction = (
TransferTransaction()
.add_token_transfer(token_id, source_id, -1)
.add_token_transfer(token_id, recipient_id, 1)
.freeze_with(client)
)
transaction.sign(source_private_key)
def transfer_token(client, recipient_id, token_id):
transaction = TransferTransaction(
token_transfers={
token_id: {
client.operator_account_id: -1,
recipient_id: 1,
}
}
).freeze_with(client)
transaction.sign(client.operator_private_key)

try:
receipt = transaction.execute(client)
Expand Down Expand Up @@ -266,13 +248,10 @@ def main():
recipient_id, recipient_private_key = create_new_account(client)
query_balance(client, recipient_id)

token_id_1 = create_token(client, operator_id, admin_key)
token_id_2 = create_token(client, operator_id, admin_key)

associate_token(client, recipient_id, recipient_private_key, [token_id_1, token_id_2])
transfer_token(client, operator_id, operator_key, recipient_id, token_id_1)
dissociate_token(client, recipient_id, recipient_private_key, [token_id_2])
delete_token(client, token_id_1, admin_key)
token_id = create_token(client, operator_id, admin_key)
associate_token(client, recipient_id, recipient_private_key, token_id)
transfer_token(client, recipient_id, token_id)
delete_token(client, token_id, admin_key)

topic_id = create_topic(client)
submit_message(client, topic_id)
Expand Down
Loading

0 comments on commit fa8e920

Please sign in to comment.