Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
LehaoLin committed Sep 29, 2022
0 parents commit 93dd71d
Show file tree
Hide file tree
Showing 28 changed files with 21,854 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
*/node_modules/
.env
cache/
artifacts/
backend/assets/
backend/contracts/web3dp-show.sol
scripts/mint-nft.mjs
scripts/store-assets.mjs
59 changes: 59 additions & 0 deletions backend/contracts/web3dp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Contract based on https://docs.openzeppelin.com/contracts/4.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract Web3DP is ERC721, ERC721Enumerable, ERC721URIStorage{
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

constructor() ERC721("Web3DP", "WP") {}

function mintNFT(address recipient, string memory uri)
public
returns (uint256)
{
_tokenIds.increment();

uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, uri);

return newItemId;
}

// The following functions are overrides required by Solidity.

function _beforeTokenTransfer(address from, address to, uint256 tokenIds)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenIds);
}

function _burn(uint256 tokenIds) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenIds);
}

function tokenURI(uint256 tokenIds)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenIds);
}

function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
41 changes: 41 additions & 0 deletions backend/contracts/web3dp_label.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

contract Web3DPLabel{
struct Label {
uint256 label_id;
address user;
string label;
uint256 status;
uint256 token_id;
}

// tokenID => Label[]
mapping(uint256 => Label[]) public label_map;

function addLabel(string memory label, uint256 token_id) public {
Label memory newLabel = Label(label_map[token_id].length+1, msg.sender, label, 1, token_id);
label_map[token_id].push(newLabel);
}

function removeLabel(string memory label, uint256 token_id) public {
Label memory newLabel = Label(label_map[token_id].length+1, msg.sender, label, 0, token_id);
label_map[token_id].push(newLabel);
}

function getLabels(uint256 token_id) public view returns (Label[] memory) {
return label_map[token_id];
}

function getLabel(uint256 token_id, uint256 label_id) public view returns (string memory) {
return label_map[token_id][label_id-1].label;
}

function getLabelUser(uint256 token_id, uint256 label_id) public view returns (address) {
return label_map[token_id][label_id-1].user;
}

function getLabelStatus(uint256 token_id, uint256 label_id) public view returns (uint256) {
return label_map[token_id][label_id-1].status;
}
}
26 changes: 26 additions & 0 deletions backend/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/
require("@nomiclabs/hardhat-ethers");
require('dotenv').config();
const { PRIVATE_KEY } = process.env;
module.exports = {
defaultNetwork: "PolygonMumbai",
networks: {
hardhat: {
},
PolygonMumbai : {
url: "https://rpc-mumbai.maticvigil.com",
accounts: [PRIVATE_KEY]
}
},
solidity: {
version: "0.8.12",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
}
Loading

0 comments on commit 93dd71d

Please sign in to comment.