Documentation
¶
Index ¶
- Constants
- Variables
- type AccessControlContract
- func (accessControl *AccessControlContract) GetRoleAdmin(ctx context.ContextInterface, role []byte) ([]byte, error)
- func (accessControl *AccessControlContract) GrantRole(ctx context.ContextInterface, role []byte, account string) error
- func (accessControl *AccessControlContract) HasRole(ctx context.ContextInterface, role []byte, account string) (bool, error)
- func (accessControl *AccessControlContract) Initialize(ctx context.ContextInterface) error
- func (accessControl *AccessControlContract) RenounceRole(ctx context.ContextInterface, msg context.Message, role []byte, account string) error
- func (accessControl *AccessControlContract) RevokeRole(ctx context.ContextInterface, role []byte, account string) error
- func (accessControl *AccessControlContract) SetRoleAdmin(ctx context.ContextInterface, role []byte, adminRole []byte) error
- type EventOwnershipTransferred
- type EventRoleAdminChanged
- type EventRoleGranted
- type EventRoleRevoked
- type IAccessControl
- type IOwnable
- type OwnableContract
- func (ownable *OwnableContract) Initialize(ctx context.ContextInterface) error
- func (ownable *OwnableContract) Owner(ctx context.ContextInterface) (string, error)
- func (ownable *OwnableContract) RenounceOwnership(ctx context.ContextInterface) error
- func (ownable *OwnableContract) TransferOwnership(ctx context.ContextInterface, newOwner string) error
Constants ¶
const ( OwnableInitializedKey = "owner~initialized" OwnerKey = "owner~account" )
const ( SuperAdminRole = "super~admin~role" RoleAdminPrefix = "role~admin" RolePrefix = "role~account" )
Variables ¶
var (
ErrRoleNotFound = errors.New("role not found")
)
var (
HashedSuperAdminRole = sha3.Sum256([]byte(SuperAdminRole))
)
Functions ¶
This section is empty.
Types ¶
type AccessControlContract ¶
type AccessControlContract struct {
contractapi.Contract
IOwnable
}
AccessControlContract implements IAccessControl
func NewAccessControlContract ¶
func NewAccessControlContract(ownable IOwnable) *AccessControlContract
func (*AccessControlContract) GetRoleAdmin ¶
func (accessControl *AccessControlContract) GetRoleAdmin(ctx context.ContextInterface, role []byte) ([]byte, error)
GetRoleAdmin returns role's admin role
func (*AccessControlContract) GrantRole ¶
func (accessControl *AccessControlContract) GrantRole(ctx context.ContextInterface, role []byte, account string) error
GrantRole grants `role` to `account` only when operator has `role`'s admin role - emit event `RoleGranted` if succ
func (*AccessControlContract) HasRole ¶
func (accessControl *AccessControlContract) HasRole(ctx context.ContextInterface, role []byte, account string) (bool, error)
HasRole returns if account has been granted `role`
func (*AccessControlContract) Initialize ¶
func (accessControl *AccessControlContract) Initialize(ctx context.ContextInterface) error
func (*AccessControlContract) RenounceRole ¶
func (accessControl *AccessControlContract) RenounceRole(ctx context.ContextInterface, msg context.Message, role []byte, account string) error
RenounceRole by account itself
func (*AccessControlContract) RevokeRole ¶
func (accessControl *AccessControlContract) RevokeRole(ctx context.ContextInterface, role []byte, account string) error
Revoke grants `role` to `account` only when operator has `role`'s admin role - emit event `RoleRevoked` if succ
func (*AccessControlContract) SetRoleAdmin ¶
func (accessControl *AccessControlContract) SetRoleAdmin(ctx context.ContextInterface, role []byte, adminRole []byte) error
SetRoleAdmin only when operator is the owner - only default role - emit event `RoleAdminChanged`
type EventOwnershipTransferred ¶
EventOwnershipTransferred emit when the owner changed
type EventRoleAdminChanged ¶
EventRoleAdminChanged emit when role's admin role changed
type EventRoleGranted ¶
EventRoleGranted emit when a account granted a role
type EventRoleRevoked ¶
EventRoleRevoked emit when a account's role got revoked
type IAccessControl ¶
type IAccessControl interface {
IOwnable
Initialize(ctx context.ContextInterface) error
SetRoleAdmin(ctx context.ContextInterface, role []byte, adminRole []byte) error
GetRoleAdmin(ctx context.ContextInterface, role []byte) ([]byte, error)
HasRole(ctx context.ContextInterface, role []byte, account string) (bool, error)
GrantRole(ctx context.ContextInterface, role []byte, account string) error
RevokeRole(ctx context.ContextInterface, role []byte, account string) error
RenounceRole(ctx context.ContextInterface, msg context.Message, role []byte, account string) error
}
IAccessControl defines the interfaces which access control contract must implement
type IOwnable ¶
type IOwnable interface {
Initialize(ctx context.ContextInterface) error
Owner(ctx context.ContextInterface) (string, error)
RenounceOwnership(ctx context.ContextInterface) error
TransferOwnership(ctx context.ContextInterface, newOwner string) error
}
IOwnable defines the interfaces which ownable contract must implement
type OwnableContract ¶
type OwnableContract struct {
contractapi.Contract
// contains filtered or unexported fields
}
OwnableContract implements IOwnable which provides basic access control mechanism where there is an owner can be granted exclusive access to specific functions.
func NewOwnableContract ¶
func NewOwnableContract() *OwnableContract
func (*OwnableContract) Initialize ¶
func (ownable *OwnableContract) Initialize(ctx context.ContextInterface) error
Initialize will set the owner
func (*OwnableContract) Owner ¶
func (ownable *OwnableContract) Owner(ctx context.ContextInterface) (string, error)
Owner returns the address of the current owner - ZeroAddress will be returned if current owner is empty
func (*OwnableContract) RenounceOwnership ¶
func (ownable *OwnableContract) RenounceOwnership(ctx context.ContextInterface) error
RenounceOwnership will reset owner to ZeroAddress - only current Owner has this permission
func (*OwnableContract) TransferOwnership ¶
func (ownable *OwnableContract) TransferOwnership(ctx context.ContextInterface, newOwner string) error
TransferOwnership will transfer ownership to newOwner - only current Owner has this permission