Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate blacklisted members on whitelist #15

Open
wants to merge 1 commit into
base: test
Choose a base branch
from
Open
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
77 changes: 41 additions & 36 deletions contract.sol
Original file line number Diff line number Diff line change
@@ -1,81 +1,86 @@
pragma solidity >=0.5.0 < 0.6.0;
contract TokenReward {

struct Member {
string name;
bool isWhitelisted;
uint8 accumulatedPoints;
uint8 rating;
}
//Mappings
address owner;//Our state variable
mapping(address => Member) public members;//each Member has an address
address owner;//declaring state variable owner
mapping(address => Member) public members;//each Memberis 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 NewMember(string _name);//Trigers when a new name is added
event Whitelisted(address indexed _member, string _name);
event Blacklisted(address indexed _member, string _name);//trigers new blacklisting
event NewReward(address indexed _member, uint reward);//trigers new reward and the member
event NewRating(address indexed _ratedBy, address indexed _memberRated, uint rating);//trigers new rating
event Whitelisted(address indexed _member, string _name);//Triggers a searchable whitelisted member.
event Blacklisted(address indexed _member, string _name);//Triggers a searchable blacklisted member.
event NewReward(address indexed _member, uint reward);//Triggers a searchable rewarded member with amount of reward.
event NewRating(address indexed _ratedBy, address indexed _memberRated, uint rating);//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];//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
}

constructor () public {//Only the owner of the contract will call this
}
//Initializing permissions for both the creator and admins
constructor () public {
owner = msg.sender;
admins[msg.sender] = true;
}

//This function helps to add a new Admin and can be called only by the owner
//This function adds a new Admin and can be called only by the owner
function addAdmin(address __newAdmin) public OnlyOwner returns(bool) {
admins[__newAdmin] = true;
return true;
return true;
}

//This adds a new member and can be called only by admins and the owner

//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;
}
//This function whitelist a member and can be called only by admins and the owner
function whiteListMember(address __member) public view OnlyAdminOrOwner returns(bool) {
Member storage memberStruct = members[__member];
memberStruct.isWhitelisted = true;

emit Whitelisted(__member, memberStruct.name);

emit Whitelisted(__member, __memberStruct.name);
return true;
}


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

emit Blacklisted(__member, memberStruct.name);
return true;
}


// This function removes a member from the blacklist and can be called only by admins and the owner
function formerBlackListMember(address __member ) public OnlyAdminOrOwner returns(bool) {

Member storage memberStruct = members[__member];
memberStruct.isWhitelisted = true;

emit Whitelisted(__member, memberStruct.name);
return true;

}


// This function checks if a member is whitelisted or not
function isWhitelisted(address __member)internal view returns(bool) {
Member memory memberStruct = members[__member];
Expand All @@ -88,18 +93,18 @@ contract TokenReward {
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;

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

emit NewRating(msg.sender, __membertorate, ratingPoint);
return true;
}
Expand Down