validate

package
v0.0.0-...-aac2901 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: GPL-3.0 Imports: 12 Imported by: 6

Documentation

Overview

Package validate provides tools to validate command line (or Request) input

Index

Constants

View Source
const ValidBlockIdWithRange = ValidBlockId | ValidArgumentRange
View Source
const ValidBlockIdWithRangeAndDate = ValidBlockIdWithRange | ValidArgumentDate

Variables

View Source
var ErrTooManyRanges = errors.New("too many ranges")

Functions

func HasArticulationKey

func HasArticulationKey(on bool) bool

HasArticulationKey returns true if the articulation key is present

func IsBlockHash

func IsBlockHash(str string) bool

func IsBlockNumber

func IsBlockNumber(str string) (bool, blknum_t)

func IsBlockNumberList

func IsBlockNumberList(strs []string) (bool, []blknum_t)

func IsDateTimeString

func IsDateTimeString(str string) bool

func IsRange

func IsRange(chain, str string) (bool, error)

func IsTimestamp

func IsTimestamp(str string) (bool, blknum_t)

func IsTransBlockHashAndId

func IsTransBlockHashAndId(str string) bool

func IsTransBlockNumAndId

func IsTransBlockNumAndId(strIn string) bool

func IsTransHash

func IsTransHash(str string) bool

func IsTransIndex

func IsTransIndex(str string) bool

func IsValidBlockId

func IsValidBlockId(chain string, ids []string, validTypes ValidArgumentType) (bool, error)

func IsValidFourByte

func IsValidFourByte(val string) bool

func IsValidFourByteE

func IsValidFourByteE(val string) (bool, error)

func IsValidHash

func IsValidHash(hash string) bool

func IsValidTopic

func IsValidTopic(val string) bool

func IsValidTopicE

func IsValidTopicE(val string) (bool, error)

func IsValidTransId

func IsValidTransId(chain string, ids []string, validTypes ValidArgumentType) (bool, error)

func ToIsoDateStr2

func ToIsoDateStr2(dateStr string) string

func Usage

func Usage(msg string, values ...string) error

func ValidateAddresses

func ValidateAddresses(args []string) error

func ValidateAtLeastOneAddr

func ValidateAtLeastOneAddr(args []string) error

func ValidateAtLeastOneNonSentinal

func ValidateAtLeastOneNonSentinal(args []string) error

func ValidateEnum

func ValidateEnum(field, value, valid string) error

func ValidateEnumRequired

func ValidateEnumRequired(field, value, valid string) error

func ValidateEnumSlice

func ValidateEnumSlice(field string, values []string, valid string) error

func ValidateExactlyOneAddr

func ValidateExactlyOneAddr(args []string) error

func ValidateIdentifiers

func ValidateIdentifiers(chain string, ids []string, validTypes ValidArgumentType, maxRanges int, results *[]identifiers.Identifier) error

ValidateIdentifiers validates multiple identifiers against multiple valid types (specified as bitmasks). If any of the identifiers are invalid, it returns error If all identifiers are valid, it returns nil

Examples:

ValidateIdentifiers(identifiers, ValidArgumentBlockNumber | ValidArgumentDate, 0)
ValidateIdentifiers(identifiers, ValidArgumentRange, 1)

This routine can be used for both block identifiers and transaction

func ValidateIdentifiersWithBounds

func ValidateIdentifiersWithBounds(chain string, ids []string, validTypes ValidArgumentType, maxRanges int, results *[]identifiers.Identifier) (base.BlockRange, error)

ValidateIdentifiersWithBounds Is a helper function to return bounds in addition to validating identifiers

Types

type InvalidIdentifierLiteralError

type InvalidIdentifierLiteralError struct {
	Value string
	Msg   string
}

func (*InvalidIdentifierLiteralError) Error

type ValidArgumentType

type ValidArgumentType uint16

ValidArgumentType is a bitmask used to make it easier to validate multiple block identifiers (which usually are arguments to `chifra` commands). This way we can specify that we want e.g. both block number and a special block as valid arguments

const (
	ValidArgumentBlockHash ValidArgumentType = 1 << iota
	ValidArgumentBlockNumber
	ValidArgumentTimestamp
	ValidArgumentDate
	ValidArgumentRange
	ValidArgumentSpecialBlock
	ValidArgumentTransHash
	ValidArgumentTransBlockNumberAndId
	ValidArgumentTransBlockHashAndId
)

Jump to

Keyboard shortcuts

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