Skip to content

Commit

Permalink
Added modifiers and comments to the code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtomes123 committed May 7, 2018
1 parent 9c38e6a commit 633fe97
Showing 1 changed file with 57 additions and 43 deletions.
100 changes: 57 additions & 43 deletions Backend/Dogtags.sol
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
pragma solidity ^0.4.19;
/*
This contract was created by Jakub Tomeš and is licensed under MIT license
Github: https://github.com/jtomes123/ethtags
*/

/*
A contract that stores data of the main contract.
This allows the main contract to be more easily updated.
*/
contract DogtagsDataStorage {
//Address of the owner, initially the person that deploys the contract
address owner;
//Address of the main contract
address currentContract;

//The constructor
function DogtagsDataStorage(address newContract) public {
owner = msg.sender;
currentContract = newContract;
}

//Modifier that checks if the sender is authorised to make any changes
modifier onlyAuthorized {
require(msg.sender == owner || msg.sender == currentContract);
_;
}
//Modifier that checks if the sender is owner
modifier onlyOwner {
require(msg.sender == owner);
_;
}

//Setters for the owner and contract
function setOwner(address newOwner) public onlyOwner {
owner = newOwner;
}
function setContract(address newContract) public onlyAuthorized {
currentContract = newContract;
}

struct Dogtag {
string name;
string content;
bool verified;
bool canVerify;
bool isAdmin;

address verifier;
}

//Storage for strings
mapping (address => mapping(string => string)) strings;
function getString(address user, string key) view public returns(string) {
return strings[user][key];
Expand All @@ -43,6 +48,7 @@ contract DogtagsDataStorage {
strings[user][key] = value;
}

//Storage for bools
mapping (address => mapping(string => bool)) bools;
function getBool(address user, string key) view public returns(bool) {
return bools[user][key];
Expand All @@ -51,6 +57,7 @@ contract DogtagsDataStorage {
bools[user][key] = value;
}

//Storage for addresses
mapping (address => mapping(string => address)) addresses;
function getAddress(address user, string key) view public returns(address) {
return addresses[user][key];
Expand All @@ -59,6 +66,7 @@ contract DogtagsDataStorage {
addresses[user][key] = value;
}

//Storage for uints
mapping (address => mapping(string => uint)) ints;
function getInt(address user, string key) view public returns(uint) {
return ints[user][key];
Expand All @@ -67,6 +75,7 @@ contract DogtagsDataStorage {
ints[user][key] = value;
}
}
/* Main Contract */
contract Dogtags {
DogtagsDataStorage data;
address owner;
Expand All @@ -75,14 +84,27 @@ contract Dogtags {
owner = msg.sender;
}

//Modifier that checks if the sender is owner
modifier onlyOwner {
require(msg.sender == owner);
_;
}
//Modifier that checks if the sender is owner or admin
modifier onlyAdmin {
require(msg.sender == owner || data.getBool(msg.sender, "isAdmin"));
_;
}
//Modifier that checks if the sender can verify
modifier onlyVerifier {
require(msg.sender == owner || data.getBool(msg.sender, "isAdmin") || data.getBool(msg.sender, "isVerifier"));
_;
}

//Sets the address of DataStorageContract this is necessary for the contract to function
function setDataStorageContract(address newContract) public onlyOwner {
data = DogtagsDataStorage(newContract);
}

//Getters
function GetDogtagContent(address adr) public constant returns(string) {
return data.getString(adr, "content");
Expand Down Expand Up @@ -110,6 +132,10 @@ contract Dogtags {
}

//Setters

/*
These functions set the content of the dogtag
*/
function SetDogtag(string name, string content) public payable {
data.setString(msg.sender, "name", name);
data.setString(msg.sender, "content", content);
Expand All @@ -122,46 +148,34 @@ contract Dogtags {
data.setString(msg.sender, "name", name);
data.setBool(msg.sender, "isVerified", false);
}
function SetNewOwner(address adr) public {
if(msg.sender == owner) {
owner = adr;
}

//Set new owner of the contract
function SetNewOwner(address adr) public onlyOwner {
owner = adr;
}
function SetAdminStatus(address adr, bool status) public {
if (msg.sender == owner) {
if (data.getBool(adr, "isAdmin") != status) {
data.setBool(adr, "isAdmin", status);
} else {
revert();
}
} else {
revert();
}

//Set if the address is admin
function SetAdminStatus(address adr, bool status) public onlyOwner {
data.setBool(adr, "isAdmin", status);
}
function SetVerificationStatus(address adr, bool status) public {
if (data.getBool(msg.sender, "isVerifier") || msg.sender == owner) {
data.setBool(adr, "isVerified", status);
data.setAddress(adr, "verifier", msg.sender);
} else {
revert();
}

//Set if dogtag is verified or not
function SetVerificationStatus(address adr, bool status) public onlyVerifier {
data.setBool(adr, "isVerified", status);
data.setAddress(adr, "verifier", msg.sender);
}
function SetVerifierStatus(address adr, bool status) public {
if (msg.sender == owner || data.getBool(msg.sender, "isAdmin")) {
if (data.getBool(msg.sender, "isVerifier") != status) {
data.setBool(adr, "isVerifier", status);
} else {
revert();
}

//Gives address the ability to verify users
function SetVerifierStatus(address adr, bool status) public onlyAdmin {
if (data.getBool(msg.sender, "isVerifier") != status) {
data.setBool(adr, "isVerifier", status);
} else {
revert();
}
}
function Withdraw(uint amount) public {
if (msg.sender == owner) {
if (address(this).balance - amount > address(this).balance / 10) {
owner.transfer(amount);
}
function Withdraw(uint amount) public onlyOwner {
if (address(this).balance - amount > address(this).balance / 10) {
owner.transfer(amount);
}
}
function Donate() public payable {
Expand Down

0 comments on commit 633fe97

Please sign in to comment.