Documentation ¶
Index ¶
- Constants
- Variables
- func PermFlagToString(pf PermFlag) (perm string)
- type AccountPermissions
- type AddRoleArgs
- type BasePermissions
- func (p *BasePermissions) Get(ty PermFlag) (bool, error)
- func (p *BasePermissions) IsSet(ty PermFlag) bool
- func (p *BasePermissions) ResultantPerms() PermFlag
- func (p *BasePermissions) Set(ty PermFlag, value bool) error
- func (p BasePermissions) String() string
- func (p *BasePermissions) Unset(ty PermFlag) error
- type ErrInvalidPermission
- type ErrValueNotSet
- type HasBaseArgs
- type HasRoleArgs
- type PermArgs
- type PermFlag
- type RmRoleArgs
- type SetBaseArgs
- type SetGlobalArgs
- type UnsetBaseArgs
Constants ¶
const ( // chain permissions Root PermFlag = 1 << iota // 1 Send // 2 Call // 4 CreateContract // 8 CreateAccount // 16 Bond // 32 Name // 64 // moderator permissions HasBase SetBase UnsetBase SetGlobal HasRole AddRole RmRole NumPermissions uint = 14 // NOTE Adjust this too. We can support upto 64 TopPermFlag PermFlag = 1 << (NumPermissions - 1) AllPermFlags PermFlag = TopPermFlag | (TopPermFlag - 1) DefaultPermFlags PermFlag = Send | Call | CreateContract | CreateAccount | Bond | Name | HasBase | HasRole )
Base permission references are like unix (the index is already bit shifted)
Variables ¶
var ( GlobalPermissionsAddress = word256.Zero256[:20] GlobalPermissionsAddress256 = word256.Zero256 )
var ( ZeroBasePermissions = BasePermissions{0, 0} ZeroAccountPermissions = AccountPermissions{ Base: ZeroBasePermissions, } DefaultAccountPermissions = AccountPermissions{ Base: BasePermissions{ Perms: DefaultPermFlags, SetBit: AllPermFlags, }, Roles: []string{}, } )
Functions ¶
func PermFlagToString ¶
PermFlagToString assumes the permFlag is valid, else returns "#-UNKNOWN-#"
Types ¶
type AccountPermissions ¶
type AccountPermissions struct { Base BasePermissions `json:"base"` Roles []string `json:"roles"` }
func ConvertPermissionsMapAndRolesToAccountPermissions ¶ added in v0.16.0
func ConvertPermissionsMapAndRolesToAccountPermissions(permissions map[string]int, roles []string) (*AccountPermissions, error)
ConvertMapStringIntToPermissions converts a map of string-integer pairs and a slice of strings for the roles to an AccountPermissions type. The integer needs to be greater than zero to set the permission. For all unmentioned permissions the ZeroBasePermissions is defaulted to. TODO: [ben] re-evaluate the use of int for setting the permission.
func (*AccountPermissions) AddRole ¶
func (aP *AccountPermissions) AddRole(role string) bool
Returns true if the role is added, and false if it already exists
func (*AccountPermissions) Clone ¶ added in v0.16.0
func (accountPermissions *AccountPermissions) Clone() AccountPermissions
Clone clones the account permissions
func (*AccountPermissions) HasRole ¶
func (aP *AccountPermissions) HasRole(role string) bool
Returns true if the role is found
func (*AccountPermissions) RmRole ¶
func (aP *AccountPermissions) RmRole(role string) bool
Returns true if the role is removed, and false if it is not found
type AddRoleArgs ¶
func (*AddRoleArgs) PermFlag ¶
func (*AddRoleArgs) PermFlag() PermFlag
type BasePermissions ¶
type BasePermissions struct { // bit array with "has"/"doesn't have" for each permission Perms PermFlag `json:"perms"` // bit array with "set"/"not set" for each permission (not-set should fall back to global) SetBit PermFlag `json:"set"` }
Base chain permissions struct
func (*BasePermissions) Get ¶
func (p *BasePermissions) Get(ty PermFlag) (bool, error)
Get a permission value. ty should be a power of 2. ErrValueNotSet is returned if the permission's set bit is off, and should be caught by caller so the global permission can be fetched
func (*BasePermissions) IsSet ¶
func (p *BasePermissions) IsSet(ty PermFlag) bool
Check if the permission is set
func (*BasePermissions) ResultantPerms ¶ added in v0.16.0
func (p *BasePermissions) ResultantPerms() PermFlag
Returns the Perms PermFlag masked with SetBit bit field to give the resultant permissions enabled by this BasePermissions
func (*BasePermissions) Set ¶
func (p *BasePermissions) Set(ty PermFlag, value bool) error
Set a permission bit. Will set the permission's set bit to true.
func (BasePermissions) String ¶
func (p BasePermissions) String() string
func (*BasePermissions) Unset ¶
func (p *BasePermissions) Unset(ty PermFlag) error
Set the permission's set bit to false
type ErrInvalidPermission ¶
type ErrInvalidPermission PermFlag
permission number out of bounds
func (ErrInvalidPermission) Error ¶
func (e ErrInvalidPermission) Error() string
type ErrValueNotSet ¶
type ErrValueNotSet PermFlag
set=false. This error should be caught and the global value fetched for the permission by the caller
func (ErrValueNotSet) Error ¶
func (e ErrValueNotSet) Error() string
type HasBaseArgs ¶
func (*HasBaseArgs) PermFlag ¶
func (*HasBaseArgs) PermFlag() PermFlag
type HasRoleArgs ¶
func (*HasRoleArgs) PermFlag ¶
func (*HasRoleArgs) PermFlag() PermFlag
type PermArgs ¶
type PermArgs interface {
PermFlag() PermFlag
}
Arguments are a registered interface in the PermissionsTx, so binary handles the arguments and each permission function gets a type-byte PermFlag() maps the type-byte to the permission The account sending the PermissionsTx must have this PermFlag set
type PermFlag ¶
type PermFlag uint64
A particular permission
func PermStringToFlag ¶
PermStringToFlag maps camel- and snake case strings to the the corresponding permission flag.
type RmRoleArgs ¶
func (*RmRoleArgs) PermFlag ¶
func (*RmRoleArgs) PermFlag() PermFlag
type SetBaseArgs ¶
type SetBaseArgs struct { Address []byte `json:"address"` Permission PermFlag `json:"permission"` Value bool `json:"value"` }
func (*SetBaseArgs) PermFlag ¶
func (*SetBaseArgs) PermFlag() PermFlag
type SetGlobalArgs ¶
func (*SetGlobalArgs) PermFlag ¶
func (*SetGlobalArgs) PermFlag() PermFlag
type UnsetBaseArgs ¶
type UnsetBaseArgs struct { Address []byte `json:"address"` Permission PermFlag `json:"permission"` }
func (*UnsetBaseArgs) PermFlag ¶
func (*UnsetBaseArgs) PermFlag() PermFlag