types

package module
v0.0.0-...-10d33f6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: GPL-3.0 Imports: 7 Imported by: 187

README

eth2-types

This repository is the place for defining the common ETH2 data types

Documentation

Overview

Package types contains ETH2 data types shared between various parts of the system (beacon chain, validator, slasher).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMulOverflow  = errors.New("multiplication overflows")
	ErrAddOverflow  = errors.New("addition overflows")
	ErrSubUnderflow = errors.New("subtraction underflow")
	ErrDivByZero    = errors.New("integer divide by zero")
)

Functions

func Add64

func Add64(a, b uint64) (uint64, error)

Add64 adds two 64-bit unsigned integers and checks if they lead to an overflow. If they do not, it returns the result without an error.

func Div64

func Div64(a, b uint64) (uint64, error)

Div64 divides two 64-bit unsigned integers and checks for errors.

func HexDecodeOrDie

func HexDecodeOrDie(t *testing.T, str string) []byte

func Mod64

func Mod64(a, b uint64) (uint64, error)

Mod64 finds remainder of division of two 64-bit unsigned integers and checks for errors.

func Mul64

func Mul64(a, b uint64) (uint64, error)

Mul64 multiples two 64-bit unsigned integers and checks if they lead to an overflow. If they do not, it returns the result without an error.

func Sub64

func Sub64(a, b uint64) (uint64, error)

Sub64 subtracts two 64-bit unsigned integers and checks for errors.

Types

type CommitteeIndex

type CommitteeIndex uint64

CommitteeIndex in eth2.

func (CommitteeIndex) HashTreeRoot

func (c CommitteeIndex) HashTreeRoot() ([32]byte, error)

HashTreeRoot returns calculated hash root.

func (CommitteeIndex) HashTreeRootWith

func (c CommitteeIndex) HashTreeRootWith(hh *fssz.Hasher) error

HashWithDefaultHasher hashes a HashRoot object with a Hasher from the default HasherPool.

func (*CommitteeIndex) MarshalSSZ

func (c *CommitteeIndex) MarshalSSZ() ([]byte, error)

MarshalSSZ marshals committee index into a serialized object.

func (*CommitteeIndex) MarshalSSZTo

func (c *CommitteeIndex) MarshalSSZTo(dst []byte) ([]byte, error)

MarshalSSZTo marshals committee index with the provided byte slice.

func (*CommitteeIndex) SizeSSZ

func (c *CommitteeIndex) SizeSSZ() int

SizeSSZ returns the size of the serialized object.

func (*CommitteeIndex) UnmarshalSSZ

func (c *CommitteeIndex) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ deserializes the provided bytes buffer into the committee index object.

type Domain

type Domain []byte

Domain represents a 32 bytes domain object in Ethereum beacon chain consensus.

func (Domain) HashTreeRoot

func (e Domain) HashTreeRoot() ([32]byte, error)

HashTreeRoot returns calculated hash root.

func (Domain) HashTreeRootWith

func (e Domain) HashTreeRootWith(hh *fssz.Hasher) error

HashTreeRootWith hashes a Domain object with a Hasher from the default HasherPool.

func (*Domain) MarshalSSZ

func (e *Domain) MarshalSSZ() ([]byte, error)

MarshalSSZ marshals Domain into a serialized object.

func (*Domain) MarshalSSZTo

func (e *Domain) MarshalSSZTo(dst []byte) ([]byte, error)

MarshalSSZTo marshals Domain with the provided byte slice.

func (*Domain) SizeSSZ

func (e *Domain) SizeSSZ() int

SizeSSZ returns the size of the serialized object.

func (*Domain) UnmarshalSSZ

func (e *Domain) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ deserializes the provided bytes buffer into the Domain object.

type Epoch

type Epoch uint64

Epoch represents a single epoch.

func MaxEpoch

func MaxEpoch(a, b Epoch) Epoch

MaxEpoch returns the larger of the two epochs.

func MinEpoch

func MinEpoch(a, b Epoch) Epoch

MinEpoch returns the smaller of the two epochs.

func (Epoch) Add

func (e Epoch) Add(x uint64) Epoch

Add increases epoch by x. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Epoch) AddEpoch

func (e Epoch) AddEpoch(x Epoch) Epoch

AddEpoch increases epoch using another epoch value. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Epoch) Div

func (e Epoch) Div(x uint64) Epoch

Div divides epoch by x. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Epoch) HashTreeRoot

func (e Epoch) HashTreeRoot() ([32]byte, error)

HashTreeRoot returns calculated hash root.

