types

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
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)

View Source
const (
	PermArgsTypeHasBase   = byte(0x01)
	PermArgsTypeSetBase   = byte(0x02)
	PermArgsTypeUnsetBase = byte(0x03)
	PermArgsTypeSetGlobal = byte(0x04)
	PermArgsTypeHasRole   = byte(0x05)
	PermArgsTypeAddRole   = byte(0x06)
	PermArgsTypeRmRole    = byte(0x07)
)

Variables

View Source
var (
	GlobalPermissionsAddress    = word256.Zero256[:20]
	GlobalPermissionsAddress256 = word256.Zero256
)
View Source
var (
	ZeroBasePermissions    = BasePermissions{0, 0}
	ZeroAccountPermissions = AccountPermissions{
		Base: ZeroBasePermissions,
	}
	DefaultAccountPermissions = AccountPermissions{
		Base: BasePermissions{
			Perms:  DefaultPermFlags,
			SetBit: AllPermFlags,
		},
		Roles: []string{},
	}
)

Functions

func PermFlagToString

func PermFlagToString(pf PermFlag) (perm string)

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

func ConvertPermissionsMapAndRolesToAccountPermissions(permissions map[string]bool, roles []string) (*AccountPermissions, error)

ConvertMapStringIntToPermissions converts a map of string-bool pairs and a slice of strings for the roles to an AccountPermissions type. If the value in the permissions map is true for a particular permission string then the permission will be set in the AccountsPermissions. For all unmentioned permissions the ZeroBasePermissions is defaulted to.

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

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

type AddRoleArgs struct {
	Address []byte `json:"address"`
	Role    string `json:"role"`
}

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

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

type HasBaseArgs struct {
	Address    []byte   `json:"address"`
	Permission PermFlag `json:"permission"`
}

func (*HasBaseArgs) PermFlag

func (*HasBaseArgs) PermFlag() PermFlag

type HasRoleArgs

type HasRoleArgs struct {
	Address []byte `json:"address"`
	Role    string `json:"role"`
}

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

func PermStringToFlag(perm string) (pf PermFlag, err error)

PermStringToFlag maps camel- and snake case strings to the the corresponding permission flag.

type RmRoleArgs

type RmRoleArgs struct {
	Address []byte `json:"address"`
	Role    string `json:"role"`
}

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

type SetGlobalArgs struct {
	Permission PermFlag `json:"permission"`
	Value      bool     `json:"value"`
}

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

Jump to

Keyboard shortcuts

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