Document methods and make everything camelCase
This commit is contained in:
parent
3cf9be4528
commit
7ac1502885
|
|
@ -19,9 +19,8 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
event NewTokenENS(uint256 indexed token, string indexed ENS, address indexed triggered_by);
|
event NewTokenENS(uint256 indexed token, string indexed ENS, address indexed triggered_by);
|
||||||
|
|
||||||
struct Build {
|
struct Build {
|
||||||
string commit_hash;
|
string commitHash;
|
||||||
string git_repository;
|
string gitRepository;
|
||||||
string author;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,9 +32,9 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
string name; // Name of the site
|
string name; // Name of the site
|
||||||
string description; // Description about the site
|
string description; // Description about the site
|
||||||
string image; // Preview Image IPFS Link
|
string image; // Preview Image IPFS Link
|
||||||
string external_url; // Site URL
|
string externalURL; // Site URL
|
||||||
string ENS; // ENS ID
|
string ENS; // ENS ID
|
||||||
uint256 current_build; // The current build number (Increments by one with each change, starts at zero)
|
uint256 currentBuild; // The current build number (Increments by one with each change, starts at zero)
|
||||||
mapping(uint256 => Build) builds; // Mapping to build details for each build number
|
mapping(uint256 => Build) builds; // Mapping to build details for each build number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,16 +54,25 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Mints a token and returns a tokenId.
|
||||||
|
*
|
||||||
|
* If the `tokenId` has not been minted before, and the `to` address is not zero, emits a {Transfer} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the caller must have ``collectionOwner``'s admin role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function mint(
|
function mint(
|
||||||
address to,
|
address to,
|
||||||
string memory name,
|
string memory name,
|
||||||
string memory description,
|
string memory description,
|
||||||
string memory image,
|
string memory image,
|
||||||
string memory external_url,
|
string memory externalURL,
|
||||||
string memory ENS,
|
string memory ENS,
|
||||||
string memory commit_hash,
|
string memory commitHash,
|
||||||
string memory git_repository,
|
string memory gitRepository
|
||||||
string memory author
|
|
||||||
) public payable requireCollectionOwner returns (uint256) {
|
) public payable requireCollectionOwner returns (uint256) {
|
||||||
uint256 tokenId = _tokenIds.current();
|
uint256 tokenId = _tokenIds.current();
|
||||||
_mint(to, tokenId);
|
_mint(to, tokenId);
|
||||||
|
|
@ -74,16 +82,26 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
app.name = name;
|
app.name = name;
|
||||||
app.description = description;
|
app.description = description;
|
||||||
app.image = image;
|
app.image = image;
|
||||||
app.external_url = external_url;
|
app.externalURL = externalURL;
|
||||||
app.ENS = ENS;
|
app.ENS = ENS;
|
||||||
|
|
||||||
// The mint interaction is considered to be the first build of the site. Updates from now on all increment the current_build by one and update the mapping.
|
// The mint interaction is considered to be the first build of the site. Updates from now on all increment the currentBuild by one and update the mapping.
|
||||||
app.current_build = 0;
|
app.currentBuild = 0;
|
||||||
app.builds[0] = Build(commit_hash, git_repository, author);
|
app.builds[0] = Build(commitHash, gitRepository);
|
||||||
|
|
||||||
return tokenId;
|
return tokenId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Returns the token metadata associated with the `tokenId`.
|
||||||
|
*
|
||||||
|
* Returns a based64 encoded string value of the URI.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function tokenURI(
|
function tokenURI(
|
||||||
uint256 tokenId
|
uint256 tokenId
|
||||||
) public view virtual override returns (string memory) {
|
) public view virtual override returns (string memory) {
|
||||||
|
|
@ -96,14 +114,13 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
'"name":"', app.name, '",',
|
'"name":"', app.name, '",',
|
||||||
'"description":"', app.description, '",',
|
'"description":"', app.description, '",',
|
||||||
'"owner":"', Strings.toHexString(uint160(owner), 20), '",',
|
'"owner":"', Strings.toHexString(uint160(owner), 20), '",',
|
||||||
'"external_url":"', app.external_url, '",',
|
'"external_url":"', app.externalURL, '",',
|
||||||
'"image":"', app.image, '",',
|
'"image":"', app.image, '",',
|
||||||
'"attributes": [',
|
'"attributes": [',
|
||||||
'{"trait_type": "ENS", "value":"', app.ENS,'"},',
|
'{"trait_type": "ENS", "value":"', app.ENS,'"},',
|
||||||
'{"trait_type": "Commit Hash", "value":"', app.builds[app.current_build].commit_hash,'"},',
|
'{"trait_type": "Commit Hash", "value":"', app.builds[app.currentBuild].commitHash,'"},',
|
||||||
'{"trait_type": "Repository", "value":"', app.builds[app.current_build].git_repository,'"},',
|
'{"trait_type": "Repository", "value":"', app.builds[app.currentBuild].gitRepository,'"},',
|
||||||
'{"trait_type": "Author", "value":"', app.builds[app.current_build].author,'"},',
|
'{"trait_type": "Version", "value":"', Strings.toString(app.currentBuild),'"}',
|
||||||
'{"trait_type": "Version", "value":"', Strings.toString(app.current_build),'"}',
|
|
||||||
']',
|
']',
|
||||||
'}'
|
'}'
|
||||||
);
|
);
|
||||||
|
|
@ -111,6 +128,17 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
return string(abi.encodePacked(_baseURI(), Base64.encode((dataURI))));
|
return string(abi.encodePacked(_baseURI(), Base64.encode((dataURI))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Adds a new address with the`tokenController` privileges to a previously minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {RoleGranted} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenOwner` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function addTokenController(
|
function addTokenController(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
address controller
|
address controller
|
||||||
|
|
@ -119,6 +147,17 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
_grantRole(_tokenRole(tokenId, "CONTROLLER"), controller);
|
_grantRole(_tokenRole(tokenId, "CONTROLLER"), controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Strips an address from their `tokenController` privileges on a previously minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {RoleRevoked} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenOwner` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function removeTokenController(
|
function removeTokenController(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
address controller
|
address controller
|
||||||
|
|
@ -127,6 +166,9 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
_revokeRole(_tokenRole(tokenId, "CONTROLLER"), controller);
|
_revokeRole(_tokenRole(tokenId, "CONTROLLER"), controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev See {IERC165-supportsInterface}.
|
||||||
|
*/
|
||||||
function supportsInterface(
|
function supportsInterface(
|
||||||
bytes4 interfaceId
|
bytes4 interfaceId
|
||||||
) public view virtual override(ERC721, AccessControl) returns (bool) {
|
) public view virtual override(ERC721, AccessControl) returns (bool) {
|
||||||
|
|
@ -158,19 +200,44 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
super._beforeTokenTransfer(from, to, tokenId, batchSize);
|
super._beforeTokenTransfer(from, to, tokenId, batchSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev A baseURI internal function implementation to be called in the `tokenURI` function.
|
||||||
|
*/
|
||||||
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,";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Updates the `externalURL` metadata field of a minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {NewTokenExternalURL} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenController` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function setTokenExternalURL(
|
function setTokenExternalURL(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
string memory _tokenExternalURL
|
string memory _tokenExternalURL
|
||||||
) public virtual requireTokenController(tokenId) {
|
) public virtual requireTokenController(tokenId) {
|
||||||
_requireMinted(tokenId);
|
_requireMinted(tokenId);
|
||||||
_apps[tokenId].external_url = _tokenExternalURL;
|
_apps[tokenId].externalURL = _tokenExternalURL;
|
||||||
emit NewTokenExternalURL(tokenId, _tokenExternalURL, msg.sender);
|
emit NewTokenExternalURL(tokenId, _tokenExternalURL, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Updates the `ENS` metadata field of a minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {NewTokenENS} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenController` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function setTokenENS(
|
function setTokenENS(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
string memory _tokenENS
|
string memory _tokenENS
|
||||||
|
|
@ -180,6 +247,17 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
emit NewTokenENS(tokenId, _tokenENS, msg.sender);
|
emit NewTokenENS(tokenId, _tokenENS, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Updates the `name` metadata field of a minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {NewTokenName} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenController` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function setTokenName(
|
function setTokenName(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
string memory _tokenName
|
string memory _tokenName
|
||||||
|
|
@ -189,6 +267,17 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
emit NewTokenName(tokenId, _tokenName, msg.sender);
|
emit NewTokenName(tokenId, _tokenName, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Updates the `description` metadata field of a minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {NewTokenDescription} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenController` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function setTokenDescription(
|
function setTokenDescription(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
string memory _tokenDescription
|
string memory _tokenDescription
|
||||||
|
|
@ -198,6 +287,17 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
emit NewTokenDescription(tokenId, _tokenDescription, msg.sender);
|
emit NewTokenDescription(tokenId, _tokenDescription, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Updates the `image` metadata field of a minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {NewTokenImage} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenController` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function setTokenImage(
|
function setTokenImage(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
string memory _tokenImage
|
string memory _tokenImage
|
||||||
|
|
@ -207,27 +307,47 @@ contract FleekERC721 is ERC721, FleekAccessControl {
|
||||||
emit NewTokenImage(tokenId, _tokenImage, msg.sender);
|
emit NewTokenImage(tokenId, _tokenImage, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Adds a new build to a minted `tokenId`'s builds mapping.
|
||||||
|
*
|
||||||
|
* May emit a {NewBuild} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenController` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function setTokenBuild(
|
function setTokenBuild(
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
string memory _commit_hash,
|
string memory _commitHash,
|
||||||
string memory _git_repository,
|
string memory _gitRepository
|
||||||
string memory _author
|
|
||||||
) public virtual requireTokenController(tokenId) {
|
) public virtual requireTokenController(tokenId) {
|
||||||
_requireMinted(tokenId);
|
_requireMinted(tokenId);
|
||||||
_apps[tokenId].builds[++_apps[tokenId].current_build] = Build(
|
_apps[tokenId].builds[++_apps[tokenId].currentBuild] = Build(
|
||||||
_commit_hash,
|
_commitHash,
|
||||||
_git_repository,
|
_gitRepository
|
||||||
_author
|
|
||||||
);
|
);
|
||||||
emit NewBuild(tokenId, _commit_hash, msg.sender);
|
emit NewBuild(tokenId, _commitHash, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Burns a previously minted `tokenId`.
|
||||||
|
*
|
||||||
|
* May emit a {Transfer} event.
|
||||||
|
*
|
||||||
|
* Requirements:
|
||||||
|
*
|
||||||
|
* - the tokenId must be minted and valid.
|
||||||
|
* - the sender must have the `tokenOwner` role.
|
||||||
|
*
|
||||||
|
*/
|
||||||
function burn(
|
function burn(
|
||||||
uint256 tokenId
|
uint256 tokenId
|
||||||
) public virtual requireTokenOwner(tokenId) {
|
) public virtual requireTokenOwner(tokenId) {
|
||||||
super._burn(tokenId);
|
super._burn(tokenId);
|
||||||
|
|
||||||
if (bytes(_apps[tokenId].external_url).length != 0) {
|
if (bytes(_apps[tokenId].externalURL).length != 0) {
|
||||||
delete _apps[tokenId];
|
delete _apps[tokenId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue