chainlib

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextUserValueKeyDappID = "dappID"
	RetryListeningInterval    = 10 // seconds
)
View Source
const (
	TendermintStatusQuery = "status"
)

Variables

This section is empty.

Functions

func GetApiInterfaceFromServiceApi added in v0.9.0

func GetApiInterfaceFromServiceApi(serviceApi *spectypes.ServiceApi, connectionType string) *spectypes.ApiInterface

func GetListenerWithRetryGrpc

func GetListenerWithRetryGrpc(protocol string, addr string) net.Listener

func ListenWithRetry

func ListenWithRetry(app *fiber.App, address string)

Types

type BaseChainParser

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

func (*BaseChainParser) GetSpecApiByTag added in v0.9.0

func (bcp *BaseChainParser) GetSpecApiByTag(tag string) (spectypes.ServiceApi, bool)

func (*BaseChainParser) SetTaggedApis added in v0.9.0

func (bcp *BaseChainParser) SetTaggedApis(taggedApis map[string]spectypes.ServiceApi)

type BaseChainProxy

type BaseChainProxy struct {
	NodeUrl common.NodeUrl
	// contains filtered or unexported fields
}

type ChainFetcher

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

func NewChainFetcher

func NewChainFetcher(ctx context.Context, chainProxy ChainProxy, chainParser ChainParser, endpoint *lavasession.RPCProviderEndpoint) *ChainFetcher

func (*ChainFetcher) FetchBlockHashByNum

func (cf *ChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*ChainFetcher) FetchEndpoint

func (cf *ChainFetcher) FetchEndpoint() lavasession.RPCProviderEndpoint

func (*ChainFetcher) FetchLatestBlockNum

func (cf *ChainFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)

type ChainListener

type ChainListener interface {
	Serve(ctx context.Context)
}

func NewChainListener

func NewChainListener(
	ctx context.Context,
	listenEndpoint *lavasession.RPCEndpoint,
	relaySender RelaySender,
	rpcConsumerLogs *metrics.RPCConsumerLogs,
	chainParser ChainParser,
) (ChainListener, error)

type ChainMessage

type ChainMessage interface {
	RequestedBlock() int64
	ChainMessageForSend
}

type ChainMessageForSend

type ChainMessageForSend interface {
	GetServiceApi() *spectypes.ServiceApi
	GetInterface() *spectypes.ApiInterface
	GetRPCMessage() parser.RPCInput
}

func CraftChainMessage

func CraftChainMessage(serviceApi spectypes.ServiceApi, chainParser ChainParser, craftData *CraftData) (ChainMessageForSend, error)

type ChainParser

type ChainParser interface {
	ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)
	SetSpec(spec spectypes.Spec)
	DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)
	ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)
	GetSpecApiByTag(tag string) (specApi spectypes.ServiceApi, existed bool)
	CraftMessage(serviceApi spectypes.ServiceApi, craftData *CraftData) (ChainMessageForSend, error)
}

func NewChainParser

func NewChainParser(apiInterface string) (chainParser ChainParser, err error)

type ChainProxy

type ChainProxy interface {
	SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error) // has to be thread safe, reuse code within ParseMsg as common functionality
}

func GetChainProxy added in v0.5.0

func GetChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, chainParser ChainParser) (ChainProxy, error)

func NewGrpcChainProxy

func NewGrpcChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration, parser ChainParser) (ChainProxy, error)

func NewJrpcChainProxy

func NewJrpcChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration, chainParser ChainParser) (ChainProxy, error)

func NewRestChainProxy

func NewRestChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration) (ChainProxy, error)

func NewtendermintRpcChainProxy

func NewtendermintRpcChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration) (ChainProxy, error)

type CraftData

type CraftData struct {
	Path           string
	Data           []byte
	ConnectionType string
}

type DummyChainFetcher

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

func NewDummyChainFetcher added in v0.15.0

func NewDummyChainFetcher(ctx context.Context, endpoint *lavasession.RPCProviderEndpoint) *DummyChainFetcher

