types

package
v0.0.0-...-da72ffe Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

pkg/types/protocol.go

Index

Constants

View Source
const (
	// HashSize defines the size of a SHA-256 hash in bytes.
	HashSize = 32

	// AddressSize defines the size of an address or public key in bytes.
	AddressSize = 20

	// MaxPayloadSize defines the maximum allowed payload size in bytes.
	MaxPayloadSize = 1 << 20 // 1 MB maximum payload size to prevent excessive memory usage
)

Variables

View Source
var (
	ZeroAddress = Address{}

	// StakingAddress is the address used for staking transactions.
	StakingAddress = Address{19: 0x01} // Set the last byte to 0x01; others default to 0x00
)
View Source
var (
	ZeroHash = Hash{}

	ErrInvalidHashLength = errors.New("invalid address length")
)
View Source
var ErrInvalidAddressLength = errors.New("invalid address length")

ErrInvalidAddressLength is returned when the address does not have the correct length.

Functions

func HashData

func HashData(data []byte) []byte

HashData creates a SHA-256 hash of the input data.

func HashEqual

func HashEqual(a, b Hash) bool

HashEqual compares two hashes for equality.

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded address or not.

func IsZeroAddress

func IsZeroAddress(h Address) bool

func IsZeroHash

func IsZeroHash(h Hash) bool

Types

type Address

type Address [AddressSize]byte

Address represents a fixed-size 20-byte Ethereum-like address.

func AddressFromBytes

func AddressFromBytes(bytes []byte) Address

AddressFromBytes creates an Address from a byte slice. Panics if the slice is not exactly 20 bytes.

func AddressFromHex

func AddressFromHex(s string) (Address, error)

AddressFromHex creates an Address from a hex string. The hex string may have a "0x" prefix. Returns an error if the string is not valid hex or does not represent exactly 20 bytes.

func FromCommonAddress

func FromCommonAddress(cAddr common.Address) Address

FromCommonAddress converts common.Address to types.Address.

func MustAddressFromHex

func MustAddressFromHex(s string) Address

MustAddressFromHex creates an Address from a hex string. Panics if the string is not a valid hex or does not represent exactly 20 bytes.

func NewAddress

func NewAddress(bytes []byte) (Address, error)

NewAddress creates a new Address from a byte slice. Returns an error if the slice is not exactly 20 bytes.

func PublicKeyToAddress

func PublicKeyToAddress(pubKey []byte) (Address, error)

PublicKeyToAddress derives the Address from the public key. This function should implement the logic to derive the address from the public key, similar to Ethereum's address derivation (e.g., Keccak-256 hash and take last 20 bytes).

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns the byte representation of the Address.

func (Address) Equals

func (a Address) Equals(other Address) bool

Equals compares two Addresses for equality.

func (Address) Hex

func (a Address) Hex() string

Hex returns the EIP-55 checksummed hexadecimal string representation of the address.

func (Address) IsZero

func (a Address) IsZero() bool

IsZero checks if the address is the zero address.

func (Address) MarshalBinary

func (a Address) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Address) MarshalYAML

func (a Address) MarshalYAML() (interface{}, error)

MarshalYAML customizes the YAML marshalling of Address.

func (Address) ShortHex

func (a Address) ShortHex() string

ShortHex returns a shortened version of the address for display purposes.

func (Address) String

func (a Address) String() string

String returns the hexadecimal string representation of the Address with "0x" prefix. Implements the fmt.Stringer interface.

func (Address) ToCommonAddress

func (a Address) ToCommonAddress() common.Address

ToCommonAddress converts types.Address to common.Address. This is useful for interaction with go-ethereum client. Otherwise types.Address and common.Address are identical in value.

func (*Address) UnmarshalBinary

func (a *Address) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Address) UnmarshalYAML

func (a *Address) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML customizes the YAML unmarshalling of Address.

type DbType

type DbType string

func (DbType) String

func (t DbType) String() string

type HandlerStatus

type HandlerStatus byte
const (
	HandlerStatusError   HandlerStatus = 0x00
	HandlerStatusSuccess HandlerStatus = 0x01
)

func (HandlerStatus) Byte

func (hs HandlerStatus) Byte() byte

func (HandlerStatus) String

func (hs HandlerStatus) String() string

type HandlerType

type HandlerType byte

HandlerType represents different types of handlers

const (
	WriteHandlerType HandlerType = 'W' // 'W' for WRITE
	ReadHandlerType  HandlerType = 'R' // 'R' for READ
)

Define the handlers as 1-byte constants

func (*HandlerType) FromByte

func (h *HandlerType) FromByte(b byte) error

FromByte converts a byte into a HandlerType

func (HandlerType) String

func (h HandlerType) String() string

type Hash

type Hash [HashSize]byte

Hash represents a 32-byte SHA-256 hash.

func FromCommonHash

func FromCommonHash(cAddr common.Hash) Hash

FromCommonHash converts common.Hash to types.Hash.

func HashFromBytes

