Skip to content
Next Next commit
feat: implement ERC721Mintable and ERC721Burnable
  • Loading branch information
shrugs committed Sep 4, 2018
commit 3f0d55784ba911d3d0b21743773c5fcf6fb27d20
8 changes: 6 additions & 2 deletions contracts/mocks/ERC721BasicMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import "../token/ERC721/ERC721Basic.sol";
*/
contract ERC721BasicMock is ERC721Basic {
function mint(address _to, uint256 _tokenId) public {
super._mint(_to, _tokenId);
_mint(_to, _tokenId);
}

function mintWithTokenURI(address _to, uint256 _tokenId, string) public {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's that third unused parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokenURI, but since it's not used in the implementation of the mock, I removed the name to stop solc from complaining

_mint(_to, _tokenId);
}

function burn(uint256 _tokenId) public {
super._burn(ownerOf(_tokenId), _tokenId);
_burn(ownerOf(_tokenId), _tokenId);
}
}
18 changes: 18 additions & 0 deletions contracts/mocks/ERC721MintableBurnableImpl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity ^0.4.24;

import "../token/ERC721/ERC721.sol";
import "../token/ERC721/ERC721Mintable.sol";
import "../token/ERC721/ERC721Burnable.sol";


/**
* @title ERC721MintableBurnableImpl
*/
contract ERC721MintableBurnableImpl is ERC721, ERC721Mintable, ERC721Burnable {
constructor(address[] _minters)
ERC721Mintable(_minters)
ERC721("Test", "TEST")
public
{
}
}
19 changes: 7 additions & 12 deletions contracts/mocks/ERC721Mock.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
pragma solidity ^0.4.24;

import "../token/ERC721/ERC721.sol";
import "../token/ERC721/ERC721Mintable.sol";
import "../token/ERC721/ERC721Burnable.sol";


/**
* @title ERC721Mock
* This mock just provides a public mint and burn functions for testing purposes,
* and a public setter for metadata URI
*/
contract ERC721Mock is ERC721 {
constructor(string name, string symbol) public
ERC721(name, symbol)
{ }

function mint(address _to, uint256 _tokenId) public {
_mint(_to, _tokenId);
}

function burn(uint256 _tokenId) public {
_burn(ownerOf(_tokenId), _tokenId);
}
contract ERC721Mock is ERC721, ERC721Mintable, ERC721Burnable {
constructor(string _name, string _symbol, address[] _minters) public
ERC721Mintable(_minters)
ERC721(_name, _symbol)
{}

function exists(uint256 _tokenId) public view returns (bool) {
return _exists(_tokenId);
Expand Down
5 changes: 2 additions & 3 deletions contracts/token/ERC20/ERC20Mintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import "../../access/rbac/MinterRole.sol";


/**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
* @title ERC20Mintable
* @dev ERC20 minting logic
*/
contract ERC20Mintable is ERC20, MinterRole {
event Mint(address indexed to, uint256 amount);
Expand Down
12 changes: 12 additions & 0 deletions contracts/token/ERC721/ERC721Burnable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity ^0.4.24;

import "./ERC721.sol";

contract ERC721Burnable is ERC721 {
function burn(uint256 _tokenId)
public
{
require(_isApprovedOrOwner(msg.sender, _tokenId));
_burn(ownerOf(_tokenId), _tokenId);
}
}
77 changes: 77 additions & 0 deletions contracts/token/ERC721/ERC721Mintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pragma solidity ^0.4.24;

import "./ERC721.sol";
import "../../access/rbac/MinterRole.sol";


/**
* @title ERC721Mintable
* @dev ERC721 minting logic
*/
contract ERC721Mintable is ERC721, MinterRole {
event Mint(address indexed to, uint256 tokenId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Minted, as per #1181?

event MintFinished();

bool public mintingFinished = false;

constructor(address[] _minters)
MinterRole(_minters)
public
{
}

modifier canMint() {
require(!mintingFinished);
_;
}

/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _tokenId The token id to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(
address _to,
uint256 _tokenId
)
public
onlyMinter
canMint
returns (bool)
{
_mint(_to, _tokenId);
emit Mint(_to, _tokenId);
return true;
}

function mintWithTokenURI(
address _to,
uint256 _tokenId,
string _tokenURI
)
public
onlyMinter
canMint
returns (bool)
{
mint(_to, _tokenId);
_setTokenURI(_tokenId, _tokenURI);
return true;
}

/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting()
public
onlyMinter
canMint
returns (bool)
{
mintingFinished = true;
emit MintFinished();
return true;
}
}
Loading