Skip to content

Commit

Permalink
smart contract + remove node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreyes committed Apr 4, 2021
1 parent 8565faa commit f45fca2
Show file tree
Hide file tree
Showing 19,200 changed files with 173 additions and 3,325,281 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
160 changes: 160 additions & 0 deletions contracts/CeloCrowdfund.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

// Importing OpenZeppelin's SafeMath Implementation
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract CeloCrowdfund {
// SafeMath for safe integer operations
using SafeMath for uint256;

// List of all the projects
Project[] private projects;

// event for when new project starts
event ProjectStarted(
address contractAddress,
address projectCreator,
string title,
string description,
string imageLink,
uint256 fundRaisingDeadline,
uint256 goalAmount
);

function startProject(
string calldata title,
string calldata description,
string calldata imageLink,
uint durationInDays,
uint amountToRaise
) external {
uint raiseUntil = block.timestamp.add(durationInDays.mul(1 days));

Project newProject = new Project (payable(msg.sender), title, description, imageLink, raiseUntil, amountToRaise);
projects.push(newProject);

emit ProjectStarted(
address(newProject),
msg.sender,
title,
description,
imageLink,
raiseUntil,
amountToRaise
);
}

function returnProjects() external view returns(Project[] memory) {
return projects;
}
}

contract Project {
using SafeMath for uint256;

enum ProjectState {
Fundraising,
Expired,
Successful
}

// Initialize public variables
address payable public creator;
uint public goalAmount;
uint public completeAt;
uint256 public currentBalance;
uint public raisingDeadline;
string public title;
string public description;
string public imageLink;

// Initialize state at fundraising
ProjectState public state = ProjectState.Fundraising;
mapping (address => uint) public contributions;

// Event when funding is received
event ReceivedFunding(address contributor, uint amount, uint currentTotal);

// Event for when the project creator has received their funds
event CreatorPaid(address recipient);

modifier theState(ProjectState _state) {
require(state == _state);
_;
}

constructor
(
address payable projectCreator,
string memory projectTitle,
string memory projectDescription,
string memory projectImageLink,
uint fundRaisingDeadline,
uint projectGoalAmount
) {
creator = projectCreator;
title = projectTitle;
description = projectDescription;
imageLink = projectImageLink;
goalAmount = projectGoalAmount;
raisingDeadline = fundRaisingDeadline;
currentBalance = 0;
}

// Fund a project
function contribute() external theState(ProjectState.Fundraising) payable {
require(msg.sender != creator);
contributions[msg.sender] = contributions[msg.sender].add(msg.value);
currentBalance = currentBalance.add(msg.value);
emit ReceivedFunding(msg.sender, msg.value, currentBalance);
checkIfFundingCompleteOrExpired();
}

// check project state
function checkIfFundingCompleteOrExpired() public {
if (currentBalance >= goalAmount) {
state = ProjectState.Successful;
payOut();
} else if (block.timestamp > raisingDeadline) {
state = ProjectState.Expired;
}
completeAt = block.timestamp;
}

function payOut() internal theState(ProjectState.Successful) returns (bool) {
uint256 totalRaised = currentBalance;
currentBalance = 0;

if (creator.send(totalRaised)) {
emit CreatorPaid(creator);
return true;
} else {
currentBalance = totalRaised;
state = ProjectState.Successful;
}

return false;
}

function getDetails() public view returns
(
address payable projectCreator,
string memory projectTitle,
string memory projectDescription,
string memory projectImageLink,
uint fundRaisingDeadline,
ProjectState currentState,
uint256 projectGoalAmount,
uint256 currentAmount
) {
projectCreator = creator;
projectTitle = title;
projectDescription = description;
projectImageLink = imageLink;
fundRaisingDeadline = raisingDeadline;
currentState = state;
projectGoalAmount = goalAmount;
currentAmount = currentBalance;
}
}
1 change: 0 additions & 1 deletion node_modules/.bin/_mocha

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/esparse

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/esvalidate

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/flat

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/he

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/js-yaml

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/miller-rabin

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/mime

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/mkdirp

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/mocha

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/node-gyp-build

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/node-gyp-build-optional

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/node-gyp-build-test

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/rlp

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/semver

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/sha.js

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/sshpk-conv

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/sshpk-sign

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/sshpk-verify

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/ts-node

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/ts-node-script

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/ts-node-transpile-only

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/ts-script

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/tsc

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/tsserver

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/uuid

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/which

This file was deleted.

Loading

0 comments on commit f45fca2

Please sign in to comment.