Core
Other
Utils
Nestable Render Utils

RMRKNestableRenderUtils

RMRK team

RMRKNestableRenderUtils

Smart contract of the RMRK Nestable render utils module.

Methods

checkExpectedParent

function checkExpectedParent(address childAddress, uint256 childId, address expectedParent, uint256 expectedParentId) external view

Check if the child is owned by the expected parent.

Reverts if child token is not owned by an NFT.Reverts if child token is not owned by the expected parent.

Parameters

NameTypeDescription
childAddressaddressAddress of the child contract
childIduint256ID of the child token
expectedParentaddressAddress of the expected parent contract
expectedParentIduint256ID of the expected parent token

directOwnerOfWithParentsPerspective

function directOwnerOfWithParentsPerspective(address collection, uint256 tokenId) external view returns (address directOwner, uint256 ownerId, bool isNFT, bool inParentsActiveChildren, bool inParentsPendingChildren)

Used to retrieve the immediate owner of the given token, and whether it is on the parent's active or pending children list.

If the immediate owner is not an NFT, the function returns false for both inParentsActiveChildren and inParentsPendingChildren.

Parameters

NameTypeDescription
collectionaddressAddress of the token's collection smart contract
tokenIduint256ID of the token

Returns

NameTypeDescription
directOwneraddressAddress of the given token's owner
ownerIduint256The ID of the parent token. Should be 0 if the owner is an externally owned account
isNFTboolThe boolean value signifying whether the owner is an NFT or not
inParentsActiveChildrenboolA boolean value signifying whether the token is in the parent's active children list
inParentsPendingChildrenboolA boolean value signifying whether the token is in the parent's pending children list

getChildIndex

function getChildIndex(address parentAddress, uint256 parentId, address childAddress, uint256 childId) external view returns (uint256 index)

Used to retrieve the given child's index in its parent's child tokens array.

Parameters

NameTypeDescription
parentAddressaddressAddress of the parent token's collection smart contract
parentIduint256ID of the parent token
childAddressaddressAddress of the child token's colection smart contract
childIduint256ID of the child token

Returns

NameTypeDescription
indexuint256The index of the child token in the parent token's child tokens array

getParent

function getParent(address childAddress, uint256 childId) external view returns (address parentAddress, uint256 parentId)

Used to retrieve the contract address and ID of the parent token of the specified child token.

Reverts if child token is not owned by an NFT.

Parameters

NameTypeDescription
childAddressaddressAddress of the child token's collection smart contract
childIduint256ID of the child token

Returns

NameTypeDescription
parentAddressaddressAddress of the parent token's collection smart contract
parentIduint256ID of the parent token

getPendingChildIndex

function getPendingChildIndex(address parentAddress, uint256 parentId, address childAddress, uint256 childId) external view returns (uint256 index)

Used to retrieve the given child's index in its parent's pending child tokens array.

Parameters

NameTypeDescription
parentAddressaddressAddress of the parent token's collection smart contract
parentIduint256ID of the parent token
childAddressaddressAddress of the child token's colection smart contract
childIduint256ID of the child token

Returns

NameTypeDescription
indexuint256The index of the child token in the parent token's pending child tokens array

getTotalDescendants

function getTotalDescendants(address collection, uint256 tokenId) external view returns (uint256 totalDescendants, bool hasMoreThanOneLevelOfNesting_)

Used to retrieve the total number of descendants of the given token and whether it has more than one level of nesting.

Parameters

NameTypeDescription
collectionaddressAddress of the token's collection smart contract
tokenIduint256ID of the token

Returns

NameTypeDescription
totalDescendantsuint256The total number of descendants of the given token
hasMoreThanOneLevelOfNesting_boolA boolean value indicating whether the given token has more than one level of nesting

hasMoreThanOneLevelOfNesting

function hasMoreThanOneLevelOfNesting(address collection, uint256 tokenId) external view returns (bool hasMoreThanOneLevelOfNesting_)

Used to retrieve whether a token has more than one level of nesting.

Parameters

NameTypeDescription
collectionaddressAddress of the token's collection smart contract
tokenIduint256ID of the token

Returns

NameTypeDescription
hasMoreThanOneLevelOfNesting_boolA boolean value indicating whether the given token has more than one level of nesting

isTokenRejectedOrAbandoned

function isTokenRejectedOrAbandoned(address collection, uint256 tokenId) external view returns (bool isRejectedOrAbandoned)

Used to identify if the given token is rejected or abandoned. That is, it's parent is an NFT but this token is neither on the parent's active nor pending children list.

Returns false if the immediate owner is not an NFT.

Parameters

NameTypeDescription
collectionaddressAddress of the token's collection smart contract
tokenIduint256ID of the token

Returns

NameTypeDescription
isRejectedOrAbandonedboolWhether the token is rejected or abandoned

validateChildOf

function validateChildOf(address parentAddress, address childAddress, uint256 parentId, uint256 childId) external view returns (bool validChild)

Used to validate whether the specified child token is owned by a given parent token.

Parameters

NameTypeDescription
parentAddressaddressAddress of the parent token's collection smart contract
childAddressaddressAddress of the child token's collection smart contract
parentIduint256ID of the parent token
childIduint256ID of the child token

Returns

NameTypeDescription
validChildboolA boolean value indicating whether the child token is owned by the parent token or not

validateChildrenOf

function validateChildrenOf(address parentAddress, address[] childAddresses, uint256 parentId, uint256[] childIds) external view returns (bool isValid, bool[] validityOfChildren)

Used to validate whether the specified child token is owned by a given parent token.

Parameters

NameTypeDescription
parentAddressaddressAddress of the parent token's collection smart contract
childAddressesaddress[]An array of the child token's collection smart contract addresses
parentIduint256ID of the parent token
childIdsuint256[]An array of child token IDs to verify

Returns

NameTypeDescription
isValidboolA boolean value indicating whether all of the child tokens are owned by the parent token or not
validityOfChildrenbool[]An array of boolean values indicating whether each of the child tokens are owned by the parent token or not

Errors

RMRKChildNotFoundInParent

error RMRKChildNotFoundInParent()

Attempting to find the index of a child token on a parent which does not own it.

RMRKMismachedArrayLength

error RMRKMismachedArrayLength()

Attempting to pass complementary arrays of different lengths

RMRKParentIsNotNFT

error RMRKParentIsNotNFT()

Attempting an operation requiring the token being nested, while it is not

RMRKUnexpectedParent

error RMRKUnexpectedParent()

Attempting an operation expecting a parent to the token which is not the actual one