ids

package
v1.11.10-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: BSD-3-Clause Imports: 13 Imported by: 1,020

Documentation

Index

Constants

View Source
const (
	NodeIDPrefix = "NodeID-"
	NodeIDLen    = ShortIDLen
)
View Source
const BitsPerByte = 8

BitsPerByte is the number of bits per byte

View Source
const (
	IDLen = 32
)
View Source
const NumBits = 256

NumBits is the number of bits this patricia tree manages

View Source
const ShortIDLen = 20

Variables

View Source
var (
	// Empty is a useful all zero value
	Empty = ID{}
)
View Source
var (
	EmptyNodeID = NodeID{}
)
View Source
var (
	ErrNoIDWithAlias = errors.New("there is no ID with alias")
)
View Source
var (
	ShortEmpty = ShortID{}
)

ShortEmpty is a useful all zero value

Functions

func EqualSubset

func EqualSubset(start, stop int, id1, id2 ID) bool

EqualSubset takes in two indices and two ids and returns if the ids are equal from bit start to bit end (non-inclusive). Bit indices are defined as: [7 6 5 4 3 2 1 0] [15 14 13 12 11 10 9 8] ... [255 254 253 252 251 250 249 248] Where index 7 is the MSB of byte 0.

func FirstDifferenceSubset

func FirstDifferenceSubset(start, stop int, id1, id2 ID) (int, bool)

FirstDifferenceSubset takes in two indices and two ids and returns the index of the first difference between the ids inside bit start to bit end (non-inclusive). Bit indices are defined above

func GetRelevantAliases added in v1.7.6

func GetRelevantAliases(aliaser Aliaser, ids []ID) (map[ID][]string, error)

GetRelevantAliases returns the aliases with the redundant identity alias removed (each id is aliased to at least itself).

func ShortIDsToStrings added in v1.7.11

func ShortIDsToStrings(ids []ShortID) []string

ShortIDsToStrings converts an array of shortIDs to an array of their string representations

Types

type Aliaser

type Aliaser interface {
	AliaserReader
	AliaserWriter

	// PrimaryAliasOrDefault returns the first alias of [id], or ID string as a
	// default if no alias exists
	PrimaryAliasOrDefault(id ID) string
}

Aliaser allows one to give an ID aliases and lookup the aliases given to an ID.

func NewAliaser added in v1.6.2

func NewAliaser() Aliaser

type AliaserReader added in v1.6.2

type AliaserReader interface {
	// Lookup returns the ID associated with alias
	Lookup(alias string) (ID, error)

	// PrimaryAlias returns the first alias of [id]
	PrimaryAlias(id ID) (string, error)

	// Aliases returns the aliases of an ID
	Aliases(id ID) ([]string, error)
}

AliaserReader allows one to lookup the aliases given to an ID.

type AliaserWriter added in v1.6.2

type AliaserWriter interface {
	// Alias gives [id] the alias [alias]
	Alias(id ID, alias string) error

	// RemoveAliases of the provided ID
	RemoveAliases(id ID)
}

AliaserWriter allows one to give an ID aliases. An ID can have arbitrarily many aliases; two IDs may not have the same alias.

type ID

type ID [IDLen]byte

ID wraps a 32 byte hash used as an identifier

func FromString

func FromString(idStr string) (ID, error)

FromString is the inverse of ID.String()

func FromStringOrPanic added in v1.11.0

func FromStringOrPanic(idStr string) ID

FromStringOrPanic is the same as FromString, but will panic on error

func GenerateTestID added in v0.8.0

func GenerateTestID() ID

GenerateTestID returns a new ID that should only be used for testing

func ToID

func ToID(bytes []byte) (ID, error)

ToID attempt to convert a byte slice into an id

func (ID) Bit

func (id ID) Bit(i uint) int

Bit returns the bit value at the ith index of the byte array. Returns 0 or 1

func (ID) Compare added in v1.10.18

func (id ID) Compare(other ID) int

func (ID) Hex

func (id ID) Hex() string

Hex returns a hex encoded string of this id.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (ID) MarshalText added in v1.5.0

func (id ID) MarshalText() ([]byte, error)

func (ID) Prefix

func (id ID) Prefix(prefixes ...uint64) ID

