众筹合约开发(一)

CrowdFund.sol

/*
作者:key

时间:2020/10/25    17:2

分析:
一个needer      受益者      
多个player      捐助者

运行环境 remix


*/

pragma solidity^0.4.25;
//众筹合约
contract CrowdFund{
    
    
    uint256 neederAmount=0; //needer的数量,初始化为0
    mapping(uint256 => Needer) neederMap;
    
    struct Funder{
    
        address funderAddress; //捐助者的地址
        uint256 toMoney;  //捐助的数量
    }
    
    struct Needer{
    
        address neederAddress;  //受益者地址
        uint256 goal;   //募集资金目标
        uint256 amount; //现在募集的资金
        uint256 funderAccount; //捐助者的数量
        mapping(uint256 => Funder) amountOrigin; //这笔募捐资金的来源
    }
    
    function newNeeder(address _neederAddress,uint256 _goal) public{
    
        neederMap[neederAmount] =Needer(_neederAddress,_goal,0,0);//初始化
        neederAmount++;
    }
    
    function contribute(address _funderAddress,uint _neederAmount)public payable{
    
        Needer storage _needer = neederMap[_neederAmount];
        _needer.amount +=msg.value;
        _needer.funderAccount++;
        _needer.amountOrigin[_needer.funderAccount] = Funder(_funderAddress,msg.value);
    }
    
    function isConpelete(uint256 _neederAmount) public{
    
        Needer storage _needer = neederMap[_neederAmount];
        if(_needer.amount >= _needer.goal){
    
            _needer.neederAddress.transfer(_needer.amount);
        }
    }
    
    function print(uint256 neederAmount) public view returns(uint256,uint256,uint256){
    
        return(neederMap[neederAmount].goal,neederMap[neederAmount].amount,neederMap[neederAmount].funderAccount);
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43402353/article/details/109275960