So here is my problem .
I have 2 users of my DApp : Admin and User
Admin is the contract owner and can access admin panel of my DApp . User is a normal user having something like a conditional access . The contract owner creates a transactionId ( similar to a token Id ) and corresponding to that Id I have mapped submitters and approvers . Submitter submits a transaction and approver approves that transaction after transaction has been submitted by the submitter .
Now my idea is that the User's UI will somewhat be like he gets 2 lists : one containing transactions that he has to submit ( the admin granted him the role of submitter for those particular transaction Ids ) and , the other list is containing transactions that he has to approve ( the admin granted him the role of approver for those particular transaction Ids ) .
I'll share the code snippet here :
contract MyContract {
constructor() {
admin = msg.sender;
_grantRole(ADMIN,admin); // when contract is deployed ADMIN role is granted to msg.sender i.e. the deployer of the contract
}
mapping(uint256 => address[]) public transactionIdToApproversArray;
mapping(uint256 => address[]) public transactionIdToSubmittersArray;
function submit(uint256 _transactionId, address[] memory _submitters ,address[] memory _approvers,uint256 _numConfirmationsRequired) external onlyRole(ADMIN) {
require(_approvers.length>1,"Approvers required must be greater than 1");
require(_numConfirmationsRequired>0 && _numConfirmationsRequired<=_approvers.length,"Num of confirmations are not in sync with the number of approvers");
for (uint i = 0; i < _submitters.length; i++) {
require(_submitters[i] != address(0),"address cannot be a zero address");
_grantRole(SUBMITTER,_submitters[i]);
// do something
}
for (uint i=0;i<_approvers.length;i++){
require(_approvers[i] != address(0),"address cannot be a zero address");
_grantRole(APPROVER,_approvers[i]);
// do something
}
}
}
The problem that I currently have is when I pass an array of submitters and approvers , they are set as universal submitters and approvers ( means they have become submitters and approvers in the context of whole contract , I want to limit submitters' and approvers' access to a particular transaction Id only ) . I've used Openzeppelin's access control right now .
Thank you in advance .
SUBMITTER
andAPPROVER
? How do you check the assigned role?AccessControl
. It is tested and works. A different approach might work but I can't verify without the code.