refactor: change token controller role validation to _beforeTokenTransfer function
This commit is contained in:
parent
b426d718f6
commit
752bbb896a
|
|
@ -12,7 +12,6 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
using Counters for Counters.Counter;
|
using Counters for Counters.Counter;
|
||||||
|
|
||||||
event NewBuild(uint256 indexed token, string indexed commit_hash);
|
event NewBuild(uint256 indexed token, string indexed commit_hash);
|
||||||
|
|
||||||
event NewTokenName(uint256 indexed token, string indexed name);
|
event NewTokenName(uint256 indexed token, string indexed name);
|
||||||
event NewTokenDescription(uint256 indexed token, string indexed description);
|
event NewTokenDescription(uint256 indexed token, string indexed description);
|
||||||
event NewTokenImage(uint256 indexed token, string indexed image);
|
event NewTokenImage(uint256 indexed token, string indexed image);
|
||||||
|
|
@ -69,7 +68,6 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
) public payable requireCollectionOwner returns (uint256) {
|
) public payable requireCollectionOwner returns (uint256) {
|
||||||
uint256 tokenId = _tokenIds.current();
|
uint256 tokenId = _tokenIds.current();
|
||||||
_mint(to, tokenId);
|
_mint(to, tokenId);
|
||||||
addTokenController(tokenId, to);
|
|
||||||
_tokenIds.increment();
|
_tokenIds.increment();
|
||||||
|
|
||||||
App storage app = _apps[tokenId];
|
App storage app = _apps[tokenId];
|
||||||
|
|
@ -145,35 +143,31 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
return super.supportsInterface(interfaceId);
|
return super.supportsInterface(interfaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferFrom(
|
/**
|
||||||
address from,
|
* @dev Override of _beforeTokenTransfer of ERC721.
|
||||||
address to,
|
* Here it needs to update the token controller roles for mint, burn and transfer.
|
||||||
uint256 tokenId
|
* IMPORTANT: The function for clearing token controllers is not implemented yet.
|
||||||
) public virtual override {
|
*/
|
||||||
super.transferFrom(from, to, tokenId);
|
function _beforeTokenTransfer(
|
||||||
_clearTokenControllers(tokenId);
|
|
||||||
}
|
|
||||||
|
|
||||||
function safeTransferFrom(
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 tokenId
|
|
||||||
) public virtual override {
|
|
||||||
super.safeTransferFrom(from, to, tokenId, "");
|
|
||||||
_clearTokenControllers(tokenId);
|
|
||||||
}
|
|
||||||
|
|
||||||
function safeTransferFrom(
|
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
bytes memory data
|
uint256 batchSize
|
||||||
) public virtual override {
|
) internal virtual override {
|
||||||
super._safeTransfer(from, to, tokenId, data);
|
if (from != address(0) && to != address(0)) {
|
||||||
_clearTokenControllers(tokenId);
|
// Transfer
|
||||||
|
_clearTokenControllers(tokenId);
|
||||||
|
_grantRole(_tokenRole(tokenId, "CONTROLLER"), to);
|
||||||
|
} else if (from == address(0)) {
|
||||||
|
// Mint
|
||||||
|
_grantRole(_tokenRole(tokenId, "CONTROLLER"), to);
|
||||||
|
} else if (to == address(0)) {
|
||||||
|
// Burn
|
||||||
|
_clearTokenControllers(tokenId);
|
||||||
|
}
|
||||||
|
super._beforeTokenTransfer(from, to, tokenId, batchSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function _baseURI() internal view virtual override returns (string memory) {
|
function _baseURI() internal view virtual override returns (string memory) {
|
||||||
return "data:application/json;base64,";
|
return "data:application/json;base64,";
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +224,11 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
string memory _author
|
string memory _author
|
||||||
) public virtual requireTokenController(tokenId) {
|
) public virtual requireTokenController(tokenId) {
|
||||||
_requireMinted(tokenId);
|
_requireMinted(tokenId);
|
||||||
_apps[tokenId].builds[++_apps[tokenId].current_build] = Build(_commit_hash, _git_repository, _author);
|
_apps[tokenId].builds[++_apps[tokenId].current_build] = Build(
|
||||||
|
_commit_hash,
|
||||||
|
_git_repository,
|
||||||
|
_author
|
||||||
|
);
|
||||||
emit NewBuild(tokenId, _commit_hash);
|
emit NewBuild(tokenId, _commit_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,9 +246,7 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _clearTokenControllers(
|
function _clearTokenControllers(uint256 tokenId) internal {
|
||||||
uint256 tokenId
|
|
||||||
) internal {
|
|
||||||
// TODO: Remove token controllers from AccessControl
|
// TODO: Remove token controllers from AccessControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue