Ist es möglich, den ACL Smart-Contract zu schreiben?

Ich frage mich, ob es möglich ist, eine Zugriffskontrollliste zu erstellen und Benutzerrechte per Smart-Contract in einer privaten Blockchain zu ändern? Kann ich die Sicherheitsrichtlinie per Smart-Contract einrichten?

Antworten (1)

Natürlich kannst du. Durch die Verwendung modifiersund starke Verwendung msg.senderkann eine starke ACL eingerichtet werden. Beispiel ist

pragma solidity ^0.4.0;
contract SecondaryContract {
    bool public contractStatus = false;
    address public adminAddress;
    mapping (address => ACL) listOfAccountsWithCustomACL;
    struct ACL {
      string name;
      string somePermissions;
    }

    function SecondaryContract() {
      adminAddress = msg.sender;
      contractStatus = true;
    }

    // Modifier functions to set up first layer of ACL
    modifier onlyBy(address _account){
       if (msg.sender != _account) throw;
       _;
   }

   modifier onlyIfActive() {
     if (contractStatus) throw;
     _;
   }

   modifier onlyByCreator(){
      if (msg.sender != adminAddress) throw;
      _;
  }

   modifier onlyAfter(uint _time) {
      if (now < _time) throw;
      _;
   }

   modifier onlyBefore(uint _time) {
     if (now > _time) throw;
     _;
   }
    function Foo() onlyBy(someTrustAddress){
      // Can be called by a list of addresses specified
    }

    function Bar() onlyByCreator(){
      // Can be called ONLY by the person that initialized this contract
    }

    function Zam() onlyIfActive() {
      // Can only be called in the contractStatus is true
    }

    // Deactivates the contract which prevents Zam from being called
    // Only the origin creator of the smart contract can call this
    function deactivateContract() onlyByCreator {
      contractStatus = false;
    }
}

Dies msg.senderkann zu einem Konto einer Person gehören, die ein öffentliches privates Schlüsselpaar besitzt, oder sogar zu einem anderen Smart Contract selbst, der möglicherweise eine eigene ACL hat