types

package
v1.6.20 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModuleName defines the module name
	ModuleName = "capability"

	// StoreKey defines the primary module store key
	StoreKey = ModuleName

	// MemStoreKey defines the in-memory store key
	MemStoreKey = "mem_capability"
)

Variables

View Source
var (
	ErrInvalidCapabilityName    = sdkerrors.Register(ModuleName, 2, "capability name not valid")
	ErrNilCapability            = sdkerrors.Register(ModuleName, 3, "provided capability is nil")
	ErrCapabilityTaken          = sdkerrors.Register(ModuleName, 4, "capability name already taken")
	ErrOwnerClaimed             = sdkerrors.Register(ModuleName, 5, "given owner already claimed capability")
	ErrCapabilityNotOwned       = sdkerrors.Register(ModuleName, 6, "capability not owned by module")
	ErrCapabilityNotFound       = sdkerrors.Register(ModuleName, 7, "capability not found")
	ErrCapabilityOwnersNotFound = sdkerrors.Register(ModuleName, 8, "owners not found for capability")
)

x/capability module sentinel errors

View Source
var (
	// KeyIndex defines the key that stores the current globally unique capability
	// index.
	KeyIndex = []byte("index")

	// KeyPrefixIndexCapability defines a key prefix that stores index to capability
	// name mappings.
	KeyPrefixIndexCapability = []byte("capability_index")
)

Functions

func FwdCapabilityKey

func FwdCapabilityKey(module string, cap *Capability) []byte

FwdCapabilityKey returns a forward lookup key for a given module and capability reference.

func IndexFromKey

func IndexFromKey(key []byte) uint64

IndexFromKey returns an index from a call to IndexToKey for a given capability index.

func IndexToKey

func IndexToKey(index uint64) []byte

IndexToKey returns bytes to be used as a key for a given capability index.

func RevCapabilityKey

func RevCapabilityKey(module, name string) []byte

RevCapabilityKey returns a reverse lookup key for a given module and capability name.

Types

type Capability

type Capability struct {
	Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty" yaml:"index"`
}

func NewCapability

func NewCapability(index uint64) *Capability

NewCapability returns a reference to a new Capability to be used as an actual capability.

func (*Capability) GetIndex

func (m *Capability) GetIndex() uint64

func (*Capability) String

func (ck *Capability) String() string

String returns the string representation of a Capability. The string contains the Capability's memory reference as the string is to be used in a composite key and to authenticate capabilities.

type CapabilityOwners

type CapabilityOwners struct {
	Owners []Owner `protobuf:"bytes,1,rep,name=owners,proto3" json:"owners"`
}

CapabilityOwners defines a set of owners of a single Capability. The set of owners must be unique.

func NewCapabilityOwners

func NewCapabilityOwners() *CapabilityOwners

func (*CapabilityOwners) Get

func (co *CapabilityOwners) Get(owner Owner) (int, bool)

Get returns (i, true) of the provided owner in the CapabilityOwners if the owner exists, where i indicates the owner's index in the set. Otherwise (i, false) where i indicates where in the set the owner should be added.

func (*CapabilityOwners) Remove

func (co *CapabilityOwners) Remove(owner Owner)

Remove removes a provided owner from the CapabilityOwners if it exists. If the owner does not exist, Remove is considered a no-op.

func (*CapabilityOwners) Set

func (co *CapabilityOwners) Set(owner Owner) error

Set attempts to add a given owner to the CapabilityOwners. If the owner already exists, an error will be returned. Set runs in O(log n) average time and O(n) in the worst case.

type Owner

type Owner struct {
	Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty" yaml:"module"`
	Name   string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty" yaml:"name"`
}

func NewOwner

func NewOwner(module, name string) Owner

func (Owner) Key

func (o Owner) Key() string

Key returns a composite key for an Owner.

func (Owner) String

func (o Owner) String() string

Jump to

Keyboard shortcuts

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