Интересно, можно ли создать список контроля доступа и изменить права пользователя с помощью смарт-контракта в приватном блокчейне? Могу ли я настроить политику безопасности с помощью смарт-контракта?
Да, конечно ты можешь. Используя modifiers
и активно используя msg.sender
сильный ACL, можно настроить. Пример
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;
}
}
Это msg.sender
может принадлежать учетной записи лица, владеющего парой открытого закрытого ключа, или даже самому другому смарт-контракту, который может иметь собственный ACL.