LiskArchive/lips

Remove code redundancy in transfer methods of LIP 0052

mjerkov opened this issue · 0 comments

Motivation

In LIP 0052, transfer function and command, as well as cross-chain transfer function and command, have unnecessary code duplication in the verification part.

Current Specifications

Currently, transfer command

    if NFTStore[nftID] does not exist:
        raise Exception("NFT substore entry does not exist")
    if len(getNFTOwner(nftID)) == LENGTH_CHAIN_ID:
        raise Exception("NFT is escrowed to another chain")
    if getNFTOwner(nftID) != senderAddress:
        raise Exception("Transfer not initiated by the NFT owner")
    if getLockingModule(nftID) != NFT_NOT_LOCKED:
        raise Exception("Locked NFTs cannot be transferred")

and function

    if NFTStore[nftID] does not exist:
        emitFailedTransferEvent(senderAddress, recipientAddress, nftID, RESULT_NFT_DOES_NOT_EXIST)
        raise Exception("NFT substore entry does not exist")
    if len(getNFTOwner(nftID)) == LENGTH_CHAIN_ID:
        emitFailedTransferEvent(senderAddress, recipientAddress, nftID, RESULT_NFT_ESCROWED)
        raise Exception("NFT is escrowed to another chain")
    if getNFTOwner(nftID) != senderAddress:
        emitFailedTransferEvent(senderAddress, recipientAddress, nftID, RESULT_INITIATED_BY_NONOWNER)
        raise Exception("Transfer not initiated by the NFT owner")
    if getLockingModule(nftID) != NFT_NOT_LOCKED:
        emitFailedTransferEvent(senderAddress, recipientAddress, nftID, RESULT_NFT_LOCKED)
        raise Exception("Locked NFTs cannot be transferred")

do the same checks, with the only difference that command verification does not emit failed transfer events.

Similar repetition exists in the cross-chain transfer function and command.

Proposed Specifications

Regarding the transfer command and method: Factorize the repeating verification code into a verifyTransferInteral function.
Regarding the cross-chain transfer command and method: Factorize the repeating verification code into a a verifyTransferCrossChainInternal function.

Affected LIPs

0052