Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 500ngdev4ethTokenReward
As a means of wrapping up on our summary, we would create a 500NigeriaDevs4Eth (500ND4E) token, this token will serve as a reward token on this platform, this token will be used to reward diligence, consistency and commitment to learning. This token would allow students access swaggs within the platform, students can unlock platform goodies based on how many tokens they have. This token contract will have the following rules : Only whitelisted members of this platform can hold this token Members can only be whitelisted by the contract owner or any of the admins (mentor) on the platform Not more than 2 tokens can be rewarded to any member at any time t Mentors cannot be rewarded any tokens Only admins or contract owner can reward a member Only members with proven track records can be rewarded (using 5 star rating, 3 and above) Anybody can rate a member (Note : Only members can be rated), rating weight is calculated as follows : Admins => 3pt Member => 1pt 5 star member => 2pt 15pt equals 1star.
As a means of wrapping up on our summary, we would create a 500NigeriaDevs4Eth (500ND4E) token, this token will serve as a reward token on this platform, this token will be used to reward diligence, consistency and commitment to learning. This token would allow students access swaggs within the platform, students can unlock platform goodies based on how many tokens they have. This token contract will have the following rules :
- Only whitelisted members of this platform can hold this token Members can only be whitelisted by the contract owner or any of the admins (mentor) on the platform Not more than 2 tokens can be rewarded to any member at any time t Mentors cannot be rewarded any tokens
- Only admins or contract owner can reward a member Only members with proven track records can be rewarded (using 5 star rating, 3 and above)
- Anybody can rate a member (Note : Only members can be rated), rating weight is calculated as follows : Admins => 3pt Member => 1pt 5 star member => 2pt 15pt equals 1star.
As an assingment,all 500ngdev4eth students are to improve on this contract here on github and the deadline for submission or pushing to the test branch is 2000 CAT on Sunday,29th of December,2019.
115 changes: 58 additions & 57 deletions contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,109 +2,115 @@ pragma solidity >=0.5.0 < 0.6.0;
contract TokenReward {

struct Member {
uint8 rating;
string name;
bool isWhitelisted;
uint8 accumulatedPoints;
uint8 rating;
}

address owner;
mapping(address => Member) public members;
mapping(address => uint ) public reward;
mapping(address => bool ) public admins;
mapping(address => uint ) public balances;

event NewMember(string _name);
event Blacklisted(address indexed _member, string _name);
event NewReward(address indexed _member, uint reward);
event NewRating(address indexed _ratedBy, address indexed _memberRated, uint rating);

//Mappings
address owner;//declaring state variable owner
mapping(address => Member) public members;//each Member is recognised by an address
mapping(address => uint ) public reward;//captures the reward in uint of each address
mapping(address => bool ) public admins;//captures the addresses that are admins or not
mapping(address => uint ) public balances;//captures the balances in uint of each address

//Events
event MemberAdded(string msg,address indexed _member, string _name);//Triggers a searchable whitelisted member.
event Whitelisted(string msg,address indexed _member);//Triggers a searchable whitelisted member.
event Blacklisted(string msg,address indexed _member);//Triggers a searchable blacklisted member.
event NewReward(string msg,address indexed _member);//Triggers a searchable rewarded member with amount of reward.
event NewRating(string msg,address indexed _membertorate);//Populates searchable rated member with rating.

//Modifiers
modifier OnlyOwner() {
require(msg.sender == owner, "Only contract owner is allowed to call this function");
_;
_;//This allows only the owner to make changes
}

modifier OnlyAdminOrOwner() {
require(admins[msg.sender] == true, "Only admins or contract owner is allowed to call this function");
_;
_;//This allows only admin or owner to make changes
}

modifier IsWhitelisted(address __member) {
Member memory memberStruct = members[__member];
Member memory memberStruct = members[__member];//Any member that is whitelisted is now called memberStruct
require(memberStruct.isWhitelisted == true, "This address is not whitelisted");
_;
}

_;//This allows only whitelisted member to make changes
}
//Initializing permissions for both the creator and admins
constructor () public {
owner = msg.sender;
admins[msg.sender] = true;
}

function addAdmin(address __newAdmin) public OnlyOwner returns(bool) {

//This function adds a new Admin and can be called only by the owner
// It's convention (but not required) to start function parameter
// variable names with an underscore (_) in order to differentiate them from global variables.
function _addAdmin(address __newAdmin) public OnlyOwner returns(bool) {
admins[__newAdmin] = true;
return true;
return true;
}


function AddMember(address __member, string memory __memberName) public OnlyAdminOrOwner returns(bool) {
//This function adds a new member to the whitelist and emits the event
//and can be called only by admins and the owner.
function _AddMember(address __member, string memory __memberName) public OnlyAdminOrOwner returns(bool) {
Member memory __memberStruct;
__memberStruct.name = __memberName;
__memberStruct.isWhitelisted = true;
members[__member] = __memberStruct;

emit NewMember(__memberName);
return true;
}

function whiteListMember(address __member) public OnlyAdminOrOwner returns(bool) {
Member memory memberStruct = members[__member];
memberStruct.isWhitelisted = true;
emit MemberAdded("A new member has been added with the following information:"__member, __memberStruct.name);
//A message Alert for the adding a New Member
return true;
}
function blackListMember(address __member) public OnlyAdminOrOwner returns(bool) {
Member memory memberStruct = members[__member];
}

//This function blacklist a member and can be called only by admins and the owner
function _blackListMember(address __member) public OnlyAdminOrOwner returns(bool) {
Member storage memberStruct = members[__member];
memberStruct.isWhitelisted = false;

emit Blacklisted("A new member has been blacklisted with the following information:"__member);
return true;
}

function isWhitelisted(address __member) view internal returns(bool) {
// This function checks if a member is whitelisted or not
function _isWhitelisted(address __member)internal view returns(bool) {
Member memory memberStruct = members[__member];
emit Whitelisted("A new member has been whitelisted with the following information:",__member);
return memberStruct.isWhitelisted;
}

function rateMember(address __membertorate) public IsWhitelisted(__membertorate) returns(bool) {
Member memory __memberStruct = members[__membertorate];
//This function rate a member and can be called by whitelisted members
function _rateMember(address __membertorate) public IsWhitelisted(__membertorate) returns(bool) {
Member storage __memberStruct = members[__membertorate];
uint8 ratingPoint;
require(admins[msg.sender] || isWhitelisted(msg.sender), "You're not qualified to rate any member");
require(admins[msg.sender] || _isWhitelisted(msg.sender), "You're not qualified to rate any member");
if (admins[msg.sender]) {
ratingPoint = 3;
}
if (members[__membertorate].rating == 5) {
if (members[__membertorate].rating == 5) {
ratingPoint = 2;
} else {
ratingPoint = 1;
ratingPoint = 1;
}
__memberStruct.accumulatedPoints = __memberStruct.accumulatedPoints + ratingPoint;
__memberStruct.accumulatedPoints = __memberStruct.accumulatedPoints + ratingPoint;

(uint8 __memberPoint, uint8 __starRating) = calculateReward(__memberStruct.accumulatedPoints, __memberStruct.rating);
(uint8 __memberPoint, uint8 __starRating) = _calculateReward(__memberStruct.accumulatedPoints, __memberStruct.rating);
__memberStruct.accumulatedPoints = __memberPoint;
__memberStruct.rating = __starRating;

emit NewRating(msg.sender, __membertorate, ratingPoint);
emit NewRating("A new member has been newly rated with the following information:",__membertorate);
return true;
}

function rewardMember(address __memberToReward) public OnlyAdminOrOwner returns(bool) {
//This function rewards members
function _rewardMember(address __memberToReward) public OnlyAdminOrOwner returns(bool) {
require(admins[__memberToReward] == false, "admins cannot be rewarded tokens");
require(members[__memberToReward].rating >= 3, "member do not have a proven track record");
balances[__memberToReward] = balances[__memberToReward] + 2;
emit NewReward("A new member has been newly rewarded with the following information:", __membertoReward);
return true;
}

function calculateReward(uint8 __pointsScored, uint8 __starRating) pure internal returns(uint8, uint8) {
//This function helps calculate the members' reward base on point scored and star rating
function _calculateReward(uint8 __pointsScored, uint8 __starRating) internal pure returns(uint8, uint8) {
if (__pointsScored < 10 ) {
return (__pointsScored, __starRating);
}
Expand All @@ -113,11 +119,6 @@ contract TokenReward {
uint8 currentStarRating = __starRating + uint8(1);
return (__pointremained, currentStarRating);
}
return (__pointremained, __starRating
);
return (__pointremained, __starRating);
}
}