internal

package
v0.0.0-...-ae8e89f Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockNotFound  = xerrors.New("block not found")
	ErrNotImplemented = xerrors.New("not implemented")
)

Functions

func ContextWithOptions

func ContextWithOptions(ctx context.Context, opts ...ClientOption) context.Context

func GetParentHeight

func GetParentHeight(height uint64) uint64

Types

type Client

type Client interface {
	// BatchGetBlockMetadata fetches the BlockMetadata given a block range [from, to).
	// The implementation should consider the following optimizations whenever possible:
	// - Query the block header only.
	// - Use the batch API to reduce the number of network round-trips.
	// - If batch API is unavailable, it may use goroutines to parallelize the query.
	BatchGetBlockMetadata(ctx context.Context, tag uint32, from uint64, to uint64) ([]*api.BlockMetadata, error)

	// GetBlockByHeight fetches the raw block given a block height.
	// Optionally it may implement blockchain-specific handling using opts.
	// For example, in ethereum transaction trace may be skipped if WithBestEffort is enabled.
	GetBlockByHeight(ctx context.Context, tag uint32, height uint64, opts ...ClientOption) (*api.Block, error)

	// GetBlockByHash fetches the raw block given a block hash and/or height.
	// For most blockchains, the unique identifier of a block is the hash, and the hash should be used in the query.
	// If the blockchain uses the height as the unique identifier, or orphaned blocks are skipped, the height may be used in the query.
	// Optionally it may implement blockchain-specific handling using opts.
	GetBlockByHash(ctx context.Context, tag uint32, height uint64, hash string, opts ...ClientOption) (*api.Block, error)

	// GetLatestHeight returns the height of the latest block.
	GetLatestHeight(ctx context.Context) (uint64, error)

	// UpgradeBlock upgrades a block to a new tag.
	// It is used in backfiller when UpgradeFromTag is enabled.
	// It should return ErrNotImplemented until there is a need for a new tag.
	UpgradeBlock(ctx context.Context, block *api.Block, newTag uint32) (*api.Block, error)

	// CanReprocess returns true if the block is retryable during dlq processing.
	// It should return false unless WithBestEffort is applicable to the blockchain.
	CanReprocess(tag uint32, height uint64) bool

	// GetAccountProof returns the account proof for an given account at a target block.
	// Note that, in req, height is required while blockHash is optional.
	GetAccountProof(ctx context.Context, req *api.GetVerifiedAccountStateRequest) (*api.GetAccountProofResponse, error)
}

func WithInstrumentInterceptor

func WithInstrumentInterceptor(client Client, scope tally.Scope, logger *zap.Logger) Client

WithInstrumentInterceptor returns an instrumented client.

func WithParserInterceptor

func WithParserInterceptor(client Client, parser parser.Parser, config *config.Config, logger *zap.Logger) Client

WithParserInterceptor returns a new client which validates the data using the specified parser.

type ClientFactory

type ClientFactory interface {
	Master() Client
	Slave() Client
	Validator() Client
	Consensus() Client
}

func NewJsonrpcClientFactory

func NewJsonrpcClientFactory(params JsonrpcClientParams, clientFactory JsonrpcClientFactoryFn) ClientFactory

func NewRestapiClientFactory

func NewRestapiClientFactory(params RestapiClientParams, clientFactory RestapiClientFactoryFn) ClientFactory

type ClientOption

type ClientOption func(options *ClientOptions)

func WithBestEffort

func WithBestEffort() ClientOption

WithBestEffort enables the client to query data in a best-effort manner. It may return partial results when this option is enabled.

type ClientOptions

type ClientOptions struct {
	BestEffort bool
}

func OptionsFromContext

func OptionsFromContext(ctx context.Context) *ClientOptions

type ClientParams

type ClientParams struct {
	fx.In
	Master    Client `name:"master"`
	Slave     Client `name:"slave"`
	Validator Client `name:"validator"`
	Consensus Client `name:"consensus"`
}

type JsonrpcClientFactoryFn

type JsonrpcClientFactoryFn func(client jsonrpc.Client) Client

type JsonrpcClientParams

type JsonrpcClientParams struct {
	fx.In
	fxparams.Params
	MasterClient    jsonrpc.Client `name:"master"`
	SlaveClient     jsonrpc.Client `name:"slave"`
	ValidatorClient jsonrpc.Client `name:"validator"`
	ConsensusClient jsonrpc.Client `name:"consensus"`
	DLQ             dlq.DLQ
}

type Params

type Params struct {
	fx.In
	fxparams.Params
	Parser         parser.Parser
	Bitcoin        ClientFactory `name:"bitcoin" optional:"true"`
	Bsc            ClientFactory `name:"bsc" optional:"true"`
	Ethereum       ClientFactory `name:"ethereum" optional:"true"`
	Rosetta        ClientFactory `name:"rosetta" optional:"true"`
	Solana         ClientFactory `name:"solana" optional:"true"`
	Polygon        ClientFactory `name:"polygon" optional:"true"`
	Avacchain      ClientFactory `name:"avacchain" optional:"true"`
	Arbitrum       ClientFactory `name:"arbitrum" optional:"true"`
	Optimism       ClientFactory `name:"optimism" optional:"true"`
	Base           ClientFactory `name:"base" optional:"true"`
	Fantom         ClientFactory `name:"fantom" optional:"true"`
	Aptos          ClientFactory `name:"aptos" optional:"true"`
	EthereumBeacon ClientFactory `name:"ethereum/beacon" optional:"true"`
	CosmosStaking  ClientFactory `name:"cosmos/staking" optional:"true"`
	CardanoStaking ClientFactory `name:"cardano/staking" optional:"true"`
}

type RestapiClientFactoryFn

type RestapiClientFactoryFn func(client restapi.Client) Client

type RestapiClientParams

type RestapiClientParams struct {
	fx.In
	fxparams.Params
	MasterClient    restapi.Client `name:"master"`
	SlaveClient     restapi.Client `name:"slave"`
	ValidatorClient restapi.Client `name:"validator"`
	ConsensusClient restapi.Client `name:"consensus"`
	DLQ             dlq.DLQ
}

type Result

type Result struct {
	fx.Out
	Master    Client `name:"master"`
	Slave     Client `name:"slave"`
	Validator Client `name:"validator"`
	Consensus Client `name:"consensus"`
}

func NewClient

func NewClient(params Params) (Result, error)

Jump to

Keyboard shortcuts

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