diff --git a/test.py b/test.py index a161187..d2a3de4 100644 --- a/test.py +++ b/test.py @@ -5,11 +5,13 @@ from src.account.account_id import AccountId from src.account.account_create_transaction import AccountCreateTransaction from src.crypto.private_key import PrivateKey +from src.crypto.public_key import PublicKey from src.tokens.token_create_transaction import TokenCreateTransaction from src.tokens.token_associate_transaction import TokenAssociateTransaction from src.transaction.transfer_transaction import TransferTransaction from src.response_code import ResponseCode from src.tokens.token_delete_transaction import TokenDeleteTransaction +from cryptography.hazmat.primitives import serialization def load_operator_credentials(): """Load operator credentials from environment variables.""" @@ -52,7 +54,7 @@ def create_new_account(client, initial_balance=100000000): return new_account_id, new_account_private_key -def create_token(client, operator_id, admin_key): +def create_token(client, operator_id, admin_public_key_bytes): """Create a new token and return its TokenId instance.""" transaction = ( TokenCreateTransaction() @@ -61,10 +63,10 @@ def create_token(client, operator_id, admin_key): .set_decimals(2) .set_initial_supply(1000) .set_treasury_account_id(operator_id) - .set_admin_key(admin_key) + .set_admin_key(admin_public_key_bytes) .freeze_with(client) ) - transaction.sign(admin_key) + # transaction.sign(admin_key) transaction.sign(client.operator_private_key) @@ -149,13 +151,18 @@ def main(): operator_id, operator_key = load_operator_credentials() # admin_key = PrivateKey.from_string(os.getenv('ADMIN_KEY')) admin_key = PrivateKey.generate() + admin_public_key = admin_key.public_key + admin_public_key_bytes = admin_public_key.public_bytes( + encoding=serialization.Encoding.Raw, + format=serialization.PublicFormat.Raw + ) network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) client = Client(network) client.set_operator(operator_id, operator_key) recipient_id, recipient_private_key = create_new_account(client) - token_id = create_token(client, operator_id, admin_key) + token_id = create_token(client, operator_id, admin_public_key_bytes) associate_token(client, recipient_id, recipient_private_key, token_id) transfer_token(client, recipient_id, token_id) delete_token(client, token_id, admin_key)