I have 3 contracts that I want to implement. The contracts are master
, admin
and customer
. So the master contract is initiated by a single person, the owner of the private chain (based on geth). The admin
contract provides access to certain addresses. These admin
instances are created by the master
. I am using a modifier
to ensure this. The customer
contract can be interacted with only by the admin
and master
contract.
I have mapped these addresses
to accounts (with username and pw) stored on my local Redis db
. Snipper of my contract structure is below:
Master Contract
contract MasterContract{
bool public state = false;
address public masterAddress;
bool permCheck;
// ACL
// Subject(Role) - Object/Subject - permission - On/Off
mapping (uint => mapping(uint => perm)) public acl;
// Init Function
function masterContractInit(string name,string detail){
if(msg.sender!="0x0"){
throw;
}else{
masterAddress = msg.sender;
}
}
modifier onlyMasterAccess{
if (msg.sender == masterAddress) _
else throw;
}
}
The admin contract
contract AdminContract{
bool state=false;
struct Admin{
bool status;
string name;
}
mapping (address => admin ) public admins;
// How to reference this masterAddress?
modifier checkMasterAndAdminAccess{
if (msg.sender == masterAddress || admins[msg.sender].status) _
else throw;
}
function initAdminContract() onlyMasterAccess{
state = true;
}
function addAdmin(address addr, string name) onlyMasterAccess{
admins[addr]=Admin(true, name);
}
function revokeAdmin(address addr) onlyMasterAccess{
if(addr!="0x0"){
throw;
}else{
admins[addr].status = false;
}
}
}
Customer contract
contract Customer{
bool public state = false;
function initCustomerContract() onlyMasterAccess{
state = true;
}
function foo() checkMasterAndAdminAccess{
// Do something here
// only admin or master can call this function
}
function bar(){
// Do something, but allow others to modify this
}
}
Now I need to further understand how to combine these contracts and reference the master and admin address in customer contract to use the modifier checkMasterAndAdminAccess
. Ideally when compiling into ABI and using it in my Nodejs
app, I would want to place these contracts into separate files as they will become massive.
Is this a recommended practice?
There will only be one instance of master contract
controlled by only person (so only one address will have access to it). The other contracts may be instantiated more than once
Can I get some guidance on how to achieve the above.