Documentation ¶
Index ¶
- type Keeper
- func (k Keeper) GetLatestIndex(ctx sdk.Context) uint64
- func (k Keeper) GetOwners(ctx sdk.Context, index uint64) (types.CapabilityOwners, bool)
- func (k *Keeper) InitMemStore(ctx sdk.Context)
- func (k Keeper) InitializeCapability(ctx sdk.Context, index uint64, owners types.CapabilityOwners)
- func (k Keeper) InitializeIndex(ctx sdk.Context, index uint64) error
- func (k *Keeper) IsInitialized(ctx sdk.Context) bool
- func (k *Keeper) ScopeToModule(moduleName string) ScopedKeeper
- func (k *Keeper) Seal()
- func (k Keeper) SetOwners(ctx sdk.Context, index uint64, owners types.CapabilityOwners)
- type ScopedKeeper
- func (sk ScopedKeeper) AuthenticateCapability(ctx sdk.Context, cap *types.Capability, name string) bool
- func (sk ScopedKeeper) ClaimCapability(ctx sdk.Context, cap *types.Capability, name string) error
- func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capability, bool)
- func (sk ScopedKeeper) GetCapabilityName(ctx sdk.Context, cap *types.Capability) string
- func (sk ScopedKeeper) GetOwners(ctx sdk.Context, name string) (*types.CapabilityOwners, bool)
- func (sk ScopedKeeper) LookupModules(ctx sdk.Context, name string) ([]string, *types.Capability, error)
- func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capability, error)
- func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) error
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.BinaryCodec, storeKey, memKey storetypes.StoreKey) *Keeper
NewKeeper constructs a new CapabilityKeeper instance and initializes maps for capability map and scopedModules map.
func (Keeper) GetLatestIndex ¶
GetLatestIndex returns the latest index of the CapabilityKeeper
func (*Keeper) InitMemStore ¶
InitMemStore will assure that the module store is a memory store (it will panic if it's not) and willl initialize it. The function is safe to be called multiple times. InitMemStore must be called every time the app starts before the keeper is used (so `BeginBlock` or `InitChain` - whichever is first). We need access to the store so we can't initialize it in a constructor.
func (Keeper) InitializeCapability ¶
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 ¶
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) IsInitialized ¶
IsInitialized returns true if the keeper is properly initialized, and false otherwise.
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.
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.