Prefix this id to create a more selective id. This can be used to store multiple values under the same key. For example: prefix1(id) -> confidence prefix2(id) -> vertex This will return a new id and not modify the original id.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

func (*ID) UnmarshalText added in v1.4.10

func (id *ID) UnmarshalText(text []byte) error

func (ID) XOR added in v1.10.4

func (id ID) XOR(other ID) ID

XOR this id and the provided id and return the resulting id.

Note: this id is not modified.

type NodeID added in v1.7.11

type NodeID ShortID

func BuildTestNodeID added in v1.10.16

func BuildTestNodeID(src []byte) NodeID

BuildTestNodeID is an utility to build NodeID from bytes in UTs It must not be used in production code. In production code we should use ToNodeID, which performs proper length checking.

func GenerateTestNodeID added in v1.7.11

func GenerateTestNodeID() NodeID

GenerateTestNodeID returns a new ID that should only be used for testing

func NodeIDFromCert added in v1.7.11

func NodeIDFromCert(cert *staking.Certificate) NodeID

func NodeIDFromString added in v1.7.11

func NodeIDFromString(nodeIDStr string) (NodeID, error)

NodeIDFromString is the inverse of NodeID.String()

func ToNodeID added in v1.7.11

func ToNodeID(bytes []byte) (NodeID, error)

ToNodeID attempt to convert a byte slice into a node id

func (NodeID) Bytes added in v1.7.11

func (id NodeID) Bytes() []byte

func (NodeID) Compare added in v1.10.18

func (id NodeID) Compare(other NodeID) int

func (NodeID) MarshalJSON added in v1.7.11

func (id NodeID) MarshalJSON() ([]byte, error)

func (NodeID) MarshalText added in v1.7.11

func (id NodeID) MarshalText() ([]byte, error)

func (NodeID) String added in v1.7.11

func (id NodeID) String() string

func (*NodeID) UnmarshalJSON added in v1.7.11

func (id *NodeID) UnmarshalJSON(b []byte) error

func (*NodeID) UnmarshalText added in v1.7.11

func (id *NodeID) UnmarshalText(text []byte) error

type RequestID added in v1.9.1

type RequestID struct {
	// The node this request came from
	NodeID NodeID
	// The chain this request came from
	SourceChainID ID
	// The chain the expected response should come from
	DestinationChainID ID
	// The unique identifier for this request
	RequestID uint32
	// The message opcode
	Op byte
}

RequestID is a unique identifier for an in-flight request pending a response.

type ShortID

type ShortID [ShortIDLen]byte

ShortID wraps a 20 byte hash as an identifier

func GenerateTestShortID added in v0.8.0

func GenerateTestShortID() ShortID

GenerateTestShortID returns a new ID that should only be used for testing

func ShortFromPrefixedString added in v0.8.0

func ShortFromPrefixedString(idStr, prefix string) (ShortID, error)

ShortFromPrefixedString returns a ShortID assuming the cb58 format is prefixed

func ShortFromString

func ShortFromString(idStr string) (ShortID, error)

ShortFromString is the inverse of ShortID.String()

func ToShortID

func ToShortID(bytes []byte) (ShortID, error)

ToShortID attempt to convert a byte slice into an id

func (ShortID) Bytes

func (id ShortID) Bytes() []byte

Bytes returns the 20 byte hash as a slice. It is assumed this slice is not modified.

func (ShortID) Compare added in v1.10.18

func (id ShortID) Compare(other ShortID) int

func (ShortID) Hex

func (id ShortID) Hex() string

Hex returns a hex encoded string of this id.

func (ShortID) MarshalJSON

func (id ShortID) MarshalJSON() ([]byte, error)

func (ShortID) MarshalText added in v1.7.11

func (id ShortID) MarshalText() ([]byte, error)

func (ShortID) PrefixedString added in v0.8.0

func (id ShortID) PrefixedString(prefix string) string

PrefixedString returns the String representation with a prefix added

func (ShortID) String

func (id ShortID) String() string

func (*ShortID) UnmarshalJSON

func (id *ShortID) UnmarshalJSON(b []byte) error

func (*ShortID) UnmarshalText added in v1.7.11

func (id *ShortID) UnmarshalText(text []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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