-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransparencyLedger.sol
More file actions
82 lines (72 loc) · 2.49 KB
/
Copy pathTransparencyLedger.sol
File metadata and controls
82 lines (72 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title Transparency Ledger for Public or Corporate Projects
/// @notice A decentralized registry that records project details on-chain
/// @dev Designed for transparency, not efficiency (data is public and immutable)
contract TransparencyLedger {
struct Project {
uint256 id;
string projectName;
uint256 projectValue; // in smallest currency unit, e.g. wei or cents
string workerCompany;
string location;
address addedBy;
uint256 timestamp;
}
Project[] private projects;
uint256 private nextId = 1;
address public owner;
event ProjectAdded(
uint256 indexed id,
string projectName,
uint256 projectValue,
string workerCompany,
string location,
address indexed addedBy
);
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can add projects");
_;
}
constructor() {
owner = msg.sender;
}
/// @notice Add a new project to the public ledger
/// @param _projectName The project name
/// @param _projectValue The project value (in smallest unit)
/// @param _workerCompany The contractor or executing company
/// @param _location The location where the project is executed
function addProject(
string calldata _projectName,
uint256 _projectValue,
string calldata _workerCompany,
string calldata _location
) external onlyOwner {
projects.push(
Project({
id: nextId,
projectName: _projectName,
projectValue: _projectValue,
workerCompany: _workerCompany,
location: _location,
addedBy: msg.sender,
timestamp: block.timestamp
})
);
emit ProjectAdded(nextId, _projectName, _projectValue, _workerCompany, _location, msg.sender);
nextId++;
}
/// @notice Returns all recorded projects
function getAllProjects() external view returns (Project[] memory) {
return projects;
}
/// @notice Get a specific project by ID
function getProjectById(uint256 _id) external view returns (Project memory) {
require(_id > 0 && _id < nextId, "Invalid project ID");
return projects[_id - 1];
}
/// @notice Get the total number of recorded projects
function totalProjects() external view returns (uint256) {
return projects.length;
}
}