Skip to content

Task 2-1: IMX Rental Support Validation

Phase: 2 Priority: Medium Module: rental Depends 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ào RentalService/RentalProcessor. IMX chainId thường là IMX_MAINNET = 13372 hoặc IMX_TESTNET — kiểm tra constants đang dùng trong project. Nếu IMX rental return không được support, cần throw RENTAL_UNSUPPORTED_CHAIN thay 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ới createRentNftIMX:
    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 returnRentNft khô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-nft với IMX chainId → createRentNftIMX được gọi (không gọi EVM path)
  • [ ] POST /rental/return-rent-nft với IMX chainId → trả về RENTAL_UNSUPPORTED_CHAIN error
  • [ ] POST /rental/rent-nft với IMX chainId → trả về RENTAL_UNSUPPORTED_CHAIN error
  • [ ] EVM returnRentNft vẫn hoạt động bình thường sau khi thêm validation
  • [ ] Solana rentNft vẫ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.ts
  • src/rental/constants/rental.constants.ts