Skip to content

Instantly share code, notes, and snippets.

@zendevil
Created July 25, 2021 04:00
Show Gist options
  • Save zendevil/67065f2cb3f7d569763feaa85ce1c4a5 to your computer and use it in GitHub Desktop.
Save zendevil/67065f2cb3f7d569763feaa85ce1c4a5 to your computer and use it in GitHub Desktop.
Creation.sol
pragma solidity >=0.6.0;
//import "./strings.sol";
contract Creation {
//using strings for *;
address creator;
string creationId;
string creatorId;
uint public bidEnd;
uint public percentage; // 100% == 10^8
uint public minToRaise;
constructor(address _creator, string memory _creationId,
string memory _creatorId, uint _percentage,
uint _minToRaise, uint _bidEnd) payable {
creator = _creator;
creationId = _creationId;
creatorId = _creatorId;
percentage = _percentage;
minToRaise = _minToRaise;
bidEnd = _bidEnd;
}
struct Order {
address investor;
uint amount;
string investorId;
uint timestamp;
}
Order[] public orders;
event onOrder(address investor, address creator,
string investorId, string creationId,
string creatorId,
uint timestamp, uint balance);
event onPayout(address investor, address creator,
string investorId, string creationId,
string creatorId,
uint timestamp, uint amount);
event Amount(uint amount);
function buy(string memory investorId) public payable {
orders.push(Order(msg.sender, msg.value, investorId, block.timestamp));
emit onOrder(msg.sender, creator, investorId,
creationId, creatorId,
block.timestamp, address(this).balance);
}
function payout() public payable {
uint ordersLength = orders.length;
uint totalRaised = 0;
for (uint i = 0; i < ordersLength; i++) {
totalRaised += orders[i].amount;
emit Amount(orders[i].amount);
}
for (uint i = 0; i < ordersLength; i++) {
payable(orders[i].investor).transfer(msg.value * orders[i].amount / totalRaised);
emit onPayout(orders[i].investor, creator, orders[i].investorId, creationId, creatorId, block.timestamp,
msg.value * orders[i].amount / totalRaised);
}
}
function getRaised() public returns (uint totalRaised) {
uint ordersLength = orders.length;
totalRaised = 0;
for (uint i = 0; i < ordersLength; i++) {
emit Amount(orders[i].amount);
totalRaised += orders[i].amount;
}
return totalRaised;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment