identifiers

package
v0.0.0-...-2a3d9f8 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: GPL-3.0 Imports: 14 Imported by: 1

Documentation

Overview

Package identifiers aides in the parsing of command line block and/or transaction identifiers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBlockNumberMap

func GetBlockNumberMap(chain string, ids []Identifier) (map[base.Blknum]bool, error)

func GetBlockNumbers

func GetBlockNumbers(chain string, ids []Identifier) ([]base.Blknum, error)

func GetBounds

func GetBounds(chain string, ids *[]Identifier) (ret base.BlockRange, err error)

GetBounds returns the earliest and latest blocks for an array of identifiers

func GetTransactionIds

func GetTransactionIds(chain string, ids []Identifier) ([]types.Appearance, error)

func IdsToApps

func IdsToApps(chain string, ids []Identifier) ([]types.Appearance, int, error)

Types

type Identifier

type Identifier struct {
	StartType    IdentifierType `json:"startType,omitempty"`
	Start        Point          `json:"start,omitempty"`
	EndType      IdentifierType `json:"endType,omitempty"`
	End          Point          `json:"end,omitempty"`
	ModifierType IdentifierType `json:"modifierType,omitempty"`
	Modifier     Modifier       `json:"modifier,omitempty"`
	Orig         string         `json:"-"`
}

func NewBlockRange

func NewBlockRange(rangeStr string) (*Identifier, error)

NewBlockRange parses a string containing block range and returns a struct that always has Start, StartType, EndType, ModifierType fields and may as well have End and Modifier, if they are defined. *Type fields can be used to quickly check what is the type of the values.

Consult ./parser.go for the supported format TODO: This does not handle the zero block correctly

func NewTxRange

func NewTxRange(rangeStr string) (*Identifier, error)

func (*Identifier) ResolveBlocks

func (id *Identifier) ResolveBlocks(chain string) ([]base.Blknum, error)

ResolveBlocks resolves a list of identifiers to a list of blocks (excluding the last block)

func (*Identifier) ResolveTxs

func (id *Identifier) ResolveTxs(chain string) ([]types.Appearance, error)

func (*Identifier) String

func (id *Identifier) String() string

func (*Identifier) UnmarshalJSON

func (id *Identifier) UnmarshalJSON(data []byte) error

type IdentifierType

type IdentifierType int64
const (
	NotDefined IdentifierType = iota
	BlockNumber
	BlockTimestamp
	BlockHash
	BlockDate
	BlockSpecial
	TransactionIndex
	TransactionHash
	Period
	Step
)

func (IdentifierType) String

func (id IdentifierType) String() string

type Modifier

type Modifier struct {
	Step   uint   `parser:"@Unsigned" json:"step,omitempty"`
	Period string `parser:"| @('hourly'|'daily'|'weekly'|'monthly'|'quarterly'|'annually'|'next'|'prev'|'all')" json:"period,omitempty"`
}

Modifier changes the meaning of the given range. For example, if step of 10 is provided, the range does not mean "each block from start to end" anymore, but instead "every 10th block from start to end". Similarly a period can be provided to get only blocks based on frequency (e.g. weekly)

type Point

type Point struct {
	Number  uint   `parser:"@Hex|@Unsigned" json:"number,omitempty"`
	Hash    string `parser:"| @Hash" json:"hash,omitempty"`
	Date    string `parser:"| @Date" json:"date,omitempty"`
	Special string `parser:"| @Special" json:"special,omitempty"`
}

A Point carries information about when a range starts or ends. It can be a block number, a date or special name (e.g. "london" is translated to block 12965000)

func (Point) String

func (p Point) String() string

type Range

type Range struct {
	Points   []*Point  `parser:"@@('-'@@)?"`
	Modifier *Modifier `parser:"(':'@@)?"`
}

Range is uses after having defined both Point and Modifier, we can construct our Range, which consist of a starting point, optionally followed by an ending point and optionally finished by a modifier. Separators for points and modifier are defined above as PointSeparator and ModifierSeparator

func Parse

func Parse(source string) (*Range, error)

Parse takes a string and tries to parse it into Range struct, which always have at least one Point (but no more than two: start and end) and may have Modifier.

type WrongModifierError

type WrongModifierError struct {
	Token string
}

func (*WrongModifierError) Error

func (e *WrongModifierError) Error() string

Jump to

Keyboard shortcuts

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