Update LIP0052 - improve code readability, correct/improve `getCollectionID`, `getChainID` and `lock` functions, typos
mjerkov opened this issue · 0 comments
mjerkov commented
Motivation
Several issues in LIP 0052 have been noticed:
getCollectionID
function enforces that an NFT must be stored before returning the correspondingcollectionID
. However, in the foreign-chain part of the execution of the cross-chain ccm, there is a call to theisNFTSupported
function, which in turn callsgetCollectionID
function. This is a problem, since at that point the NFT is not yet stored on the foreign chain, and the execution would fail.module
argument oflock
function is not checked against a possiblenft
input value, equal to the current value ofNFT_NOT_LOCKED
. This results in an unexpected behaviour of not locking the module.- Checks whether an NFT is escrowed or locked should be factored out to separate functions with self-explanatory names. Thus, when these checks are encountered elsewhere in the pseudocode, their purpose would be clear.
- Several typos and/or code quality improvements are recommended.
- In
crossChainNFTTransferParamsSchema
for the cross-chain transfer command, the propertymessageFeeTokenID
is not needed, since it is does not appear anywhere in the execution.
Current Specifications
- In
getCollectionID
, there is a check which ensures that NFT should be stored in the NFT store:
def getCollectionID(nftID: NFTID) -> CollectionID:
if NFTStore[nftID] does not exist:
raise Exception("NFT substore entry does not exist")
return nftID[`LENGTH_CHAIN_ID`:(`LENGTH_CHAIN_ID` + `LENGTH_COLLECTION_ID`)]
- In
lock
, there is no check thatmodule
should not be equal toNFT_NOT_LOCKED
. - In several functions, there are checks to ensure that an NFT is/isn't escrowed, e.g.
if len(getNFTOwner(nftID)) == LENGTH_CHAIN_ID:
Furthermore, in several functions there are checks to ensure that an NFT is/isn't locked, e.g.
if getLockingModule(nftID) != NFT_NOT_LOCKED:
- In pattern definition for
lockingModule
property ofuserStoreSchema
there is a typo (extra]
at the end of pattern expression):
"lockingModule": {
"dataType": "string",
"minLength": MIN_LENGTH_MODULE_NAME,
"maxLength": MAX_LENGTH_MODULE_NAME,
"pattern": "^[a-zA-Z0-9]*$]",
"fieldNumber": 1
}
Furthermore, the specification of the getCollectionID
function has unnecessary "`" characters:
nftID[`LENGTH_CHAIN_ID`:(`LENGTH_CHAIN_ID` + `LENGTH_COLLECTION_ID`)]
Also, the return statement of the getAttributes
function has unnecessary parentheses:
return(entry['attributes'])
- Currently,
messageFeeTokenID
is a property ofcrossChainNFTTransferParamsSchema
.
Proposed Specifications
- In
getCollectionID
, remove the check whether NFT is stored in the NFT store:
def getCollectionID(nftID: NFTID) -> CollectionID:
return nftID[`LENGTH_CHAIN_ID`:(`LENGTH_CHAIN_ID` + `LENGTH_COLLECTION_ID`)]
- In
lock
, add the check to ensure that the value of themodule
argument is not equal toNFT_NOT_LOCKED
. - Define dedicated functions
isNFTEscrowed
andisNFTLocked
that perform the mentioned checks and refactor the code accordingly. - Remove the extra symbols.
- Remove
messageFeeTokenID
fromcrossChainNFTTransferParamsSchema
and update the code accordingly. The following check in theverify
function of the cross-chain transfer command now becomes obsolete:
if messageFeeTokenID != Interoperability.getMessageFeeTokenID(receivingChainID):
raise Exception("Mismatching message fee Token ID")
Affected LIPs
0052