chains

package
v0.0.1-rc2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeChainTypeHook

func DecodeChainTypeHook(from reflect.Type, to reflect.Type, data interface{}) (interface{}, error)

DecodeChainTypeHook decode hook to convert strings to ChainType

Types

type BaseChainProvider

type BaseChainProvider struct {
	Config    ChainProviderConfig
	ChainName string
	ChainID   string
	// contains filtered or unexported fields
}

BaseChainProvider is a base object for connecting with the chain network.

type BaseChainProviderConfig

type BaseChainProviderConfig struct {
	Endpoints      []string      `mapstructure:"endpoints"       toml:"endpoints"`
	ChainType      ChainType     `mapstructure:"chain_type"      toml:"chain_type"`
	MaxRetry       int           `mapstructure:"max_retry"       toml:"max_retry"`
	QueryTimeout   time.Duration `mapstructure:"query_timeout"   toml:"query_timeout"`
	ExecuteTimeout time.Duration `mapstructure:"execute_timeout" toml:"execute_timeout"`
	ChainID        uint64        `mapstructure:"chain_id"        toml:"chain_id"`

	TunnelRouterAddress string `mapstructure:"tunnel_router_address" toml:"tunnel_router_address"`
}

BaseChainProviderConfig contains common field for particular chain provider.

type ChainProvider

type ChainProvider interface {
	KeyProvider
	// Init initialize to the chain.
	Init(ctx context.Context) error

	// QueryTunnelInfo queries the tunnel information from the destination chain.
	QueryTunnelInfo(
		ctx context.Context,
		tunnelID uint64,
		tunnelDestinationAddr string,
	) (*chainstypes.Tunnel, error)

	// RelayPacket relays the packet from the source chain to the destination chain.
	RelayPacket(ctx context.Context, packet *bandtypes.Packet) error

	// QueryBalance queries balance by given key name from the destination chain.
	QueryBalance(ctx context.Context, keyName string) (*big.Int, error)

	// GetChainName retrieves the chain name from the chain provider.
	GetChainName() string
}

ChainProvider defines the interface for the chain interaction with the destination chain.

type ChainProviderConfig

type ChainProviderConfig interface {
	NewChainProvider(
		chainName string,
		log *zap.Logger,
		debug bool,
		wallet wallet.Wallet,
	) (ChainProvider, error)

	GetChainType() ChainType
	Validate() error
}

ChainProviderConfig defines the interface for creating a chain provider object.

type ChainProviderConfigs

type ChainProviderConfigs map[string]ChainProviderConfig

ChainProviderConfigs is a collection of ChainProviderConfig interfaces (mapped by chainName)

type ChainProviders

type ChainProviders map[string]ChainProvider

ChainProviders is a collection of ChainProvider interfaces (mapped by chainName)

type ChainType

type ChainType int

ChainType represents the type of chain.

const (
	ChainTypeUndefined ChainType = iota
	ChainTypeEVM
)

func ToChainType

func ToChainType(s string) ChainType

ToChainType converts a string to a ChainType.

func (ChainType) MarshalText

func (c ChainType) MarshalText() ([]byte, error)

MarshalText is used for toml encoding.

func (ChainType) String

func (c ChainType) String() string

String returns the string representation of the ChainType.

func (*ChainType) UnmarshalText

func (c *ChainType) UnmarshalText(text []byte) error

UnmarshalText is used for toml decoding.

type Client

type Client interface {
	// GetNonce returns the nonce of the given address
	GetNonce(address string) (uint64, error)

	// BroadcastTx broadcasts the given raw transaction
	BroadcastTx(rawTx string) (string, error)

	// GetBalances returns the balances of the given accounts
	GetBalances(accounts []string) ([]*big.Int, error)

	// GetTunnelNonce returns the nonce of the given tunnel
	GetTunnelNonce(targetAddress string, tunnelID uint64) (uint64, error)
}

Client defines the interface for the target chain client

type KeyProvider

type KeyProvider interface {
	// AddKeyByMnemonic adds a key using a mnemonic phrase.
	AddKeyByMnemonic(
		keyName string,
		mnemonic string,
		coinType uint32,
		account uint,
		index uint,
	) (*chainstypes.Key, error)

	// AddKeyByPrivateKey adds a key using a private key.
	AddKeyByPrivateKey(keyName string, privateKeyHex string) (*chainstypes.Key, error)

	// DeleteKey deletes the key information and private key
	DeleteKey(keyName string) error

	// ExportPrivateKey exports private key of specified key name.
	ExportPrivateKey(keyName string) (string, error)

	// ListKeys lists all keys
	ListKeys() []*chainstypes.Key

	// ShowKey shows the address of the given key
	ShowKey(keyName string) (string, error)

	// LoadFreeSenders loads key info to prepare to relay the packet
	LoadFreeSenders() error
}

KeyProvider defines the interface for the key interaction with destination chain

type Registry

type Registry struct {
	Chains map[string]Client
}

Registry is a collection of chain clients.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new chain registry.

func (*Registry) Register

func (r *Registry) Register(chainID string, client Client) error

Register registers a chain client to the registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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