From 8286b71c84f31b7de162ab3f054116fd497db094 Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Wed, 30 Nov 2022 16:56:28 +0330 Subject: [PATCH] Fix errors and make the contract environment ready for compiling. --- contracts/FleekERC721.sol | 59 +++++++++++++++++++++------------------ deploy/deploy.js | 20 +++++++++++++ scripts/deploy.js | 31 -------------------- 3 files changed, 52 insertions(+), 58 deletions(-) create mode 100644 deploy/deploy.js delete mode 100644 scripts/deploy.js diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol index e7be2d2..515e94a 100644 --- a/contracts/FleekERC721.sol +++ b/contracts/FleekERC721.sol @@ -11,15 +11,15 @@ contract FleekERC721 is ERC721, FleekAccessControl { using Counters for Counters.Counter; struct Build { - string commit; - string repository; + string commit_hash; + string git_repository; } struct Site { - string URI; //ipfs hash example - string ENS; - uint256 currentBuild; - Build[] builds; + bytes32 external_url; //ipfs hash example + bytes32 ENS; + uint256 current_build; + mapping(uint256 => Build) builds; } Counters.Counter private _tokenIds; @@ -40,19 +40,24 @@ contract FleekERC721 is ERC721, FleekAccessControl { function mint( address to, - string memory URI, - string memory ENS, - string memory commit, - string memory repository + bytes32 external_url, + bytes32 ENS, + string memory commit_hash, + string memory git_repository ) public payable requireCollectionOwner returns (uint256) { uint256 tokenId = _tokenIds.current(); _mint(to, tokenId); addTokenController(tokenId, to); _tokenIds.increment(); - Build[] memory _builds = new Build[](1); - _builds[0] = Build(commit, repository); - _sites[tokenId] = Site(URI, ENS, 0, _builds); + Site storage site = _sites[tokenId]; + site.external_url = external_url; + site.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. + site.current_build = 0; + site.builds[0] = Build(commit_hash, git_repository); + return tokenId; } @@ -70,18 +75,18 @@ contract FleekERC721 is ERC721, FleekAccessControl { ) public view virtual override returns (string memory) { _requireMinted(tokenId); address owner = ownerOf(tokenId); - Site memory site = _sites[tokenId]; + Site storage site = _sites[tokenId]; // prettier-ignore bytes memory dataURI = abi.encodePacked( '{', '"owner":"', owner, '",', '"ENS":"', site.ENS, '",', - '"URI":"', site.URI, '",', + '"external_url":"', site.external_url, '",', '"build:{', - '"id":"', site.currentBuild, '",', - '"commit":"', site.builds[site.currentBuild].commit, '",', - '"repository":"', site.builds[site.currentBuild].repository, '"' + '"id":"', site.current_build, '",', + '"commit_hash":"', site.builds[site.current_build].commit_hash, '",', + '"repository":"', site.builds[site.current_build].git_repository, '"' '}', '}' ); @@ -115,17 +120,17 @@ contract FleekERC721 is ERC721, FleekAccessControl { return "data:application/json;base64,"; } - function _setTokenURI( + function _setTokenExternalURL( uint256 tokenId, - string memory _tokenURI + bytes32 _tokenExternalURL ) internal virtual requireTokenController(tokenId) { _requireMinted(tokenId); - _sites[tokenId].URI = _tokenURI; + _sites[tokenId].external_url = _tokenExternalURL; } function _setTokenENS( uint256 tokenId, - string memory _tokenENS + bytes32 _tokenENS ) internal virtual requireTokenController(tokenId) { _requireMinted(tokenId); _sites[tokenId].ENS = _tokenENS; @@ -133,12 +138,12 @@ contract FleekERC721 is ERC721, FleekAccessControl { function _setTokenBuild( uint256 tokenId, - string memory _commit, - string memory _repository + string memory _commit_hash, + string memory _git_repository ) internal virtual requireTokenController(tokenId) { _requireMinted(tokenId); - _sites[tokenId].builds.push(Build(_commit, _repository)); - _sites[tokenId].currentBuild = _sites[tokenId].builds.length - 1; + _sites[tokenId].builds[_sites[tokenId].current_build] = Build(_commit_hash, _git_repository); + _sites[tokenId].current_build = _sites[tokenId].current_build + 1; } function _burn(uint256 tokenId) internal virtual override { @@ -148,7 +153,7 @@ contract FleekERC721 is ERC721, FleekAccessControl { ); super._burn(tokenId); - if (bytes(_sites[tokenId].URI).length != 0) { + if (_sites[tokenId].external_url.length != 0) { delete _sites[tokenId]; } } diff --git a/deploy/deploy.js b/deploy/deploy.js new file mode 100644 index 0000000..6702f1c --- /dev/null +++ b/deploy/deploy.js @@ -0,0 +1,20 @@ +module.exports = async ({ getNamedAccounts, deployments }) => { + const { deploy, log } = deployments; + const namedAccounts = await getNamedAccounts(); + const { deployer } = namedAccounts; + + const deployResult = await deploy('FleekERC721', { + from: deployer, + args: ['FleekSites', 'FLKSITE'], + }); + if (deployResult.newlyDeployed) { + log( + `contract FleekSites deployed at ${deployResult.address} using ${deployResult.receipt.gasUsed} gas` + ); + } else { + log(`using pre-existing contract FleekSites at ${deployResult.address}`); + } +}; +//You can put an array of tags below. Tags can be anything and say when a this script should be run. So you can write different scripts for local, prod or other deploys +//For example when you run 'npx hardhat --network hardhat deploy --tags local' hardhat will run all deploy scripts that have the tag local, could be multiple dif scripts +module.exports.tags = []; \ No newline at end of file diff --git a/scripts/deploy.js b/scripts/deploy.js deleted file mode 100644 index fea61c0..0000000 --- a/scripts/deploy.js +++ /dev/null @@ -1,31 +0,0 @@ -const argv = require('minimist')(process.argv.slice(2)); -const contractName = argv.contract; -const params = argv.param || []; - -if (!contractName) { - console.log('No contract name provided'); - process.exit(1); -} - -async function main() { - console.log('Deploying contract:', contractName); - console.log('With params:', params); - - const [deployer] = await ethers.getSigners(); - - console.log('Deploying contracts with the account:', deployer.address); - console.log('Account balance:', (await deployer.getBalance()).toString()); - - // const factory = await ethers.getContractFactory(contractName); - - // // Start deployment, returning a promise that resolves to a contract object - // const contract = await factory.deploy(...params); - // console.log('Contract deployed to address:', contract.address); -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - });