DAPP公排拆分互助模式系统开发方案实现,3M/DAPP拆分公排互助系统开发详细规则(开发项目)及源码

简介:  Blockchain technology can build an efficient and reliable value transmission system, promote the Internet to become a network infrastructure for building social trust, achieve effective transmission of value, and call this the Value Internet. Blockchain provides a new type of social trust mechanis

Blockchain technology can build an efficient and reliable value transmission system, promote the Internet to become a network infrastructure for building social trust, achieve effective transmission of value, and call this the Value Internet. Blockchain provides a new type of social trust mechanism, laying a new foundation for the development of the digital economy. The innovation of "blockchain+" application indicators a new direction for industrial innovation and public services

What is blockchain? In a word, it is a special Distributed database. Firstly, the main function of blockchain is to store information. Any information that needs to be saved can be written to or read from the blockchain, so it is a database.

Blockchain technology, also known as distributed ledger technology, is an internet database technology characterized by decentralization, openness, and transparency, allowing everyone to participate in database records. Blockchain technology is not a single technology, but a comprehensive technology system that integrates multiple research achievements

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;

import "./IERC165.sol";
import "./IERC721.sol";
import "./Address.sol"; //导入库

/// @dev Note: the ERC-165 identifier for this interface is 0x150b7a02.
interface ERC721TokenReceiver {
/// @notice Handle the receipt of an NFT
/// @dev The ERC721 smart contract calls this function on the recipient
/// after a transfer. This function MAY throw to revert and reject the
/// transfer. Return of other than the magic value MUST result in the
/// transaction being reverted.
/// Note: the contract address is always the message sender.
/// @param _operator The address which called safeTransferFrom function
/// @param _from The address which previously owned the token
/// @param _tokenId The NFT identifier which is being transferred
/// @param _data Additional data with no specified format
/// @return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))
/// unless throwing
function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes memory _data) external returns(bytes4);
}

contract ERC721 is IERC721,IERC165 {
mapping(bytes4 => bool)supportsInterfaces;
bytes4 invalidID = 0xffffffff;

bytes4 constant ERC165_InterfaceID=0x01ffc9a7;     //erc165
bytes4 constant ERC721_InterfaceID=0x80ac58cd;     //erc721 
mapping(address=>uint256)ercTokenCount;            //记录用户token count;
mapping(uint256=>address)ercTokenOwner;            //记录token的拥有者;
mapping(uint256=>address)ercTokenApproved; 
mapping(address=>mapping(address=>bool))ercOperatorForAll;

using Address for address;

constructor(){
    _registerInterface(ERC165_InterfaceID);
    _registerInterface(ERC721_InterfaceID);
}

//授权
modifier canOperator(uint256 _tokenId){
    address owner = ercTokenOwner[_tokenId];
    require(msg.sender == owner || ercOperatorForAll[owner][msg.sender]);
    _;
}

//转账
modifier canTransfer(uint256 _tokenId,address _from){
    address owner = ercTokenOwner[_tokenId];
    require(owner==_from);
    require(msg.sender == owner || msg.sender == ercTokenApproved[_tokenId] || ercOperatorForAll[owner][msg.sender]);
    _;
}

function _registerInterface(bytes4 interfaceID)internal {
    supportsInterfaces[interfaceID]=true;
}
function supportsInterface(bytes4 interfaceID) override  external view returns (bool) {
    require(invalidID != interfaceID);
    return supportsInterfaces[interfaceID];
}

//721
function balanceOf(address _owner) override external view returns (uint256){
    return ercTokenCount[_owner];

}

function ownerOf(uint256 _tokenId) override external view returns (address){
    return ercTokenOwner[_tokenId];
}

function getApproved(uint256 _tokenId) override external view returns (address){
    return ercTokenApproved[_tokenId];
}

function isApprovedForAll(address _owner, address _operator) external view returns (bool){
    return ercOperatorForAll[_owner][_operator];
}

function approve(address _approved, uint256 _tokenId) override external payable{
    ercTokenApproved[_tokenId]=_approved;
    emit Approval(msg.sender,_approved,_tokenId);
}

function setApprovalForAll(address _operator, bool _approved) override external{
    ercOperatorForAll[msg.sender][_operator]=_approved;
    emit ApprovalForAll(msg.sender,_operator,_approved);
}

function transferFrom(address _from, address _to, uint256 _tokenId) override  external payable{
    _transferFrom(_from,_to,_tokenId);
}

function _transferFrom(address _from, address _to, uint256 _tokenId)internal canTransfer(_tokenId,_from){
    ercTokenOwner[_tokenId] = _to;      //更改属主;
    ercTokenCount[_from]-=1;
    ercTokenCount[_to]+=1;
    ercTokenApproved[_tokenId] = address(0);
    emit Transfer(_from, _to,  _tokenId);
}

function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes memory data) override external payable{
    _safeTransferFrom(_from,_to,_tokenId,data);
}

function safeTransferFrom(address _from, address _to, uint256 _tokenId)override external payable{
    _safeTransferFrom(_from,_to,_tokenId,"");
}

function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes memory data) internal { //安全转账即判断对方是否有资格持有ERCtoken,避免转错
    _transferFrom(_from, _to, _tokenId);

    //add safe code
    if(_to.isContract()){           //首先判断对方是否是合约
        bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender,_from,_tokenId,data);   //是否实现了ERC721Received
        require(retval == ERC721TokenReceiver.onERC721Received.selector);
    }
}

function mint(address _to,uint256 _tokenId,bytes memory data)external{
    require(_to != address(0));
    require(ercTokenOwner[_tokenId]==address(0));

    ercTokenOwner[_tokenId]= _to;
    ercTokenCount[_to]+=1;

    if(_to.isContract()){           //首先判断对方是否是合约
        bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender,address(0),_tokenId,data);   //是否实现了ERC721Received
        require(retval == ERC721TokenReceiver.onERC721Received.selector);
    }

    emit Transfer(address(0),_to,_tokenId);
}

}

相关文章
|
8天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17291 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
2天前
|
人工智能 安全 网络安全
|
6天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1326 3
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2397 7
|
19天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3872 22
|
20天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。