Last active
November 1, 2022 10:50
-
-
Save prajwolrg/484e7a7b8c6c00a2fde425ab251e60d6 to your computer and use it in GitHub Desktop.
RMRK checkForInheritanceLoop function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.15; | |
uint256 private constant _MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP = 100; | |
function _checkForInheritanceLoop( | |
uint256 currentId, | |
address targetContract, | |
uint256 targetId | |
) private view { | |
for (uint256 i; i < _MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP; ) { | |
( | |
address nextOwner, | |
uint256 nextOwnerTokenId, | |
bool isNft | |
) = IRMRKNesting(targetContract).rmrkOwnerOf(targetId); | |
// If there's a final address, we're good. There's no loop. | |
if (!isNft) { | |
return; | |
} | |
// Ff the current nft is an ancestor at some point, there is an inheritance loop | |
if (nextOwner == address(this) && nextOwnerTokenId == currentId) { | |
revert RMRKNestingTransferToDescendant(); | |
} | |
// We reuse the parameters to save some contract size | |
targetContract = nextOwner; | |
targetId = nextOwnerTokenId; | |
unchecked { | |
++i; | |
} | |
} | |
revert RMRKNestingTooDeep(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment