access

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	OwnableInitializedKey = "owner~initialized"
	OwnerKey              = "owner~account"
)
View Source
const (
	SuperAdminRole = "super~admin~role"

	RoleAdminPrefix = "role~admin"
	RolePrefix      = "role~account"
)

Variables

View Source
var (
	ErrRoleNotFound = errors.New("role not found")
)
View Source
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

type EventOwnershipTransferred struct {
	PreviousOwner library.Address
	NewOwner      library.Address
}

EventOwnershipTransferred emit when the owner changed

type EventRoleAdminChanged

type EventRoleAdminChanged struct {
	Role              []byte
	PreviousAdminRole []byte
	NewAdminRole      []byte
}

EventRoleAdminChanged emit when role's admin role changed

type EventRoleGranted

type EventRoleGranted struct {
	Role    []byte
	Account library.Address
	Sender  library.Address
}

EventRoleGranted emit when a account granted a role

type EventRoleRevoked

type EventRoleRevoked struct {
	Role    []byte
	Account library.Address
	Sender  library.Address
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL