-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.sol
65 lines (54 loc) · 2.32 KB
/
main.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ResearchPaperRegistry {
struct Scientist {
string name;
string[] researchPaperCIDs;
}
constructor() {
owner = payable(msg.sender);
}
address payable public owner;
address[] public users;
mapping(address => Scientist) public scientists;
// Function to add a new scientist
function registerScientist(string memory scientistName) external {
require(bytes(scientistName).length > 0, "Scientist name must not be empty");
Scientist storage scientist = scientists[msg.sender];
scientist.name = scientistName;
}
// Function to add a new research paper CID for an existing scientist
function addResearchPaper(string memory newResearchPaperCID) external {
Scientist storage scientist = scientists[msg.sender];
require(bytes(scientist.name).length > 0, "Scientist is not registered");
scientist.researchPaperCIDs.push(newResearchPaperCID);
}
// Function to get the number of research papers for a scientist
function getResearchPaperCount(address scientistAddress) external view returns (uint256) {
return scientists[scientistAddress].researchPaperCIDs.length;
}
// Function to get a specific research paper CID for a scientist
function getResearchPaperCID(address scientistAddress, uint256 index) external view returns (string memory) {
Scientist storage scientist = scientists[scientistAddress];
require(index < scientist.researchPaperCIDs.length, "Invalid index");
return scientist.researchPaperCIDs[index];
}
function deposit() public payable {
require(msg.value == 1 ether, "Deposit amount must be 1 ETH");
}
// Function to add a user to the registry
function addUser(address userAddress) external {
require(userAddress != address(0), "Invalid user address");
require(!isUserRegistered(userAddress), "User is already registered");
users.push(userAddress);
}
// Function to check if a user is already registered
function isUserRegistered(address userAddress) public view returns (bool) {
for (uint256 i = 0; i < users.length; i++) {
if (users[i] == userAddress) {
return true;
}
}
return false;
}
}