PtahDao/ProTradex/Meta2032智能合約系統(tǒng)開(kāi)發(fā)詳情介紹及源碼案例
區(qū)塊鏈?zhǔn)欠植际綌?shù)據(jù)存儲(chǔ)、點(diǎn)對(duì)點(diǎn)傳輸、共識(shí)機(jī)制、加密算法等計(jì)算機(jī)技術(shù)的新型應(yīng)用模式。
狹義來(lái)講,區(qū)塊鏈?zhǔn)且环N按照時(shí)間順序?qū)?shù)據(jù)區(qū)塊以順序相連的方式組合成的一種鏈?zhǔn)綌?shù)據(jù)結(jié)構(gòu),并以密碼學(xué)方式保證的不可篡改和不可偽造的分布式賬本。
廣義來(lái)講,區(qū)塊鏈技術(shù)是利用塊鏈?zhǔn)綌?shù)據(jù)結(jié)構(gòu)來(lái)驗(yàn)證與存儲(chǔ)數(shù)據(jù)、利用分布式節(jié)點(diǎn)共識(shí)算法來(lái)生成和更新數(shù)據(jù)、利用密碼學(xué)的方式保證數(shù)據(jù)傳輸和訪問(wèn)的安全、利用由自動(dòng)化腳本代碼組成的智能合約來(lái)編程和操作數(shù)據(jù)的一種全新的分布式基礎(chǔ)架構(gòu)與計(jì)算方式。
在區(qū)塊鏈技術(shù)中的數(shù)據(jù)有一定的順序性,搭建詳細(xì):I35模式7O98開(kāi)發(fā)O7I8 每個(gè)數(shù)據(jù)區(qū)塊都有一個(gè)“哈希值”代碼,在鏈狀數(shù)據(jù)結(jié)構(gòu)中,任意區(qū)塊中的數(shù)據(jù)改變都會(huì)影響后續(xù)與之相關(guān)所有區(qū)塊的信息變化。這一技術(shù)確保區(qū)塊鏈上的每個(gè)區(qū)塊數(shù)據(jù)都不能隨意被篡改、刪除或破壞。因此,區(qū)塊鏈技術(shù)在保證電子檔案完整、真實(shí)的基礎(chǔ)上還具有較強(qiáng)的追溯性
//SPDX-License-Identifier:MIT
pragma solidity^0.8.0;
import"openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import"./IERC4907.sol";
contract ERC4907 is ERC721URIStorage,IERC4907{
struct UserInfo{
address user;//address of user role
uint64 expires;//unix timestamp,user expires
}
mapping(uint256=>UserInfo)internal _users;
constructor(string memory name_,string memory symbol_)ERC721(name_,symbol_){}
///notice set the user and expires of a NFT
///dev The zero address indicates there is no user
///Throws if`tokenId`is not valid NFT
///param user The new user of the NFT
///param expires UNIX timestamp,The new user could use the NFT before expires
function setUser(
uint256 tokenId,
address user,
uint64 expires
)public virtual override{
require(
_isApprovedOrOwner(msg.sender,tokenId),
"ERC721:transfer caller is not owner nor approved"
);
UserInfo storage info=_users[tokenId];
info.user=user;
info.expires=expires;
emit UpdateUser(tokenId,user,expires);
}
///notice Get the user address of an NFT
///dev The zero address indicates that there is no user or the user is expired
///param tokenId The NFT to get the user address for
///return The user address for this NFT
function userOf(uint256 tokenId)
public
view
virtual
override
returns(address)
{
if(uint256(_users[tokenId].expires)>=block.timestamp){
return _users[tokenId].user;
}else{
return address(0);
}
}
///notice Get the user expires of an NFT
///dev The zero value indicates that there is no user
///param tokenId The NFT to get the user expires for
///return The user expires for this NFT
function userExpires(uint256 tokenId)
public
view
virtual
override
returns(uint256)
{
return _users[tokenId].expires;
}
///dev See{IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override
returns(bool)
{
return
interfaceId==type(IERC4907).interfaceId||
super.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
)internal virtual override{
super._beforeTokenTransfer(from,to,tokenId);
if(from!=to&&_users[tokenId].user!=address(0)){
delete _users[tokenId];
emit UpdateUser(tokenId,address(0),0);
}
}
}