Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Phygital Scripts #77

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions contracts/phygital/Phygital.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;

mapping(uint256 => bytes16) public nfcId;
mapping(uint256 => bytes16) public phygitalID;

mapping(bytes16 => bool) public nfcCheck;
mapping(bytes16 => bool) public assetStatus;

IACCESSMASTER flowRoles;

Expand Down Expand Up @@ -111,14 +111,12 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
constructor(
string memory name,
string memory symbol,
uint256 _nftPrice,
address tradeHubAddress,
address flowContract
) ERC721(name, symbol) {
flowRoles = IACCESSMASTER(flowContract);
tradeHub = tradeHubAddress;
accessMasterAddress = flowContract;
nftPrice = _nftPrice;
}

/// @notice transferring funds
Expand Down Expand Up @@ -152,16 +150,16 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
function createAsset(
string memory metadataURI,
uint96 royaltyPercentBasisPoint,
bytes16 _nfcId
bytes16 _phygitalID
) public onlyCreator returns (uint256) {
// We cannot just use balanceOf to create the new tokenId because tokens
// can be burned (destroyed), so we need a separate counter.
require(!nfcCheck[_nfcId], "Phygital: NFC Tag is already stored!");
require(!assetStatus[_phygitalID], "Phygital: NFC Tag is already stored!");
Counter++;
uint256 currentTokenID = Counter;

nfcId[currentTokenID] = _nfcId;
nfcCheck[_nfcId] = true;
phygitalID[currentTokenID] = _phygitalID;
assetStatus[_phygitalID] = true;

_safeMint(_msgSender(), currentTokenID);
_setTokenURI(currentTokenID, metadataURI);
Expand Down Expand Up @@ -197,16 +195,16 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
address creator,
string memory metadataURI,
uint96 royaltyPercentBasisPoint,
bytes16 _nfcId
bytes16 _phygitalID
) public onlyOperator returns (uint256) {
// We cannot just use balanceOf to create the new tokenId because tokens
// can be burned (destroyed), so we need a separate counter.
require(!nfcCheck[_nfcId], "Phygital: NFC Tag is already stored!");
require(!assetStatus[_phygitalID], "Phygital: NFC Tag is already stored!");
Counter++;
uint256 currentTokenID = Counter;

nfcId[currentTokenID] = _nfcId;
nfcCheck[_nfcId] = true;
phygitalID[currentTokenID] = _phygitalID;
assetStatus[_phygitalID] = true;

_safeMint(creator, currentTokenID);
_setTokenURI(currentTokenID, metadataURI);
Expand Down Expand Up @@ -333,18 +331,6 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {

/** Getter Functions **/

/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
require(_exists(tokenId), "Phygital: Non-Existent Asset");
string memory _tokenURI = _tokenURIs[tokenId];

return _tokenURI;
}

/************* Rental(ERC4907) ***************** */
/// @dev IERC4907 implementation
function userOf(uint256 tokenId) public view returns (address) {
Expand All @@ -371,6 +357,20 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {

/////////////////////////////////////////////////

/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
require(_exists(tokenId), "SignatureSeries: Non-Existent Asset");
string memory _tokenURI = _tokenURIs[tokenId];

return _tokenURI;
}



function _beforeTokenTransfer(
address from,
address to,
Expand Down
13 changes: 6 additions & 7 deletions contracts/phygital/PhygitalA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ contract PhygitalA is

mapping(uint256 => string) private _tokenURIs;

mapping(uint256 => bytes16) public nfcId;
mapping(uint256 => bytes16) public phygitalID;

mapping(bytes16 => bool) public nfcCheck;
mapping(bytes16 => bool) public assetStatus;

// INTERFACES
IACCESSMASTER flowRoles;
Expand Down Expand Up @@ -164,15 +164,14 @@ contract PhygitalA is
return (prevQuantity, quantity);
}


/// @dev to register Asset NFC ID TO the tokenID
function registerAssetId(
uint256 tokenId,
bytes16 _nfcId
bytes16 _phygitalID
) external onlyOperator {
require(!nfcCheck[_nfcId],"PhygitalA: It's already registerd");
nfcId[tokenId] = _nfcId;
nfcCheck[_nfcId] = true;
require(!assetStatus[_phygitalID],"PhygitalA: It's already registerd");
phygitalID[tokenId] = _phygitalID;
assetStatus[_phygitalID] = true;
}

/**
Expand Down
Loading
Loading