func (*DummyChainFetcher) FetchBlockHashByNum

func (cf *DummyChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*DummyChainFetcher) FetchEndpoint added in v0.15.0

func (*DummyChainFetcher) FetchLatestBlockNum

func (cf *DummyChainFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)

type GrpcChainListener

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

func NewGrpcChainListener

func NewGrpcChainListener(
	ctx context.Context,
	listenEndpoint *lavasession.RPCEndpoint,
	relaySender RelaySender,
	rpcConsumerLogs *metrics.RPCConsumerLogs,
	chainParser ChainParser) (chainListener *GrpcChainListener)

func (*GrpcChainListener) Serve

func (apil *GrpcChainListener) Serve(ctx context.Context)

Serve http server for GrpcChainListener

type GrpcChainParser

type GrpcChainParser struct {
	BaseChainParser
	// contains filtered or unexported fields
}

func NewGrpcChainParser

func NewGrpcChainParser() (chainParser *GrpcChainParser, err error)

NewGrpcChainParser creates a new instance of GrpcChainParser

func (*GrpcChainParser) ChainBlockStats

func (apip *GrpcChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData)

func (*GrpcChainParser) CraftMessage

func (apip *GrpcChainParser) CraftMessage(serviceApi spectypes.ServiceApi, craftData *CraftData) (ChainMessageForSend, error)

func (*GrpcChainParser) DataReliabilityParams

func (apip *GrpcChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*GrpcChainParser) ParseMsg