func (Epoch) HashTreeRootWith

func (e Epoch) HashTreeRootWith(hh *fssz.Hasher) error

HashWithDefaultHasher hashes a HashRoot object with a Hasher from the default HasherPool.

func (*Epoch) MarshalSSZ

func (e *Epoch) MarshalSSZ() ([]byte, error)

MarshalSSZ marshals epoch into a serialized object.

func (*Epoch) MarshalSSZTo

func (e *Epoch) MarshalSSZTo(dst []byte) ([]byte, error)

MarshalSSZTo marshals epoch with the provided byte slice.

func (Epoch) Mod

func (e Epoch) Mod(x uint64) Epoch

Mod returns result of `epoch % x`. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Epoch) Mul

func (e Epoch) Mul(x uint64) Epoch

Mul multiplies epoch by x. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Epoch) SafeAdd

func (e Epoch) SafeAdd(x uint64) (Epoch, error)

SafeAdd increases epoch by x. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Epoch) SafeAddEpoch

func (e Epoch) SafeAddEpoch(x Epoch) (Epoch, error)

SafeAddEpoch increases epoch using another epoch value. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Epoch) SafeDiv

func (e Epoch) SafeDiv(x uint64) (Epoch, error)

SafeDiv divides epoch by x. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Epoch) SafeMod

func (e Epoch) SafeMod(x uint64) (Epoch, error)

SafeMod returns result of `epoch % x`. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Epoch) SafeMul

func (e Epoch) SafeMul(x uint64) (Epoch, error)

SafeMul multiplies epoch by x. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Epoch) SafeSub

func (e Epoch) SafeSub(x uint64) (Epoch, error)

SafeSub subtracts x from the epoch. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (*Epoch) SizeSSZ

func (e *Epoch) SizeSSZ() int

SizeSSZ returns the size of the serialized object.

func (Epoch) Sub

func (e Epoch) Sub(x uint64) Epoch

Sub subtracts x from the epoch. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (*Epoch) UnmarshalSSZ

func (e *Epoch) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ deserializes the provided bytes buffer into the epoch object.

type SSZBytes

type SSZBytes []byte

SSZUint64 is a bytes slice that satisfies the fast-ssz interface.

func (*SSZBytes) HashTreeRoot

func (b *SSZBytes) HashTreeRoot() ([32]byte, error)

HashTreeRoot hashes the uint64 object following the SSZ standard.

func (*SSZBytes) HashTreeRootWith

func (b *SSZBytes) HashTreeRootWith(hh *fssz.Hasher) error

HashTreeRootWith hashes the uint64 object with the given hasher.

type SSZUint64

type SSZUint64 uint64

SSZUint64 is a uint64 type that satisfies the fast-ssz interface.

func (*SSZUint64) HashTreeRoot

func (s *SSZUint64) HashTreeRoot() ([32]byte, error)

HashTreeRoot returns calculated hash root.

func (*SSZUint64) HashTreeRootWith

func (s *SSZUint64) HashTreeRootWith(hh *fssz.Hasher) error

HashWithDefaultHasher hashes a HashRoot object with a Hasher from the default HasherPool.

func (*SSZUint64) MarshalSSZ

func (s *SSZUint64) MarshalSSZ() ([]byte, error)

MarshalSSZ marshals uin64 into a serialized object.

func (*SSZUint64) MarshalSSZTo

func (s *SSZUint64) MarshalSSZTo(dst []byte) ([]byte, error)

MarshalSSZTo marshals the uint64 with the provided byte slice.

func (*SSZUint64) SizeSSZ

func (s *SSZUint64) SizeSSZ() int

SizeSSZ returns the size of the serialized representation.

func (*SSZUint64) UnmarshalSSZ

func (s *SSZUint64) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ deserializes the provided bytes buffer into the uint64 object.

type Slot

type Slot uint64

Slot represents a single slot.

func MaxSlot

func MaxSlot(a, b Slot) Slot

MaxSlot returns the larger of the two slots.

func MinSlot

func MinSlot(a, b Slot) Slot

MinSlot returns the smaller of the two slots.

func (Slot) Add

func (s Slot) Add(x uint64) Slot

Add increases slot by x. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) AddSlot

func (s Slot) AddSlot(x Slot) Slot

AddSlot increases slot by another slot. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) Div

func (s Slot) Div(x uint64) Slot

Div divides slot by x. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) DivSlot

func (s Slot) DivSlot(x Slot) Slot

DivSlot divides slot by another slot. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) HashTreeRoot

