Files
prysm/consensus-types/primitives/domain.go
Raul Jordan 001f719cc3 Move ETH2 Types Into Prysm (#10534)
* move eth2 types into Prysm

* bazel

* lint

* use existing math helpers

* rem eth2-types dep

Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2022-04-28 13:57:40 +00:00

58 lines
1.1 KiB
Go

package types
import (
"fmt"
fssz "github.com/ferranbt/fastssz"
)
var _ fssz.HashRoot = (Domain)([]byte{})
var _ fssz.Marshaler = (*Domain)(nil)
var _ fssz.Unmarshaler = (*Domain)(nil)
// Domain represents a 32 bytes domain object in Ethereum beacon chain consensus.
type Domain []byte
// HashTreeRoot --
func (e Domain) HashTreeRoot() ([32]byte, error) {
return fssz.HashWithDefaultHasher(e)
}
// HashTreeRootWith --
func (e Domain) HashTreeRootWith(hh *fssz.Hasher) error {
hh.PutBytes(e[:])
return nil
}
// UnmarshalSSZ --
func (e *Domain) UnmarshalSSZ(buf []byte) error {
if len(buf) != e.SizeSSZ() {
return fmt.Errorf("expected buffer of length %d received %d", e.SizeSSZ(), len(buf))
}
var b [32]byte
item := Domain(b[:])
copy(item, buf)
*e = item
return nil
}
// MarshalSSZTo --
func (e *Domain) MarshalSSZTo(dst []byte) ([]byte, error) {
marshalled, err := e.MarshalSSZ()
if err != nil {
return nil, err
}
return append(dst, marshalled...), nil
}
// MarshalSSZ --
func (e *Domain) MarshalSSZ() ([]byte, error) {
return *e, nil
}
// SizeSSZ --
func (e *Domain) SizeSSZ() int {
return 32
}