func (apip *GrpcChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

ParseMsg parses message data into chain message object

func (*GrpcChainParser) SetSpec

func (apip *GrpcChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the GrpcChainParser

type GrpcChainProxy

type GrpcChainProxy struct {
	BaseChainProxy
	// contains filtered or unexported fields
}

func (*GrpcChainProxy) SendNodeMsg

func (cp *GrpcChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type JrpcChainProxy

type JrpcChainProxy struct {
	BaseChainProxy
	// contains filtered or unexported fields
}

func (*JrpcChainProxy) SendNodeMsg

func (cp *JrpcChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type JsonRPCChainListener

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

func NewJrpcChainListener

func NewJrpcChainListener(ctx context.Context, listenEndpoint *lavasession.RPCEndpoint, relaySender RelaySender, rpcConsumerLogs *metrics.RPCConsumerLogs) (chainListener *JsonRPCChainListener)

NewJrpcChainListener creates a new instance of JsonRPCChainListener

func (*JsonRPCChainListener) Serve

func (apil *JsonRPCChainListener) Serve(ctx context.Context)

Serve http server for JsonRPCChainListener

type JsonRPCChainParser

type JsonRPCChainParser struct {
	BaseChainParser
	// contains filtered or unexported fields
}

func NewJrpcChainParser

func NewJrpcChainParser() (chainParser *JsonRPCChainParser, err error)

NewJrpcChainParser creates a new instance of JsonRPCChainParser

func (*JsonRPCChainParser) ChainBlockStats

func (apip *JsonRPCChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData)

func (*JsonRPCChainParser) CraftMessage

func (apip *JsonRPCChainParser) CraftMessage(serviceApi spectypes.ServiceApi, craftData *CraftData) (ChainMessageForSend, error)

func (*JsonRPCChainParser) DataReliabilityParams

func (apip *JsonRPCChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*JsonRPCChainParser) GetInternalPaths

func (apip *JsonRPCChainParser) GetInternalPaths() map[string]struct{}

func (*JsonRPCChainParser) ParseMsg

func (apip *JsonRPCChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

this func parses message data into chain message object

func (*JsonRPCChainParser) SetSpec

func (apip *JsonRPCChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the JsonRPCChainParser

type LavaChainFetcher

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

func NewLavaChainFetcher

func NewLavaChainFetcher(ctx context.Context, clientCtx client.Context) *LavaChainFetcher

func (*LavaChainFetcher) FetchBlockHashByNum

func (lcf *LavaChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*LavaChainFetcher) FetchEndpoint

func (lcf *LavaChainFetcher) FetchEndpoint() lavasession.RPCProviderEndpoint

func (*LavaChainFetcher) FetchLatestBlockNum

func (lcf *LavaChainFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)

type RelaySender

type RelaySender interface {
	SendRelay(
		ctx context.Context,
		url string,
		req string,
		connectionType string,
		dappID string,
		analytics *metrics.RelayMetrics,
		metadataValues []pairingtypes.Metadata,
	) (*pairingtypes.RelayReply, *pairingtypes.Relayer_RelaySubscribeClient, error)
}

type RestChainListener

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

func NewRestChainListener

func NewRestChainListener(ctx context.Context, listenEndpoint *lavasession.RPCEndpoint, relaySender RelaySender, rpcConsumerLogs *metrics.RPCConsumerLogs) (chainListener *RestChainListener)

NewRestChainListener creates a new instance of RestChainListener

func (*RestChainListener) Serve

func (apil *RestChainListener) Serve(ctx context.Context)

Serve http server for RestChainListener

type RestChainParser

type RestChainParser struct {
	BaseChainParser
	// contains filtered or unexported fields
}

func NewRestChainParser

func NewRestChainParser() (chainParser *RestChainParser, err error)

NewRestChainParser creates a new instance of RestChainParser

func (*RestChainParser) ChainBlockStats

func (apip *RestChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData)

func (*RestChainParser) CraftMessage

func (apip *RestChainParser) CraftMessage(serviceApi spectypes.ServiceApi, craftData *CraftData) (ChainMessageForSend, error)

func (*RestChainParser) DataReliabilityParams

func (apip *RestChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*RestChainParser) ParseMsg

func (apip *RestChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

ParseMsg parses message data into chain message object

func (*RestChainParser) SetSpec

func (apip *RestChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the RestChainParser

type RestChainProxy

type RestChainProxy struct {
	BaseChainProxy
}

func (*RestChainProxy) SendNodeMsg

func (rcp *RestChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type TendermintChainParser

type TendermintChainParser struct {
	BaseChainParser
	// contains filtered or unexported fields
}

func NewTendermintRpcChainParser

func NewTendermintRpcChainParser() (chainParser *TendermintChainParser, err error)

NewTendermintRpcChainParser creates a new instance of TendermintChainParser

func (*TendermintChainParser) ChainBlockStats

func (apip *TendermintChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData, spec.BlocksInFinalizationProof)

func (*TendermintChainParser) CraftMessage

func (apip *TendermintChainParser) CraftMessage(serviceApi spectypes.ServiceApi, craftData *CraftData) (ChainMessageForSend, error)

func (*TendermintChainParser) DataReliabilityParams

func (apip *TendermintChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*TendermintChainParser) ParseMsg

func (apip *TendermintChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

ParseMsg parses message data into chain message object

func (*TendermintChainParser) SetSpec

func (apip *TendermintChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the TendermintChainParser

type TendermintRpcChainListener

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

func NewTendermintRpcChainListener

func NewTendermintRpcChainListener(ctx context.Context, listenEndpoint *lavasession.RPCEndpoint, relaySender RelaySender, rpcConsumerLogs *metrics.RPCConsumerLogs) (chainListener *TendermintRpcChainListener)

NewTendermintRpcChainListener creates a new instance of TendermintRpcChainListener

func (*TendermintRpcChainListener) Serve

func (apil *TendermintRpcChainListener) Serve(ctx context.Context)

Serve http server for TendermintRpcChainListener

Directories

Path Synopsis
rpcclient
package rpcclient implements bi-directional JSON-RPC 2.0 on multiple transports.
package rpcclient implements bi-directional JSON-RPC 2.0 on multiple transports.
testproto
Package testproto is a reverse proxy.
Package testproto is a reverse proxy.

Jump to

Keyboard shortcuts

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