pragma solidity ^0.4.0;
contract fund{
//需要众筹的人
struct Needer{
address neederAddress; //地址
uint goal; //目标
uint sum; //已筹到的钱
uint funderNum; //捐赠者人数
mapping(uint => Funder) funderList; //捐赠者列表
}
//捐赠者
struct Funder{
address funderAddress; //捐赠者地址
uint money; //捐赠钱数
}
//需要众筹人数
uint neederNum;
//需要众筹者列表
mapping(uint => Needer) neederList;
//创建新的需要众筹者
function newNeeder(address _address, uint _goal) public {
neederNum++;
neederList[neederNum] = Needer(_address, _goal, 0, 0);
}
//捐赠
function contribute(address _funderAddress, uint _neederId) public payable{
Needer storage needer = neederList[_neederId];
needer.sum += msg.value;
needer.funderNum++;
needer.funderList[needer.funderNum] = Funder(_funderAddress, msg.value);
}
//转钱
function transfer(uint _neederId) public payable {
Needer storage needer = neederList[_neederId];
if(needer.sum >= needer.goal){
needer.neederAddress.transfer(needer.sum);
}
}
}
solidity50行代码实现众筹项目
最新推荐文章于 2023-12-13 09:37:27 发布