Created
December 22, 2017 17:58
-
-
Save Muhammad-Altabba/090b712755f2b5bf2dbedce6b76d66dc to your computer and use it in GitHub Desktop.
Solidity Sample: Separation of Rules & Logic from Data Structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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