Task 2-1: IMX Rental Support Validation
Phase: 2 Priority: Medium Module:
rentalDepends on: Không có Reference: docs/bountyhunter-blockchain-p2/details/feature-nft-rental/SPEC.md
Background
Hiện tại chỉ có createRentNft xử lý ImmutableX path (qua createRentNftIMX). Các operations returnRentNft, rentNft, và cancelRentNft không có kiểm tra IMX chain — nếu được gọi với IMX chainId, có thể fail với lỗi không rõ ràng hoặc gọi nhầm EVM contract. Cần validate chainId trước khi dispatch và bổ sung IMX implementations hoặc document rõ ràng giới hạn.
Tasks
Note:
ImmutableUtil(hoặc tương đương) cần được inject vàoRentalService/RentalProcessor. IMXchainIdthường làIMX_MAINNET = 13372hoặcIMX_TESTNET— kiểm tra constants đang dùng trong project. Nếu IMX rental return không được support, cần throwRENTAL_UNSUPPORTED_CHAINthay vì silently fail.
- [ ] Thêm chain validation helper:
function validateRentalChain(chainId: number, operation: string): void { const supported = [...EVM_SUPPORTED_CHAINS, ...SOLANA_CHAIN_IDS]; if (!supported.includes(chainId)) { throw new Error(`Chain ${chainId} not supported for rental ${operation}`); } if (IMX_CHAIN_IDS.includes(chainId) && !IMX_RENTAL_SUPPORTED_OPS.includes(operation)) { throw new Error(`IMX chain does not support rental operation: ${operation}`); } } - [ ] Gọi validation ở đầu mỗi operation trong
RentalService:async returnRentNft(dto: ReturnRentNftDto): Promise<...> { validateRentalChain(dto.chainId, 'RETURN_RENT'); // ...rest of logic } - [ ] Audit
createRentNft— đảm bảo IMX path được gọi đúng vớicreateRentNftIMX:if (IMX_CHAIN_IDS.includes(dto.chainId)) { return this.createRentNftIMX(dto); } return this.blockchainUtil.createRentNft(dto); - [ ] Thêm IMX constants nếu chưa có:
export const IMX_CHAIN_IDS = [ ChainId.IMX_MAINNET, ChainId.IMX_TESTNET, ]; export const IMX_RENTAL_SUPPORTED_OPS = ['CREATE_RENT']; // Chỉ create được support - [ ] Document trong code comment: IMX
returnRentNftkhông được support và lý do - [ ] Log rõ ràng khi unsupported chain được call:
this.logger.warn(`[RENTAL] Unsupported chainId=${dto.chainId} for operation=RETURN_RENT`);
Verification / Acceptance Criteria
- [ ]
POST /rental/create-rent-nftvới IMX chainId →createRentNftIMXđược gọi (không gọi EVM path) - [ ]
POST /rental/return-rent-nftvới IMX chainId → trả vềRENTAL_UNSUPPORTED_CHAINerror - [ ]
POST /rental/rent-nftvới IMX chainId → trả vềRENTAL_UNSUPPORTED_CHAINerror - [ ] EVM
returnRentNftvẫn hoạt động bình thường sau khi thêm validation - [ ] Solana
rentNftvẫn hoạt động bình thường (nếu có Solana rental path) - [ ] TypeScript compile không có lỗi
Files to Modify
src/rental/rental.service.tssrc/rental/constants/rental.constants.ts