-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBetterHashRepo.sol
More file actions
91 lines (73 loc) · 3.55 KB
/
BetterHashRepo.sol
File metadata and controls
91 lines (73 loc) · 3.55 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
83
84
85
86
87
88
89
90
91
pragma solidity ^0.5.2;
contract BetterHashRepo {
uint public repoID;
struct Repo {
address repoMaster;
uint commitCount;
bool isPublic;
mapping(address => bool) whiteList;
mapping(uint => string) commitLog;
}
mapping(uint => Repo) public repoInfo;
mapping(bytes32 => uint) public nameToRepoID;
mapping(uint => bytes32) public idToName;
event NewRepo (uint indexed repo, address indexed owner, bytes32 name, bool isPublic, uint forkOf);
event AddCommit (uint indexed repo, uint commitCount, address indexed commiter, string IPFS, string message, uint timestamp);
constructor() public {}
function sendCommit (uint _repoID, string memory _commitHash, string memory _commitMessage) public {
require(repoInfo[repoID].isPublic || repoInfo[_repoID].whiteList[msg.sender], "You are not authorized to commit to this repo.");
repoInfo[_repoID].commitLog[repoInfo[_repoID].commitCount] = _commitHash;
emit AddCommit (_repoID, repoInfo[_repoID].commitCount, msg.sender, _commitHash, _commitMessage, now);
repoInfo[_repoID].commitCount += 1;
}
function newHashRepo (bytes32 _name, bool _isPublic) public returns (uint) {
require(nameToRepoID[_name] == 0, "Repo name has been taken, please choose another name.");
repoID += 1;
repoInfo[repoID].repoMaster = msg.sender;
repoInfo[repoID].whiteList[msg.sender] = true;
repoInfo[repoID].commitCount = 0;
repoInfo[repoID].isPublic = _isPublic;
nameToRepoID[_name] = repoID;
idToName[repoID] = _name;
emit NewRepo (repoID, msg.sender, _name, _isPublic, 0);
return repoID;
}
function forkRepo (uint _repoID, bytes32 _name, bool _isPublic) public returns (uint) {
require(nameToRepoID[_name] == 0, "Repo name has been taken, please choose another name.");
repoID += 1;
repoInfo[repoID].repoMaster = msg.sender;
repoInfo[repoID].whiteList[msg.sender] = true;
repoInfo[repoID].commitCount = repoInfo[_repoID].commitCount;
repoInfo[repoID].isPublic = _isPublic;
repoInfo[repoID].isPublic = _isPublic;
nameToRepoID[_name] = repoID;
for (uint i = 0; i<repoInfo[_repoID].commitCount; i++) {
repoInfo[repoID].commitLog[i] = repoInfo[_repoID].commitLog[i];
}
emit NewRepo (repoID, msg.sender, _name, _isPublic, _repoID);
return repoID;
}
function AddToWhiteList (uint _repoID, address _add) public {
require(repoInfo[_repoID].repoMaster == msg.sender, "You are not the repo master.");
repoInfo[repoID].whiteList[_add] = true;
}
function RemoveFromWhiteList (uint _repoID, address _remove) public {
require(repoInfo[_repoID].repoMaster == msg.sender, "You are not the repo master.");
repoInfo[repoID].whiteList[_remove] = false;
}
function GetCommitCount (uint _repoID) public view returns(uint) {
return repoInfo[_repoID].commitCount;
}
function GetCommitHash (uint _repoID, uint _commitID) public view returns(string memory) {
return repoInfo[_repoID].commitLog[_commitID];
}
function GetRepoID (bytes32 _name) public view returns(uint) {
return nameToRepoID[_name];
}
function GetRepoName (uint _repoID) public view returns(bytes32) {
return idToName[_repoID];
}
function GetLastestCommit (uint _repoID) public view returns(string memory) {
return repoInfo[_repoID].commitLog[(repoInfo[_repoID].commitCount - 1)];
}
}