Skip to content

Instantly share code, notes, and snippets.

@prajwolrg
Created November 1, 2022 15:00
Show Gist options
  • Select an option

  • Save prajwolrg/1ee8a1bdb02fa96dc9788ff0a366b6ec to your computer and use it in GitHub Desktop.

Select an option

Save prajwolrg/1ee8a1bdb02fa96dc9788ff0a366b6ec to your computer and use it in GitHub Desktop.

Revisions

  1. Prajwol Gyawali created this gist Nov 1, 2022.
    27 changes: 27 additions & 0 deletions addResourceToToken.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    pragma solidity ^0.8.15;

    function _addResourceToToken(
    uint256 tokenId,
    uint64 resourceId,
    uint64 overwrites
    ) internal {
    if (_tokenResources[tokenId][resourceId])
    revert RMRKResourceAlreadyExists();

    if (bytes(_resources[resourceId]).length == 0)
    revert RMRKNoResourceMatchingId();

    if (_pendingResources[tokenId].length >= 128)
    revert RMRKMaxPendingResourcesReached();

    _tokenResources[tokenId][resourceId] = true;

    _pendingResources[tokenId].push(resourceId);

    if (overwrites != uint64(0)) {
    _resourceOverwrites[tokenId][resourceId] = overwrites;
    emit ResourceOverwriteProposed(tokenId, resourceId, overwrites);
    }

    emit ResourceAddedToToken(tokenId, resourceId);
    }