|
5 | 5 | from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction |
6 | 6 | from hiero_sdk_python.account.account_id import AccountId |
7 | 7 | from hiero_sdk_python.account.account_info import AccountInfo |
| 8 | +from hiero_sdk_python.account.account_update_transaction import AccountUpdateTransaction |
| 9 | +from hiero_sdk_python.Duration import Duration |
8 | 10 | from hiero_sdk_python.hbar import Hbar |
9 | 11 | from hiero_sdk_python.query.account_info_query import AccountInfoQuery |
10 | 12 | from hiero_sdk_python.response_code import ResponseCode |
| 13 | +from hiero_sdk_python.timestamp import Timestamp |
11 | 14 | from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt |
12 | 15 | from tck.handlers.registry import rpc_method |
13 | | -from tck.param.account import CreateAccountParams, GetAccountInfoParams |
| 16 | +from tck.param.account import CreateAccountParams, GetAccountInfoParams, UpdateAccountParams |
14 | 17 | from tck.response.account import ( |
15 | 18 | CreateAccountResponse, |
16 | 19 | GetAccountInfoResponse, |
17 | 20 | StakingInfoResponse, |
18 | 21 | TokenRelationshipResponse, |
| 22 | + UpdateAccountResponse, |
19 | 23 | ) |
20 | 24 | from tck.util.client_utils import get_client |
21 | 25 | from tck.util.constants import DEFAULT_GRPC_TIMEOUT |
@@ -78,6 +82,59 @@ def create_account(params: CreateAccountParams) -> CreateAccountResponse: |
78 | 82 | return CreateAccountResponse(account_id, ResponseCode(receipt.status).name) |
79 | 83 |
|
80 | 84 |
|
| 85 | +def _build_update_account_transaction(params: UpdateAccountParams) -> AccountUpdateTransaction: |
| 86 | + transaction = AccountUpdateTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT) |
| 87 | + transaction.set_auto_renew_period(None) |
| 88 | + |
| 89 | + if params.accountId is not None: |
| 90 | + transaction.set_account_id(AccountId.from_string(params.accountId)) |
| 91 | + |
| 92 | + if params.key is not None: |
| 93 | + transaction.set_key(get_key_from_string(params.key)) |
| 94 | + |
| 95 | + if params.expirationTime is not None: |
| 96 | + transaction.set_expiration_time(Timestamp(params.expirationTime, 0)) |
| 97 | + |
| 98 | + if params.receiverSignatureRequired is not None: |
| 99 | + transaction.set_receiver_signature_required(params.receiverSignatureRequired) |
| 100 | + |
| 101 | + if params.maxAutoTokenAssociations is not None: |
| 102 | + transaction.set_max_automatic_token_associations(params.maxAutoTokenAssociations) |
| 103 | + |
| 104 | + if params.stakedAccountId is not None: |
| 105 | + transaction.set_staked_account_id(AccountId.from_string(params.stakedAccountId)) |
| 106 | + |
| 107 | + if params.stakedNodeId is not None: |
| 108 | + transaction.set_staked_node_id(params.stakedNodeId) |
| 109 | + |
| 110 | + if params.declineStakingReward is not None: |
| 111 | + transaction.set_decline_staking_reward(params.declineStakingReward) |
| 112 | + |
| 113 | + if params.memo is not None: |
| 114 | + transaction.set_account_memo(params.memo) |
| 115 | + |
| 116 | + if params.autoRenewPeriod is not None: |
| 117 | + transaction.set_auto_renew_period(Duration(params.autoRenewPeriod)) |
| 118 | + |
| 119 | + return transaction |
| 120 | + |
| 121 | + |
| 122 | +@rpc_method("updateAccount") |
| 123 | +def update_account(params: UpdateAccountParams) -> UpdateAccountResponse: |
| 124 | + """Update an account using TCK updateAccount parameters.""" |
| 125 | + client = get_client(params.sessionId) |
| 126 | + |
| 127 | + transaction = _build_update_account_transaction(params) |
| 128 | + |
| 129 | + if params.commonTransactionParams is not None: |
| 130 | + params.commonTransactionParams.apply_common_params(transaction, client) |
| 131 | + |
| 132 | + response = transaction.execute(client, wait_for_receipt=False) |
| 133 | + receipt: TransactionReceipt = response.get_receipt(client, validate_status=True) |
| 134 | + |
| 135 | + return UpdateAccountResponse(ResponseCode(receipt.status).name) |
| 136 | + |
| 137 | + |
81 | 138 | def _enum_name(value) -> str | None: |
82 | 139 | if value is None: |
83 | 140 | return None |
|
0 commit comments