permission

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 3 Imported by: 33

Documentation

Index

Constants

View Source
const (
	// Chain permissions.
	// These permissions grant the ability for accounts to perform certain transition within the execution package
	// Root is a reserved permission currently unused that may be used in the future to grant super-user privileges
	// for instance to a governance contract
	Root types.PermFlag = 1 << iota // 1
	// Send permits an account to issue a SendTx to transfer value from one account to another. Note that value can
	// still be transferred with a CallTx by specifying an Amount in the InputTx. Funding an account is the basic
	// prerequisite for an account to act in the system so is often used as a surrogate for 'account creation' when
	// sending to a unknown account - in order for this to be permitted the input account needs the CreateAccount
	// permission in addition.
	Send // 2
	// Call permits and account to issue a CallTx, which can be used to call (run) the code of an existing
	// account/contract (these are synonymous in Burrow/EVM). A CallTx can be used to create an account if it points to
	// a nil address - in order for an account to be permitted to do this the input (calling) account needs the
	// CreateContract permission in addition.
	Call // 4
	// CreateContract permits the input account of a CallTx to create a new contract/account when CallTx.Address is nil
	// and permits an executing contract in the EVM to create a new contract programmatically.
	CreateContract // 8
	// CreateAccount permits an input account of a SendTx to add value to non-existing (unfunded) accounts
	CreateAccount // 16
	// Bond is a reserved permission for making changes to the validator set - currently unused
	Bond // 32
	// Name permits manipulation of the name registry by allowing an account to issue a NameTx
	Name // 64

	// Moderator permissions.
	// These permissions concern the alteration of the chain permissions listed above. Each permission relates to a
	// particular canonical permission mutation or query function. When an account is granted a moderation permission
	// it is permitted to call that function. See snative.go for a marked-up description of what each function does.
	HasBase
	SetBase
	UnsetBase
	SetGlobal
	HasRole
	AddRole
	RemoveRole

	NumPermissions uint = 14 // NOTE Adjust this too. We can support upto 64

	TopPermFlag      types.PermFlag = 1 << (NumPermissions - 1)
	AllPermFlags     types.PermFlag = TopPermFlag | (TopPermFlag - 1)
	DefaultPermFlags types.PermFlag = Send | Call | CreateContract | CreateAccount | Bond | Name | HasBase | HasRole

	// Chain permissions strings
	RootString           string = "root"
	SendString                  = "send"
	CallString                  = "call"
	CreateContractString        = "createContract"
	CreateAccountString         = "createAccount"
	BondString                  = "bond"
	NameString                  = "name"

	// Moderator permissions strings
	HasBaseString    = "hasBase"
	SetBaseString    = "setBase"
	UnsetBaseString  = "unsetBase"
	SetGlobalString  = "setGlobal"
	HasRoleString    = "hasRole"
	AddRoleString    = "addRole"
	RemoveRoleString = "removeRole"
	UnknownString    = "#-UNKNOWN-#"

	AllString = "all"
)

Base permission references are like unix (the index is already bit shifted)

Variables

View Source
var (
	ZeroBasePermissions    = types.BasePermissions{0, 0}
	ZeroAccountPermissions = types.AccountPermissions{
		Base: ZeroBasePermissions,
	}
	DefaultAccountPermissions = types.AccountPermissions{
		Base: types.BasePermissions{
			Perms:  DefaultPermFlags,
			SetBit: AllPermFlags,
		},
		Roles: []string{},
	}
	AllAccountPermissions = types.AccountPermissions{
		Base: types.BasePermissions{
			Perms:  AllPermFlags,
			SetBit: AllPermFlags,
		},
		Roles: []string{},
	}
)

Functions

func BasePermissionsFromStringList

func BasePermissionsFromStringList(permissions []string) (types.BasePermissions, error)

Builds a composite BasePermission by creating a PermFlag from permissions strings and setting them all

func BasePermissionsString

func BasePermissionsString(basePermissions types.BasePermissions) string

Generates a human readable string from the resultant permissions of basePermission

func BasePermissionsToStringList

func BasePermissionsToStringList(basePermissions types.BasePermissions) ([]string, error)

Builds a list of set permissions from a BasePermission by creating a list of permissions strings from the resultant permissions of basePermissions

func ConvertPermissionsMapAndRolesToAccountPermissions

func ConvertPermissionsMapAndRolesToAccountPermissions(permissions map[string]bool,
	roles []string) (*types.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 PermFlagFromStringList

func PermFlagFromStringList(permissions []string) (types.PermFlag, error)

Builds a composite PermFlag by mapping each permission string in permissions to its flag and composing them with binary or

func PermFlagToString

func PermFlagToString(pf types.PermFlag) string

Returns the string name of a single bit non-composite PermFlag, or otherwise UnknownString See BasePermissionsToStringList to generate a string representation of a composite PermFlag

func PermFlagToStringList

func PermFlagToStringList(permFlag types.PermFlag) ([]string, error)

Creates a list of individual permission flag strings from a possibly composite PermFlag by projecting out each bit and adding its permission string if it is set

func PermStringToFlag

func PermStringToFlag(perm string) (types.PermFlag, error)

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

func String

func String(permFlag types.PermFlag) string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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