Documentation
¶
Overview ¶
pkg/types/protocol.go
Index ¶
- Constants
- Variables
- func HashData(data []byte) []byte
- func HashEqual(a, b Hash) bool
- func IsHexAddress(s string) bool
- func IsZeroAddress(h Address) bool
- func IsZeroHash(h Hash) bool
- type Address
- func (a Address) Bytes() []byte
- func (a Address) Equals(other Address) bool
- func (a Address) Hex() string
- func (a Address) IsZero() bool
- func (a Address) MarshalBinary() ([]byte, error)
- func (a Address) MarshalJSON() ([]byte, error)
- func (a Address) MarshalText() ([]byte, error)
- func (a Address) MarshalYAML() (interface{}, error)
- func (a Address) ShortHex() string
- func (a Address) String() string
- func (a Address) ToCommonAddress() common.Address
- func (a *Address) UnmarshalBinary(data []byte) error
- func (a *Address) UnmarshalJSON(data []byte) error
- func (a *Address) UnmarshalText(text []byte) error
- func (a *Address) UnmarshalYAML(value *yaml.Node) error
- type DbType
- type HandlerStatus
- type HandlerType
- type Hash
- func (h Hash) Bytes() []byte
- func (h Hash) Equal(other Hash) bool
- func (h Hash) Hex() string
- func (h Hash) MarshalBinary() ([]byte, error)
- func (h Hash) MarshalText() ([]byte, error)
- func (h Hash) MarshalYAML() (interface{}, error)
- func (h Hash) String() string
- func (h Hash) ToCommonHash() common.Hash
- func (h *Hash) UnmarshalBinary(data []byte) error
- func (h *Hash) UnmarshalText(text []byte) error
- func (h *Hash) UnmarshalYAML(value *yaml.Node) error
- type Permission
- type Priority
- type ProtocolType
- type Role
- type Roles
- type SignerType
- type Target
- type TransportType
Constants ¶
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 ¶
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 )
var ( ZeroHash = Hash{} ErrInvalidHashLength = errors.New("invalid address length") )
var ErrInvalidAddressLength = errors.New("invalid address length")
ErrInvalidAddressLength is returned when the address does not have the correct length.
Functions ¶
func IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded address or not.
func IsZeroAddress ¶
func IsZeroHash ¶
Types ¶
type Address ¶
type Address [AddressSize]byte
Address represents a fixed-size 20-byte Ethereum-like address.
func AddressFromBytes ¶
AddressFromBytes creates an Address from a byte slice. Panics if the slice is not exactly 20 bytes.
func AddressFromHex ¶
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 ¶
FromCommonAddress converts common.Address to types.Address.
func MustAddressFromHex ¶
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 ¶
NewAddress creates a new Address from a byte slice. Returns an error if the slice is not exactly 20 bytes.
func PublicKeyToAddress ¶
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) Hex ¶
Hex returns the EIP-55 checksummed hexadecimal string representation of the address.
func (Address) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Address) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Address) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Address) MarshalYAML ¶
MarshalYAML customizes the YAML marshalling of Address.
func (Address) String ¶
String returns the hexadecimal string representation of the Address with "0x" prefix. Implements the fmt.Stringer interface.
func (Address) ToCommonAddress ¶
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 ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Address) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
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 ¶
Hash represents a 32-byte SHA-256 hash.
func FromCommonHash ¶
FromCommonHash converts common.Hash to types.Hash.
func HashFromBytes ¶
HashFromBytes creates a Hash from a byte slice. Returns an error if the slice is not exactly HashSize bytes.
func HashFromHex ¶
HashFromHex creates an Hash from a hex string. The hex string may have a "0x" prefix.
func (Hash) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Hash) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Hash) MarshalYAML ¶
MarshalYAML customizes the YAML marshalling of Hash.
func (Hash) ToCommonHash ¶
func (*Hash) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (*Hash) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Permission ¶
type Permission string
Permission represents an action that can be performed.
func (Permission) String ¶
func (p Permission) String() string
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 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 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