router

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeConnectionError = iota + 100
	CodeServerError
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GetAddressFn

type GetAddressFn func(
	ctx context.Context,
	request *namespacetypes.AddressRequest,
) (*namespacetypes.AddressResponse, error)

type GetQueryCtxFn

type GetQueryCtxFn func(height int64, prove bool) (sdk.Context, error)

type Option

type Option func(r *routerImpl)

func WithRouterKey added in v1.1.0

func WithRouterKey(key string) Option

WithRouterKey sets the router routerKey for the game shard <> base shard communications.

type Result

type Result struct {
	*routerv1.SendMessageResponse
	// contains filtered or unexported fields
}

type ResultStorage

type ResultStorage interface {
	Result(key string) (Result, bool)
	SetResult(msg *routerv1.SendMessageResponse)
}

func NewMemoryResultStorage

func NewMemoryResultStorage(keepAlive time.Duration) ResultStorage

type Router

type Router interface {
	// SendMessage queues a message to be sent to a game shard.
	SendMessage(_ context.Context, personaTag, namespace, sender, msgID string, msg []byte) error
	// Query queries a game shard.
	Query(ctx context.Context, request []byte, resource, namespace string) ([]byte, error)
	// MessageResult gets the game shard transaction Result that originated from an EVM tx.
	MessageResult(_ context.Context, evmTxHash string) ([]byte, string, uint32, error)
	// PostBlockHook is a custom hook function that is executed in Polaris after a block is formed. This is ONLY
	// available via our custom fork of Polaris. This function works by iterating over all the transactions and checking
	// if we have any matches currently in the queue. Two conditions need to be met to fire off a transaction:
	//
	// 1. The transaction's `To` address is in the queue. This is because, within the precompile, msg.sender is likely
	// the address of the contract that the user wrote to interact with the router/cardinal system. Thus, if their
	// contract addr is 0xFoo, then msg.sender in the context of the precompile will be 0xFoo, and the user calling the
	// contract will have the `To` address of the transaction be 0xFoo.
	//
	// 2. The transaction was actually successful. We don't want to fire off the cross-shard transaction if their EVM
	// transaction reverted.
	//
	// There are problems with this approach, however. The tie between what's in the queue and an EVM transaction is
	// incredibly weak. It would be better if we had access to tx_hash in the precompile, as this can uniquely identify
	// an EVM transaction. Consider a user who calls the contract 0xFoo two times in one block. How do we know which
	// one called the Router? TODO: work with polaris to find a solution to this problem.
	PostBlockHook(ethtypes.Transactions, ethtypes.Receipts, ethtypes.Signer)
}

Router defines the methods required to interact with a game shard. The methods are invoked from EVM smart contracts.

func NewRouter

func NewRouter(logger log.Logger, ctxGetter GetQueryCtxFn, addrGetter GetAddressFn, opts ...Option) Router

NewRouter returns a Router.

Jump to

Keyboard shortcuts

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