keeper

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper defines the capability module's keeper. It is responsible for provisioning, tracking, and authenticating capabilities at runtime. During application initialization, the keeper can be hooked up to modules through unique function references so that it can identify the calling module when later invoked.

When the initial state is loaded from disk, the keeper allows the ability to create new capability keys for all previously allocated capability identifiers (allocated during execution of past transactions and assigned to particular modes), and keep them in a memory-only store while the chain is running.

The keeper allows the ability to create scoped sub-keepers which are tied to a single specific module.

func NewKeeper

func NewKeeper(cdc codec.BinaryMarshaler, storeKey, memKey sdk.StoreKey) *Keeper

NewKeeper constructs a new CapabilityKeeper instance and initializes maps for capability map and scopedModules map.

func (Keeper) GetLatestIndex

func (k Keeper) GetLatestIndex(ctx sdk.Context) uint64

GetLatestIndex returns the latest index of the CapabilityKeeper

func (Keeper) GetOwners

func (k Keeper) GetOwners(ctx sdk.Context, index uint64) (types.CapabilityOwners, bool)

GetOwners returns the capability owners with a given index.

func (*Keeper) InitializeAndSeal

func (k *Keeper) InitializeAndSeal(ctx sdk.Context)

InitializeAndSeal loads all capabilities from the persistent KVStore into the in-memory store and seals the keeper to prevent further modules from creating a scoped keeper. InitializeAndSeal must be called once after the application state is loaded.

func (Keeper) InitializeCapability

func (k Keeper) InitializeCapability(ctx sdk.Context, index uint64, owners types.CapabilityOwners)

InitializeCapability takes in an index and an owners array. It creates the capability in memory and sets the fwd and reverse keys for each owner in the memstore. It is used during initialization from genesis.

func (Keeper) InitializeIndex

func (k Keeper) InitializeIndex(ctx sdk.Context, index uint64) error

InitializeIndex sets the index to one (or greater) in InitChain according to the GenesisState. It must only be called once. It will panic if the provided index is 0, or if the index is already set.

func (*Keeper) ScopeToModule

func (k *Keeper) ScopeToModule(moduleName string) ScopedKeeper

ScopeToModule attempts to create and return a ScopedKeeper for a given module by name. It will panic if the keeper is already sealed or if the module name already has a ScopedKeeper.

func (Keeper) SetOwners

func (k Keeper) SetOwners(ctx sdk.Context, index uint64, owners types.CapabilityOwners)

SetOwners set the capability owners to the store

type ScopedKeeper

type ScopedKeeper struct {
	// contains filtered or unexported fields
}

ScopedKeeper defines a scoped sub-keeper which is tied to a single specific module provisioned by the capability keeper. Scoped keepers must be created at application initialization and passed to modules, which can then use them to claim capabilities they receive and retrieve capabilities which they own by name, in addition to creating new capabilities & authenticating capabilities passed by other modules.

func (ScopedKeeper) AuthenticateCapability

func (sk ScopedKeeper) AuthenticateCapability(ctx sdk.Context, cap *types.Capability, name string) bool

AuthenticateCapability attempts to authenticate a given capability and name from a caller. It allows for a caller to check that a capability does in fact correspond to a particular name. The scoped keeper will lookup the capability from the internal in-memory store and check against the provided name. It returns true upon success and false upon failure.

Note, the capability's forward mapping is indexed by a string which should contain its unique memory reference.

func (ScopedKeeper) ClaimCapability

func (sk ScopedKeeper) ClaimCapability(ctx sdk.Context, cap *types.Capability, name string) error

ClaimCapability attempts to claim a given Capability. The provided name and the scoped module's name tuple are treated as the owner. It will attempt to add the owner to the persistent set of capability owners for the capability index. If the owner already exists, it will return an error. Otherwise, it will also set a forward and reverse index for the capability and capability name.

func (ScopedKeeper) GetCapability

func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capability, bool)

GetCapability allows a module to fetch a capability which it previously claimed by name. The module is not allowed to retrieve capabilities which it does not own.

func (ScopedKeeper) GetCapabilityName

func (sk ScopedKeeper) GetCapabilityName(ctx sdk.Context, cap *types.Capability) string

GetCapabilityName allows a module to retrieve the name under which it stored a given capability given the capability

func (ScopedKeeper) GetOwners

func (sk ScopedKeeper) GetOwners(ctx sdk.Context, name string) (*types.CapabilityOwners, bool)

GetOwners all the Owners that own the capability associated with the name this ScopedKeeper uses to refer to the capability

func (ScopedKeeper) LookupModules

func (sk ScopedKeeper) LookupModules(ctx sdk.Context, name string) ([]string, *types.Capability, error)

LookupModules returns all the module owners for a given capability as a string array and the capability itself. The method returns an error if either the capability or the owners cannot be retreived from the memstore.

func (ScopedKeeper) NewCapability

func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capability, error)

NewCapability attempts to create a new capability with a given name. If the capability already exists in the in-memory store, an error will be returned. Otherwise, a new capability is created with the current global unique index. The newly created capability has the scoped module name and capability name tuple set as the initial owner. Finally, the global index is incremented along with forward and reverse indexes set in the in-memory store.

Note, namespacing is completely local, which is safe since records are prefixed with the module name and no two ScopedKeeper can have the same module name.

func (ScopedKeeper) ReleaseCapability

func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) error

ReleaseCapability allows a scoped module to release a capability which it had previously claimed or created. After releasing the capability, if no more owners exist, the capability will be globally removed.

Jump to

Keyboard shortcuts

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