Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muhammad-Altabba/090b712755f2b5bf2dbedce6b76d66dc to your computer and use it in GitHub Desktop.
Save Muhammad-Altabba/090b712755f2b5bf2dbedce6b76d66dc to your computer and use it in GitHub Desktop.
Solidity Sample: Separation of Rules & Logic from Data Structure
contract ManagableAuthorization{
//Simplified in a way that all readers can read all data. In real case scenario you will have more complex logic.
mapping(address => bool) readers;
modifier canRead(){
//your logic for example:
require(readers[msg.sender]);
_;
}
//........ the rest of the class code.........
}
contract PeopleRepository is ManagableAuthorization{
struct Person {
bytes32 name;
uint birthDate;
}
mapping(address => Person) people;
function readPerson(address personAddress) public canRead returns(bytes32, uint) {
Person storage person = people[personAddress];
return(person.name, person.birthDate);
}
//........ the rest of the class code.........
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment