types

package
v7.0.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SubModuleName defines the IBC port name
	SubModuleName = "port"

	// StoreKey is the store key string for IBC ports
	StoreKey = SubModuleName

	// RouterKey is the message route for IBC ports
	RouterKey = SubModuleName

	// QuerierRoute is the querier route for IBC ports
	QuerierRoute = SubModuleName
)

Variables

View Source
var (
	ErrPortExists   = errorsmod.Register(SubModuleName, 2, "port is already binded")
	ErrPortNotFound = errorsmod.Register(SubModuleName, 3, "port not found")
	ErrInvalidPort  = errorsmod.Register(SubModuleName, 4, "invalid port")
	ErrInvalidRoute = errorsmod.Register(SubModuleName, 5, "route not found")
)

IBC port sentinel errors

Functions

func GetModuleOwner

func GetModuleOwner(modules []string) string

GetModuleOwner enforces that only IBC and the module bound to port can own the capability while future implementations may allow multiple modules to bind to a port, currently we only allow one module to be bound to a port at any given time

Types

type IBCModule

type IBCModule interface {
	// OnChanOpenInit will verify that the relayer-chosen parameters
	// are valid and perform any custom INIT logic.
	// It may return an error if the chosen parameters are invalid
	// in which case the handshake is aborted.
	// If the provided version string is non-empty, OnChanOpenInit should return
	// the version string if valid or an error if the provided version is invalid.
	// If the version string is empty, OnChanOpenInit is expected to
	// return a default version string representing the version(s) it supports.
	// If there is no default version string for the application,
	// it should return an error if provided version is empty string.
	OnChanOpenInit(
		ctx sdk.Context,
		order channeltypes.Order,
		connectionHops []string,
		portID string,
		channelID string,
		channelCap *capabilitytypes.Capability,
		counterparty channeltypes.Counterparty,
		version string,
	) (string, error)

	// OnChanOpenTry will verify the relayer-chosen parameters along with the
	// counterparty-chosen version string and perform custom TRY logic.
	// If the relayer-chosen parameters are invalid, the callback must return
	// an error to abort the handshake. If the counterparty-chosen version is not
	// compatible with this modules supported versions, the callback must return
	// an error to abort the handshake. If the versions are compatible, the try callback
	// must select the final version string and return it to core IBC.
	// OnChanOpenTry may also perform custom initialization logic
	OnChanOpenTry(
		ctx sdk.Context,
		order channeltypes.Order,
		connectionHops []string,
		portID,
		channelID string,
		channelCap *capabilitytypes.Capability,
		counterparty channeltypes.Counterparty,
		counterpartyVersion string,
	) (version string, err error)

	// OnChanOpenAck will error if the counterparty selected version string
	// is invalid to abort the handshake. It may also perform custom ACK logic.
	OnChanOpenAck(
		ctx sdk.Context,
		portID,
		channelID string,
		counterpartyChannelID string,
		counterpartyVersion string,
	) error

	// OnChanOpenConfirm will perform custom CONFIRM logic and may error to abort the handshake.
	OnChanOpenConfirm(
		ctx sdk.Context,
		portID,
		channelID string,
	) error

	OnChanCloseInit(
		ctx sdk.Context,
		portID,
		channelID string,
	) error

	OnChanCloseConfirm(
		ctx sdk.Context,
		portID,
		channelID string,
	) error

	// OnRecvPacket must return an acknowledgement that implements the Acknowledgement interface.
	// In the case of an asynchronous acknowledgement, nil should be returned.
	// If the acknowledgement returned is successful, the state changes on callback are written,
	// otherwise the application state changes are discarded. In either case the packet is received
	// and the acknowledgement is written (in synchronous cases).
	OnRecvPacket(
		ctx sdk.Context,
		packet channeltypes.Packet,
		relayer sdk.AccAddress,
	) exported.Acknowledgement

	OnAcknowledgementPacket(
		ctx sdk.Context,
		packet channeltypes.Packet,
		acknowledgement []byte,
		relayer sdk.AccAddress,
	) error

	OnTimeoutPacket(
		ctx sdk.Context,
		packet channeltypes.Packet,
		relayer sdk.AccAddress,
	) error
}

IBCModule defines an interface that implements all the callbacks that modules must define as specified in ICS-26

type ICS4Wrapper

type ICS4Wrapper interface {
	SendPacket(
		ctx sdk.Context,
		chanCap *capabilitytypes.Capability,
		sourcePort string,
		sourceChannel string,
		timeoutHeight clienttypes.Height,
		timeoutTimestamp uint64,
		data []byte,
	) (sequence uint64, err error)

	WriteAcknowledgement(
		ctx sdk.Context,
		chanCap *capabilitytypes.Capability,
		packet exported.PacketI,
		ack exported.Acknowledgement,
	) error

	GetAppVersion(
		ctx sdk.Context,
		portID,
		channelID string,
	) (string, bool)
}

ICS4Wrapper implements the ICS4 interfaces that IBC applications use to send packets and acknowledgements.

type Middleware

type Middleware interface {
	IBCModule
	ICS4Wrapper
}

Middleware must implement IBCModule to wrap communication from core IBC to underlying application and ICS4Wrapper to wrap communication from underlying application to core IBC.

type Router

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

The router is a map from module name to the IBCModule which contains all the module-defined callbacks required by ICS-26

func NewRouter

func NewRouter() *Router

func (*Router) AddRoute

func (rtr *Router) AddRoute(module string, cbs IBCModule) *Router

AddRoute adds IBCModule for a given module name. It returns the Router so AddRoute calls can be linked. It will panic if the Router is sealed.

func (*Router) GetRoute

func (rtr *Router) GetRoute(module string) (IBCModule, bool)

GetRoute returns a IBCModule for a given module.

func (*Router) HasRoute

func (rtr *Router) HasRoute(module string) bool

HasRoute returns true if the Router has a module registered or false otherwise.

func (*Router) Seal

func (rtr *Router) Seal()

Seal prevents the Router from any subsequent route handlers to be registered. Seal will panic if called more than once.

func (Router) Sealed

func (rtr Router) Sealed() bool

Sealed returns a boolean signifying if the Router is sealed or not.

Jump to

Keyboard shortcuts

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