tools

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Flags = &flags{}
View Source
var GetFirehoseClientCmd = func(zlog *zap.Logger, tracer logging.Tracer, transformsSetter TransformsSetter) *cobra.Command {
	out := &cobra.Command{
		Use:   "firehose-client",
		Short: "Connects to a Firehose endpoint over gRPC and print block stream as JSON to terminal",
		Args:  cobra.ExactArgs(3),
		RunE:  getFirehoseClientE(zlog, tracer, transformsSetter),
	}
	out.Flags().StringP("api-token-env-var", "a", "FIREHOSE_API_TOKEN", "Look for a JWT in this environment variable to authenticate against endpoint")
	out.Flags().String("compression", "none", "The HTTP compression: use either 'none', 'gzip' or 'zstd'")
	out.Flags().String("cursor", "", "Use this cursor with the request to resume your stream at the following block pointed by the cursor")
	out.Flags().BoolP("plaintext", "p", false, "Use plaintext connection to Firehose")
	out.Flags().BoolP("insecure", "k", false, "Use SSL connection to Firehose but skip SSL certificate validation")
	out.Flags().Bool("print-cursor-only", false, "Skip block decoding, only print the step cursor (useful for performance testing)")
	out.Flags().Bool("final-blocks-only", false, "Only ask for final blocks")

	return out
}

You should add your custom 'transforms' flags to this command in your init(), then parse them in transformsSetter

View Source
var GetFirehosePrometheusExporterCmd = func(zlog *zap.Logger, tracer logging.Tracer, transformsSetter TransformsSetter) *cobra.Command {
	out := &cobra.Command{
		Use:   "firehose-prometheus-exporter <endpoint:port>",
		Short: "stream blocks near the chain HEAD and report to prometheus",
		Args:  cobra.ExactArgs(1),
		RunE:  runPrometheusExporterE(zlog, tracer, transformsSetter),
	}
	out.Flags().StringP("api-token-env-var", "a", "FIREHOSE_API_TOKEN", "Look for a JWT in this environment variable to authenticate against endpoint")

	out.Flags().BoolP("plaintext", "p", false, "Use plaintext connection to firehose")
	out.Flags().BoolP("insecure", "k", false, "Skip SSL certificate validation when connecting to firehose")

	return out
}

You should add your custom 'transforms' flags to this command in your init(), then parse them in transformsSetter

View Source
var GetFirehoseSingleBlockClientCmd = func(zlog *zap.Logger, tracer logging.Tracer) *cobra.Command {
	out := &cobra.Command{
		Use:     "firehose-single-block-client {endpoint} {block_num|block_num:block_id|cursor}",
		Short:   "fetch a single block from firehose and print as JSON",
		Args:    cobra.ExactArgs(2),
		RunE:    getFirehoseSingleBlockClientE(zlog, tracer),
		Example: "firehose-single-block-client --compression=gzip my.firehose.endpoint:443 2344:0x32d8e8d98a798da98d6as9d69899as86s9898d8ss8d87",
	}
	out.Flags().StringP("api-token-env-var", "a", "FIREHOSE_API_TOKEN", "Look for a JWT in this environment variable to authenticate against endpoint")
	out.Flags().String("compression", "none", "http compression: use either 'none', 'gzip' or 'zstd'")
	out.Flags().BoolP("plaintext", "p", false, "Use plaintext connection to firehose")
	out.Flags().BoolP("insecure", "k", false, "Skip SSL certificate validation when connecting to firehose")
	return out
}

You should add your custom 'transforms' flags to this command in your init(), then parse them in transformsSetter

View Source
var GetMergedBlocksUpgrader = func(zlog *zap.Logger, tracer logging.Tracer, tweakFunc func(cmd *cobra.Command, block *bstream.Block) (*bstream.Block, error)) *cobra.Command {
	out := &cobra.Command{
		Use:   "upgrade-merged-blocks <source> <destination> <start> <stop>",
		Short: "from a merged-blocks source, rewrite blocks to a new merged-blocks destination, while applying all possible upgrades",
		Args:  cobra.ExactArgs(4),
		RunE:  getMergedBlockUpgrader(zlog, tracer, tweakFunc),
	}

	return out
}

Functions

func CheckMergedBlocks

func CheckMergedBlocks(
	ctx context.Context,
	logger *zap.Logger,
	storeURL string,
	fileBlockSize uint32,
	blockRange BlockRange,
	blockPrinter func(block *bstream.Block),
	printDetails PrintDetails,
) error

func DownloadFirehoseBlocks

func DownloadFirehoseBlocks(
	ctx context.Context,
	endpoint string,
	jwt string,
	insecure bool,
	plaintext bool,
	startBlock uint64,
	stopBlock uint64,
	destURL string,
	respDecoder FirehoseResponseDecoder,
	tweakBlock func(*bstream.Block) (*bstream.Block, error),
	logger *zap.Logger) error

func FlagMergedBlocks

func FlagMergedBlocks(
	ctx context.Context,
	logger *zap.Logger,
	sourceStoreURL string,
	destStoreURL string,
	fileBlockSize uint32,
	blockRange BlockRange,
) error

FlagMergedBlocks will write a list of base-block-numbers to a store, for merged-blocks-files that are broken or missing broken merged-blocks-files are the ones that contain "empty" blocks (no ID) or unlinkable blocks there could be false positives on unlinkable blocks, though output files are like this: 0000123100.broken 0000123500.missing

func PrettyBlockNum

func PrettyBlockNum(b uint64) string

func RoundToBundleEndBlock

func RoundToBundleEndBlock(block, fileBlockSize uint32) uint32

func RoundToBundleStartBlock

func RoundToBundleStartBlock(block, fileBlockSize uint32) uint32

func WalkBlockPrefix

func WalkBlockPrefix(blockRange BlockRange, fileBlockSize uint32) string

Types

type BlockNum

type BlockNum uint64

func (BlockNum) String

func (b BlockNum) String() string

type BlockRange

type BlockRange struct {
	Start uint64
	Stop  uint64
}

func (BlockRange) Bounded

func (b BlockRange) Bounded() bool

func (BlockRange) ReprocRange

func (b BlockRange) ReprocRange() string

func (BlockRange) String

func (b BlockRange) String() string

func (BlockRange) Unbounded

func (b BlockRange) Unbounded() bool

type FilteringFilters

type FilteringFilters struct {
	Include string
	Exclude string
	System  string
}

func (*FilteringFilters) Key

func (f *FilteringFilters) Key() string

type FirehoseResponseDecoder

type FirehoseResponseDecoder func(in *anypb.Any) (*bstream.Block, error)

FirehoseResponseDecoder will usually look like this (+ error handling):

block := &pbcodec.Block{} 									// chain-specific protobuf Block
anypb.UnmarshalTo(in, in.block, proto.UnmarshalOptions{})
return codec.BlockFromProto(block) 							// chain-specific bstream block converter

type PrintDetails

type PrintDetails uint8
const (
	PrintNothing PrintDetails = iota
	PrintStats
	PrintFull
	MaxUint64 = ^uint64(0)
)

type TransformsSetter

type TransformsSetter func(cmd *cobra.Command) ([]*anypb.Any, error)

Jump to

Keyboard shortcuts

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