Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
691 changes: 691 additions & 0 deletions miniwallet/contracts/nft/HRC721/HRC721.sol

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions miniwallet/contracts/nft/HRC721/extensions/HRC721Burnable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: Apache-2.0

// Creator: Chiru Labs
// Sep 1st 2022, Modification for MiniWallet by John Whitton

pragma solidity ^0.8.4;

import "../HRC721.sol";
import "@openzeppelin/contracts/utils/Context.sol";

/**
* @title HRC721 Burnable Token
* @dev HRC721 Token that can be irreversibly burned (destroyed).
*/
abstract contract HRC721Burnable is Context, HRC721 {
/**
* @dev Burns `tokenId`. See {HRC721-_burn}.
*
* Requirements:
*
* - The caller must own `tokenId` or be an approved operator.
*/
function burn(uint256 tokenId) public virtual {
TokenOwnership memory prevOwnership = ownershipOf(tokenId);

bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr ||
isApprovedForAll(prevOwnership.addr, _msgSender()) ||
getApproved(tokenId) == _msgSender());

if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved();

_burn(tokenId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: Apache-2.0

// Creator: Chiru Labs
// Sep 1st 2022, Modification for MiniWallet by John Whitton

pragma solidity ^0.8.4;

import "../HRC721.sol";

error AllOwnershipsHaveBeenSet();
error QuantityMustBeNonZero();
error NoTokensMintedYet();

abstract contract HRC721OwnersExplicit is HRC721 {
uint256 public nextOwnerToExplicitlySet;

/**
* @dev Explicitly set `owners` to eliminate loops in future calls of ownerOf().
*/
function _setOwnersExplicit(uint256 quantity) internal {
if (quantity == 0) revert QuantityMustBeNonZero();
if (_currentIndex == 0) revert NoTokensMintedYet();
uint256 _nextOwnerToExplicitlySet = nextOwnerToExplicitlySet;
if (_nextOwnerToExplicitlySet >= _currentIndex)
revert AllOwnershipsHaveBeenSet();

// Index underflow is impossible.
// Counter or index overflow is incredibly unrealistic.
unchecked {
uint256 endIndex = _nextOwnerToExplicitlySet + quantity - 1;

// Set the end index to be the last token index
if (endIndex + 1 > _currentIndex) {
endIndex = _currentIndex - 1;
}

for (uint256 i = _nextOwnerToExplicitlySet; i <= endIndex; i++) {
if (
_ownerships[i].addr == address(0) && !_ownerships[i].burned
) {
TokenOwnership memory ownership = ownershipOf(i);
_ownerships[i].addr = ownership.addr;
_ownerships[i].startTimestamp = ownership.startTimestamp;
}
}

nextOwnerToExplicitlySet = endIndex + 1;
}
}
}
Loading