Skip to content

Instantly share code, notes, and snippets.

@prajwolrg
Last active November 1, 2022 10:50
Show Gist options
  • Save prajwolrg/484e7a7b8c6c00a2fde425ab251e60d6 to your computer and use it in GitHub Desktop.
Save prajwolrg/484e7a7b8c6c00a2fde425ab251e60d6 to your computer and use it in GitHub Desktop.
RMRK checkForInheritanceLoop function
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