Skip to content

Instantly share code, notes, and snippets.

@prajwolrg
Created November 1, 2022 11:04
Show Gist options
  • Save prajwolrg/5145eb6b7f934783c92efb07016c6833 to your computer and use it in GitHub Desktop.
Save prajwolrg/5145eb6b7f934783c92efb07016c6833 to your computer and use it in GitHub Desktop.
Add child
pragma solidity ^0.8.15;
function addChild(uint256 parentTokenId, uint256 childTokenId)
public
virtual
{
_requireMinted(parentTokenId);
if (!_msgSender().isContract()) revert RMRKIsNotContract();
Child memory child = Child({
contractAddress: _msgSender(),
tokenId: childTokenId
});
uint256 length = pendingChildrenOf(parentTokenId).length;
if (length < 128) {
_childIsInPending[child.contractAddress][child.tokenId] = 1; // We use 1 as true
_pendingChildren[parentTokenId].push(child);
} else {
revert RMRKMaxPendingChildrenReached();
}
// Previous length matches the index for the new child
emit ChildProposed(parentTokenId, _msgSender(), childTokenId, length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment