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);
}

}

相关文章
|
5月前
|
安全
链游系统开发DAPP项目逻辑讲解方案
链游系统开发具有以下优势:   1.Decentralization:Chain game systems are based on blockchain technology and do not rely on centralized servers,providing a more fair and transparent gaming environment.   2.Data security:Through the decentralized characteristics and encryption algorithms of blockchain,the chai
|
5月前
|
人工智能 算法 安全
DAPP 合约拆分公排模式项目系统开发技术讲解
DAPp 互助模式系统的核心理念是“共创、共享、共赢”。通过整合优质资源,平台致力于为用户提供一个公平、公正、透明的互助环境。用户在这里可以实现信息的快速传播,从而为互助需求提供便捷的服务。
|
7月前
|
算法 区块链 UED
dapp矩阵公排互助系统开发|方案设计|模式案例
Web3.0的智能合约技术可以实现无需信任的推广活动
|
7月前
|
安全 区块链 UED
DAPP去中心化公排互助系统开发|详情逻辑|案例分析
智能合约是一种基于区块链技术的自动化执行合约的工具
|
安全 区块链
区块链交易所开发运营版丨区块链交易所系统开发规则详细/项目案例/设计功能/需求逻辑/源码部署
Blockchain exchange refers to an online platform built on blockchain technology for trading and managing digital assets, such as cryptocurrencies (such as Bitcoin, Ethereum, etc.) and other digital assets or tokens. Blockchain exchanges allow users to buy, sell, store, and manage digital assets.
IPPswap交易所系统开发详细指南丨需求设计丨教程方案丨源码项目
Based on the development of the IPPSwap exchange exchange exchange bottom pool LP pledge mining system you mentioned, the following is an overview of its basic process and elements
|
存储 安全
DAPP/3M互助拆分公排双轨系统开发详细逻辑/案例分析/方案项目/技术分析/源码平台
 DApp是指基于区块练技术的去中心化应用程序,它的特点是去中心化、透明、安全、不可篡改等特点。
|
存储 算法 前端开发
区块链 DAPP 互助逻辑模式系统开发技术源码方案
string public name; uint public goal; uint public progress; address public admin; mapping (address => bool) public members;
|
存储 前端开发 测试技术
众筹互助智能合约系统开发(开发案例)丨dapp智能合约众筹互助丨公排拆分丨系统开发详细规则/成熟技术/方案设计/源码说明
 智能合约互助系统开发是指创建并实现基于智能合约技术的互助系统。智能合约是一种在区块链上执行的自动化计算代码,它可以在事先设定的条件满足时执行相应的操作,无需依赖人工干预。智能合约互助系统旨在通过智能合约技术来优化和自动化互助服务的提供和管理。
|
存储 机器人 大数据
量化交易机器人系统开发(开发策略)及案例丨数字货币区块链交易所系统开发详细项目/方案设计/开发逻辑/源码版
  区块链的核心技术之一就是公开且透明的交易信息。一般情况下,在区块链内产生、流转和存储的信息是对所有节点用户开放的,其高度的透明化也使得区块内的所有人都能够查看数据的所有相关信息同时使用其应用。因此,区块链技术在信息共享与数据交换领域具有一定的优势。