2

Let's say as per business I want to restrict certain users(addresses) from seeing the logs for a contract. I know there is "modifier" which can be set to function, to give access rights but Can we do similar thing to events(onlyAllowedAddress below)? or else what is an alternate to do so?

contract MyData{
   address allowedAddress;
   string A;

   modifier onlyAllowedAddress(){
    require(allowedAddress == msg.sender);
    _;
   }
   event MyDataLogs(string _a) **onlyAllowedAddress**;

  function setA(string arg){
   A = arg;
   MyDataLogs(arg);
 }
}
0

There is no way to do what you want. If an event is sent, it can be read by anyone, anytime, from any node (at least in the current version of Ethereum).

| improve this answer | |
0

AFAIK, you can't throw on an Event. The purpose of an Event is to basically log something out that can be read (by watching it).

You should just handle the logic of posting the event (or not posting) in the method sending the Event.

function setA(string arg) { 
    A = arg; 
    if (msg.sender == allowedAddress)
        MyDataLogs(arg);
}
| improve this answer | |
  • Thanku for reply, but I think this won't serve my need. I have some of the actors who always gonna write and there are other few members, whom I need to restrict from reading. May be I need to handle it at application/service layer before calling event hook. – Ct_Upen Sep 25 '17 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.