func (s Slot) HashTreeRoot() ([32]byte, error)

HashTreeRoot returns calculated hash root.

func (Slot) HashTreeRootWith

func (s Slot) HashTreeRootWith(hh *fssz.Hasher) error

HashWithDefaultHasher hashes a HashRoot object with a Hasher from the default HasherPool.

func (*Slot) MarshalSSZ

func (s *Slot) MarshalSSZ() ([]byte, error)

MarshalSSZ marshals slot into a serialized object.

func (*Slot) MarshalSSZTo

func (s *Slot) MarshalSSZTo(dst []byte) ([]byte, error)

MarshalSSZTo marshals slot with the provided byte slice.

func (Slot) Mod

func (s Slot) Mod(x uint64) Slot

Mod returns result of `slot % x`. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) ModSlot

func (s Slot) ModSlot(x Slot) Slot

ModSlot returns result of `slot % slot`. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) Mul

func (s Slot) Mul(x uint64) Slot

Mul multiplies slot by x. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) MulSlot

func (s Slot) MulSlot(x Slot) Slot

MulSlot multiplies slot by another slot. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) SafeAdd

func (s Slot) SafeAdd(x uint64) (Slot, error)

SafeAdd increases slot by x. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeAddSlot

func (s Slot) SafeAddSlot(x Slot) (Slot, error)

SafeAddSlot increases slot by another slot. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeDiv

func (s Slot) SafeDiv(x uint64) (Slot, error)

SafeDiv divides slot by x. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeDivSlot

func (s Slot) SafeDivSlot(x Slot) (Slot, error)

SafeDivSlot divides slot by another slot. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeMod

func (s Slot) SafeMod(x uint64) (Slot, error)

SafeMod returns result of `slot % x`. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeModSlot

func (s Slot) SafeModSlot(x Slot) (Slot, error)

SafeModSlot returns result of `slot % slot`. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeMul

func (s Slot) SafeMul(x uint64) (Slot, error)

SafeMul multiplies slot by x. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeMulSlot

func (s Slot) SafeMulSlot(x Slot) (Slot, error)

SafeMulSlot multiplies slot by another slot. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeSub

func (s Slot) SafeSub(x uint64) (Slot, error)

SafeSub subtracts x from the slot. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (Slot) SafeSubSlot

func (s Slot) SafeSubSlot(x Slot) (Slot, error)

SafeSubSlot finds difference between two slot values. In case of arithmetic issues (overflow/underflow/div by zero) error is returned.

func (*Slot) SizeSSZ

func (s *Slot) SizeSSZ() int

SizeSSZ returns the size of the serialized object.

func (Slot) Sub

func (s Slot) Sub(x uint64) Slot

Sub subtracts x from the slot. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (Slot) SubSlot

func (s Slot) SubSlot(x Slot) Slot

SubSlot finds difference between two slot values. In case of arithmetic issues (overflow/underflow/div by zero) panic is thrown.

func (*Slot) UnmarshalSSZ

func (s *Slot) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ deserializes the provided bytes buffer into the slot object.

type ValidatorIndex

type ValidatorIndex uint64

ValidatorIndex in eth2.

func (ValidatorIndex) Add

Add increases validator index by x.

func (ValidatorIndex) Div

Div divides validator index by x.

func (ValidatorIndex) HashTreeRoot

func (v ValidatorIndex) HashTreeRoot() ([32]byte, error)

HashTreeRoot returns calculated hash root.

func (ValidatorIndex) HashTreeRootWith

func (v ValidatorIndex) HashTreeRootWith(hh *fssz.Hasher) error

HashWithDefaultHasher hashes a HashRoot object with a Hasher from the default HasherPool.

func (*ValidatorIndex) MarshalSSZ

func (v *ValidatorIndex) MarshalSSZ() ([]byte, error)

MarshalSSZ marshals validator index into a serialized object.

func (*ValidatorIndex) MarshalSSZTo

func (v *ValidatorIndex) MarshalSSZTo(dst []byte) ([]byte, error)

MarshalSSZTo marshals validator index with the provided byte slice.

func (ValidatorIndex) Mod

Mod returns result of `validator index % x`.

func (*ValidatorIndex) SizeSSZ

func (v *ValidatorIndex) SizeSSZ() int

SizeSSZ returns the size of the serialized object.

func (ValidatorIndex) Sub

Sub subtracts x from the validator index.

func (*ValidatorIndex) UnmarshalSSZ

func (v *ValidatorIndex) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ deserializes the provided bytes buffer into the validator index object.

Jump to

Keyboard shortcuts

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