func HashFromBytes(data []byte) (Hash, error)

HashFromBytes creates a Hash from a byte slice. Returns an error if the slice is not exactly HashSize bytes.

func HashFromHex

func HashFromHex(s string) (Hash, error)

HashFromHex creates an Hash from a hex string. The hex string may have a "0x" prefix.

func SumHash

func SumHash(data []byte) Hash

SumHash computes the SHA-256 hash of the input data.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the byte slice representation of the Hash.

func (Hash) Equal

func (h Hash) Equal(other Hash) bool

Equal compares two Hashes for equality.

func (Hash) Hex

func (h Hash) Hex() string

Hex returns the hexadecimal string representation of the Hash.

func (Hash) MarshalBinary

func (h Hash) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Hash) MarshalYAML

func (h Hash) MarshalYAML() (interface{}, error)

MarshalYAML customizes the YAML marshalling of Hash.

func (Hash) String

func (h Hash) String() string

String returns the hexadecimal string representation of the Hash.

func (Hash) ToCommonHash

func (h Hash) ToCommonHash() common.Hash

func (*Hash) UnmarshalBinary

func (h *Hash) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Hash) UnmarshalYAML

func (h *Hash) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML customizes the YAML unmarshalling of Hash.

type Permission

type Permission string

Permission represents an action that can be performed.

func (Permission) String

func (p Permission) String() string

type Priority

type Priority uint8

Priority represents the importance level of a record batch

const (
	PriorityHigh Priority = iota
	PriorityNormal
	PriorityLow
)

type ProtocolType

type ProtocolType int

ProtocolType represents different application protocols.

const (
	HTTPProtocol ProtocolType = iota
	RPCProtocol
	WebSocketProtocol
	BinaryProtocol
)

ProtocolType constants using iota.

func ParseProtocolType

func ParseProtocolType(s string) (ProtocolType, error)

ParseProtocolType parses a string into a ProtocolType.

func ProtocolTypeFromUint32

func ProtocolTypeFromUint32(u uint32) ProtocolType

ProtocolTypeFromUint32 converts a uint32 to a ProtocolType.

func (ProtocolType) String

func (p ProtocolType) String() string

String returns the string representation of the ProtocolType.

func (ProtocolType) Uint32

func (p ProtocolType) Uint32() uint32

func (*ProtocolType) UnmarshalYAML

func (p *ProtocolType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows ProtocolType to be correctly unmarshalled from a YAML string.

type Role

type Role string

Role represents a user role in the system.

func (Role) String

func (r Role) String() string

type Roles

type Roles []Role

Roles represents a group of user roles in the system.

func (Roles) String

func (r Roles) String() string

type SignerType

type SignerType string

SignerType represents the type of a signer.

const (
	BlsSignerType          SignerType = "bls"
	Ed25519SignerType      SignerType = "ed25519"
	SchnorrSignerType      SignerType = "schnorr"
	Secp256k1SignerType    SignerType = "secp256k1"
	ThresholdBLSSignerType SignerType = "threshold_bls"
	UnknownSignerType      SignerType = "unknown"
)

func SignerTypeFromUint32

func SignerTypeFromUint32(u uint32) SignerType

SignerTypeFromUint32 converts a uint32 to a SignerType.

func (SignerType) MarshalJSON

func (t SignerType) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON marshaling of SignerType to uint32.

func (SignerType) MarshalYAML

func (t SignerType) MarshalYAML() (interface{}, error)

MarshalYAML customizes the YAML marshaling of SignerType to uint32.

func (SignerType) String

func (t SignerType) String() string

String returns the string representation of the SignerType.

func (SignerType) Uint32

func (t SignerType) Uint32() uint32

Uint32 returns the uint32 representation of the SignerType.

func (*SignerType) UnmarshalJSON

func (t *SignerType) UnmarshalJSON(data []byte) error

UnmarshalJSON customizes the JSON unmarshaling of SignerType from uint32.

func (*SignerType) UnmarshalYAML

func (t *SignerType) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML customizes the YAML unmarshaling of SignerType from uint32.

type Target

type Target uint8

Target specifies the distribution target type

const (
	TargetAll Target = iota
	TargetValidators
	TargetDirectPeer
)

type TransportType

type TransportType int
const (
	UDPTransportType TransportType = iota
	DummyTransportType
	QUICTransportType
	UDSTransportType
	TCPTransportType
)

func ParseTransportType

func ParseTransportType(s string) (TransportType, error)

ParseTransportType parses a string into a TransportType

func TransportTypeFromUint32

func TransportTypeFromUint32(u uint32) TransportType

TransportTypeFromUint32 converts a uint32 to a TransportType.

func (TransportType) String

func (t TransportType) String() string

String representation of TransportType

func (TransportType) Uint32

func (t TransportType) Uint32() uint32

func (*TransportType) UnmarshalYAML

func (t *TransportType) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML allows TransportType to be correctly unmarshalled from a YAML string

Jump to

Keyboard shortcuts

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