代码拉取完成,页面将自动刷新
同步操作将从 duke.du/crowFunding-eth 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
pragma solidity ^0.4.24;
import "./InvestorToFunding.sol";
contract CrowFunding {
address public creator; // 发起人
string public projectName; // 项目名称
uint public supportBalance; // 参与众筹金额
uint public targetBalance; // 众筹目标金额
uint public endTime; // 众筹截止日期
address[] public investors; //参与众筹的人,即投资人
mapping(address => bool) public investorExistMap; //标记一个人是否参与了当前众筹
InvestorToFunding i2f; //新增一个状态变量
constructor(string _projectName, uint _supporBalance, uint _targetBalance, uint _durationInSeconds, address _creator , InvestorToFunding _i2f)
public {
creator = _creator;
//creator = msg.sender;
i2f = _i2f;
projectName = _projectName;
supportBalance = _supporBalance;
targetBalance = _supporBalance;
//传递进来剩余的秒数,比如若众筹30天,则传入:30 天 * 24小时 * 60分 * 60秒 = 2592000
endTime = now + _durationInSeconds; //2592000
}
function invest() public payable {
require(investorExistMap[msg.sender] == false); //每个人只能参与一次
require(msg.value == supportBalance); //支持固定金额
investors.push(msg.sender); //添加到众筹人数组中
investorExistMap[msg.sender] = true; //标记当前账户为参与人
i2f.joinFunding(msg.sender, this); // 调用添加方法,添加到Mapping结构中
}
function drawBack() public onlyCreator{
for (uint i = 0; i < investors.length; i++){
investors[i].transfer(supportBalance);
}
// 这个合约基本就会被废弃掉, 所以就不用去处理investors,investorExistMap了
}
//查看合约当前余额
function getCurrentBalance() public view returns(uint){
return address(this).balance;
}
//返回所有的投资人
function getInvestors() public view returns(address[]){
return investors;
}
struct Request {
string purpose; //买什么
uint cost; //需要多少钱?
address shopAddress; //像谁购买
uint voteCount; //多少人赞成了,超板书则批准支出
mapping(address => bool) investorVoteMap; //赞成人的标记集合,防止一人重复投票多次
RequestStatus status; //这个申请的当前状态: 投票中,已批准, 已完成
}
enum RequestStatus {Voting, Approved, Completed}
Request[] public requests; //请求可能有多个
function createRequest( string _purpose, uint _cost, address _shopAddress) public onlyCreator{
Request memory request = Request({
purpose: _purpose,
cost: _cost,
shopAddress: _shopAddress,
voteCount: 0,
status: RequestStatus.Voting
});
requests.push(request); //将新的请求添加至数组中
}
function approveRequest(uint index) public {
//首先要确保是参与众筹的人,否则无权投票
require(investorExistMap[msg.sender]);
//根据索引找到特定的请求
Request storage request = requests[index];
//确保没有投过票,人手一票
require(!request.investorVoteMap[msg.sender]);
//如果已完成,或者已经获得批准了,就不用投票了,当前投票不会影响决策。
require(request.status == RequestStatus.Voting);
// 支持票数加1
request.voteCount++;
//标记为已投票
request.investorVoteMap[msg.sender] = true;
}
function finalizeRequest(uint index) public onlyCreator{
Request storage request = requests[index];
//合约金额充足才可以执行
require(address(this).balance >= request.cost);
//赞成人数过半
require(request.voteCount * 2 > investors.length);
//转账
request.shopAddress.transfer(request.cost);
//更新请求状态为已完成
request.status = RequestStatus.Completed;
}
modifier onlyCreator() {
require(msg.sender == creator);
_;
}
//返回投资人数量
function getInvestorsCount() public view returns (uint){
return investors.length;
}
//返回众筹剩余时间
function getRemainTime() public view returns (uint){
return (endTime - now) / 60 / 60 / 24;
}
//返回话费申请数量
function getRequestsCount() public view returns (uint) {
return requests.length;
}
// 返回某一个话费申请的具体信息
function getRequestDetailByIndex(uint index) public view returns (string, uint, address, bool, uint, uint){
//确保访问不越界
require(index < requests.length);
Request storage req = requests[index];
bool isVoted = req.investorVoteMap[msg.sender];
return(req.purpose, req.cost, req.shopAddress, isVoted, req.voteCount, uint(req.status));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。