refactor: remove capability module (#15344)
This commit is contained in:
parent
7002565ec3
commit
ccdd07ff7d
2
.github/pr_labeler.yml
vendored
2
.github/pr_labeler.yml
vendored
@ -4,8 +4,6 @@
|
||||
- x/authz/**/*
|
||||
"C:x/bank":
|
||||
- x/bank/**/*
|
||||
"C:x/capability":
|
||||
- x/capability/**/*
|
||||
"C:x/crisis":
|
||||
- x/crisis/**/*
|
||||
"C:x/distribution":
|
||||
|
||||
@ -132,6 +132,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* (x/bank) [#14894](https://github.com/cosmos/cosmos-sdk/pull/14894) Allow a human readable denomination for coins when querying bank balances. Added a `ResolveDenom` parameter to `types.QueryAllBalancesRequest`.
|
||||
* (crypto) [#15070](https://github.com/cosmos/cosmos-sdk/pull/15070) `GenerateFromPassword` and `Cost` from `bcrypt.go` now take a `uint32` instead of a `int` type.
|
||||
* (client) [#15123](https://github.com/cosmos/cosmos-sdk/pull/15123) `NewFactoryCLI` now returns an error, in addition to the `Factory`.
|
||||
* (x/capability) [#15344](https://github.com/cosmos/cosmos-sdk/pull/15344) Capability module was removed and is now housed in [IBC-GO](https://github.com/cosmos/ibc-go).
|
||||
|
||||
### Client Breaking Changes
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@ in for CometBFT and other lower-level libraries (eg. [IAVL](https://github.com/c
|
||||
|
||||
* [`x/auth`](https://github.com/cosmos/cosmos-sdk/tree/main/x/auth)
|
||||
* [`x/bank`](https://github.com/cosmos/cosmos-sdk/tree/main/x/bank)
|
||||
* [`x/capability`](https://github.com/cosmos/cosmos-sdk/tree/main/x/capability)
|
||||
* [`x/staking`](https://github.com/cosmos/cosmos-sdk/tree/main/x/staking)
|
||||
* [`x/slashing`](https://github.com/cosmos/cosmos-sdk/tree/main/x/slashing)
|
||||
* [`x/evidence`](https://github.com/cosmos/cosmos-sdk/tree/main/x/evidence)
|
||||
|
||||
@ -75,6 +75,10 @@ All the store imports are now renamed to use `cosmossdk.io/store` instead of `gi
|
||||
|
||||
### Modules
|
||||
|
||||
#### `x/capability`
|
||||
|
||||
Capability was moved to [IBC-GO](https://github.com/cosmos/ibc-go). IBC V8 will contain the necessary changes to incorporate the new module location
|
||||
|
||||
#### `x/gov`
|
||||
|
||||
##### Expedited Proposals
|
||||
|
||||
@ -1,572 +0,0 @@
|
||||
// Code generated by protoc-gen-go-pulsar. DO NOT EDIT.
|
||||
package modulev1
|
||||
|
||||
import (
|
||||
_ "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
fmt "fmt"
|
||||
runtime "github.com/cosmos/cosmos-proto/runtime"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoiface "google.golang.org/protobuf/runtime/protoiface"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
var (
|
||||
md_Module protoreflect.MessageDescriptor
|
||||
fd_Module_seal_keeper protoreflect.FieldDescriptor
|
||||
)
|
||||
|
||||
func init() {
|
||||
file_cosmos_capability_module_v1_module_proto_init()
|
||||
md_Module = File_cosmos_capability_module_v1_module_proto.Messages().ByName("Module")
|
||||
fd_Module_seal_keeper = md_Module.Fields().ByName("seal_keeper")
|
||||
}
|
||||
|
||||
var _ protoreflect.Message = (*fastReflection_Module)(nil)
|
||||
|
||||
type fastReflection_Module Module
|
||||
|
||||
func (x *Module) ProtoReflect() protoreflect.Message {
|
||||
return (*fastReflection_Module)(x)
|
||||
}
|
||||
|
||||
func (x *Module) slowProtoReflect() protoreflect.Message {
|
||||
mi := &file_cosmos_capability_module_v1_module_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
var _fastReflection_Module_messageType fastReflection_Module_messageType
|
||||
var _ protoreflect.MessageType = fastReflection_Module_messageType{}
|
||||
|
||||
type fastReflection_Module_messageType struct{}
|
||||
|
||||
func (x fastReflection_Module_messageType) Zero() protoreflect.Message {
|
||||
return (*fastReflection_Module)(nil)
|
||||
}
|
||||
func (x fastReflection_Module_messageType) New() protoreflect.Message {
|
||||
return new(fastReflection_Module)
|
||||
}
|
||||
func (x fastReflection_Module_messageType) Descriptor() protoreflect.MessageDescriptor {
|
||||
return md_Module
|
||||
}
|
||||
|
||||
// Descriptor returns message descriptor, which contains only the protobuf
|
||||
// type information for the message.
|
||||
func (x *fastReflection_Module) Descriptor() protoreflect.MessageDescriptor {
|
||||
return md_Module
|
||||
}
|
||||
|
||||
// Type returns the message type, which encapsulates both Go and protobuf
|
||||
// type information. If the Go type information is not needed,
|
||||
// it is recommended that the message descriptor be used instead.
|
||||
func (x *fastReflection_Module) Type() protoreflect.MessageType {
|
||||
return _fastReflection_Module_messageType
|
||||
}
|
||||
|
||||
// New returns a newly allocated and mutable empty message.
|
||||
func (x *fastReflection_Module) New() protoreflect.Message {
|
||||
return new(fastReflection_Module)
|
||||
}
|
||||
|
||||
// Interface unwraps the message reflection interface and
|
||||
// returns the underlying ProtoMessage interface.
|
||||
func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage {
|
||||
return (*Module)(x)
|
||||
}
|
||||
|
||||
// Range iterates over every populated field in an undefined order,
|
||||
// calling f for each field descriptor and value encountered.
|
||||
// Range returns immediately if f returns false.
|
||||
// While iterating, mutating operations may only be performed
|
||||
// on the current field descriptor.
|
||||
func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
|
||||
if x.SealKeeper != false {
|
||||
value := protoreflect.ValueOfBool(x.SealKeeper)
|
||||
if !f(fd_Module_seal_keeper, value) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Has reports whether a field is populated.
|
||||
//
|
||||
// Some fields have the property of nullability where it is possible to
|
||||
// distinguish between the default value of a field and whether the field
|
||||
// was explicitly populated with the default value. Singular message fields,
|
||||
// member fields of a oneof, and proto2 scalar fields are nullable. Such
|
||||
// fields are populated only if explicitly set.
|
||||
//
|
||||
// In other cases (aside from the nullable cases above),
|
||||
// a proto3 scalar field is populated if it contains a non-zero value, and
|
||||
// a repeated field is populated if it is non-empty.
|
||||
func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.capability.module.v1.Module.seal_keeper":
|
||||
return x.SealKeeper != false
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.capability.module.v1.Module"))
|
||||
}
|
||||
panic(fmt.Errorf("message cosmos.capability.module.v1.Module does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Clear clears the field such that a subsequent Has call reports false.
|
||||
//
|
||||
// Clearing an extension field clears both the extension type and value
|
||||
// associated with the given field number.
|
||||
//
|
||||
// Clear is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.capability.module.v1.Module.seal_keeper":
|
||||
x.SealKeeper = false
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.capability.module.v1.Module"))
|
||||
}
|
||||
panic(fmt.Errorf("message cosmos.capability.module.v1.Module does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Get retrieves the value for a field.
|
||||
//
|
||||
// For unpopulated scalars, it returns the default value, where
|
||||
// the default value of a bytes scalar is guaranteed to be a copy.
|
||||
// For unpopulated composite types, it returns an empty, read-only view
|
||||
// of the value; to obtain a mutable reference, use Mutable.
|
||||
func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch descriptor.FullName() {
|
||||
case "cosmos.capability.module.v1.Module.seal_keeper":
|
||||
value := x.SealKeeper
|
||||
return protoreflect.ValueOfBool(value)
|
||||
default:
|
||||
if descriptor.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.capability.module.v1.Module"))
|
||||
}
|
||||
panic(fmt.Errorf("message cosmos.capability.module.v1.Module does not contain field %s", descriptor.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Set stores the value for a field.
|
||||
//
|
||||
// For a field belonging to a oneof, it implicitly clears any other field
|
||||
// that may be currently set within the same oneof.
|
||||
// For extension fields, it implicitly stores the provided ExtensionType.
|
||||
// When setting a composite type, it is unspecified whether the stored value
|
||||
// aliases the source's memory in any way. If the composite value is an
|
||||
// empty, read-only value, then it panics.
|
||||
//
|
||||
// Set is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.capability.module.v1.Module.seal_keeper":
|
||||
x.SealKeeper = value.Bool()
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.capability.module.v1.Module"))
|
||||
}
|
||||
panic(fmt.Errorf("message cosmos.capability.module.v1.Module does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Mutable returns a mutable reference to a composite type.
|
||||
//
|
||||
// If the field is unpopulated, it may allocate a composite value.
|
||||
// For a field belonging to a oneof, it implicitly clears any other field
|
||||
// that may be currently set within the same oneof.
|
||||
// For extension fields, it implicitly stores the provided ExtensionType
|
||||
// if not already stored.
|
||||
// It panics if the field does not contain a composite type.
|
||||
//
|
||||
// Mutable is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.capability.module.v1.Module.seal_keeper":
|
||||
panic(fmt.Errorf("field seal_keeper of message cosmos.capability.module.v1.Module is not mutable"))
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.capability.module.v1.Module"))
|
||||
}
|
||||
panic(fmt.Errorf("message cosmos.capability.module.v1.Module does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// NewField returns a new value that is assignable to the field
|
||||
// for the given descriptor. For scalars, this returns the default value.
|
||||
// For lists, maps, and messages, this returns a new, empty, mutable value.
|
||||
func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.capability.module.v1.Module.seal_keeper":
|
||||
return protoreflect.ValueOfBool(false)
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.capability.module.v1.Module"))
|
||||
}
|
||||
panic(fmt.Errorf("message cosmos.capability.module.v1.Module does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// WhichOneof reports which field within the oneof is populated,
|
||||
// returning nil if none are populated.
|
||||
// It panics if the oneof descriptor does not belong to this message.
|
||||
func (x *fastReflection_Module) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
|
||||
switch d.FullName() {
|
||||
default:
|
||||
panic(fmt.Errorf("%s is not a oneof field in cosmos.capability.module.v1.Module", d.FullName()))
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// GetUnknown retrieves the entire list of unknown fields.
|
||||
// The caller may only mutate the contents of the RawFields
|
||||
// if the mutated bytes are stored back into the message with SetUnknown.
|
||||
func (x *fastReflection_Module) GetUnknown() protoreflect.RawFields {
|
||||
return x.unknownFields
|
||||
}
|
||||
|
||||
// SetUnknown stores an entire list of unknown fields.
|
||||
// The raw fields must be syntactically valid according to the wire format.
|
||||
// An implementation may panic if this is not the case.
|
||||
// Once stored, the caller must not mutate the content of the RawFields.
|
||||
// An empty RawFields may be passed to clear the fields.
|
||||
//
|
||||
// SetUnknown is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_Module) SetUnknown(fields protoreflect.RawFields) {
|
||||
x.unknownFields = fields
|
||||
}
|
||||
|
||||
// IsValid reports whether the message is valid.
|
||||
//
|
||||
// An invalid message is an empty, read-only value.
|
||||
//
|
||||
// An invalid message often corresponds to a nil pointer of the concrete
|
||||
// message type, but the details are implementation dependent.
|
||||
// Validity is not part of the protobuf data model, and may not
|
||||
// be preserved in marshaling or other operations.
|
||||
func (x *fastReflection_Module) IsValid() bool {
|
||||
return x != nil
|
||||
}
|
||||
|
||||
// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations.
|
||||
// This method may return nil.
|
||||
//
|
||||
// The returned methods type is identical to
|
||||
// "google.golang.org/protobuf/runtime/protoiface".Methods.
|
||||
// Consult the protoiface package documentation for details.
|
||||
func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods {
|
||||
size := func(input protoiface.SizeInput) protoiface.SizeOutput {
|
||||
x := input.Message.Interface().(*Module)
|
||||
if x == nil {
|
||||
return protoiface.SizeOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Size: 0,
|
||||
}
|
||||
}
|
||||
options := runtime.SizeInputToOptions(input)
|
||||
_ = options
|
||||
var n int
|
||||
var l int
|
||||
_ = l
|
||||
if x.SealKeeper {
|
||||
n += 2
|
||||
}
|
||||
if x.unknownFields != nil {
|
||||
n += len(x.unknownFields)
|
||||
}
|
||||
return protoiface.SizeOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Size: n,
|
||||
}
|
||||
}
|
||||
|
||||
marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) {
|
||||
x := input.Message.Interface().(*Module)
|
||||
if x == nil {
|
||||
return protoiface.MarshalOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Buf: input.Buf,
|
||||
}, nil
|
||||
}
|
||||
options := runtime.MarshalInputToOptions(input)
|
||||
_ = options
|
||||
size := options.Size(x)
|
||||
dAtA := make([]byte, size)
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if x.unknownFields != nil {
|
||||
i -= len(x.unknownFields)
|
||||
copy(dAtA[i:], x.unknownFields)
|
||||
}
|
||||
if x.SealKeeper {
|
||||
i--
|
||||
if x.SealKeeper {
|
||||
dAtA[i] = 1
|
||||
} else {
|
||||
dAtA[i] = 0
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
}
|
||||
if input.Buf != nil {
|
||||
input.Buf = append(input.Buf, dAtA...)
|
||||
} else {
|
||||
input.Buf = dAtA
|
||||
}
|
||||
return protoiface.MarshalOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Buf: input.Buf,
|
||||
}, nil
|
||||
}
|
||||
unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
|
||||
x := input.Message.Interface().(*Module)
|
||||
if x == nil {
|
||||
return protoiface.UnmarshalOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Flags: input.Flags,
|
||||
}, nil
|
||||
}
|
||||
options := runtime.UnmarshalInputToOptions(input)
|
||||
_ = options
|
||||
dAtA := input.Buf
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 0 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SealKeeper", wireType)
|
||||
}
|
||||
var v int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
v |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
x.SealKeeper = bool(v != 0)
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := runtime.Skip(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
if !options.DiscardUnknown {
|
||||
x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...)
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil
|
||||
}
|
||||
return &protoiface.Methods{
|
||||
NoUnkeyedLiterals: struct{}{},
|
||||
Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown,
|
||||
Size: size,
|
||||
Marshal: marshal,
|
||||
Unmarshal: unmarshal,
|
||||
Merge: nil,
|
||||
CheckInitialized: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.0
|
||||
// protoc (unknown)
|
||||
// source: cosmos/capability/module/v1/module.proto
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// Module is the config object of the capability module.
|
||||
type Module struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// seal_keeper defines if keeper.Seal() will run on BeginBlock() to prevent further modules from creating a scoped
|
||||
// keeper. For more details check x/capability/keeper.go.
|
||||
SealKeeper bool `protobuf:"varint,1,opt,name=seal_keeper,json=sealKeeper,proto3" json:"seal_keeper,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Module) Reset() {
|
||||
*x = Module{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_cosmos_capability_module_v1_module_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Module) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Module) ProtoMessage() {}
|
||||
|
||||
// Deprecated: Use Module.ProtoReflect.Descriptor instead.
|
||||
func (*Module) Descriptor() ([]byte, []int) {
|
||||
return file_cosmos_capability_module_v1_module_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Module) GetSealKeeper() bool {
|
||||
if x != nil {
|
||||
return x.SealKeeper
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var File_cosmos_capability_module_v1_module_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_cosmos_capability_module_v1_module_proto_rawDesc = []byte{
|
||||
0x0a, 0x28, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c,
|
||||
0x69, 0x74, 0x79, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x6f,
|
||||
0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x63, 0x6f, 0x73, 0x6d,
|
||||
0x6f, 0x73, 0x2e, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x6d, 0x6f,
|
||||
0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f,
|
||||
0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64,
|
||||
0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5c, 0x0a, 0x06, 0x4d, 0x6f, 0x64,
|
||||
0x75, 0x6c, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x61, 0x6c, 0x5f, 0x6b, 0x65, 0x65, 0x70,
|
||||
0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x73, 0x65, 0x61, 0x6c, 0x4b, 0x65,
|
||||
0x65, 0x70, 0x65, 0x72, 0x3a, 0x31, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x2b, 0x0a, 0x29, 0x67, 0x69,
|
||||
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f,
|
||||
0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x78, 0x2f, 0x63, 0x61, 0x70,
|
||||
0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x42, 0xf4, 0x01, 0x0a, 0x1f, 0x63, 0x6f, 0x6d, 0x2e,
|
||||
0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74,
|
||||
0x79, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64,
|
||||
0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x35, 0x63, 0x6f, 0x73, 0x6d,
|
||||
0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73,
|
||||
0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2f, 0x6d,
|
||||
0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76,
|
||||
0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x4d, 0xaa, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73,
|
||||
0x2e, 0x43, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x4d, 0x6f, 0x64, 0x75,
|
||||
0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43,
|
||||
0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
|
||||
0x5c, 0x56, 0x31, 0xe2, 0x02, 0x27, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x61, 0x70,
|
||||
0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56,
|
||||
0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1e,
|
||||
0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x43, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69,
|
||||
0x74, 0x79, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_cosmos_capability_module_v1_module_proto_rawDescOnce sync.Once
|
||||
file_cosmos_capability_module_v1_module_proto_rawDescData = file_cosmos_capability_module_v1_module_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_cosmos_capability_module_v1_module_proto_rawDescGZIP() []byte {
|
||||
file_cosmos_capability_module_v1_module_proto_rawDescOnce.Do(func() {
|
||||
file_cosmos_capability_module_v1_module_proto_rawDescData = protoimpl.X.CompressGZIP(file_cosmos_capability_module_v1_module_proto_rawDescData)
|
||||
})
|
||||
return file_cosmos_capability_module_v1_module_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_cosmos_capability_module_v1_module_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_cosmos_capability_module_v1_module_proto_goTypes = []interface{}{
|
||||
(*Module)(nil), // 0: cosmos.capability.module.v1.Module
|
||||
}
|
||||
var file_cosmos_capability_module_v1_module_proto_depIdxs = []int32{
|
||||
0, // [0:0] is the sub-list for method output_type
|
||||
0, // [0:0] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_cosmos_capability_module_v1_module_proto_init() }
|
||||
func file_cosmos_capability_module_v1_module_proto_init() {
|
||||
if File_cosmos_capability_module_v1_module_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_cosmos_capability_module_v1_module_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Module); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_cosmos_capability_module_v1_module_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_cosmos_capability_module_v1_module_proto_goTypes,
|
||||
DependencyIndexes: file_cosmos_capability_module_v1_module_proto_depIdxs,
|
||||
MessageInfos: file_cosmos_capability_module_v1_module_proto_msgTypes,
|
||||
}.Build()
|
||||
File_cosmos_capability_module_v1_module_proto = out.File
|
||||
file_cosmos_capability_module_v1_module_proto_rawDesc = nil
|
||||
file_cosmos_capability_module_v1_module_proto_goTypes = nil
|
||||
file_cosmos_capability_module_v1_module_proto_depIdxs = nil
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -127,7 +127,6 @@ gap in current simulation test coverage.
|
||||
Modules not returning simulation operations:
|
||||
|
||||
* `auth`
|
||||
* `capability`
|
||||
* `evidence`
|
||||
* `mint`
|
||||
* `params`
|
||||
|
||||
@ -224,7 +224,7 @@ The module manager is used throughout the application whenever an action on a co
|
||||
|
||||
* `NewManager(modules ...AppModule)`: Constructor function. It takes a list of the application's `AppModule`s and builds a new `Manager`. It is generally called from the application's main [constructor function](../basics/00-app-anatomy.md#constructor-function).
|
||||
* `SetOrderInitGenesis(moduleNames ...string)`: Sets the order in which the [`InitGenesis`](./08-genesis.md#initgenesis) function of each module will be called when the application is first started. This function is generally called from the application's main [constructor function](../basics/00-app-anatomy.md#constructor-function).
|
||||
To initialize modules successfully, module dependencies should be considered. For example, the `genutil` module must occur after `staking` module so that the pools are properly initialized with tokens from genesis accounts, the `genutils` module must also occur after `auth` so that it can access the params from auth, `capability` module should be initialized before all other modules so that it can initialize any capabilities.
|
||||
To initialize modules successfully, module dependencies should be considered. For example, the `genutil` module must occur after `staking` module so that the pools are properly initialized with tokens from genesis accounts, the `genutils` module must also occur after `auth` so that it can access the params from auth, IBC's `capability` module should be initialized before all other modules so that it can initialize any capabilities.
|
||||
* `SetOrderExportGenesis(moduleNames ...string)`: Sets the order in which the [`ExportGenesis`](./08-genesis.md#exportgenesis) function of each module will be called in case of an export. This function is generally called from the application's main [constructor function](../basics/00-app-anatomy.md#constructor-function).
|
||||
* `SetOrderBeginBlockers(moduleNames ...string)`: Sets the order in which the `BeginBlock()` function of each module will be called at the beginning of each block. This function is generally called from the application's main [constructor function](../basics/00-app-anatomy.md#constructor-function).
|
||||
* `SetOrderEndBlockers(moduleNames ...string)`: Sets the order in which the `EndBlock()` function of each module will be called at the end of each block. This function is generally called from the application's main [constructor function](../basics/00-app-anatomy.md#constructor-function).
|
||||
|
||||
@ -252,13 +252,6 @@ const config = {
|
||||
],
|
||||
to: "/main/modules/bank",
|
||||
},
|
||||
{
|
||||
from: [
|
||||
"/main/modules/capability/01_concepts",
|
||||
"/main/modules/capability/02_state",
|
||||
],
|
||||
to: "/main/modules/capability",
|
||||
},
|
||||
{
|
||||
from: [
|
||||
"/main/modules/crisis/01_state",
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package cosmos.capability.module.v1;
|
||||
|
||||
import "cosmos/app/v1alpha1/module.proto";
|
||||
|
||||
// Module is the config object of the capability module.
|
||||
message Module {
|
||||
option (cosmos.app.v1alpha1.module) = {
|
||||
go_import: "github.com/cosmos/cosmos-sdk/x/capability"
|
||||
};
|
||||
|
||||
// seal_keeper defines if keeper.Seal() will run on BeginBlock() to prevent further modules from creating a scoped
|
||||
// keeper. For more details check x/capability/keeper.go.
|
||||
bool seal_keeper = 1;
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package cosmos.capability.v1beta1;
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/capability/types";
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "amino/amino.proto";
|
||||
|
||||
// Capability defines an implementation of an object capability. The index
|
||||
// provided to a Capability must be globally unique.
|
||||
message Capability {
|
||||
uint64 index = 1;
|
||||
}
|
||||
|
||||
// Owner defines a single capability owner. An owner is defined by the name of
|
||||
// capability and the module name.
|
||||
message Owner {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string module = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
// CapabilityOwners defines a set of owners of a single Capability. The set of
|
||||
// owners must be unique.
|
||||
message CapabilityOwners {
|
||||
repeated Owner owners = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package cosmos.capability.v1beta1;
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "cosmos/capability/v1beta1/capability.proto";
|
||||
import "amino/amino.proto";
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/capability/types";
|
||||
|
||||
// GenesisOwners defines the capability owners with their corresponding index.
|
||||
message GenesisOwners {
|
||||
// index is the index of the capability owner.
|
||||
uint64 index = 1;
|
||||
|
||||
// index_owners are the owners at the given index.
|
||||
CapabilityOwners index_owners = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
|
||||
}
|
||||
|
||||
// GenesisState defines the capability module's genesis state.
|
||||
message GenesisState {
|
||||
// index is the capability global index.
|
||||
uint64 index = 1;
|
||||
|
||||
// owners represents a map from index to owners of the capability index
|
||||
// index key is string to allow amino marshalling.
|
||||
repeated GenesisOwners owners = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
|
||||
}
|
||||
@ -66,9 +66,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
consensus "github.com/cosmos/cosmos-sdk/x/consensus"
|
||||
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
|
||||
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
|
||||
@ -117,7 +114,6 @@ var (
|
||||
auth.AppModuleBasic{},
|
||||
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
|
||||
bank.AppModuleBasic{},
|
||||
capability.AppModuleBasic{},
|
||||
staking.AppModuleBasic{},
|
||||
mint.AppModuleBasic{},
|
||||
distr.AppModuleBasic{},
|
||||
@ -174,7 +170,6 @@ type SimApp struct {
|
||||
// keepers
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
BankKeeper bankkeeper.Keeper
|
||||
CapabilityKeeper *capabilitykeeper.Keeper
|
||||
StakingKeeper *stakingkeeper.Keeper
|
||||
SlashingKeeper slashingkeeper.Keeper
|
||||
MintKeeper mintkeeper.Keeper
|
||||
@ -261,14 +256,13 @@ func NewSimApp(
|
||||
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey,
|
||||
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
|
||||
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
|
||||
evidencetypes.StoreKey, capabilitytypes.StoreKey,
|
||||
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey,
|
||||
evidencetypes.StoreKey, authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey,
|
||||
)
|
||||
|
||||
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
|
||||
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
|
||||
// not include this key.
|
||||
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, "testingkey")
|
||||
memKeys := storetypes.NewMemoryStoreKeys("testingkey")
|
||||
|
||||
// register the streaming service with the BaseApp
|
||||
if err := bApp.SetStreamingService(appOpts, appCodec, keys); err != nil {
|
||||
@ -292,11 +286,6 @@ func NewSimApp(
|
||||
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
bApp.SetParamStore(&app.ConsensusParamsKeeper)
|
||||
|
||||
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
|
||||
// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
|
||||
// their scoped modules in `NewApp` with `ScopeToModule`
|
||||
app.CapabilityKeeper.Seal()
|
||||
|
||||
// add keepers
|
||||
app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, keys[authtypes.StoreKey], authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
|
||||
@ -400,7 +389,6 @@ func NewSimApp(
|
||||
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
|
||||
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
|
||||
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
|
||||
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
|
||||
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
|
||||
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
|
||||
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
|
||||
@ -421,10 +409,8 @@ func NewSimApp(
|
||||
// there is nothing left over in the validator fee pool, so as to keep the
|
||||
// CanWithdrawInvariant invariant.
|
||||
// NOTE: staking module is required if HistoricalEntries param > 0
|
||||
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
|
||||
app.ModuleManager.SetOrderBeginBlockers(
|
||||
upgradetypes.ModuleName,
|
||||
capabilitytypes.ModuleName,
|
||||
minttypes.ModuleName,
|
||||
distrtypes.ModuleName,
|
||||
slashingtypes.ModuleName,
|
||||
@ -445,11 +431,7 @@ func NewSimApp(
|
||||
// NOTE: The genutils module must occur after staking so that pools are
|
||||
// properly initialized with tokens from genesis accounts.
|
||||
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
|
||||
// NOTE: Capability module must occur first so that it can initialize any capabilities
|
||||
// so that other modules that want to create or claim capabilities afterwards in InitChain
|
||||
// can do so safely.
|
||||
genesisModuleOrder := []string{
|
||||
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName,
|
||||
genesisModuleOrder := []string{authtypes.ModuleName, banktypes.ModuleName,
|
||||
distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName,
|
||||
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
|
||||
feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
|
||||
authzmodulev1 "cosmossdk.io/api/cosmos/authz/module/v1"
|
||||
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
|
||||
capabilitymodulev1 "cosmossdk.io/api/cosmos/capability/module/v1"
|
||||
consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
|
||||
crisismodulev1 "cosmossdk.io/api/cosmos/crisis/module/v1"
|
||||
distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1"
|
||||
@ -38,7 +37,6 @@ import (
|
||||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
|
||||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
@ -86,10 +84,8 @@ var (
|
||||
// there is nothing left over in the validator fee pool, so as to keep the
|
||||
// CanWithdrawInvariant invariant.
|
||||
// NOTE: staking module is required if HistoricalEntries param > 0
|
||||
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
|
||||
BeginBlockers: []string{
|
||||
upgradetypes.ModuleName,
|
||||
capabilitytypes.ModuleName,
|
||||
minttypes.ModuleName,
|
||||
distrtypes.ModuleName,
|
||||
slashingtypes.ModuleName,
|
||||
@ -115,11 +111,7 @@ var (
|
||||
// NOTE: The genutils module must occur after staking so that pools are
|
||||
// properly initialized with tokens from genesis accounts.
|
||||
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
|
||||
// NOTE: Capability module must occur first so that it can initialize any capabilities
|
||||
// so that other modules that want to create or claim capabilities afterwards in InitChain
|
||||
// can do so safely.
|
||||
InitGenesis: []string{
|
||||
capabilitytypes.ModuleName,
|
||||
authtypes.ModuleName,
|
||||
banktypes.ModuleName,
|
||||
distrtypes.ModuleName,
|
||||
@ -198,12 +190,6 @@ var (
|
||||
Name: distrtypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&distrmodulev1.Module{}),
|
||||
},
|
||||
{
|
||||
Name: capabilitytypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&capabilitymodulev1.Module{
|
||||
SealKeeper: true,
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: evidencetypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&evidencemodulev1.Module{}),
|
||||
|
||||
@ -27,7 +27,6 @@ import (
|
||||
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||
@ -199,7 +198,6 @@ func TestRunMigrations(t *testing.T) {
|
||||
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
||||
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
||||
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
||||
"capability": capability.AppModule{}.ConsensusVersion(),
|
||||
},
|
||||
)
|
||||
if tc.expRunErr {
|
||||
@ -249,7 +247,6 @@ func TestInitGenesisOnMigration(t *testing.T) {
|
||||
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
||||
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
||||
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
||||
"capability": capability.AppModule{}.ConsensusVersion(),
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -46,8 +46,6 @@ import (
|
||||
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
consensus "github.com/cosmos/cosmos-sdk/x/consensus"
|
||||
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
@ -84,7 +82,6 @@ var (
|
||||
auth.AppModuleBasic{},
|
||||
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
|
||||
bank.AppModuleBasic{},
|
||||
capability.AppModuleBasic{},
|
||||
staking.AppModuleBasic{},
|
||||
mint.AppModuleBasic{},
|
||||
distr.AppModuleBasic{},
|
||||
@ -126,7 +123,6 @@ type SimApp struct {
|
||||
// keepers
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
BankKeeper bankkeeper.Keeper
|
||||
CapabilityKeeper *capabilitykeeper.Keeper
|
||||
StakingKeeper *stakingkeeper.Keeper
|
||||
SlashingKeeper slashingkeeper.Keeper
|
||||
MintKeeper mintkeeper.Keeper
|
||||
@ -210,7 +206,6 @@ func NewSimApp(
|
||||
&app.autoCliOpts,
|
||||
&app.AccountKeeper,
|
||||
&app.BankKeeper,
|
||||
&app.CapabilityKeeper,
|
||||
&app.StakingKeeper,
|
||||
&app.SlashingKeeper,
|
||||
&app.MintKeeper,
|
||||
|
||||
@ -27,7 +27,6 @@ import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
@ -209,7 +208,6 @@ func TestAppImportExport(t *testing.T) {
|
||||
{app.GetKey(paramtypes.StoreKey), newApp.GetKey(paramtypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(govtypes.StoreKey), newApp.GetKey(govtypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(evidencetypes.StoreKey), newApp.GetKey(evidencetypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(capabilitytypes.StoreKey), newApp.GetKey(capabilitytypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(authzkeeper.StoreKey), newApp.GetKey(authzkeeper.StoreKey), [][]byte{authzkeeper.GrantKey, authzkeeper.GrantQueuePrefix}},
|
||||
}
|
||||
|
||||
|
||||
@ -85,10 +85,6 @@
|
||||
"genutil": {
|
||||
"gentxs": []
|
||||
},
|
||||
"capability": {
|
||||
"index": "1",
|
||||
"owners": []
|
||||
},
|
||||
"mint": {
|
||||
"minter": {
|
||||
"inflation": "0.130000000000000000",
|
||||
|
||||
@ -22,7 +22,6 @@ import (
|
||||
|
||||
var beginBlockOrder = []string{
|
||||
"upgrade",
|
||||
"capability",
|
||||
"mint",
|
||||
"distribution",
|
||||
"slashing",
|
||||
@ -46,7 +45,6 @@ var endBlockersOrder = []string{
|
||||
"crisis",
|
||||
"gov",
|
||||
"staking",
|
||||
"capability",
|
||||
"auth",
|
||||
"bank",
|
||||
"distribution",
|
||||
@ -65,7 +63,6 @@ var endBlockersOrder = []string{
|
||||
}
|
||||
|
||||
var initGenesisOrder = []string{
|
||||
"capability",
|
||||
"auth",
|
||||
"bank",
|
||||
"distribution",
|
||||
|
||||
@ -10,7 +10,6 @@ Here are some production-grade modules that can be used in Cosmos SDK applicatio
|
||||
* [Auth](./auth/README.md) - Authentication of accounts and transactions for Cosmos SDK applications.
|
||||
* [Authz](./authz/README.md) - Authorization for accounts to perform actions on behalf of other accounts.
|
||||
* [Bank](./bank/README.md) - Token transfer functionalities.
|
||||
* [Capability](./capability/README.md) - Object capability implementation.
|
||||
* [Crisis](./crisis/README.md) - Halting the blockchain under certain circumstances (e.g. if an invariant is broken).
|
||||
* [Distribution](./distribution/README.md) - Fee distribution, and staking token provision distribution.
|
||||
* [Evidence](./evidence/README.md) - Evidence handling for double signing, misbehaviour, etc.
|
||||
|
||||
@ -1,134 +0,0 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# `x/capability`
|
||||
|
||||
## Overview
|
||||
|
||||
`x/capability` is an implementation of a Cosmos SDK module, per [ADR 003](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-003-dynamic-capability-store.md),
|
||||
that allows for provisioning, tracking, and authenticating multi-owner capabilities
|
||||
at runtime.
|
||||
|
||||
The keeper maintains two states: persistent and ephemeral in-memory. The persistent
|
||||
store maintains a globally unique auto-incrementing index and a mapping from
|
||||
capability index to a set of capability owners that are defined as a module and
|
||||
capability name tuple. The in-memory ephemeral state keeps track of the actual
|
||||
capabilities, represented as addresses in local memory, with both forward and reverse indexes.
|
||||
The forward index maps module name and capability tuples to the capability name. The
|
||||
reverse index maps between the module and capability name and the capability itself.
|
||||
|
||||
The keeper allows the creation of "scoped" sub-keepers which are tied to a particular
|
||||
module by name. 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. A scoped keeper cannot escape its scope,
|
||||
so a module cannot interfere with or inspect capabilities owned by other modules.
|
||||
|
||||
The keeper provides no other core functionality that can be found in other modules
|
||||
like queriers, REST and CLI handlers, and genesis state.
|
||||
|
||||
## Initialization
|
||||
|
||||
During application initialization, the keeper must be instantiated with a persistent
|
||||
store key and an in-memory store key.
|
||||
|
||||
```go
|
||||
type App struct {
|
||||
// ...
|
||||
|
||||
capabilityKeeper *capability.Keeper
|
||||
}
|
||||
|
||||
func NewApp(...) *App {
|
||||
// ...
|
||||
|
||||
app.capabilityKeeper = capability.NewKeeper(codec, persistentStoreKey, memStoreKey)
|
||||
}
|
||||
```
|
||||
|
||||
After the keeper is created, it can be used to create scoped sub-keepers which
|
||||
are passed to other modules that can create, authenticate, and claim capabilities.
|
||||
After all the necessary scoped keepers are created and the state is loaded, the
|
||||
main capability keeper must be sealed to prevent further scoped keepers from
|
||||
being created.
|
||||
|
||||
```go
|
||||
func NewApp(...) *App {
|
||||
// ...
|
||||
|
||||
// Creating a scoped keeper
|
||||
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
|
||||
|
||||
// Seal the capability keeper to prevent any further modules from creating scoped
|
||||
// sub-keepers.
|
||||
app.capabilityKeeper.Seal()
|
||||
|
||||
return app
|
||||
}
|
||||
```
|
||||
|
||||
## Contents
|
||||
|
||||
* [Concepts](#concepts)
|
||||
* [Capabilities](#capabilities)
|
||||
* [Stores](#stores)
|
||||
* [State](#state)
|
||||
* [In persisted KV store](#in-persisted-kv-store)
|
||||
* [In-memory KV store](#in-memory-kv-store)
|
||||
|
||||
## Concepts
|
||||
|
||||
### Capabilities
|
||||
|
||||
Capabilities are multi-owner. A scoped keeper can create a capability via `NewCapability`
|
||||
which creates a new unique, unforgeable object-capability reference. The newly
|
||||
created capability is automatically persisted; the calling module need not call
|
||||
`ClaimCapability`. Calling `NewCapability` will create the capability with the
|
||||
calling module and name as a tuple to be treated the capabilities first owner.
|
||||
|
||||
Capabilities can be claimed by other modules which add them as owners. `ClaimCapability`
|
||||
allows a module to claim a capability key which it has received from another
|
||||
module so that future `GetCapability` calls will succeed. `ClaimCapability` MUST
|
||||
be called if a module which receives a capability wishes to access it by name in
|
||||
the future. Again, capabilities are multi-owner, so if multiple modules have a
|
||||
single Capability reference, they will all own it. If a module receives a capability
|
||||
from another module but does not call `ClaimCapability`, it may use it in the executing
|
||||
transaction but will not be able to access it afterwards.
|
||||
|
||||
`AuthenticateCapability` can be called by any module to check that a capability
|
||||
does in fact correspond to a particular name (the name can be un-trusted user input)
|
||||
with which the calling module previously associated it.
|
||||
|
||||
`GetCapability` allows a module to fetch a capability which it has previously
|
||||
claimed by name. The module is not allowed to retrieve capabilities which it does
|
||||
not own.
|
||||
|
||||
### Stores
|
||||
|
||||
* MemStore
|
||||
* KeyStore
|
||||
|
||||
## State
|
||||
|
||||
### In persisted KV store
|
||||
|
||||
1. Global unique capability index
|
||||
2. Capability owners
|
||||
|
||||
Indexes:
|
||||
|
||||
* Unique index: `[]byte("index") -> []byte(currentGlobalIndex)`
|
||||
* Capability Index: `[]byte("capability_index") | []byte(index) -> ProtocolBuffer(CapabilityOwners)`
|
||||
|
||||
### In-memory KV store
|
||||
|
||||
1. Initialized flag
|
||||
2. Mapping between the module and capability tuple and the capability name
|
||||
3. Mapping between the module and capability name and its index
|
||||
|
||||
Indexes:
|
||||
|
||||
* Initialized flag: `[]byte("mem_initialized")`
|
||||
* RevCapabilityKey: `[]byte(moduleName + "/rev/" + capabilityName) -> []byte(index)`
|
||||
* FwdCapabilityKey: `[]byte(moduleName + "/fwd/" + capabilityPointerAddress) -> []byte(capabilityName)`
|
||||
@ -1,108 +0,0 @@
|
||||
package capability_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
type CapabilityTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
app *runtime.App
|
||||
cdc codec.Codec
|
||||
ctx sdk.Context
|
||||
keeper *keeper.Keeper
|
||||
memKey *storetypes.MemoryStoreKey
|
||||
}
|
||||
|
||||
func (suite *CapabilityTestSuite) SetupTest() {
|
||||
suite.memKey = storetypes.NewMemoryStoreKey("testingkey")
|
||||
|
||||
startupCfg := simtestutil.DefaultStartUpConfig()
|
||||
startupCfg.BaseAppOption = func(ba *baseapp.BaseApp) {
|
||||
ba.MountStores(suite.memKey)
|
||||
}
|
||||
|
||||
app, err := simtestutil.SetupWithConfiguration(testutil.AppConfig,
|
||||
startupCfg,
|
||||
&suite.cdc,
|
||||
&suite.keeper,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.app = app
|
||||
suite.ctx = app.BaseApp.NewContext(false, cmtproto.Header{Height: 1})
|
||||
}
|
||||
|
||||
// The following test case mocks a specific bug discovered in https://github.com/cosmos/cosmos-sdk/issues/9800
|
||||
// and ensures that the current code successfully fixes the issue.
|
||||
func (suite *CapabilityTestSuite) TestInitializeMemStore() {
|
||||
sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName)
|
||||
|
||||
cap1, err := sk1.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap1)
|
||||
|
||||
// mock statesync by creating new keeper that shares persistent state but loses in-memory map
|
||||
newKeeper := keeper.NewKeeper(suite.cdc, suite.app.UnsafeFindStoreKey(types.StoreKey).(*storetypes.KVStoreKey), suite.memKey)
|
||||
newSk1 := newKeeper.ScopeToModule(banktypes.ModuleName)
|
||||
|
||||
// Mock App startup
|
||||
ctx := suite.app.BaseApp.NewUncachedContext(false, cmtproto.Header{})
|
||||
newKeeper.Seal()
|
||||
suite.Require().False(newKeeper.IsInitialized(ctx), "memstore initialized flag set before BeginBlock")
|
||||
|
||||
// Mock app beginblock and ensure that no gas has been consumed and memstore is initialized
|
||||
ctx = suite.app.BaseApp.NewContext(false, cmtproto.Header{}).WithBlockGasMeter(storetypes.NewGasMeter(50))
|
||||
prevBlockGas := ctx.BlockGasMeter().GasConsumed()
|
||||
prevGas := ctx.GasMeter().GasConsumed()
|
||||
restartedModule := capability.NewAppModule(suite.cdc, *newKeeper, true)
|
||||
restartedModule.BeginBlock(ctx, abci.RequestBeginBlock{})
|
||||
gasUsed := ctx.GasMeter().GasConsumed()
|
||||
suite.Require().True(newKeeper.IsInitialized(ctx), "memstore initialized flag not set")
|
||||
blockGasUsed := ctx.BlockGasMeter().GasConsumed()
|
||||
|
||||
suite.Require().Equal(prevBlockGas, blockGasUsed, "ensure beginblocker consumed no block gas during execution")
|
||||
suite.Require().Equal(prevGas, gasUsed, "ensure beginblocker consumed no gas during execution")
|
||||
|
||||
// Mock the first transaction getting capability and subsequently failing
|
||||
// by using a cached context and discarding all cached writes.
|
||||
cacheCtx, _ := ctx.CacheContext()
|
||||
_, ok := newSk1.GetCapability(cacheCtx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
|
||||
// Ensure that the second transaction can still receive capability even if first tx fails.
|
||||
ctx = suite.app.BaseApp.NewContext(false, cmtproto.Header{})
|
||||
|
||||
cap1, ok = newSk1.GetCapability(ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
|
||||
// Ensure the capabilities don't get reinitialized on next BeginBlock
|
||||
// by testing to see if capability returns same pointer
|
||||
// also check that initialized flag is still set
|
||||
restartedModule.BeginBlock(ctx, abci.RequestBeginBlock{})
|
||||
recap, ok := newSk1.GetCapability(ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(cap1, recap, "capabilities got reinitialized after second BeginBlock")
|
||||
suite.Require().True(newKeeper.IsInitialized(ctx), "memstore initialized flag not set")
|
||||
}
|
||||
|
||||
func TestCapabilityTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(CapabilityTestSuite))
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
package capability
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
// InitGenesis initializes the capability module's state from a provided genesis
|
||||
// state.
|
||||
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
|
||||
if err := k.InitializeIndex(ctx, genState.Index); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// set owners for each index
|
||||
for _, genOwner := range genState.Owners {
|
||||
k.SetOwners(ctx, genOwner.Index, genOwner.IndexOwners)
|
||||
}
|
||||
// initialize in-memory capabilities
|
||||
k.InitMemStore(ctx)
|
||||
}
|
||||
|
||||
// ExportGenesis returns the capability module's exported genesis.
|
||||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
|
||||
index := k.GetLatestIndex(ctx)
|
||||
owners := []types.GenesisOwners{}
|
||||
|
||||
for i := uint64(1); i < index; i++ {
|
||||
capabilityOwners, ok := k.GetOwners(ctx, i)
|
||||
if !ok || len(capabilityOwners.Owners) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
genOwner := types.GenesisOwners{
|
||||
Index: i,
|
||||
IndexOwners: capabilityOwners,
|
||||
}
|
||||
owners = append(owners, genOwner)
|
||||
}
|
||||
|
||||
return &types.GenesisState{
|
||||
Index: index,
|
||||
Owners: owners,
|
||||
}
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package capability_test
|
||||
|
||||
import (
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/testutil"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func (suite *CapabilityTestSuite) TestGenesis() {
|
||||
sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName)
|
||||
sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName)
|
||||
|
||||
cap1, err := sk1.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap1)
|
||||
|
||||
err = sk2.ClaimCapability(suite.ctx, cap1, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
cap2, err := sk2.NewCapability(suite.ctx, "ica")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap2)
|
||||
|
||||
genState := capability.ExportGenesis(suite.ctx, *suite.keeper)
|
||||
|
||||
// create new app that does not share persistent or in-memory state
|
||||
// and initialize app from exported genesis state above.
|
||||
var newKeeper *keeper.Keeper
|
||||
newApp, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &newKeeper)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
newSk1 := newKeeper.ScopeToModule(banktypes.ModuleName)
|
||||
newSk2 := newKeeper.ScopeToModule(stakingtypes.ModuleName)
|
||||
deliverCtx, _ := newApp.BaseApp.NewUncachedContext(false, cmtproto.Header{}).WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).CacheContext()
|
||||
|
||||
capability.InitGenesis(deliverCtx, *newKeeper, *genState)
|
||||
|
||||
// check that all previous capabilities exist in new app after InitGenesis
|
||||
sk1Cap1, ok := newSk1.GetCapability(deliverCtx, "transfer")
|
||||
suite.Require().True(ok, "could not get first capability after genesis on first ScopedKeeper")
|
||||
suite.Require().Equal(*cap1, *sk1Cap1, "capability values not equal on first ScopedKeeper")
|
||||
|
||||
sk2Cap1, ok := newSk2.GetCapability(deliverCtx, "transfer")
|
||||
suite.Require().True(ok, "could not get first capability after genesis on first ScopedKeeper")
|
||||
suite.Require().Equal(*cap1, *sk2Cap1, "capability values not equal on first ScopedKeeper")
|
||||
|
||||
sk2Cap2, ok := newSk2.GetCapability(deliverCtx, "ica")
|
||||
suite.Require().True(ok, "could not get second capability after genesis on second ScopedKeeper")
|
||||
suite.Require().Equal(*cap2, *sk2Cap2, "capability values not equal on second ScopedKeeper")
|
||||
}
|
||||
@ -1,497 +0,0 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
|
||||
"cosmossdk.io/store/prefix"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
"cosmossdk.io/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
type (
|
||||
// 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.
|
||||
Keeper struct {
|
||||
cdc codec.BinaryCodec
|
||||
storeKey storetypes.StoreKey
|
||||
memKey storetypes.StoreKey
|
||||
capMap map[uint64]*types.Capability
|
||||
scopedModules map[string]struct{}
|
||||
sealed bool
|
||||
}
|
||||
|
||||
// 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.
|
||||
ScopedKeeper struct {
|
||||
cdc codec.BinaryCodec
|
||||
storeKey storetypes.StoreKey
|
||||
memKey storetypes.StoreKey
|
||||
capMap map[uint64]*types.Capability
|
||||
module string
|
||||
}
|
||||
)
|
||||
|
||||
// NewKeeper constructs a new CapabilityKeeper instance and initializes maps
|
||||
// for capability map and scopedModules map.
|
||||
func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey) *Keeper {
|
||||
return &Keeper{
|
||||
cdc: cdc,
|
||||
storeKey: storeKey,
|
||||
memKey: memKey,
|
||||
capMap: make(map[uint64]*types.Capability),
|
||||
scopedModules: make(map[string]struct{}),
|
||||
sealed: false,
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (k *Keeper) ScopeToModule(moduleName string) ScopedKeeper {
|
||||
if k.sealed {
|
||||
panic("cannot scope to module via a sealed capability keeper")
|
||||
}
|
||||
if strings.TrimSpace(moduleName) == "" {
|
||||
panic("cannot scope to an empty module name")
|
||||
}
|
||||
|
||||
if _, ok := k.scopedModules[moduleName]; ok {
|
||||
panic(fmt.Sprintf("cannot create multiple scoped keepers for the same module name: %s", moduleName))
|
||||
}
|
||||
|
||||
k.scopedModules[moduleName] = struct{}{}
|
||||
|
||||
return ScopedKeeper{
|
||||
cdc: k.cdc,
|
||||
storeKey: k.storeKey,
|
||||
memKey: k.memKey,
|
||||
capMap: k.capMap,
|
||||
module: moduleName,
|
||||
}
|
||||
}
|
||||
|
||||
// Seal seals the keeper to prevent further modules from creating a scoped keeper.
|
||||
// Seal may be called during app initialization for applications that do not wish to create scoped keepers dynamically.
|
||||
func (k *Keeper) Seal() {
|
||||
if k.sealed {
|
||||
panic("cannot initialize and seal an already sealed capability keeper")
|
||||
}
|
||||
|
||||
k.sealed = true
|
||||
}
|
||||
|
||||
// IsSealed returns if the keeper is sealed.
|
||||
func (k *Keeper) IsSealed() bool {
|
||||
return k.sealed
|
||||
}
|
||||
|
||||
// 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 (k *Keeper) InitMemStore(ctx sdk.Context) {
|
||||
memStore := ctx.KVStore(k.memKey)
|
||||
memStoreType := memStore.GetStoreType()
|
||||
|
||||
if memStoreType != storetypes.StoreTypeMemory {
|
||||
panic(fmt.Sprintf("invalid memory store type; got %s, expected: %s", memStoreType, storetypes.StoreTypeMemory))
|
||||
}
|
||||
|
||||
// Create a context with no `BlockGasMeter`, and no `GasMeter`. This ensures we do not consume gas during local
|
||||
// initialization logic.
|
||||
noGasCtx := ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithGasMeter(storetypes.NewInfiniteGasMeter())
|
||||
|
||||
// check if memory store has not been initialized yet by checking if initialized flag is nil.
|
||||
if !k.IsInitialized(noGasCtx) {
|
||||
prefixStore := prefix.NewStore(noGasCtx.KVStore(k.storeKey), types.KeyPrefixIndexCapability)
|
||||
iterator := storetypes.KVStorePrefixIterator(prefixStore, nil)
|
||||
|
||||
// initialize the in-memory store for all persisted capabilities
|
||||
defer iterator.Close()
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
index := types.IndexFromKey(iterator.Key())
|
||||
|
||||
var capOwners types.CapabilityOwners
|
||||
|
||||
k.cdc.MustUnmarshal(iterator.Value(), &capOwners)
|
||||
k.InitializeCapability(noGasCtx, index, capOwners)
|
||||
}
|
||||
|
||||
// set the initialized flag so we don't rerun initialization logic
|
||||
memStore := noGasCtx.KVStore(k.memKey)
|
||||
memStore.Set(types.KeyMemInitialized, []byte{1})
|
||||
}
|
||||
}
|
||||
|
||||
// IsInitialized returns true if the keeper is properly initialized, and false otherwise.
|
||||
func (k *Keeper) IsInitialized(ctx sdk.Context) bool {
|
||||
memStore := ctx.KVStore(k.memKey)
|
||||
return memStore.Get(types.KeyMemInitialized) != nil
|
||||
}
|
||||
|
||||
// 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 (k Keeper) InitializeIndex(ctx sdk.Context, index uint64) error {
|
||||
if index == 0 {
|
||||
panic("SetIndex requires index > 0")
|
||||
}
|
||||
latest := k.GetLatestIndex(ctx)
|
||||
if latest > 0 {
|
||||
panic("SetIndex requires index to not be set")
|
||||
}
|
||||
|
||||
// set the global index to the passed index
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
store.Set(types.KeyIndex, types.IndexToKey(index))
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLatestIndex returns the latest index of the CapabilityKeeper
|
||||
func (k Keeper) GetLatestIndex(ctx sdk.Context) uint64 {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
return types.IndexFromKey(store.Get(types.KeyIndex))
|
||||
}
|
||||
|
||||
// SetOwners set the capability owners to the store
|
||||
func (k Keeper) SetOwners(ctx sdk.Context, index uint64, owners types.CapabilityOwners) {
|
||||
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixIndexCapability)
|
||||
indexKey := types.IndexToKey(index)
|
||||
|
||||
// set owners in persistent store
|
||||
prefixStore.Set(indexKey, k.cdc.MustMarshal(&owners))
|
||||
}
|
||||
|
||||
// GetOwners returns the capability owners with a given index.
|
||||
func (k Keeper) GetOwners(ctx sdk.Context, index uint64) (types.CapabilityOwners, bool) {
|
||||
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixIndexCapability)
|
||||
indexKey := types.IndexToKey(index)
|
||||
|
||||
// get owners for index from persistent store
|
||||
ownerBytes := prefixStore.Get(indexKey)
|
||||
if ownerBytes == nil {
|
||||
return types.CapabilityOwners{}, false
|
||||
}
|
||||
var owners types.CapabilityOwners
|
||||
k.cdc.MustUnmarshal(ownerBytes, &owners)
|
||||
return owners, true
|
||||
}
|
||||
|
||||
// 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 (k Keeper) InitializeCapability(ctx sdk.Context, index uint64, owners types.CapabilityOwners) {
|
||||
memStore := ctx.KVStore(k.memKey)
|
||||
|
||||
cap := types.NewCapability(index)
|
||||
for _, owner := range owners.Owners {
|
||||
// Set the forward mapping between the module and capability tuple and the
|
||||
// capability name in the memKVStore
|
||||
memStore.Set(types.FwdCapabilityKey(owner.Module, cap), []byte(owner.Name))
|
||||
|
||||
// Set the reverse mapping between the module and capability name and the
|
||||
// index in the in-memory store. Since marshalling and unmarshalling into a store
|
||||
// will change memory address of capability, we simply store index as value here
|
||||
// and retrieve the in-memory pointer to the capability from our map
|
||||
memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index))
|
||||
|
||||
// Set the mapping from index from index to in-memory capability in the go map
|
||||
k.capMap[index] = cap
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capability, error) {
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return nil, errors.Wrap(types.ErrInvalidCapabilityName, "capability name cannot be empty")
|
||||
}
|
||||
store := ctx.KVStore(sk.storeKey)
|
||||
|
||||
if _, ok := sk.GetCapability(ctx, name); ok {
|
||||
return nil, errors.Wrapf(types.ErrCapabilityTaken, fmt.Sprintf("module: %s, name: %s", sk.module, name))
|
||||
}
|
||||
|
||||
// create new capability with the current global index
|
||||
index := types.IndexFromKey(store.Get(types.KeyIndex))
|
||||
cap := types.NewCapability(index)
|
||||
|
||||
// update capability owner set
|
||||
if err := sk.addOwner(ctx, cap, name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// increment global index
|
||||
store.Set(types.KeyIndex, types.IndexToKey(index+1))
|
||||
|
||||
memStore := ctx.KVStore(sk.memKey)
|
||||
|
||||
// Set the forward mapping between the module and capability tuple and the
|
||||
// capability name in the memKVStore
|
||||
memStore.Set(types.FwdCapabilityKey(sk.module, cap), []byte(name))
|
||||
|
||||
// Set the reverse mapping between the module and capability name and the
|
||||
// index in the in-memory store. Since marshalling and unmarshalling into a store
|
||||
// will change memory address of capability, we simply store index as value here
|
||||
// and retrieve the in-memory pointer to the capability from our map
|
||||
memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(index))
|
||||
|
||||
// Set the mapping from index from index to in-memory capability in the go map
|
||||
sk.capMap[index] = cap
|
||||
|
||||
logger(ctx).Info("created new capability", "module", sk.module, "name", name)
|
||||
|
||||
return cap, nil
|
||||
}
|
||||
|
||||
// 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 (sk ScopedKeeper) AuthenticateCapability(ctx sdk.Context, cap *types.Capability, name string) bool {
|
||||
if strings.TrimSpace(name) == "" || cap == nil {
|
||||
return false
|
||||
}
|
||||
return sk.GetCapabilityName(ctx, cap) == name
|
||||
}
|
||||
|
||||
// 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 (sk ScopedKeeper) ClaimCapability(ctx sdk.Context, cap *types.Capability, name string) error {
|
||||
if cap == nil {
|
||||
return errors.Wrap(types.ErrNilCapability, "cannot claim nil capability")
|
||||
}
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return errors.Wrap(types.ErrInvalidCapabilityName, "capability name cannot be empty")
|
||||
}
|
||||
// update capability owner set
|
||||
if err := sk.addOwner(ctx, cap, name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
memStore := ctx.KVStore(sk.memKey)
|
||||
|
||||
// Set the forward mapping between the module and capability tuple and the
|
||||
// capability name in the memKVStore
|
||||
memStore.Set(types.FwdCapabilityKey(sk.module, cap), []byte(name))
|
||||
|
||||
// Set the reverse mapping between the module and capability name and the
|
||||
// index in the in-memory store. Since marshalling and unmarshalling into a store
|
||||
// will change memory address of capability, we simply store index as value here
|
||||
// and retrieve the in-memory pointer to the capability from our map
|
||||
memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(cap.GetIndex()))
|
||||
|
||||
logger(ctx).Info("claimed capability", "module", sk.module, "name", name, "capability", cap.GetIndex())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) error {
|
||||
if cap == nil {
|
||||
return errors.Wrap(types.ErrNilCapability, "cannot release nil capability")
|
||||
}
|
||||
name := sk.GetCapabilityName(ctx, cap)
|
||||
if len(name) == 0 {
|
||||
return errors.Wrap(types.ErrCapabilityNotOwned, sk.module)
|
||||
}
|
||||
|
||||
memStore := ctx.KVStore(sk.memKey)
|
||||
|
||||
// Delete the forward mapping between the module and capability tuple and the
|
||||
// capability name in the memKVStore
|
||||
memStore.Delete(types.FwdCapabilityKey(sk.module, cap))
|
||||
|
||||
// Delete the reverse mapping between the module and capability name and the
|
||||
// index in the in-memory store.
|
||||
memStore.Delete(types.RevCapabilityKey(sk.module, name))
|
||||
|
||||
// remove owner
|
||||
capOwners := sk.getOwners(ctx, cap)
|
||||
capOwners.Remove(types.NewOwner(sk.module, name))
|
||||
|
||||
prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability)
|
||||
indexKey := types.IndexToKey(cap.GetIndex())
|
||||
|
||||
if len(capOwners.Owners) == 0 {
|
||||
// remove capability owner set
|
||||
prefixStore.Delete(indexKey)
|
||||
// since no one owns capability, we can delete capability from map
|
||||
delete(sk.capMap, cap.GetIndex())
|
||||
} else {
|
||||
// update capability owner set
|
||||
prefixStore.Set(indexKey, sk.cdc.MustMarshal(capOwners))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capability, bool) {
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return nil, false
|
||||
}
|
||||
memStore := ctx.KVStore(sk.memKey)
|
||||
|
||||
key := types.RevCapabilityKey(sk.module, name)
|
||||
indexBytes := memStore.Get(key)
|
||||
index := sdk.BigEndianToUint64(indexBytes)
|
||||
|
||||
if len(indexBytes) == 0 {
|
||||
// If a tx failed and NewCapability got reverted, it is possible
|
||||
// to still have the capability in the go map since changes to
|
||||
// go map do not automatically get reverted on tx failure,
|
||||
// so we delete here to remove unnecessary values in map
|
||||
// TODO: Delete index correctly from capMap by storing some reverse lookup
|
||||
// in-memory map. Issue: https://github.com/cosmos/cosmos-sdk/issues/7805
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
cap := sk.capMap[index]
|
||||
if cap == nil {
|
||||
panic("capability found in memstore is missing from map")
|
||||
}
|
||||
|
||||
return cap, true
|
||||
}
|
||||
|
||||
// GetCapabilityName allows a module to retrieve the name under which it stored a given
|
||||
// capability given the capability
|
||||
func (sk ScopedKeeper) GetCapabilityName(ctx sdk.Context, cap *types.Capability) string {
|
||||
if cap == nil {
|
||||
return ""
|
||||
}
|
||||
memStore := ctx.KVStore(sk.memKey)
|
||||
|
||||
return string(memStore.Get(types.FwdCapabilityKey(sk.module, cap)))
|
||||
}
|
||||
|
||||
// GetOwners all the Owners that own the capability associated with the name this ScopedKeeper uses
|
||||
// to refer to the capability
|
||||
func (sk ScopedKeeper) GetOwners(ctx sdk.Context, name string) (*types.CapabilityOwners, bool) {
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return nil, false
|
||||
}
|
||||
cap, ok := sk.GetCapability(ctx, name)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability)
|
||||
indexKey := types.IndexToKey(cap.GetIndex())
|
||||
|
||||
var capOwners types.CapabilityOwners
|
||||
|
||||
bz := prefixStore.Get(indexKey)
|
||||
if len(bz) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
sk.cdc.MustUnmarshal(bz, &capOwners)
|
||||
|
||||
return &capOwners, true
|
||||
}
|
||||
|
||||
// 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 (sk ScopedKeeper) LookupModules(ctx sdk.Context, name string) ([]string, *types.Capability, error) {
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return nil, nil, errors.Wrap(types.ErrInvalidCapabilityName, "cannot lookup modules with empty capability name")
|
||||
}
|
||||
cap, ok := sk.GetCapability(ctx, name)
|
||||
if !ok {
|
||||
return nil, nil, errors.Wrap(types.ErrCapabilityNotFound, name)
|
||||
}
|
||||
|
||||
capOwners, ok := sk.GetOwners(ctx, name)
|
||||
if !ok {
|
||||
return nil, nil, errors.Wrap(types.ErrCapabilityOwnersNotFound, name)
|
||||
}
|
||||
|
||||
mods := make([]string, len(capOwners.Owners))
|
||||
for i, co := range capOwners.Owners {
|
||||
mods[i] = co.Module
|
||||
}
|
||||
|
||||
return mods, cap, nil
|
||||
}
|
||||
|
||||
func (sk ScopedKeeper) addOwner(ctx sdk.Context, cap *types.Capability, name string) error {
|
||||
prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability)
|
||||
indexKey := types.IndexToKey(cap.GetIndex())
|
||||
|
||||
capOwners := sk.getOwners(ctx, cap)
|
||||
|
||||
if err := capOwners.Set(types.NewOwner(sk.module, name)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update capability owner set
|
||||
prefixStore.Set(indexKey, sk.cdc.MustMarshal(capOwners))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sk ScopedKeeper) getOwners(ctx sdk.Context, cap *types.Capability) *types.CapabilityOwners {
|
||||
prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability)
|
||||
indexKey := types.IndexToKey(cap.GetIndex())
|
||||
|
||||
bz := prefixStore.Get(indexKey)
|
||||
|
||||
if len(bz) == 0 {
|
||||
return types.NewCapabilityOwners()
|
||||
}
|
||||
|
||||
var capOwners types.CapabilityOwners
|
||||
sk.cdc.MustUnmarshal(bz, &capOwners)
|
||||
return &capOwners
|
||||
}
|
||||
|
||||
func logger(ctx sdk.Context) log.Logger {
|
||||
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
|
||||
}
|
||||
@ -1,310 +0,0 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
var (
|
||||
stakingModuleName = "staking"
|
||||
bankModuleName = "bank"
|
||||
)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
ctx sdk.Context
|
||||
keeper *keeper.Keeper
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) SetupTest() {
|
||||
key := storetypes.NewKVStoreKey(types.StoreKey)
|
||||
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
suite.ctx = testCtx.Ctx
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(capability.AppModuleBasic{})
|
||||
suite.keeper = keeper.NewKeeper(encCfg.Codec, key, key)
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestSeal() {
|
||||
sk := suite.keeper.ScopeToModule(bankModuleName)
|
||||
suite.Require().Panics(func() {
|
||||
suite.keeper.ScopeToModule(" ")
|
||||
})
|
||||
|
||||
caps := make([]*types.Capability, 5)
|
||||
// Get Latest Index before creating new ones to sychronize indices correctly
|
||||
prevIndex := suite.keeper.GetLatestIndex(suite.ctx)
|
||||
|
||||
for i := range caps {
|
||||
cap, err := sk.NewCapability(suite.ctx, fmt.Sprintf("transfer-%d", i))
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap)
|
||||
suite.Require().Equal(uint64(i)+prevIndex, cap.GetIndex())
|
||||
|
||||
caps[i] = cap
|
||||
}
|
||||
|
||||
suite.Require().NotPanics(func() {
|
||||
suite.keeper.Seal()
|
||||
})
|
||||
|
||||
for i, cap := range caps {
|
||||
got, ok := sk.GetCapability(suite.ctx, fmt.Sprintf("transfer-%d", i))
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(cap, got)
|
||||
suite.Require().Equal(uint64(i)+prevIndex, got.GetIndex())
|
||||
}
|
||||
|
||||
suite.Require().Panics(func() {
|
||||
suite.keeper.Seal()
|
||||
})
|
||||
|
||||
suite.Require().Panics(func() {
|
||||
_ = suite.keeper.ScopeToModule(stakingModuleName)
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestNewCapability() {
|
||||
sk := suite.keeper.ScopeToModule(bankModuleName)
|
||||
|
||||
got, ok := sk.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().False(ok)
|
||||
suite.Require().Nil(got)
|
||||
|
||||
cap, err := sk.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap)
|
||||
|
||||
got, ok = sk.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(cap, got)
|
||||
suite.Require().True(cap == got, "expected memory addresses to be equal")
|
||||
|
||||
got, ok = sk.GetCapability(suite.ctx, "invalid")
|
||||
suite.Require().False(ok)
|
||||
suite.Require().Nil(got)
|
||||
|
||||
got, ok = sk.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(cap, got)
|
||||
suite.Require().True(cap == got, "expected memory addresses to be equal")
|
||||
|
||||
cap2, err := sk.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().Error(err)
|
||||
suite.Require().Nil(cap2)
|
||||
|
||||
got, ok = sk.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(cap, got)
|
||||
suite.Require().True(cap == got, "expected memory addresses to be equal")
|
||||
|
||||
cap, err = sk.NewCapability(suite.ctx, " ")
|
||||
suite.Require().Error(err)
|
||||
suite.Require().Nil(cap)
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestAuthenticateCapability() {
|
||||
sk1 := suite.keeper.ScopeToModule(bankModuleName)
|
||||
sk2 := suite.keeper.ScopeToModule(stakingModuleName)
|
||||
|
||||
cap1, err := sk1.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap1)
|
||||
|
||||
forgedCap := types.NewCapability(cap1.Index) // index should be the same index as the first capability
|
||||
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, forgedCap, "transfer"))
|
||||
suite.Require().False(sk2.AuthenticateCapability(suite.ctx, forgedCap, "transfer"))
|
||||
|
||||
cap2, err := sk2.NewCapability(suite.ctx, "bond")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap2)
|
||||
|
||||
got, ok := sk1.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
|
||||
suite.Require().True(sk1.AuthenticateCapability(suite.ctx, cap1, "transfer"))
|
||||
suite.Require().True(sk1.AuthenticateCapability(suite.ctx, got, "transfer"))
|
||||
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, cap1, "invalid"))
|
||||
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, cap2, "transfer"))
|
||||
|
||||
suite.Require().True(sk2.AuthenticateCapability(suite.ctx, cap2, "bond"))
|
||||
suite.Require().False(sk2.AuthenticateCapability(suite.ctx, cap2, "invalid"))
|
||||
suite.Require().False(sk2.AuthenticateCapability(suite.ctx, cap1, "bond"))
|
||||
|
||||
sk2.ReleaseCapability(suite.ctx, cap2)
|
||||
suite.Require().False(sk2.AuthenticateCapability(suite.ctx, cap2, "bond"))
|
||||
|
||||
badCap := types.NewCapability(100)
|
||||
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, badCap, "transfer"))
|
||||
suite.Require().False(sk2.AuthenticateCapability(suite.ctx, badCap, "bond"))
|
||||
|
||||
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, cap1, " "))
|
||||
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, nil, "transfer"))
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestClaimCapability() {
|
||||
sk1 := suite.keeper.ScopeToModule(bankModuleName)
|
||||
sk2 := suite.keeper.ScopeToModule(stakingModuleName)
|
||||
sk3 := suite.keeper.ScopeToModule("foo")
|
||||
|
||||
cap, err := sk1.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap)
|
||||
|
||||
suite.Require().Error(sk1.ClaimCapability(suite.ctx, cap, "transfer"))
|
||||
suite.Require().NoError(sk2.ClaimCapability(suite.ctx, cap, "transfer"))
|
||||
|
||||
got, ok := sk1.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(cap, got)
|
||||
|
||||
got, ok = sk2.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(cap, got)
|
||||
|
||||
suite.Require().Error(sk3.ClaimCapability(suite.ctx, cap, " "))
|
||||
suite.Require().Error(sk3.ClaimCapability(suite.ctx, nil, "transfer"))
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestGetOwners() {
|
||||
sk1 := suite.keeper.ScopeToModule(bankModuleName)
|
||||
sk2 := suite.keeper.ScopeToModule(stakingModuleName)
|
||||
sk3 := suite.keeper.ScopeToModule("foo")
|
||||
|
||||
sks := []keeper.ScopedKeeper{sk1, sk2, sk3}
|
||||
|
||||
cap, err := sk1.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap)
|
||||
|
||||
suite.Require().NoError(sk2.ClaimCapability(suite.ctx, cap, "transfer"))
|
||||
suite.Require().NoError(sk3.ClaimCapability(suite.ctx, cap, "transfer"))
|
||||
|
||||
expectedOrder := []string{bankModuleName, "foo", stakingModuleName}
|
||||
// Ensure all scoped keepers can get owners
|
||||
for _, sk := range sks {
|
||||
owners, ok := sk.GetOwners(suite.ctx, "transfer")
|
||||
mods, gotCap, err := sk.LookupModules(suite.ctx, "transfer")
|
||||
|
||||
suite.Require().True(ok, "could not retrieve owners")
|
||||
suite.Require().NotNil(owners, "owners is nil")
|
||||
|
||||
suite.Require().NoError(err, "could not retrieve modules")
|
||||
suite.Require().NotNil(gotCap, "capability is nil")
|
||||
suite.Require().NotNil(mods, "modules is nil")
|
||||
suite.Require().Equal(cap, gotCap, "caps not equal")
|
||||
|
||||
suite.Require().Equal(len(expectedOrder), len(owners.Owners), "length of owners is unexpected")
|
||||
for i, o := range owners.Owners {
|
||||
// Require owner is in expected position
|
||||
suite.Require().Equal(expectedOrder[i], o.Module, "module is unexpected")
|
||||
suite.Require().Equal(expectedOrder[i], mods[i], "module in lookup is unexpected")
|
||||
}
|
||||
}
|
||||
|
||||
// foo module releases capability
|
||||
err = sk3.ReleaseCapability(suite.ctx, cap)
|
||||
suite.Require().Nil(err, "could not release capability")
|
||||
|
||||
// new expected order and scoped capabilities
|
||||
expectedOrder = []string{bankModuleName, stakingModuleName}
|
||||
sks = []keeper.ScopedKeeper{sk1, sk2}
|
||||
|
||||
// Ensure all scoped keepers can get owners
|
||||
for _, sk := range sks {
|
||||
owners, ok := sk.GetOwners(suite.ctx, "transfer")
|
||||
mods, cap, err := sk.LookupModules(suite.ctx, "transfer")
|
||||
|
||||
suite.Require().True(ok, "could not retrieve owners")
|
||||
suite.Require().NotNil(owners, "owners is nil")
|
||||
|
||||
suite.Require().NoError(err, "could not retrieve modules")
|
||||
suite.Require().NotNil(cap, "capability is nil")
|
||||
suite.Require().NotNil(mods, "modules is nil")
|
||||
|
||||
suite.Require().Equal(len(expectedOrder), len(owners.Owners), "length of owners is unexpected")
|
||||
for i, o := range owners.Owners {
|
||||
// Require owner is in expected position
|
||||
suite.Require().Equal(expectedOrder[i], o.Module, "module is unexpected")
|
||||
suite.Require().Equal(expectedOrder[i], mods[i], "module in lookup is unexpected")
|
||||
}
|
||||
}
|
||||
|
||||
_, ok := sk1.GetOwners(suite.ctx, " ")
|
||||
suite.Require().False(ok, "got owners from empty capability name")
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestReleaseCapability() {
|
||||
sk1 := suite.keeper.ScopeToModule(bankModuleName)
|
||||
sk2 := suite.keeper.ScopeToModule(stakingModuleName)
|
||||
|
||||
cap1, err := sk1.NewCapability(suite.ctx, "transfer")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap1)
|
||||
|
||||
suite.Require().NoError(sk2.ClaimCapability(suite.ctx, cap1, "transfer"))
|
||||
|
||||
cap2, err := sk2.NewCapability(suite.ctx, "bond")
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(cap2)
|
||||
|
||||
suite.Require().Error(sk1.ReleaseCapability(suite.ctx, cap2))
|
||||
|
||||
suite.Require().NoError(sk2.ReleaseCapability(suite.ctx, cap1))
|
||||
got, ok := sk2.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().False(ok)
|
||||
suite.Require().Nil(got)
|
||||
|
||||
suite.Require().NoError(sk1.ReleaseCapability(suite.ctx, cap1))
|
||||
got, ok = sk1.GetCapability(suite.ctx, "transfer")
|
||||
suite.Require().False(ok)
|
||||
suite.Require().Nil(got)
|
||||
|
||||
suite.Require().Error(sk1.ReleaseCapability(suite.ctx, nil))
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestRevertCapability() {
|
||||
sk := suite.keeper.ScopeToModule(bankModuleName)
|
||||
|
||||
ms := suite.ctx.MultiStore()
|
||||
|
||||
msCache := ms.CacheMultiStore()
|
||||
cacheCtx := suite.ctx.WithMultiStore(msCache)
|
||||
|
||||
capName := "revert"
|
||||
// Create capability on cached context
|
||||
cap, err := sk.NewCapability(cacheCtx, capName)
|
||||
suite.Require().NoError(err, "could not create capability")
|
||||
|
||||
// Check that capability written in cached context
|
||||
gotCache, ok := sk.GetCapability(cacheCtx, capName)
|
||||
suite.Require().True(ok, "could not retrieve capability from cached context")
|
||||
suite.Require().Equal(cap, gotCache, "did not get correct capability from cached context")
|
||||
|
||||
// Check that capability is NOT written to original context
|
||||
got, ok := sk.GetCapability(suite.ctx, capName)
|
||||
suite.Require().False(ok, "retrieved capability from original context before write")
|
||||
suite.Require().Nil(got, "capability not nil in original store")
|
||||
|
||||
// Write to underlying memKVStore
|
||||
msCache.Write()
|
||||
|
||||
got, ok = sk.GetCapability(suite.ctx, capName)
|
||||
suite.Require().True(ok, "could not retrieve capability from context")
|
||||
suite.Require().Equal(cap, got, "did not get correct capability from context")
|
||||
}
|
||||
|
||||
func TestKeeperTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(KeeperTestSuite))
|
||||
}
|
||||
@ -1,213 +0,0 @@
|
||||
package capability
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
|
||||
modulev1 "cosmossdk.io/api/cosmos/capability/module/v1"
|
||||
"cosmossdk.io/depinject"
|
||||
|
||||
store "cosmossdk.io/store/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
var (
|
||||
_ module.BeginBlockAppModule = AppModule{}
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// AppModuleBasic
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// AppModuleBasic implements the AppModuleBasic interface for the capability module.
|
||||
type AppModuleBasic struct {
|
||||
cdc codec.Codec
|
||||
}
|
||||
|
||||
func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic {
|
||||
return AppModuleBasic{cdc: cdc}
|
||||
}
|
||||
|
||||
// Name returns the capability module's name.
|
||||
func (AppModuleBasic) Name() string {
|
||||
return types.ModuleName
|
||||
}
|
||||
|
||||
// RegisterLegacyAminoCodec does nothing. Capability does not support amino.
|
||||
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
|
||||
|
||||
// RegisterInterfaces registers the module's interface types
|
||||
func (a AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {}
|
||||
|
||||
// DefaultGenesis returns the capability module's default genesis state.
|
||||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
||||
return cdc.MustMarshalJSON(types.DefaultGenesis())
|
||||
}
|
||||
|
||||
// ValidateGenesis performs genesis state validation for the capability module.
|
||||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
||||
var genState types.GenesisState
|
||||
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
||||
}
|
||||
return genState.Validate()
|
||||
}
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the capability module.
|
||||
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {
|
||||
}
|
||||
|
||||
// GetTxCmd returns the capability module's root tx command.
|
||||
func (a AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
|
||||
|
||||
// GetQueryCmd returns the capability module's root query command.
|
||||
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// AppModule
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// AppModule implements the AppModule interface for the capability module.
|
||||
type AppModule struct {
|
||||
AppModuleBasic
|
||||
|
||||
keeper keeper.Keeper
|
||||
|
||||
sealKeeper bool
|
||||
}
|
||||
|
||||
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, sealKeeper bool) AppModule {
|
||||
return AppModule{
|
||||
AppModuleBasic: NewAppModuleBasic(cdc),
|
||||
keeper: keeper,
|
||||
sealKeeper: sealKeeper,
|
||||
}
|
||||
}
|
||||
|
||||
var _ appmodule.AppModule = AppModule{}
|
||||
|
||||
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
|
||||
func (am AppModule) IsOnePerModuleType() {}
|
||||
|
||||
// IsAppModule implements the appmodule.AppModule interface.
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
// Name returns the capability module's name.
|
||||
func (am AppModule) Name() string {
|
||||
return am.AppModuleBasic.Name()
|
||||
}
|
||||
|
||||
// RegisterServices registers a GRPC query service to respond to the
|
||||
// module-specific GRPC queries.
|
||||
func (am AppModule) RegisterServices(module.Configurator) {}
|
||||
|
||||
// RegisterInvariants registers the capability module's invariants.
|
||||
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
||||
|
||||
// InitGenesis performs the capability module's genesis initialization It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate {
|
||||
var genState types.GenesisState
|
||||
// Initialize global index to index in genesis state
|
||||
cdc.MustUnmarshalJSON(gs, &genState)
|
||||
|
||||
InitGenesis(ctx, am.keeper, genState)
|
||||
|
||||
return []abci.ValidatorUpdate{}
|
||||
}
|
||||
|
||||
// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes.
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
||||
genState := ExportGenesis(ctx, am.keeper)
|
||||
return cdc.MustMarshalJSON(genState)
|
||||
}
|
||||
|
||||
// ConsensusVersion implements AppModule/ConsensusVersion.
|
||||
func (AppModule) ConsensusVersion() uint64 { return 1 }
|
||||
|
||||
// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
|
||||
// BeginBlocker calls InitMemStore to assert that the memory store is initialized.
|
||||
// It's safe to run multiple times.
|
||||
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
||||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
|
||||
|
||||
am.keeper.InitMemStore(ctx)
|
||||
|
||||
if am.sealKeeper && !am.keeper.IsSealed() {
|
||||
am.keeper.Seal()
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateGenesisState creates a randomized GenState of the capability module.
|
||||
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
|
||||
simulation.RandomizedGenState(simState)
|
||||
}
|
||||
|
||||
// RegisterStoreDecoder registers a decoder for capability module's types
|
||||
func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {
|
||||
sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc)
|
||||
}
|
||||
|
||||
// WeightedOperations returns the all the gov module operations with their respective weights.
|
||||
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
|
||||
return nil
|
||||
}
|
||||
|
||||
//
|
||||
// App Wiring Setup
|
||||
//
|
||||
|
||||
func init() {
|
||||
appmodule.Register(&modulev1.Module{},
|
||||
appmodule.Provide(ProvideModule),
|
||||
)
|
||||
}
|
||||
|
||||
//nolint:revive
|
||||
type CapabilityInputs struct {
|
||||
depinject.In
|
||||
|
||||
Config *modulev1.Module
|
||||
|
||||
KvStoreKey *store.KVStoreKey
|
||||
MemStoreKey *store.MemoryStoreKey
|
||||
Cdc codec.Codec
|
||||
}
|
||||
|
||||
//nolint:revive
|
||||
type CapabilityOutputs struct {
|
||||
depinject.Out
|
||||
|
||||
CapabilityKeeper *keeper.Keeper
|
||||
Module appmodule.AppModule
|
||||
}
|
||||
|
||||
func ProvideModule(in CapabilityInputs) CapabilityOutputs {
|
||||
k := keeper.NewKeeper(in.Cdc, in.KvStoreKey, in.MemStoreKey)
|
||||
m := NewAppModule(in.Cdc, *k, in.Config.SealKeeper)
|
||||
|
||||
return CapabilityOutputs{
|
||||
CapabilityKeeper: k,
|
||||
Module: m,
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
|
||||
// Value to the corresponding capability type.
|
||||
func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
|
||||
return func(kvA, kvB kv.Pair) string {
|
||||
switch {
|
||||
case bytes.Equal(kvA.Key, types.KeyIndex):
|
||||
idxA := sdk.BigEndianToUint64(kvA.Value)
|
||||
idxB := sdk.BigEndianToUint64(kvB.Value)
|
||||
return fmt.Sprintf("Index A: %d\nIndex B: %d\n", idxA, idxB)
|
||||
|
||||
case bytes.HasPrefix(kvA.Key, types.KeyPrefixIndexCapability):
|
||||
var capOwnersA, capOwnersB types.CapabilityOwners
|
||||
cdc.MustUnmarshal(kvA.Value, &capOwnersA)
|
||||
cdc.MustUnmarshal(kvB.Value, &capOwnersB)
|
||||
return fmt.Sprintf("CapabilityOwners A: %v\nCapabilityOwners B: %v\n", capOwnersA, capOwnersB)
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid %s key prefix %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
package simulation_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/depinject"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
func TestDecodeStore(t *testing.T) {
|
||||
var cdc codec.Codec
|
||||
err := depinject.Inject(testutil.AppConfig, &cdc)
|
||||
require.NoError(t, err)
|
||||
|
||||
dec := simulation.NewDecodeStore(cdc)
|
||||
|
||||
capOwners := types.CapabilityOwners{
|
||||
Owners: []types.Owner{{Module: "transfer", Name: "ports/transfer"}},
|
||||
}
|
||||
|
||||
kvPairs := kv.Pairs{
|
||||
Pairs: []kv.Pair{
|
||||
{
|
||||
Key: types.KeyIndex,
|
||||
Value: sdk.Uint64ToBigEndian(10),
|
||||
},
|
||||
{
|
||||
Key: types.KeyPrefixIndexCapability,
|
||||
Value: cdc.MustMarshal(&capOwners),
|
||||
},
|
||||
{
|
||||
Key: []byte{0x99},
|
||||
Value: []byte{0x99},
|
||||
},
|
||||
},
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
expectedLog string
|
||||
}{
|
||||
{"Index", "Index A: 10\nIndex B: 10\n"},
|
||||
{"CapabilityOwners", fmt.Sprintf("CapabilityOwners A: %v\nCapabilityOwners B: %v\n", capOwners, capOwners)},
|
||||
{"other", ""},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
|
||||
default:
|
||||
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
// Simulation parameter constants
|
||||
const index = "index"
|
||||
|
||||
// GenIndex returns a random global index between 1-1000
|
||||
func GenIndex(r *rand.Rand) uint64 {
|
||||
return uint64(r.Int63n(1000)) + 1
|
||||
}
|
||||
|
||||
// RandomizedGenState generates a random GenesisState for capability
|
||||
func RandomizedGenState(simState *module.SimulationState) {
|
||||
var idx uint64
|
||||
|
||||
simState.AppParams.GetOrGenerate(
|
||||
simState.Cdc, index, &idx, simState.Rand,
|
||||
func(r *rand.Rand) { idx = GenIndex(r) },
|
||||
)
|
||||
|
||||
capabilityGenesis := types.GenesisState{Index: idx}
|
||||
|
||||
bz, err := json.MarshalIndent(&capabilityGenesis, "", " ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
|
||||
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&capabilityGenesis)
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
package simulation_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState.
|
||||
// Abonormal scenarios are not tested here.
|
||||
func TestRandomizedGenState(t *testing.T) {
|
||||
interfaceRegistry := codectypes.NewInterfaceRegistry()
|
||||
cdc := codec.NewProtoCodec(interfaceRegistry)
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
simState := module.SimulationState{
|
||||
AppParams: make(simtypes.AppParams),
|
||||
Cdc: cdc,
|
||||
Rand: r,
|
||||
NumBonded: 3,
|
||||
Accounts: simtypes.RandomAccounts(r, 3),
|
||||
InitialStake: sdkmath.NewInt(1000),
|
||||
GenState: make(map[string]json.RawMessage),
|
||||
}
|
||||
|
||||
simulation.RandomizedGenState(&simState)
|
||||
|
||||
var capGenesis types.GenesisState
|
||||
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &capGenesis)
|
||||
|
||||
require.Equal(t, uint64(149), capGenesis.Index)
|
||||
require.Len(t, capGenesis.Owners, 0)
|
||||
}
|
||||
|
||||
// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState.
|
||||
func TestRandomizedGenState1(t *testing.T) {
|
||||
interfaceRegistry := codectypes.NewInterfaceRegistry()
|
||||
cdc := codec.NewProtoCodec(interfaceRegistry)
|
||||
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
// all these tests will panic
|
||||
tests := []struct {
|
||||
simState module.SimulationState
|
||||
panicMsg string
|
||||
}{
|
||||
{ // panic => reason: incomplete initialization of the simState
|
||||
module.SimulationState{}, "invalid memory address or nil pointer dereference"},
|
||||
{ // panic => reason: incomplete initialization of the simState
|
||||
module.SimulationState{
|
||||
AppParams: make(simtypes.AppParams),
|
||||
Cdc: cdc,
|
||||
Rand: r,
|
||||
}, "assignment to entry in nil map"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg)
|
||||
}
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/capability" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring
|
||||
|
||||
"cosmossdk.io/core/appconfig"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
|
||||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
|
||||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
|
||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
|
||||
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
|
||||
capabilitymodulev1 "cosmossdk.io/api/cosmos/capability/module/v1"
|
||||
consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
|
||||
genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1"
|
||||
paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1"
|
||||
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
|
||||
txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1"
|
||||
)
|
||||
|
||||
var AppConfig = appconfig.Compose(&appv1alpha1.Config{
|
||||
Modules: []*appv1alpha1.ModuleConfig{
|
||||
{
|
||||
Name: "runtime",
|
||||
Config: appconfig.WrapAny(&runtimev1alpha1.Module{
|
||||
AppName: "CapabilityApp",
|
||||
BeginBlockers: []string{
|
||||
capabilitytypes.ModuleName,
|
||||
stakingtypes.ModuleName,
|
||||
genutiltypes.ModuleName,
|
||||
},
|
||||
EndBlockers: []string{
|
||||
stakingtypes.ModuleName,
|
||||
genutiltypes.ModuleName,
|
||||
},
|
||||
InitGenesis: []string{
|
||||
capabilitytypes.ModuleName,
|
||||
authtypes.ModuleName,
|
||||
banktypes.ModuleName,
|
||||
stakingtypes.ModuleName,
|
||||
genutiltypes.ModuleName,
|
||||
paramstypes.ModuleName,
|
||||
consensustypes.ModuleName,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: authtypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&authmodulev1.Module{
|
||||
Bech32Prefix: "cosmos",
|
||||
ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{
|
||||
{Account: authtypes.FeeCollectorName},
|
||||
{Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
|
||||
{Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: banktypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&bankmodulev1.Module{}),
|
||||
},
|
||||
{
|
||||
Name: stakingtypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&stakingmodulev1.Module{}),
|
||||
},
|
||||
{
|
||||
Name: paramstypes.ModuleName,
|
||||
Config: appconfig.WrapAny(¶msmodulev1.Module{}),
|
||||
},
|
||||
{
|
||||
Name: "tx",
|
||||
Config: appconfig.WrapAny(&txconfigv1.Config{}),
|
||||
},
|
||||
{
|
||||
Name: genutiltypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&genutilmodulev1.Module{}),
|
||||
},
|
||||
{
|
||||
Name: consensustypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&consensusmodulev1.Module{}),
|
||||
},
|
||||
{
|
||||
Name: capabilitytypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&capabilitymodulev1.Module{
|
||||
SealKeeper: true,
|
||||
}),
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -1,703 +0,0 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: cosmos/capability/v1beta1/capability.proto
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/cosmos/cosmos-sdk/types/tx/amino"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// Capability defines an implementation of an object capability. The index
|
||||
// provided to a Capability must be globally unique.
|
||||
type Capability struct {
|
||||
Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Capability) Reset() { *m = Capability{} }
|
||||
func (m *Capability) String() string { return proto.CompactTextString(m) }
|
||||
func (*Capability) ProtoMessage() {}
|
||||
func (*Capability) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_6308261edd8470a9, []int{0}
|
||||
}
|
||||
func (m *Capability) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *Capability) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_Capability.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *Capability) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Capability.Merge(m, src)
|
||||
}
|
||||
func (m *Capability) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *Capability) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Capability.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Capability proto.InternalMessageInfo
|
||||
|
||||
func (m *Capability) GetIndex() uint64 {
|
||||
if m != nil {
|
||||
return m.Index
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Owner defines a single capability owner. An owner is defined by the name of
|
||||
// capability and the module name.
|
||||
type Owner struct {
|
||||
Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Owner) Reset() { *m = Owner{} }
|
||||
func (m *Owner) String() string { return proto.CompactTextString(m) }
|
||||
func (*Owner) ProtoMessage() {}
|
||||
func (*Owner) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_6308261edd8470a9, []int{1}
|
||||
}
|
||||
func (m *Owner) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *Owner) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_Owner.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *Owner) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Owner.Merge(m, src)
|
||||
}
|
||||
func (m *Owner) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *Owner) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Owner.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Owner proto.InternalMessageInfo
|
||||
|
||||
// CapabilityOwners defines a set of owners of a single Capability. The set of
|
||||
// owners must be unique.
|
||||
type CapabilityOwners struct {
|
||||
Owners []Owner `protobuf:"bytes,1,rep,name=owners,proto3" json:"owners"`
|
||||
}
|
||||
|
||||
func (m *CapabilityOwners) Reset() { *m = CapabilityOwners{} }
|
||||
func (m *CapabilityOwners) String() string { return proto.CompactTextString(m) }
|
||||
func (*CapabilityOwners) ProtoMessage() {}
|
||||
func (*CapabilityOwners) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_6308261edd8470a9, []int{2}
|
||||
}
|
||||
func (m *CapabilityOwners) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *CapabilityOwners) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_CapabilityOwners.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *CapabilityOwners) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_CapabilityOwners.Merge(m, src)
|
||||
}
|
||||
func (m *CapabilityOwners) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *CapabilityOwners) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_CapabilityOwners.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_CapabilityOwners proto.InternalMessageInfo
|
||||
|
||||
func (m *CapabilityOwners) GetOwners() []Owner {
|
||||
if m != nil {
|
||||
return m.Owners
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Capability)(nil), "cosmos.capability.v1beta1.Capability")
|
||||
proto.RegisterType((*Owner)(nil), "cosmos.capability.v1beta1.Owner")
|
||||
proto.RegisterType((*CapabilityOwners)(nil), "cosmos.capability.v1beta1.CapabilityOwners")
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("cosmos/capability/v1beta1/capability.proto", fileDescriptor_6308261edd8470a9)
|
||||
}
|
||||
|
||||
var fileDescriptor_6308261edd8470a9 = []byte{
|
||||
// 270 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0xce, 0x2f, 0xce,
|
||||
0xcd, 0x2f, 0xd6, 0x4f, 0x4e, 0x2c, 0x48, 0x4c, 0xca, 0xcc, 0xc9, 0x2c, 0xa9, 0xd4, 0x2f, 0x33,
|
||||
0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x44, 0x12, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x84,
|
||||
0xa8, 0xd5, 0x43, 0x92, 0x80, 0xaa, 0x95, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd2, 0x07,
|
||||
0xb1, 0x20, 0x1a, 0xa4, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x44, 0x48, 0x49,
|
||||
0x89, 0x8b, 0xcb, 0x19, 0xae, 0x5d, 0x48, 0x84, 0x8b, 0x35, 0x33, 0x2f, 0x25, 0xb5, 0x42, 0x82,
|
||||
0x51, 0x81, 0x51, 0x83, 0x25, 0x08, 0xc2, 0x51, 0xb2, 0xe4, 0x62, 0xf5, 0x2f, 0xcf, 0x4b, 0x2d,
|
||||
0x12, 0x12, 0xe3, 0x62, 0xcb, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x05, 0xcb, 0x73, 0x06, 0x41, 0x79,
|
||||
0x42, 0x42, 0x5c, 0x2c, 0x79, 0x89, 0xb9, 0xa9, 0x12, 0x4c, 0x60, 0x51, 0x30, 0xdb, 0x8a, 0xa5,
|
||||
0x63, 0x81, 0x3c, 0x83, 0x52, 0x38, 0x97, 0x00, 0xc2, 0x78, 0xb0, 0x21, 0xc5, 0x42, 0xce, 0x5c,
|
||||
0x6c, 0xf9, 0x60, 0x96, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x82, 0x1e, 0x4e, 0x7f, 0xe8,
|
||||
0x81, 0xb5, 0x38, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8,
|
||||
0x56, 0x27, 0xcf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71,
|
||||
0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xd2, 0x4f, 0xcf,
|
||||
0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x05, 0x26, 0x98, 0xd2, 0x2d, 0x4e,
|
||||
0xc9, 0xd6, 0xaf, 0x40, 0x0e, 0xd9, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0x48, 0x18,
|
||||
0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x07, 0x8a, 0x4b, 0x8d, 0x7b, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *Capability) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *Capability) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *Capability) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.Index != 0 {
|
||||
i = encodeVarintCapability(dAtA, i, uint64(m.Index))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *Owner) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *Owner) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *Owner) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Name) > 0 {
|
||||
i -= len(m.Name)
|
||||
copy(dAtA[i:], m.Name)
|
||||
i = encodeVarintCapability(dAtA, i, uint64(len(m.Name)))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(m.Module) > 0 {
|
||||
i -= len(m.Module)
|
||||
copy(dAtA[i:], m.Module)
|
||||
i = encodeVarintCapability(dAtA, i, uint64(len(m.Module)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *CapabilityOwners) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *CapabilityOwners) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *CapabilityOwners) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Owners) > 0 {
|
||||
for iNdEx := len(m.Owners) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Owners[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintCapability(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintCapability(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovCapability(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *Capability) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.Index != 0 {
|
||||
n += 1 + sovCapability(uint64(m.Index))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *Owner) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Module)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovCapability(uint64(l))
|
||||
}
|
||||
l = len(m.Name)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovCapability(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *CapabilityOwners) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Owners) > 0 {
|
||||
for _, e := range m.Owners {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovCapability(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovCapability(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozCapability(x uint64) (n int) {
|
||||
return sovCapability(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *Capability) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: Capability: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: Capability: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
|
||||
}
|
||||
m.Index = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.Index |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipCapability(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *Owner) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: Owner: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: Owner: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Module", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Module = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Name = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipCapability(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *CapabilityOwners) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: CapabilityOwners: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: CapabilityOwners: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Owners", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Owners = append(m.Owners, Owner{})
|
||||
if err := m.Owners[len(m.Owners)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipCapability(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthCapability
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipCapability(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowCapability
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthCapability
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupCapability
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthCapability
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthCapability = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowCapability = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupCapability = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
||||
@ -1,14 +0,0 @@
|
||||
package types
|
||||
|
||||
import "cosmossdk.io/errors"
|
||||
|
||||
// x/capability module sentinel errors
|
||||
var (
|
||||
ErrInvalidCapabilityName = errors.Register(ModuleName, 2, "capability name not valid")
|
||||
ErrNilCapability = errors.Register(ModuleName, 3, "provided capability is nil")
|
||||
ErrCapabilityTaken = errors.Register(ModuleName, 4, "capability name already taken")
|
||||
ErrOwnerClaimed = errors.Register(ModuleName, 5, "given owner already claimed capability")
|
||||
ErrCapabilityNotOwned = errors.Register(ModuleName, 6, "capability not owned by module")
|
||||
ErrCapabilityNotFound = errors.Register(ModuleName, 7, "capability not found")
|
||||
ErrCapabilityOwnersNotFound = errors.Register(ModuleName, 8, "owners not found for capability")
|
||||
)
|
||||
@ -1,49 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DefaultIndex is the default capability global index
|
||||
const DefaultIndex uint64 = 1
|
||||
|
||||
// DefaultGenesis returns the default Capability genesis state
|
||||
func DefaultGenesis() *GenesisState {
|
||||
return &GenesisState{
|
||||
Index: DefaultIndex,
|
||||
Owners: []GenesisOwners{},
|
||||
}
|
||||
}
|
||||
|
||||
// Validate performs basic genesis state validation returning an error upon any
|
||||
// failure.
|
||||
func (gs GenesisState) Validate() error {
|
||||
// NOTE: index must be greater than 0
|
||||
if gs.Index == 0 {
|
||||
return fmt.Errorf("capability index must be non-zero")
|
||||
}
|
||||
|
||||
for _, genOwner := range gs.Owners {
|
||||
if len(genOwner.IndexOwners.Owners) == 0 {
|
||||
return fmt.Errorf("empty owners in genesis")
|
||||
}
|
||||
|
||||
// all exported existing indices must be between [1, gs.Index)
|
||||
if genOwner.Index == 0 || genOwner.Index >= gs.Index {
|
||||
return fmt.Errorf("owners exist for index %d outside of valid range: %d-%d", genOwner.Index, 1, gs.Index-1)
|
||||
}
|
||||
|
||||
for _, owner := range genOwner.IndexOwners.Owners {
|
||||
if strings.TrimSpace(owner.Module) == "" {
|
||||
return fmt.Errorf("owner's module cannot be blank: %s", owner)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(owner.Name) == "" {
|
||||
return fmt.Errorf("owner's name cannot be blank: %s", owner)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,586 +0,0 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: cosmos/capability/v1beta1/genesis.proto
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/cosmos/cosmos-sdk/types/tx/amino"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// GenesisOwners defines the capability owners with their corresponding index.
|
||||
type GenesisOwners struct {
|
||||
// index is the index of the capability owner.
|
||||
Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
|
||||
// index_owners are the owners at the given index.
|
||||
IndexOwners CapabilityOwners `protobuf:"bytes,2,opt,name=index_owners,json=indexOwners,proto3" json:"index_owners"`
|
||||
}
|
||||
|
||||
func (m *GenesisOwners) Reset() { *m = GenesisOwners{} }
|
||||
func (m *GenesisOwners) String() string { return proto.CompactTextString(m) }
|
||||
func (*GenesisOwners) ProtoMessage() {}
|
||||
func (*GenesisOwners) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_94922dd16a11c23e, []int{0}
|
||||
}
|
||||
func (m *GenesisOwners) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *GenesisOwners) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_GenesisOwners.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *GenesisOwners) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GenesisOwners.Merge(m, src)
|
||||
}
|
||||
func (m *GenesisOwners) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *GenesisOwners) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GenesisOwners.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GenesisOwners proto.InternalMessageInfo
|
||||
|
||||
func (m *GenesisOwners) GetIndex() uint64 {
|
||||
if m != nil {
|
||||
return m.Index
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *GenesisOwners) GetIndexOwners() CapabilityOwners {
|
||||
if m != nil {
|
||||
return m.IndexOwners
|
||||
}
|
||||
return CapabilityOwners{}
|
||||
}
|
||||
|
||||
// GenesisState defines the capability module's genesis state.
|
||||
type GenesisState struct {
|
||||
// index is the capability global index.
|
||||
Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
|
||||
// owners represents a map from index to owners of the capability index
|
||||
// index key is string to allow amino marshalling.
|
||||
Owners []GenesisOwners `protobuf:"bytes,2,rep,name=owners,proto3" json:"owners"`
|
||||
}
|
||||
|
||||
func (m *GenesisState) Reset() { *m = GenesisState{} }
|
||||
func (m *GenesisState) String() string { return proto.CompactTextString(m) }
|
||||
func (*GenesisState) ProtoMessage() {}
|
||||
func (*GenesisState) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_94922dd16a11c23e, []int{1}
|
||||
}
|
||||
func (m *GenesisState) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *GenesisState) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GenesisState.Merge(m, src)
|
||||
}
|
||||
func (m *GenesisState) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *GenesisState) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GenesisState.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GenesisState proto.InternalMessageInfo
|
||||
|
||||
func (m *GenesisState) GetIndex() uint64 {
|
||||
if m != nil {
|
||||
return m.Index
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetOwners() []GenesisOwners {
|
||||
if m != nil {
|
||||
return m.Owners
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*GenesisOwners)(nil), "cosmos.capability.v1beta1.GenesisOwners")
|
||||
proto.RegisterType((*GenesisState)(nil), "cosmos.capability.v1beta1.GenesisState")
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("cosmos/capability/v1beta1/genesis.proto", fileDescriptor_94922dd16a11c23e)
|
||||
}
|
||||
|
||||
var fileDescriptor_94922dd16a11c23e = []byte{
|
||||
// 280 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4f, 0xce, 0x2f, 0xce,
|
||||
0xcd, 0x2f, 0xd6, 0x4f, 0x4e, 0x2c, 0x48, 0x4c, 0xca, 0xcc, 0xc9, 0x2c, 0xa9, 0xd4, 0x2f, 0x33,
|
||||
0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28,
|
||||
0xca, 0x2f, 0xc9, 0x17, 0x92, 0x84, 0x28, 0xd4, 0x43, 0x28, 0xd4, 0x83, 0x2a, 0x94, 0x12, 0x49,
|
||||
0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd2, 0x07, 0xb1, 0x20, 0x1a, 0xa4, 0xb4, 0x70, 0x9b, 0x8c, 0x64,
|
||||
0x06, 0x44, 0xad, 0x60, 0x62, 0x6e, 0x66, 0x5e, 0xbe, 0x3e, 0x98, 0x84, 0x08, 0x29, 0x35, 0x30,
|
||||
0x72, 0xf1, 0xba, 0x43, 0x5c, 0xe0, 0x5f, 0x9e, 0x97, 0x5a, 0x54, 0x2c, 0x24, 0xc2, 0xc5, 0x9a,
|
||||
0x99, 0x97, 0x92, 0x5a, 0x21, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x12, 0x04, 0xe1, 0x08, 0x45, 0x72,
|
||||
0xf1, 0x80, 0x19, 0xf1, 0xf9, 0x60, 0x55, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0xda, 0x7a,
|
||||
0x38, 0x9d, 0xab, 0xe7, 0x0c, 0x17, 0x82, 0x18, 0xec, 0xc4, 0x79, 0xe2, 0x9e, 0x3c, 0xc3, 0x8a,
|
||||
0xe7, 0x1b, 0xb4, 0x18, 0x83, 0xb8, 0xc1, 0x66, 0x41, 0xc4, 0x95, 0x0a, 0xb9, 0x78, 0xa0, 0x2e,
|
||||
0x08, 0x2e, 0x49, 0x2c, 0x49, 0xc5, 0xe1, 0x00, 0x6f, 0x2e, 0x36, 0xb8, 0xd5, 0xcc, 0x1a, 0xdc,
|
||||
0x46, 0x1a, 0x78, 0xac, 0x46, 0xf1, 0x10, 0xb2, 0xbd, 0x50, 0x23, 0x9c, 0x3c, 0x4f, 0x3c, 0x92,
|
||||
0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c,
|
||||
0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x3f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f,
|
||||
0x39, 0x3f, 0x57, 0x1f, 0x16, 0xb2, 0x60, 0x4a, 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0x02, 0x39, 0x98,
|
||||
0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xe1, 0x68, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff,
|
||||
0xa2, 0x39, 0xc7, 0xe6, 0xe2, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *GenesisOwners) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *GenesisOwners) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *GenesisOwners) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
{
|
||||
size, err := m.IndexOwners.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
if m.Index != 0 {
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(m.Index))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Owners) > 0 {
|
||||
for iNdEx := len(m.Owners) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Owners[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
if m.Index != 0 {
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(m.Index))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovGenesis(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *GenesisOwners) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.Index != 0 {
|
||||
n += 1 + sovGenesis(uint64(m.Index))
|
||||
}
|
||||
l = m.IndexOwners.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *GenesisState) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.Index != 0 {
|
||||
n += 1 + sovGenesis(uint64(m.Index))
|
||||
}
|
||||
if len(m.Owners) > 0 {
|
||||
for _, e := range m.Owners {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovGenesis(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozGenesis(x uint64) (n int) {
|
||||
return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *GenesisOwners) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: GenesisOwners: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: GenesisOwners: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
|
||||
}
|
||||
m.Index = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.Index |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field IndexOwners", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if err := m.IndexOwners.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *GenesisState) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: GenesisState: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
|
||||
}
|
||||
m.Index = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.Index |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Owners", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Owners = append(m.Owners, GenesisOwners{})
|
||||
if err := m.Owners[len(m.Owners)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipGenesis(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupGenesis
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
||||
@ -1,125 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidateGenesis(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
malleate func(*GenesisState)
|
||||
expPass bool
|
||||
}{
|
||||
{
|
||||
name: "default",
|
||||
malleate: func(_ *GenesisState) {},
|
||||
expPass: true,
|
||||
},
|
||||
{
|
||||
name: "valid genesis state",
|
||||
malleate: func(genState *GenesisState) {
|
||||
genState.Index = 10
|
||||
genOwner := GenesisOwners{
|
||||
Index: 1,
|
||||
IndexOwners: CapabilityOwners{[]Owner{{Module: "ibc", Name: "port/transfer"}}},
|
||||
}
|
||||
|
||||
genState.Owners = append(genState.Owners, genOwner)
|
||||
},
|
||||
expPass: true,
|
||||
},
|
||||
{
|
||||
name: "initial index is 0",
|
||||
malleate: func(genState *GenesisState) {
|
||||
genState.Index = 0
|
||||
genOwner := GenesisOwners{
|
||||
Index: 0,
|
||||
IndexOwners: CapabilityOwners{[]Owner{{Module: "ibc", Name: "port/transfer"}}},
|
||||
}
|
||||
|
||||
genState.Owners = append(genState.Owners, genOwner)
|
||||
},
|
||||
expPass: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "blank owner module",
|
||||
malleate: func(genState *GenesisState) {
|
||||
genState.Index = 1
|
||||
genOwner := GenesisOwners{
|
||||
Index: 1,
|
||||
IndexOwners: CapabilityOwners{[]Owner{{Module: "", Name: "port/transfer"}}},
|
||||
}
|
||||
|
||||
genState.Owners = append(genState.Owners, genOwner)
|
||||
},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "blank owner name",
|
||||
malleate: func(genState *GenesisState) {
|
||||
genState.Index = 1
|
||||
genOwner := GenesisOwners{
|
||||
Index: 1,
|
||||
IndexOwners: CapabilityOwners{[]Owner{{Module: "ibc", Name: ""}}},
|
||||
}
|
||||
|
||||
genState.Owners = append(genState.Owners, genOwner)
|
||||
},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "index above range",
|
||||
malleate: func(genState *GenesisState) {
|
||||
genState.Index = 10
|
||||
genOwner := GenesisOwners{
|
||||
Index: 12,
|
||||
IndexOwners: CapabilityOwners{[]Owner{{Module: "ibc", Name: "port/transfer"}}},
|
||||
}
|
||||
|
||||
genState.Owners = append(genState.Owners, genOwner)
|
||||
},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "index below range",
|
||||
malleate: func(genState *GenesisState) {
|
||||
genState.Index = 10
|
||||
genOwner := GenesisOwners{
|
||||
Index: 0,
|
||||
IndexOwners: CapabilityOwners{[]Owner{{Module: "ibc", Name: "port/transfer"}}},
|
||||
}
|
||||
|
||||
genState.Owners = append(genState.Owners, genOwner)
|
||||
},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "owners are empty",
|
||||
malleate: func(genState *GenesisState) {
|
||||
genState.Index = 10
|
||||
genOwner := GenesisOwners{
|
||||
Index: 0,
|
||||
IndexOwners: CapabilityOwners{[]Owner{}},
|
||||
}
|
||||
|
||||
genState.Owners = append(genState.Owners, genOwner)
|
||||
},
|
||||
expPass: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
genState := DefaultGenesis()
|
||||
tc.malleate(genState)
|
||||
err := genState.Validate()
|
||||
if tc.expPass {
|
||||
require.NoError(t, err, tc.name)
|
||||
} else {
|
||||
require.Error(t, err, tc.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
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 = "memory:capability"
|
||||
)
|
||||
|
||||
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
|
||||
// owners mappings.
|
||||
KeyPrefixIndexCapability = []byte("capability_index")
|
||||
|
||||
// KeyMemInitialized defines the key that stores the initialized flag in the memory store
|
||||
KeyMemInitialized = []byte("mem_initialized")
|
||||
)
|
||||
|
||||
// RevCapabilityKey returns a reverse lookup key for a given module and capability
|
||||
// name.
|
||||
func RevCapabilityKey(module, name string) []byte {
|
||||
return []byte(fmt.Sprintf("%s/rev/%s", module, name))
|
||||
}
|
||||
|
||||
// FwdCapabilityKey returns a forward lookup key for a given module and capability
|
||||
// reference.
|
||||
func FwdCapabilityKey(module string, cap *Capability) []byte {
|
||||
return []byte(fmt.Sprintf("%s/fwd/%#016p", module, cap))
|
||||
}
|
||||
|
||||
// IndexToKey returns bytes to be used as a key for a given capability index.
|
||||
func IndexToKey(index uint64) []byte {
|
||||
return sdk.Uint64ToBigEndian(index)
|
||||
}
|
||||
|
||||
// IndexFromKey returns an index from a call to IndexToKey for a given capability
|
||||
// index.
|
||||
func IndexFromKey(key []byte) uint64 {
|
||||
return sdk.BigEndianToUint64(key)
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
func TestRevCapabilityKey(t *testing.T) {
|
||||
expected := []byte("bank/rev/send")
|
||||
require.Equal(t, expected, types.RevCapabilityKey("bank", "send"))
|
||||
}
|
||||
|
||||
func TestFwdCapabilityKey(t *testing.T) {
|
||||
cap := types.NewCapability(23)
|
||||
expected := []byte(fmt.Sprintf("bank/fwd/%#016p", cap))
|
||||
require.Equal(t, expected, types.FwdCapabilityKey("bank", cap))
|
||||
}
|
||||
|
||||
func TestIndexToKey(t *testing.T) {
|
||||
require.Equal(t, []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc, 0x5a}, types.IndexToKey(3162))
|
||||
}
|
||||
|
||||
func TestIndexFromKey(t *testing.T) {
|
||||
require.Equal(t, uint64(3162), types.IndexFromKey([]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc, 0x5a}))
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"cosmossdk.io/errors"
|
||||
)
|
||||
|
||||
// NewCapability returns a reference to a new Capability to be used as an
|
||||
// actual capability.
|
||||
func NewCapability(index uint64) *Capability {
|
||||
return &Capability{Index: index}
|
||||
}
|
||||
|
||||
func NewOwner(module, name string) Owner {
|
||||
return Owner{Module: module, Name: name}
|
||||
}
|
||||
|
||||
// Key returns a composite key for an Owner.
|
||||
func (o Owner) Key() string {
|
||||
return fmt.Sprintf("%s/%s", o.Module, o.Name)
|
||||
}
|
||||
|
||||
func NewCapabilityOwners() *CapabilityOwners {
|
||||
return &CapabilityOwners{Owners: make([]Owner, 0)}
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (co *CapabilityOwners) Set(owner Owner) error {
|
||||
i, ok := co.Get(owner)
|
||||
if ok {
|
||||
// owner already exists at co.Owners[i]
|
||||
return errors.Wrapf(ErrOwnerClaimed, owner.String())
|
||||
}
|
||||
|
||||
// owner does not exist in the set of owners, so we insert at position i
|
||||
co.Owners = append(co.Owners, Owner{}) // expand by 1 in amortized O(1) / O(n) worst case
|
||||
copy(co.Owners[i+1:], co.Owners[i:])
|
||||
co.Owners[i] = owner
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove removes a provided owner from the CapabilityOwners if it exists. If the
|
||||
// owner does not exist, Remove is considered a no-op.
|
||||
func (co *CapabilityOwners) Remove(owner Owner) {
|
||||
if len(co.Owners) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
i, ok := co.Get(owner)
|
||||
if ok {
|
||||
// owner exists at co.Owners[i]
|
||||
co.Owners = append(co.Owners[:i], co.Owners[i+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (co *CapabilityOwners) Get(owner Owner) (int, bool) {
|
||||
// find smallest index s.t. co.Owners[i] >= owner in O(log n) time
|
||||
i := sort.Search(len(co.Owners), func(i int) bool { return co.Owners[i].Key() >= owner.Key() })
|
||||
if i < len(co.Owners) && co.Owners[i].Key() == owner.Key() {
|
||||
// owner exists at co.Owners[i]
|
||||
return i, true
|
||||
}
|
||||
|
||||
return i, false
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
)
|
||||
|
||||
func TestCapabilityKey(t *testing.T) {
|
||||
idx := uint64(3162)
|
||||
cap := types.NewCapability(idx)
|
||||
require.Equal(t, idx, cap.GetIndex())
|
||||
require.Equal(t, fmt.Sprintf("index:%d", idx), strings.TrimSpace(cap.String()))
|
||||
}
|
||||
|
||||
func TestOwner(t *testing.T) {
|
||||
o := types.NewOwner("bank", "send")
|
||||
require.Equal(t, "bank/send", o.Key())
|
||||
require.Equal(t, "module:\"bank\" name:\"send\" ", o.String())
|
||||
}
|
||||
|
||||
func TestCapabilityOwners_Set(t *testing.T) {
|
||||
co := types.NewCapabilityOwners()
|
||||
|
||||
owners := make([]types.Owner, 1024)
|
||||
for i := range owners {
|
||||
var owner types.Owner
|
||||
|
||||
if i%2 == 0 {
|
||||
owner = types.NewOwner("bank", fmt.Sprintf("send-%d", i))
|
||||
} else {
|
||||
owner = types.NewOwner("slashing", fmt.Sprintf("slash-%d", i))
|
||||
}
|
||||
|
||||
owners[i] = owner
|
||||
require.NoError(t, co.Set(owner))
|
||||
}
|
||||
|
||||
sort.Slice(owners, func(i, j int) bool { return owners[i].Key() < owners[j].Key() })
|
||||
require.Equal(t, owners, co.Owners)
|
||||
|
||||
for _, owner := range owners {
|
||||
require.Error(t, co.Set(owner))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCapabilityOwners_Remove(t *testing.T) {
|
||||
co := types.NewCapabilityOwners()
|
||||
|
||||
co.Remove(types.NewOwner("bank", "send-0"))
|
||||
require.Len(t, co.Owners, 0)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
require.NoError(t, co.Set(types.NewOwner("bank", fmt.Sprintf("send-%d", i))))
|
||||
}
|
||||
|
||||
require.Len(t, co.Owners, 5)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
co.Remove(types.NewOwner("bank", fmt.Sprintf("send-%d", i)))
|
||||
require.Len(t, co.Owners, 5-(i+1))
|
||||
}
|
||||
|
||||
require.Len(t, co.Owners, 0)
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
||||
return types.ValidateGenesis(&data)
|
||||
}
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the capability module.
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the crisis module.
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {}
|
||||
|
||||
// GetTxCmd returns the root tx command for the crisis module.
|
||||
|
||||
2
x/genutil/types/testdata/app_genesis.json
vendored
2
x/genutil/types/testdata/app_genesis.json
vendored
File diff suppressed because one or more lines are too long
2
x/genutil/types/testdata/cmt_genesis.json
vendored
2
x/genutil/types/testdata/cmt_genesis.json
vendored
File diff suppressed because one or more lines are too long
@ -246,8 +246,6 @@ module_versions:
|
||||
version: "1"
|
||||
- name: bank
|
||||
version: "2"
|
||||
- name: capability
|
||||
version: "1"
|
||||
- name: crisis
|
||||
version: "1"
|
||||
- name: distribution
|
||||
@ -412,10 +410,6 @@ Example Output:
|
||||
"name": "bank",
|
||||
"version": "2"
|
||||
},
|
||||
{
|
||||
"name": "capability",
|
||||
"version": "1"
|
||||
},
|
||||
{
|
||||
"name": "crisis",
|
||||
"version": "1"
|
||||
@ -558,10 +552,6 @@ Example Output:
|
||||
"name": "bank",
|
||||
"version": "2"
|
||||
},
|
||||
{
|
||||
"name": "capability",
|
||||
"version": "1"
|
||||
},
|
||||
{
|
||||
"name": "crisis",
|
||||
"version": "1"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user