-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeSciPlatform.sol
111 lines (91 loc) · 3.66 KB
/
DeSciPlatform.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ReputationToken.sol"; // Import the Reputation token contract
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
// Main Platform Contract
contract DeSciPlatform {
ReputationToken public reputationToken;
struct Researcher {
string name;
string credentials;
uint256 reputationScore;
bool isVerified;
address walletAddress;
}
struct Publication {
uint256 id;
address author;
string title;
string contentHash;
uint256 upvotes;
mapping(address => bool) hasVoted;
}
mapping(address => Researcher) public researchers;
mapping(uint256 => Publication) public publications;
uint256 public publicationCount;
event ResearcherRegistered(address indexed researcher, string name);
event PublicationSubmitted(uint256 indexed id, address indexed author, string title);
event PublicationUpvoted(uint256 indexed id, address indexed voter);
constructor(address _reputationToken) {
reputationToken = ReputationToken(_reputationToken);
}
function registerResearcher(
string memory _name,
string memory _credentials
) public {
require(researchers[msg.sender].walletAddress == address(0), "Already registered");
researchers[msg.sender] = Researcher({
name: _name,
credentials: _credentials,
reputationScore: 0,
isVerified: false,
walletAddress: msg.sender
});
emit ResearcherRegistered(msg.sender, _name);
}
function submitPublication(
string memory _title,
string memory _contentHash
) public {
require(researchers[msg.sender].walletAddress != address(0), "Not registered");
uint256 newPublicationId = publicationCount++;
Publication storage newPublication = publications[newPublicationId];
newPublication.id = newPublicationId;
newPublication.author = msg.sender;
newPublication.title = _title;
newPublication.contentHash = _contentHash;
newPublication.upvotes = 0;
// Award initial reputation for publishing
updateReputation(msg.sender, 10);
emit PublicationSubmitted(newPublicationId, msg.sender, _title);
}
function upvotePublication(uint256 _publicationId) public {
require(researchers[msg.sender].walletAddress != address(0), "Not registered");
require(!publications[_publicationId].hasVoted[msg.sender], "Already voted");
Publication storage publication = publications[_publicationId];
publication.upvotes += 1;
publication.hasVoted[msg.sender] = true;
// Award reputation to the author
updateReputation(publication.author, 1);
emit PublicationUpvoted(_publicationId, msg.sender);
}
function updateReputation(address _researcher, uint256 _points) internal {
researchers[_researcher].reputationScore += _points;
reputationToken.mint(_researcher, _points * 1e18); // 1 token per point
}
function getResearcherDetails(address _researcher) public view returns (
string memory name,
string memory credentials,
uint256 reputationScore,
bool isVerified
) {
Researcher memory researcher = researchers[_researcher];
return (
researcher.name,
researcher.credentials,
researcher.reputationScore,
researcher.isVerified
);
}
}