|
13 | 13 | from hiero_sdk_python.tokens.fee_assessment_method import FeeAssessmentMethod |
14 | 14 | from hiero_sdk_python.tokens.nft_id import NftId |
15 | 15 | from hiero_sdk_python.tokens.supply_type import SupplyType |
| 16 | +from hiero_sdk_python.tokens.token_airdrop_claim import TokenClaimAirdropTransaction |
| 17 | +from hiero_sdk_python.tokens.token_airdrop_pending_id import PendingAirdropId |
16 | 18 | from hiero_sdk_python.tokens.token_airdrop_transaction import TokenAirdropTransaction |
17 | 19 | from hiero_sdk_python.tokens.token_associate_transaction import TokenAssociateTransaction |
18 | 20 | from hiero_sdk_python.tokens.token_create_transaction import TokenCreateTransaction |
|
28 | 30 | from tck.param.token import ( |
29 | 31 | AirdropTokenParams, |
30 | 32 | AssociateTokenParams, |
| 33 | + ClaimTokenParams, |
31 | 34 | CreateTokenParams, |
32 | 35 | DeleteTokenParams, |
33 | 36 | FreezeTokenParams, |
|
37 | 40 | from tck.response.token import ( |
38 | 41 | AirdropTokenResponse, |
39 | 42 | AssociateTokenResponse, |
| 43 | + ClaimTokenResponse, |
40 | 44 | CreateTokenResponse, |
41 | 45 | DeleteTokenResponse, |
42 | 46 | FreezeTokenResponse, |
@@ -429,3 +433,48 @@ def airdrop_token(params: AirdropTokenParams) -> AirdropTokenResponse: |
429 | 433 | ) |
430 | 434 |
|
431 | 435 | return AirdropTokenResponse(status=ResponseCode(receipt.status).name) |
| 436 | + |
| 437 | + |
| 438 | +def _build_claim_token_transaction(params: ClaimTokenParams) -> TokenClaimAirdropTransaction: |
| 439 | + """Build a TokenClaimAirdropTransaction from TCK params.""" |
| 440 | + transaction = TokenClaimAirdropTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT) |
| 441 | + |
| 442 | + sender_id = AccountId.from_string(params.senderAccountId) |
| 443 | + receiver_id = AccountId.from_string(params.receiverAccountId) |
| 444 | + token_id = TokenId.from_string(params.tokenId) |
| 445 | + |
| 446 | + if params.serialNumbers: |
| 447 | + for serial_number in params.serialNumbers: |
| 448 | + transaction.add_pending_airdrop_id( |
| 449 | + PendingAirdropId( |
| 450 | + sender_id=sender_id, |
| 451 | + receiver_id=receiver_id, |
| 452 | + nft_id=NftId(token_id=token_id, serial_number=int(serial_number)), |
| 453 | + ) |
| 454 | + ) |
| 455 | + else: |
| 456 | + transaction.add_pending_airdrop_id( |
| 457 | + PendingAirdropId( |
| 458 | + sender_id=sender_id, |
| 459 | + receiver_id=receiver_id, |
| 460 | + token_id=token_id, |
| 461 | + ) |
| 462 | + ) |
| 463 | + |
| 464 | + return transaction |
| 465 | + |
| 466 | + |
| 467 | +@rpc_method("claimToken") |
| 468 | +def claim_token(params: ClaimTokenParams) -> ClaimTokenResponse: |
| 469 | + """Claim pending token airdrops using TCK claimToken parameters.""" |
| 470 | + client = get_client(params.sessionId) |
| 471 | + |
| 472 | + transaction = _build_claim_token_transaction(params) |
| 473 | + |
| 474 | + if params.commonTransactionParams is not None: |
| 475 | + params.commonTransactionParams.apply_common_params(transaction, client) |
| 476 | + |
| 477 | + response = transaction.execute(client, wait_for_receipt=False) |
| 478 | + receipt: TransactionReceipt = response.get_receipt(client, validate_status=True) |
| 479 | + |
| 480 | + return ClaimTokenResponse(status=ResponseCode(receipt.status).name) |
0 commit comments