pragma solidity ^0.4.20;
contract ERC20 {
? ?//獲取總的發(fā)行量
? ? function totalSupply() constant returns (uint totalSupply);
? ? //查詢賬戶余額
? ? function balanceOf(address _owner) constant returns (uint balance);
? ? // 發(fā)送Token到某個地址(轉(zhuǎn)賬)
? ? function transfer(address _to, uint _value)returns(bool success);
? ? //從地址from 發(fā)送token到to地址
? ? function transferFrom(address _from, address _to, uint _value) returns (bool success);
? ? //允許_spender從你的賬戶轉(zhuǎn)出token
? ? function approve(address _spender, uint _value)returns(bool success);
? ? //查詢允許spender轉(zhuǎn)移的Token數(shù)量
? ? function allowance(address _owner, address _spender) constant returns (uint remaining);
? ? //transfer方法調(diào)用時的通知事件
? ? event Transfer(address indexed _from, address indexed _to, uint _value);
? ? //approve方法調(diào)用時的通知事件
? ? event Approval(address indexed _owner, address indexed _spender, uint _value);
}
contract PixCoin is ERC20 {
//代幣名稱
? ? string public constant name="PixCoin";
? ? //別名
? ? string public constant symbol="PIX";
? ? //允許后面出現(xiàn)的 小數(shù)點
? ? uint public constant decimals=0;
? ? //存放指定的地址存放的token 數(shù)量
? ? mapping(address=>uint) _blanceOf;
? ? //用來存放指定的地址從指定的賬戶可以轉(zhuǎn)出的token
? ? mapping(address=>mapping(address=>uint)) _approve;
? ? //基金會組織
? ? address foundation;
? ? function PixCoin(address _foundation) public{
? ? ? ? ? foundation = _foundation;
? ? ? ? ? _blanceOf[foundation]=200000000;
? ? }
? ? ? //設(shè)置要發(fā)幣的總數(shù)額
? ? function totalSupply() constant returns (uint totalSupply){
? ? ? ? ? ? totalSupply=1000000000;
? ? }
? ? //返回指定的代幣token 數(shù)量
? ? function balanceOf(address _owner) constant returns (uint balance){
? ? ? ? ? ? balance=_blanceOf[_owner];
? ? }
? ? ? //向指定的地址轉(zhuǎn)_value;
? ? function transfer(address _to, uint _value) returns (bool success){
? ? ? ? ? ? require(_blanceOf[msg.sender]>_value);
? ? ? ? ? ? _blanceOf[msg.sender] -= _value;
? ? ? ? ? ? _blanceOf[_to] += _value;
? ? ? ? ? ? success=true;
? ? }
? ? //從指定的地址向指定的賬戶轉(zhuǎn) _value;
? ? function transferFrom(address _from, address _to, uint _value) returns (bool success){
? ? ? ? ? require(_blanceOf[_from]>_value);
? ? ? ? ? _approve[_from][_to] -= _value;
? ? ? ? ? _blanceOf[_from] -= _value;
? ? ? ? ? _blanceOf[_to] += _value;
? ? ? ? ? success=true;
? ? }
? ? //設(shè)置_spender 可以從當前地址 msg.sender 轉(zhuǎn)賬的余額.
? ? function approve(address _spender, uint _value) returns (bool success){
? ? ? ? ? ? //指定spender 可以從當前賬戶轉(zhuǎn)的余額
? ? ? ? ? ? _approve[msg.sender][_spender] = _value;
? ? ? ? ? ? success=true;
? ? }
? ? ? //設(shè)置當前賬戶
? ? function allowance(address _owner, address _spender) constant returns (uint remaining){
? ? ? ? ? ? remaining=_approve[_owner][_spender];
? ? }
}
contract ERC721 {
? ? // 返回所有非同質(zhì)代幣的數(shù)量
? ? function totalSupply() public view returns (uint256 total);
? ? // 返回_owner的非同質(zhì)代幣的數(shù)量
? ? function balanceOf(address _owner) public view returns (uint256 balance);
? ? // 返回_tokenId非同質(zhì)代幣的擁有者的地址
? ? function ownerOf(uint256 _tokenId) external view returns (address owner);
? ? // 將_tokenId非同質(zhì)代幣授權(quán)給地址_to的擁有者
? ? // approve()方法的目的是可以授權(quán)第三人來代替自己執(zhí)行交易
? ? function approve(address _to, uint256 _tokenId) external;
? ? // 將_tokenId非同質(zhì)代幣轉(zhuǎn)移給地址為_to的擁有者
? ? function transfer(address _to, uint256 _tokenId) external;
? ? // 從_from擁有者轉(zhuǎn)移_tokenId非同質(zhì)代幣給_to新的擁有者
? ? // 內(nèi)部調(diào)用transfer方法進行轉(zhuǎn)移
? ? function transferFrom(address _from, address _to, uint256 _tokenId) external;
? ? // Events
? ? // 兩個事件來分別記錄轉(zhuǎn)移和授權(quán)
? ? event Transfer(address from, address to, uint256 tokenId);
? ? event Approval(address owner, address approved, uint256 tokenId);
}
? ? Asset[] assets;
? ? mapping(address => uint) _balanceOf;
? ? mapping(uint => address) _approve;
? ? mapping(uint => address) _ownerOf;
? ? address auction;
? ? function setAuction(address _auction) public onlyOwner {
? ? ? ? auction = _auction;
? ? }
? ? function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
? ? ? ? return ((_interfaceID == InterfaceSignature_ERC165) || (_interfaceID == ????????InterfaceSignature_ERC721));
? ? }
? ? function balanceOf(address _owner) public view returns (uint256) {
? ? ? ? return _balanceOf[_owner];
? ? }
? ? function transfer( address _to, uint256 _tokenId ) external? {
? ? ? ? require(_tokenId < totalSupply());
? ? ? ? require(msg.sender == _ownerOf[_tokenId]);
? ? ? ? _balanceOf[msg.sender] --;
? ? ? ? _ownerOf[_tokenId] = _to;
? ? ? ? delete _approve[_tokenId];
? ? ? ? _balanceOf[_to] ++;
? ? }
? ? function approve(address _to, uint256 _tokenId) external? {
? ? ? ? _approve[_tokenId] = _to;
? ? }
? ? function transferFrom( address _from, address _to, uint256 _tokenId ) external? {
? ? ? ? require(_approve[_tokenId] == _to);
? ? ? ? require(_ownerOf[_tokenId] == _from);
? ? ? ? require(_tokenId < totalSupply());
? ? ? ? _balanceOf[_from] --;
? ? ? ? _ownerOf[_tokenId] = _to;
? ? ? ? delete _approve[_tokenId];
? ? ? ? _balanceOf[_to] ++;
? ? }
? ? function totalSupply() public view returns (uint) {
? ? ? ? return assets.length;
? ? }
? ? function ownerOf(uint256 _tokenId) external view returns (address owner) {
? ? ? ? owner = _ownerOf[_tokenId];
? ? ? ? asset(owner != address(0));
? ? }
? ? function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
? ? ? ? uint256 tokenCount = balanceOf(_owner);
? ? ? ? if (tokenCount == 0) {
? ? ? ? ? ? return new uint256[](0);
? ? ? ? }
? ? ? ? uint256[] memory result = new uint256[](tokenCount);
? ? ? ? uint256 totalCount = totalSupply();
? ? ? ? uint256 resultIndex = 0;
? ? ? ? uint256 idx;
? ? ? ? for (idx = 0; idx < totalCount; idx++) {
? ? ? ? ? ? if (_ownerOf[idx] == _owner) {
? ? ? ? ? ? ? ? result[resultIndex] = idx;
? ? ? ? ? ? ? ? resultIndex++;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return result;
? ? }
? ? // 創(chuàng)建新資產(chǎn)
? ? /*
? ? struct Asset {
? ? ? ? uint contenthash;
? ? ? ? uint weight;
? ? ? ? address owner;
? ? ? ? string metadata;
? ? }
? ? Asset[] assets;
? ? mapping(address => uint) _balanceOf;
? ? mapping(uint => address) _approve;
? ? mapping(uint => address) _ownerOf;
? ? */
? ? function _newToken(uint contenthash, uint weight, string metadata, address owner, uint price) private returns (uint) {
? ? ? ? Asset memory asset = Asset(contenthash, weight, owner, metadata, price);
? ? ? ? _balanceOf[owner] ++;
? ? ? ? uint id = assets.push(asset) - 1;
? ? ? ? _ownerOf[id] = owner;
? ? ? ? return id;
? ? }
? ? function newToken(uint contenthash, string metadata) public returns(uint) {
? ? ? ? return _newToken(contenthash, 100, metadata, msg.sender, 0);
? ? }
? ? // 分割資產(chǎn)
? ? function split(uint id, uint weight) public returns(bool) {
? ? ? ? Asset asset = assets[id];
? ? ? ? address owner = _ownerOf[id];
? ? ? ? uint price = asset.price * weight / asset.weight;
? ? ? ? _newToken(asset.contenthash, weight, asset.metadata, owner, price);
? ? ? ? asset.weight -= weight;
? ? ? ? asset.price -= price;
? ? }
? ? // 放入拍賣場
? ? function sell(uint id, uint price) public returns(bool) {
? ? }
}
contract CRMAuction is ICRMAuction {
? ? struct Auction {
? ? ? ? address seller;
? ? ? ? uint startingPrice;
? ? ? ? uint endingPrice;
? ? ? ? bool isEnd;
? ? }
? ? mapping (uint => Auction) autions;
? ? CRMERC20 crmERC20;
? ? CRMERC721 crmERC721;
? ? function CRMAuction(address _crmERC20, address _crmERC721) public {
? ? ? ? crmERC20 = CRMERC20(_crmERC20);
? ? ? ? crmERC721 = CRMERC721(_crmERC721);
? ? }
}
// 啟動和管理合約
contract CRM is Ownable {
? ? CRMERC20 public crmERC20;
? ? CRMERC721 public crmERC721;
? ? CRMAuction public crmAuction; // 拍賣場
? ? function CRM() public {
? ? ? ? crmERC20 = new CRMERC20();
? ? ? ? crmERC721 = new CRMERC721();
? ? ? ? crmAuction = new CRMAuction(crmERC20, crmERC721);
? ? ? ? crmERC721.setAuction(crmAuction);
? ? }
? ? // 每天對作品評獎
? ? function dispathBonus() public onlyOwner {
? ? }
}