pragma solidity ^0.4.20;
contract ERC20 {
//获取总的发行量
function totalSupply() constant returns (uint totalSupply);
//查询账户余额
function balanceOf(address _owner) constant returns (uint balance);
// 发送Token到某个地址(转账)
function transfer(address _to, uint _value)returns(bool success);
//从地址from 发送token到to地址
function transferFrom(address _from, address _to, uint _value) returns (bool success);
//允许_spender从你的账户转出token
function approve(address _spender, uint _value)returns(bool success);
//查询允许spender转移的Token数量
function allowance(address _owner, address _spender) constant returns (uint remaining);
//transfer方法调用时的通知事件
event Transfer(address indexed _from, address indexed _to, uint _value);
//approve方法调用时的通知事件
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
contract PixCoin is ERC20 {
//代币名称
string public constant name="PixCoin";
//别名
string public constant symbol="PIX";
//允许后面出现的 小数点
uint public constant decimals=0;
//存放指定的地址存放的token 数量
mapping(address=>uint) _blanceOf;
//用来存放指定的地址从指定的账户可以转出的token
mapping(address=>mapping(address=>uint)) _approve;
//基金会组织
address foundation;
function PixCoin(address _foundation) public{
foundation = _foundation;
_blanceOf[foundation]=200000000;
}
//设置要发币的总数额
function totalSupply() constant returns (uint totalSupply){
totalSupply=1000000000;
}
//返回指定的代币token 数量
function balanceOf(address _owner) constant returns (uint balance){
balance=_blanceOf[_owner];
}
//向指定的地址转_value;
function transfer(address _to, uint _value) returns (bool success){
require(_blanceOf[msg.sender]>_value);
_blanceOf[msg.sender] -= _value;
_blanceOf[_to] += _value;
success=true;
}
//从指定的地址向指定的账户转 _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;
}
//设置_spender 可以从当前地址 msg.sender 转账的余额.
function approve(address _spender, uint _value) returns (bool success){
//指定spender 可以从当前账户转的余额
_approve[msg.sender][_spender] = _value;
success=true;
}
//设置当前账户
function allowance(address _owner, address _spender) constant returns (uint remaining){
remaining=_approve[_owner][_spender];
}
}
contract ERC721 {
// 返回所有非同质代币的数量
function totalSupply() public view returns (uint256 total);
// 返回_owner的非同质代币的数量
function balanceOf(address _owner) public view returns (uint256 balance);
// 返回_tokenId非同质代币的拥有者的地址
function ownerOf(uint256 _tokenId) external view returns (address owner);
// 将_tokenId非同质代币授权给地址_to的拥有者
// approve()方法的目的是可以授权第三人来代替自己执行交易
function approve(address _to, uint256 _tokenId) external;
// 将_tokenId非同质代币转移给地址为_to的拥有者
function transfer(address _to, uint256 _tokenId) external;
// 从_from拥有者转移_tokenId非同质代币给_to新的拥有者
// 内部调用transfer方法进行转移
function transferFrom(address _from, address _to, uint256 _tokenId) external;
// Events
// 两个事件来分别记录转移和授权
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;
}
// 创建新资产
/*
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);
}
// 分割资产
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 {
}
}