Created
November 16, 2022 19:13
-
-
Save marianoeramirez/51482faa36adecc63241aa21273b5c90 to your computer and use it in GitHub Desktop.
Project1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
/* states | |
0 fundable | |
1 completed | |
*/ | |
contract FundingProject{ | |
enum State {Open, Closed} | |
struct Project{ | |
string name; | |
State state; | |
address owner; | |
} | |
Project public project; | |
constructor(string memory _name) { | |
project = Project(_name, State.Open, msg.sender); | |
} | |
modifier isOwner(){ | |
require(msg.sender == project.owner, "Only the owner can execute this"); | |
_; | |
} | |
function multiplicacion(uint a, uint b) external pure returns (uint product) { | |
return a*b; | |
} | |
function getNumber() public pure returns (int number){ | |
number = 1984; | |
} | |
function changeNumber() public pure returns (int number){ | |
number = getNumber() * -1; | |
} | |
function sendEther(address payable reciever) public payable{ | |
reciever.transfer(msg.value); | |
} | |
function getName() public view returns (string memory){ | |
return project.name; | |
} | |
event Funding(address sender, uint amount, uint total); | |
function fundProject() public payable{ | |
require(project.state == State.Closed, "The project already closed"); | |
require(msg.value > 0, "Fund Value must be greater than 0"); | |
emit Funding(msg.sender, msg.value, address(this).balance); | |
} | |
function getBalance() public view returns (uint){ | |
return address(this).balance; | |
} | |
function closeProject() public isOwner{ | |
require(project.state == State.Closed, "The project is already closed"); | |
project.state = State.Closed; | |
} | |
function withdrawAllMoney() public isOwner{ | |
require(project.state != State.Closed, "Please close the project first"); | |
payable(project.owner).transfer(address(this).balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment