types

package
v0.0.0-beta.0 Latest Latest
Warning

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

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

Documentation

Overview

Package types is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (
	// ModuleName is the name of the module.
	ModuleName = "incentives"
	// StoreKey is the store key string for incentives.
	StoreKey = ModuleName
)

Variables

View Source
var (
	ErrInvalidLengthGenesis        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowGenesis          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	// KeyPrefixIncentive is the root key prefix under which all incentives are stored.
	KeyPrefixIncentive = []byte{keyPrefixIncentive}
	// KeyPrefixCount is the key prefix used to index incentives.
	KeyPrefixCount = []byte{keyPrefixCount}
)
View Source
var (
	ErrInvalidLengthQuery        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowQuery          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group")
)

Functions

func GetIncentiveCountKey

func GetIncentiveCountKey(incentive Incentive) []byte

GetIncentiveCountKey gets the store key for the incentive count.

func GetIncentiveKey

func GetIncentiveKey(incentive Incentive) []byte

GetIncentiveKey gets the store key for an incentive.

func GetIncentiveKeyWithIndex

func GetIncentiveKeyWithIndex(incentive Incentive, index uint64) []byte

GetIncentiveKeyWithIndex gets the store key for an incentive with an index.

func IncentivesToBytes

func IncentivesToBytes(incentives ...Incentive) ([][]byte, error)

IncentivesToBytes converts a slice of Incentives to a slice of bytes.

func RegisterQueryHandler

func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterQueryHandler registers the http handlers for service Query to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterQueryHandlerClient

func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error

RegisterQueryHandlerClient registers the http handlers for service Query to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "QueryClient" to call the correct interceptors.

func RegisterQueryHandlerFromEndpoint

func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterQueryHandlerServer

func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error

RegisterQueryHandlerServer registers the http handlers for service Query to "mux". UnaryRPC :call QueryServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.

func RegisterQueryServer

func RegisterQueryServer(s grpc1.Server, srv QueryServer)

Types

type GenesisState

type GenesisState struct {
	// Registry is a list of incentives by type. The registry defined here
	// should be a subset of the incentive types defined in the incentive
	// module (keeper).
	Registry []IncentivesByType `protobuf:"bytes,1,rep,name=registry,proto3" json:"registry"`
}

GenesisState is the genesis-state for the x/incentives module.

func GetGenesisStateFromAppState

func GetGenesisStateFromAppState(cdc codec.Codec, appState map[string]json.RawMessage) GenesisState

GetGenesisStateFromAppState returns x/incentives GenesisState given raw application genesis state.

func NewDefaultGenesisState

func NewDefaultGenesisState() *GenesisState

NewDefaultGenesisState returns a default genesis state for the module.

func NewGenesisState

func NewGenesisState(incentives []IncentivesByType) *GenesisState

NewGenesisState returns a new genesis state for the module.

func (*GenesisState) Descriptor

func (*GenesisState) Descriptor() ([]byte, []int)

func (*GenesisState) GetRegistry

func (m *GenesisState) GetRegistry() []IncentivesByType

func (*GenesisState) Marshal

func (m *GenesisState) Marshal() (dAtA []byte, err error)

func (*GenesisState) MarshalTo

func (m *GenesisState) MarshalTo(dAtA []byte) (int, error)

func (*GenesisState) MarshalToSizedBuffer

func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GenesisState) ProtoMessage

func (*GenesisState) ProtoMessage()

func (*GenesisState) Reset

func (m *GenesisState) Reset()

func (*GenesisState) Size

func (m *GenesisState) Size() (n int)

func (*GenesisState) String

func (m *GenesisState) String() string

func (*GenesisState) Unmarshal

func (m *GenesisState) Unmarshal(dAtA []byte) error

func (GenesisState) ValidateBasic

func (gs GenesisState) ValidateBasic() error

ValidateBasic performs basic validation of the genesis state data returning an error for any failed validation criteria.

func (*GenesisState) XXX_DiscardUnknown

func (m *GenesisState) XXX_DiscardUnknown()

func (*GenesisState) XXX_Marshal

func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GenesisState) XXX_Merge

func (m *GenesisState) XXX_Merge(src proto.Message)

func (*GenesisState) XXX_Size

func (m *GenesisState) XXX_Size() int

func (*GenesisState) XXX_Unmarshal

func (m *GenesisState) XXX_Unmarshal(b []byte) error

type GetAllIncentivesRequest

type GetAllIncentivesRequest struct {
}

GetAllIncentivesRequest is the request type for the Query/GetAllIncentives RPC method.

func (*GetAllIncentivesRequest) Descriptor

func (*GetAllIncentivesRequest) Descriptor() ([]byte, []int)

func (*GetAllIncentivesRequest) Marshal

func (m *GetAllIncentivesRequest) Marshal() (dAtA []byte, err error)

func (*GetAllIncentivesRequest) MarshalTo

func (m *GetAllIncentivesRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetAllIncentivesRequest) MarshalToSizedBuffer

func (m *GetAllIncentivesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetAllIncentivesRequest) ProtoMessage

func (*GetAllIncentivesRequest) ProtoMessage()

func (*GetAllIncentivesRequest) Reset

func (m *GetAllIncentivesRequest) Reset()

func (*GetAllIncentivesRequest) Size

func (m *GetAllIncentivesRequest) Size() (n int)

func (*GetAllIncentivesRequest) String

func (m *GetAllIncentivesRequest) String() string

func (*GetAllIncentivesRequest) Unmarshal

func (m *GetAllIncentivesRequest) Unmarshal(dAtA []byte) error

func (*GetAllIncentivesRequest) XXX_DiscardUnknown

func (m *GetAllIncentivesRequest) XXX_DiscardUnknown()

func (*GetAllIncentivesRequest) XXX_Marshal

func (m *GetAllIncentivesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetAllIncentivesRequest) XXX_Merge

func (m *GetAllIncentivesRequest) XXX_Merge(src proto.Message)

func (*GetAllIncentivesRequest) XXX_Size

func (m *GetAllIncentivesRequest) XXX_Size() int

func (*GetAllIncentivesRequest) XXX_Unmarshal

func (m *GetAllIncentivesRequest) XXX_Unmarshal(b []byte) error

type GetAllIncentivesResponse

type GetAllIncentivesResponse struct {
	// Registry is the list of all incentives, grouped by type.
	Registry []IncentivesByType `protobuf:"bytes,1,rep,name=registry,proto3" json:"registry"`
}

GetAllIncentivesResponse is the response type for the Query/GetAllIncentives RPC method.

func (*GetAllIncentivesResponse) Descriptor

func (*GetAllIncentivesResponse) Descriptor() ([]byte, []int)

func (*GetAllIncentivesResponse) GetRegistry

func (m *GetAllIncentivesResponse) GetRegistry() []IncentivesByType

func (*GetAllIncentivesResponse) Marshal

func (m *GetAllIncentivesResponse) Marshal() (dAtA []byte, err error)

func (*GetAllIncentivesResponse) MarshalTo

func (m *GetAllIncentivesResponse) MarshalTo(dAtA []byte) (int, error)

func (*GetAllIncentivesResponse) MarshalToSizedBuffer

func (m *GetAllIncentivesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetAllIncentivesResponse) ProtoMessage

func (*GetAllIncentivesResponse) ProtoMessage()

func (*GetAllIncentivesResponse) Reset

func (m *GetAllIncentivesResponse) Reset()

func (*GetAllIncentivesResponse) Size

func (m *GetAllIncentivesResponse) Size() (n int)

func (*GetAllIncentivesResponse) String

func (m *GetAllIncentivesResponse) String() string

func (*GetAllIncentivesResponse) Unmarshal

func (m *GetAllIncentivesResponse) Unmarshal(dAtA []byte) error

func (*GetAllIncentivesResponse) XXX_DiscardUnknown

func (m *GetAllIncentivesResponse) XXX_DiscardUnknown()

func (*GetAllIncentivesResponse) XXX_Marshal

func (m *GetAllIncentivesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetAllIncentivesResponse) XXX_Merge

func (m *GetAllIncentivesResponse) XXX_Merge(src proto.Message)

func (*GetAllIncentivesResponse) XXX_Size

func (m *GetAllIncentivesResponse) XXX_Size() int

func (*GetAllIncentivesResponse) XXX_Unmarshal

func (m *GetAllIncentivesResponse) XXX_Unmarshal(b []byte) error

type GetIncentivesByTypeRequest

type GetIncentivesByTypeRequest struct {
	// IncentiveType is the incentive type i.e. (BadPriceIncentiveType, GoodPriceIncentiveType).
	IncentiveType string `protobuf:"bytes,1,opt,name=incentive_type,json=incentiveType,proto3" json:"incentive_type,omitempty"`
}

GetIncentivesByTypeRequest is the request type for the Query/GetIncentivesByType RPC method.

func (*GetIncentivesByTypeRequest) Descriptor

func (*GetIncentivesByTypeRequest) Descriptor() ([]byte, []int)

func (*GetIncentivesByTypeRequest) GetIncentiveType

func (m *GetIncentivesByTypeRequest) GetIncentiveType() string

func (*GetIncentivesByTypeRequest) Marshal

func (m *GetIncentivesByTypeRequest) Marshal() (dAtA []byte, err error)

func (*GetIncentivesByTypeRequest) MarshalTo

func (m *GetIncentivesByTypeRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetIncentivesByTypeRequest) MarshalToSizedBuffer

func (m *GetIncentivesByTypeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetIncentivesByTypeRequest) ProtoMessage

func (*GetIncentivesByTypeRequest) ProtoMessage()

func (*GetIncentivesByTypeRequest) Reset

func (m *GetIncentivesByTypeRequest) Reset()

func (*GetIncentivesByTypeRequest) Size

func (m *GetIncentivesByTypeRequest) Size() (n int)

func (*GetIncentivesByTypeRequest) String

func (m *GetIncentivesByTypeRequest) String() string

func (*GetIncentivesByTypeRequest) Unmarshal

func (m *GetIncentivesByTypeRequest) Unmarshal(dAtA []byte) error

func (*GetIncentivesByTypeRequest) XXX_DiscardUnknown

func (m *GetIncentivesByTypeRequest) XXX_DiscardUnknown()

func (*GetIncentivesByTypeRequest) XXX_Marshal

func (m *GetIncentivesByTypeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetIncentivesByTypeRequest) XXX_Merge

func (m *GetIncentivesByTypeRequest) XXX_Merge(src proto.Message)

func (*GetIncentivesByTypeRequest) XXX_Size

func (m *GetIncentivesByTypeRequest) XXX_Size() int

func (*GetIncentivesByTypeRequest) XXX_Unmarshal

func (m *GetIncentivesByTypeRequest) XXX_Unmarshal(b []byte) error

type GetIncentivesByTypeResponse

type GetIncentivesByTypeResponse struct {
	// Entries is the list of incentives of the given type.
	Entries [][]byte `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries,omitempty"`
}

GetIncentivesByTypeResponse is the response type for the Query/GetIncentivesByType RPC method.

func (*GetIncentivesByTypeResponse) Descriptor

func (*GetIncentivesByTypeResponse) Descriptor() ([]byte, []int)

func (*GetIncentivesByTypeResponse) GetEntries

func (m *GetIncentivesByTypeResponse) GetEntries() [][]byte

func (*GetIncentivesByTypeResponse) Marshal

func (m *GetIncentivesByTypeResponse) Marshal() (dAtA []byte, err error)

func (*GetIncentivesByTypeResponse) MarshalTo

func (m *GetIncentivesByTypeResponse) MarshalTo(dAtA []byte) (int, error)

func (*GetIncentivesByTypeResponse) MarshalToSizedBuffer

func (m *GetIncentivesByTypeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetIncentivesByTypeResponse) ProtoMessage

func (*GetIncentivesByTypeResponse) ProtoMessage()

func (*GetIncentivesByTypeResponse) Reset

func (m *GetIncentivesByTypeResponse) Reset()

func (*GetIncentivesByTypeResponse) Size

func (m *GetIncentivesByTypeResponse) Size() (n int)

func (*GetIncentivesByTypeResponse) String

func (m *GetIncentivesByTypeResponse) String() string

func (*GetIncentivesByTypeResponse) Unmarshal

func (m *GetIncentivesByTypeResponse) Unmarshal(dAtA []byte) error

func (*GetIncentivesByTypeResponse) XXX_DiscardUnknown

func (m *GetIncentivesByTypeResponse) XXX_DiscardUnknown()

func (*GetIncentivesByTypeResponse) XXX_Marshal

func (m *GetIncentivesByTypeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetIncentivesByTypeResponse) XXX_Merge

func (m *GetIncentivesByTypeResponse) XXX_Merge(src proto.Message)

func (*GetIncentivesByTypeResponse) XXX_Size

func (m *GetIncentivesByTypeResponse) XXX_Size() int

func (*GetIncentivesByTypeResponse) XXX_Unmarshal

func (m *GetIncentivesByTypeResponse) XXX_Unmarshal(b []byte) error

type Incentive

type Incentive interface {
	proto.Message

	// ValidateBasic does a stateless check on the incentive.
	ValidateBasic() error

	// Type returns the incentive type.
	Type() string

	// Marshall the incentive into bytes.
	Marshal() ([]byte, error)

	// Unmarshal the incentive from bytes.
	Unmarshal([]byte) error

	// Copy the incentive.
	Copy() Incentive
}

Incentive is the interface contract that must be fulfilled to allow for slashing/rewarding arbitrary events. To add a new incentive, implement this interface along with the corresponding strategy callback function. Each incentive type must be registered with its corresponding strategy function in the keeper.

func SortIncentivesByType

func SortIncentivesByType(incentives []Incentive) []Incentive

SortIncentivesByType sorts a slice of Incentives by their type.

func SortIncentivesStrategiesMap

func SortIncentivesStrategiesMap(incentiveStrategies map[Incentive]Strategy) []Incentive

SortIncentivesStrategiesMap sorts a map of IncentivesByType by their type.

type IncentivesByType

type IncentivesByType struct {
	// IncentiveType is the incentive type i.e. (BadPriceIncentiveType, GoodPriceIncentiveType).
	IncentiveType string `protobuf:"bytes,1,opt,name=incentive_type,json=incentiveType,proto3" json:"incentive_type,omitempty"`
	// Entries is a list of incentive bytes.
	Entries [][]byte `protobuf:"bytes,2,rep,name=entries,proto3" json:"entries,omitempty"`
}

IncentivesByType encapsulates a list of incentives by type. Each of the entries here must correspond to the same incentive type defined here.

func NewIncentives

func NewIncentives(name string, incentives [][]byte) IncentivesByType

NewIncentives returns a new Incentives instance.

func (*IncentivesByType) Descriptor

func (*IncentivesByType) Descriptor() ([]byte, []int)

func (*IncentivesByType) GetEntries

func (m *IncentivesByType) GetEntries() [][]byte

func (*IncentivesByType) GetIncentiveType

func (m *IncentivesByType) GetIncentiveType() string

func (*IncentivesByType) Marshal

func (m *IncentivesByType) Marshal() (dAtA []byte, err error)

func (*IncentivesByType) MarshalTo

func (m *IncentivesByType) MarshalTo(dAtA []byte) (int, error)

func (*IncentivesByType) MarshalToSizedBuffer

func (m *IncentivesByType) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*IncentivesByType) ProtoMessage

func (*IncentivesByType) ProtoMessage()

func (*IncentivesByType) Reset

func (m *IncentivesByType) Reset()

func (*IncentivesByType) Size

func (m *IncentivesByType) Size() (n int)

func (*IncentivesByType) String

func (m *IncentivesByType) String() string

func (*IncentivesByType) Unmarshal

func (m *IncentivesByType) Unmarshal(dAtA []byte) error

func (IncentivesByType) ValidateBasic

func (i IncentivesByType) ValidateBasic() error

ValidateBasic performs basic validation of the Incentives data returning an error for any failed validation criteria.

func (*IncentivesByType) XXX_DiscardUnknown

func (m *IncentivesByType) XXX_DiscardUnknown()

func (*IncentivesByType) XXX_Marshal

func (m *IncentivesByType) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*IncentivesByType) XXX_Merge

func (m *IncentivesByType) XXX_Merge(src proto.Message)

func (*IncentivesByType) XXX_Size

func (m *IncentivesByType) XXX_Size() int

func (*IncentivesByType) XXX_Unmarshal

func (m *IncentivesByType) XXX_Unmarshal(b []byte) error

type QueryClient

type QueryClient interface {
	// GetIncentivesByType returns all incentives of a given type. If the type is
	// not registered with the module, an error is returned.
	GetIncentivesByType(ctx context.Context, in *GetIncentivesByTypeRequest, opts ...grpc.CallOption) (*GetIncentivesByTypeResponse, error)
	// GetAllIncentives returns all incentives.
	GetAllIncentives(ctx context.Context, in *GetAllIncentivesRequest, opts ...grpc.CallOption) (*GetAllIncentivesResponse, error)
}

QueryClient is the client API for Query service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewQueryClient

func NewQueryClient(cc grpc1.ClientConn) QueryClient

type QueryServer

type QueryServer interface {
	// GetIncentivesByType returns all incentives of a given type. If the type is
	// not registered with the module, an error is returned.
	GetIncentivesByType(context.Context, *GetIncentivesByTypeRequest) (*GetIncentivesByTypeResponse, error)
	// GetAllIncentives returns all incentives.
	GetAllIncentives(context.Context, *GetAllIncentivesRequest) (*GetAllIncentivesResponse, error)
}

QueryServer is the server API for Query service.

type Strategy

type Strategy func(ctx sdk.Context, incentive Incentive) (updatedIncentive Incentive, err error)

Strategy defines the callback function that will be executed by the incentives module with the given context and incentive. The strategy is responsible for the following:

  1. If the strategy desires to update the incentive, it must return the updated incentive.
  2. If the strategy desires to delete the incentive, it must return nil.
  3. If the strategy desires to leave the incentive unchanged, it must return the same incentive.
  4. Applying any desired state transitions such as minting rewards, or slashing.

For an example implementation, please see the examples/ directory.

type UnimplementedQueryServer

type UnimplementedQueryServer struct {
}

UnimplementedQueryServer can be embedded to have forward compatible implementations.

func (*UnimplementedQueryServer) GetAllIncentives

func (*UnimplementedQueryServer) GetIncentivesByType

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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