Skip to content

Commit 4bd59d3

Browse files
authored
Merge pull request #6 from SpecLock/develop
Develop
2 parents 3d5a396 + 4a1df32 commit 4bd59d3

File tree

3 files changed

+244
-0
lines changed

3 files changed

+244
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ProjectFactory
2+
3+
ProjectFactory is a Solidity-based project management system that allows the creation and management of projects with milestones. Each project can have multiple milestones, and the owner can add, complete, and approve these milestones.
4+
5+
## Development
6+
7+
The development of this project is planned and tracked in the testing branches. These branches contain the latest features and improvements under development.
8+
9+
## Contracts
10+
11+
- `Project`: Manages project milestones.
12+
- `ProjectFactory`: Creates and manages multiple projects.
13+
14+
## Documentation
15+
16+
For detailed API documentation, refer to the [ProjectFactory Documentation](docs/ProjectFactory.md).

contracts/projectfactory.sol

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
/**
5+
* @title Project
6+
* @dev A contract to manage project milestones, allowing the owner to add, complete, and approve milestones.
7+
*/
8+
contract Project {
9+
struct Milestone {
10+
string title;
11+
uint256 tentativeDate;
12+
string description;
13+
uint256 amount;
14+
bool completed;
15+
}
16+
17+
address public owner;
18+
string public projectName;
19+
string public projectDescription;
20+
address payable public developerAddress;
21+
uint256 public totalCapital;
22+
Milestone[] public milestones;
23+
24+
event MilestoneAdded(uint256 indexed milestoneId, string title, uint256 amount);
25+
event MilestoneCompleted(uint256 indexed milestoneId, string proof);
26+
event MilestoneApproved(uint256 indexed milestoneId, uint256 amount);
27+
28+
modifier onlyOwner() {
29+
require(msg.sender == owner, "Solo el owner puede ejecutar esta funcion");
30+
_;
31+
}
32+
33+
constructor(
34+
string memory _projectName,
35+
string memory _projectDescription,
36+
address payable _developerAddress,
37+
address _owner
38+
) {
39+
owner = _owner;
40+
projectName = _projectName;
41+
projectDescription = _projectDescription;
42+
developerAddress = _developerAddress;
43+
}
44+
45+
function addMilestone(
46+
string memory _title,
47+
uint256 _tentativeDate,
48+
string memory _description,
49+
uint256 _amount
50+
) public onlyOwner {
51+
milestones.push(Milestone({
52+
title: _title,
53+
tentativeDate: _tentativeDate,
54+
description: _description,
55+
amount: _amount,
56+
completed: false
57+
}));
58+
emit MilestoneAdded(milestones.length - 1, _title, _amount);
59+
}
60+
61+
function completeMilestone(uint256 _milestoneId, string memory _proof) public onlyOwner {
62+
require(_milestoneId < milestones.length, "Milestone no existe");
63+
milestones[_milestoneId].completed = true;
64+
emit MilestoneCompleted(_milestoneId, _proof);
65+
}
66+
67+
function approveMilestone(uint256 _milestoneId) public onlyOwner {
68+
require(_milestoneId < milestones.length, "Milestone no existe");
69+
require(milestones[_milestoneId].completed, "Milestone no esta completado");
70+
developerAddress.transfer(milestones[_milestoneId].amount);
71+
emit MilestoneApproved(_milestoneId, milestones[_milestoneId].amount);
72+
}
73+
74+
receive() external payable {
75+
totalCapital += msg.value;
76+
}
77+
}
78+
79+
contract ProjectFactory {
80+
Project[] public projects;
81+
82+
function createProject(
83+
string memory _projectName,
84+
string memory _projectDescription,
85+
address payable _developerAddress
86+
) public returns (address) {
87+
Project newProject = new Project(
88+
_projectName,
89+
_projectDescription,
90+
_developerAddress,
91+
msg.sender
92+
);
93+
projects.push(newProject);
94+
return address(newProject);
95+
}
96+
97+
function getProjectsByOwner(address _owner) public view returns (Project[] memory) {
98+
uint count;
99+
for (uint i = 0; i < projects.length; i++) {
100+
if (projects[i].owner() == _owner) {
101+
count++;
102+
}
103+
}
104+
Project[] memory result = new Project[](count);
105+
uint index;
106+
for (uint j = 0; j < projects.length; j++) {
107+
if (projects[j].owner() == _owner) {
108+
result[index] = projects[j];
109+
index++;
110+
}
111+
}
112+
return result;
113+
}
114+
115+
function getProjectsByDeveloper(address _developer) public view returns (Project[] memory) {
116+
uint count;
117+
for (uint i = 0; i < projects.length; i++) {
118+
if (projects[i].developerAddress() == _developer) {
119+
count++;
120+
}
121+
}
122+
Project[] memory result = new Project[](count);
123+
uint index;
124+
for (uint j = 0; j < projects.length; j++) {
125+
if (projects[j].developerAddress() == _developer) {
126+
result[index] = projects[j];
127+
index++;
128+
}
129+
}
130+
return result;
131+
}
132+
}

docs/ProjectFactory.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Solidity API
2+
3+
## Project
4+
5+
_A contract to manage project milestones, allowing the owner to add, complete, and approve milestones._
6+
7+
### Contract
8+
Project : contracts/ProjectFactory.sol
9+
10+
A contract to manage project milestones, allowing the owner to add, complete, and approve milestones.
11+
12+
---
13+
### Modifiers:
14+
### onlyOwner
15+
16+
```solidity
17+
modifier onlyOwner()
18+
```
19+
20+
---
21+
### Functions:
22+
### constructor
23+
24+
```solidity
25+
constructor(string _projectName, string _projectDescription, address payable _developerAddress) public
26+
```
27+
28+
### addMilestone
29+
30+
```solidity
31+
function addMilestone(string _title, uint256 _tentativeDate, string _description, uint256 _amount) public
32+
```
33+
34+
### completeMilestone
35+
36+
```solidity
37+
function completeMilestone(uint256 _milestoneId, string _proof) public
38+
```
39+
40+
### approveMilestone
41+
42+
```solidity
43+
function approveMilestone(uint256 _milestoneId) public
44+
```
45+
46+
### receive
47+
48+
```solidity
49+
receive() external payable
50+
```
51+
52+
---
53+
### Events:
54+
### MilestoneAdded
55+
56+
```solidity
57+
event MilestoneAdded(uint256 milestoneId, string title, uint256 amount)
58+
```
59+
60+
### MilestoneCompleted
61+
62+
```solidity
63+
event MilestoneCompleted(uint256 milestoneId, string proof)
64+
```
65+
66+
### MilestoneApproved
67+
68+
```solidity
69+
event MilestoneApproved(uint256 milestoneId, uint256 amount)
70+
```
71+
72+
## ProjectFactory
73+
74+
### Contract
75+
ProjectFactory : contracts/ProjectFactory.sol
76+
77+
---
78+
### Functions:
79+
### createProject
80+
81+
```solidity
82+
function createProject(string _projectName, string _projectDescription, address payable _developerAddress) public
83+
```
84+
85+
### getProjectsByOwner
86+
87+
```solidity
88+
function getProjectsByOwner(address _owner) public view returns (contract Project[])
89+
```
90+
91+
### getProjectsByDeveloper
92+
93+
```solidity
94+
function getProjectsByDeveloper(address _developer) public view returns (contract Project[])
95+
```
96+

0 commit comments

Comments
 (0)