//SPDX-License-Identifier: SimPL-2.0 pragma solidity >=0.7.0 <0.8.9; contract zhongchou{ //投资者投资记录:投资目标,投资金额 struct toMoney{ address payable addressReceiptor; uint money; } //投资者基本信息:地址,是否被激活,总投资金额,投资次数,映射记录投资记录 struct funder{ address payable addressfunder; bool isActive; uint totalMoney; uint numberGive; mapping(uint=>toMoney)expMap; } //众筹合约:合约创建者,是否被激活,金额总需求,已投资金额,投资人数量,映射记录投资人 struct needMoneyContract{ address payable addressNeeder; // payable address addressContract; bool isActive; uint totalMoney; uint giveMoney; uint amountFunder; mapping (uint=>funder)mapFunder; } //众筹发起者:地址,激活状态,需求总金额,已经被投资的金额,发起的众筹的数量,映射记录投资合约 struct needer{ address addressNeeder; bool isActive; uint amountMoneyNeed; uint amountHasFunded; uint numberContract; mapping(uint=>needMoneyContract)expMap; }
时间: 2023-05-29 12:05:40 浏览: 289
_SPDX-License-Identifier:MIT_pragma_Solidity_^0._0x8a47f3
//定义众筹发起者和投资者
needer public theNeeder;
funder public theFunder;
//定义众筹合约
needMoneyContract public theContract;
//初始化众筹发起者和投资者
function initNeeder(address _addressNeeder, uint _amountMoneyNeed) public{
theNeeder = needer(_addressNeeder, true, _amountMoneyNeed, 0, 0);
}
function initFunder(address _addressFunder) public{
theFunder = funder(_addressFunder, true, 0, 0);
}
//创建众筹合约
function createContract() public{
require(theNeeder.isActive, "The needer is not active");
theContract = needMoneyContract(theNeeder.addressNeeder, true, theNeeder.amountMoneyNeed, 0, 0);
theNeeder.numberContract++;
theNeeder.expMap[theNeeder.numberContract] = theContract;
}
//投资众筹合约
function invest(uint _money) public payable{
require(msg.value == _money, "Please pay the correct amount");
require(theFunder.isActive, "The funder is not active");
require(theContract.isActive, "The contract is not active");
require(theContract.giveMoney + _money <= theContract.totalMoney, "The total amount of money has been reached");
theFunder.totalMoney += _money;
theFunder.numberGive++;
theFunder.expMap[theFunder.numberGive] = toMoney(msg.sender, _money);
theContract.giveMoney += _money;
theContract.amountFunder++;
theContract.mapFunder[theContract.amountFunder] = theFunder;
theFunder.addressfunder.transfer(msg.value);
}
//查询众筹合约信息
function getContract() public view returns(address, bool, uint, uint, uint){
return (theContract.addressNeeder, theContract.isActive, theContract.totalMoney, theContract.giveMoney, theContract.amountFunder);
}
//查询众筹发起者信息
function getNeeder() public view returns(address, bool, uint, uint, uint){
return (theNeeder.addressNeeder, theNeeder.isActive, theNeeder.amountMoneyNeed, theNeeder.amountHasFunded, theNeeder.numberContract);
}
//查询投资者信息
function getFunder() public view returns(address, bool, uint, uint, uint){
return (theFunder.addressfunder, theFunder.isActive, theFunder.totalMoney, theFunder.numberGive, theFunder.expMap.length);
}
阅读全文