utils

package
v0.0.0-...-78380f7 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCount

func ByteCount(b uint64) string

func Clean

func Clean() []string

Clean cleans old unused locks. Returns removed keys.

func ConvertAddressToH160

func ConvertAddressToH160(addr [20]byte) *types_pb.H160

func ConvertAddrsToH160

func ConvertAddrsToH160(ps []types.Address) []*types_pb.H160

func ConvertBytesToH2048

func ConvertBytesToH2048(data []byte) *types_pb.H2048

func ConvertBytesToH512

func ConvertBytesToH512(b []byte) *types_pb.H512

func ConvertFromInterfacePrivKey

func ConvertFromInterfacePrivKey(privkey crypto.PrivKey) (*ecdsa.PrivateKey, error)

func ConvertH160ToPAddress

func ConvertH160ToPAddress(h160 *types_pb.H160) *types.Address

func ConvertH160toAddress

func ConvertH160toAddress(h160 *types_pb.H160) [20]byte

func ConvertH2048ToBloom

func ConvertH2048ToBloom(h2048 *types_pb.H2048) [256]byte

func ConvertH256ToHash

func ConvertH256ToHash(h256 *types_pb.H256) [32]byte

func ConvertH256ToUint256Int

func ConvertH256ToUint256Int(h256 *types_pb.H256) *uint256.Int

func ConvertH384ToPublicKey

func ConvertH384ToPublicKey(h384 *types_pb.H384) [48]byte

func ConvertH512ToBytes

func ConvertH512ToBytes(h512 *types_pb.H512) []byte

func ConvertH512ToHash

func ConvertH512ToHash(h512 *types_pb.H512) [64]byte

func ConvertH768ToSignature

func ConvertH768ToSignature(h768 *types_pb.H768) [96]byte

func ConvertHashToH256

func ConvertHashToH256(hash [32]byte) *types_pb.H256

func ConvertHashToH512

func ConvertHashToH512(hash [64]byte) *types_pb.H512

func ConvertHashesToH256

func ConvertHashesToH256(hashes []types.Hash) []*types_pb.H256

func ConvertPublicKeyToH384

func ConvertPublicKeyToH384(p [48]byte) *types_pb.H384

func ConvertPubsToH384

func ConvertPubsToH384(ps []types.PublicKey) []*types_pb.H384

func ConvertSignatureToH768

func ConvertSignatureToH768(p [96]byte) *types_pb.H768

func ConvertToInterfacePrivkey

func ConvertToInterfacePrivkey(privkey *ecdsa.PrivateKey) (crypto.PrivKey, error)

func ConvertToInterfacePubkey

func ConvertToInterfacePubkey(pubkey *ecdsa.PublicKey) (crypto.PubKey, error)

func ConvertUint256IntToH256

func ConvertUint256IntToH256(i *uint256.Int) *types_pb.H256

func Copy

func Copy(b []byte) []byte

func CreateForkDigest

func CreateForkDigest(currentBlockNr *uint256.Int, genesisValidatorsRoot types.Hash) ([4]byte, error)

CreateForkDigest creates a fork digest from a genesis time and genesis validators root, utilizing the current slot to determine the active fork version in the node.

func EnsureEnoughSize

func EnsureEnoughSize(in []byte, size int) []byte

func Exists

func Exists(path string) bool

func ExternalIP

func ExternalIP() (string, error)

ExternalIP returns the first IPv4/IPv6 available.

func ExternalIPv4

func ExternalIPv4() (string, error)

ExternalIPv4 returns the first IPv4 available.

func H160sToAddress

func H160sToAddress(ps []*types_pb.H160) []types.Address

func H256sToHashes

func H256sToHashes(h256s []*types_pb.H256) []types.Hash

func H384sToPubs

func H384sToPubs(ps []*types_pb.H384) []types.PublicKey

func Hash256toS

func Hash256toS(data []byte) string

func HexPrefix

func HexPrefix(a, b []byte) ([]byte, int)

func IPAddr

func IPAddr() net.IP

IPAddr gets the external ipv4 address and converts into a libp2p formatted value.

func Keccak256

func Keccak256(data ...[]byte) []byte

func Keccak256Hash

func Keccak256Hash(data ...[]byte) (h types.Hash)

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func MBToGB

func MBToGB(b uint64) (float64, int)

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

func NewContext

func NewContext(ctx context.Context, s AppInfo) context.Context

NewContext returns a new Context that carries value.

func PrivateToString

func PrivateToString(key crypto.PrivKey) (string, error)

func PublicToString

func PublicToString(key crypto.PubKey) (string, error)

func RunEvery

func RunEvery(ctx context.Context, period time.Duration, f func())

RunEvery runs the provided command periodically. It runs in a goroutine, and can be cancelled by finishing the supplied context.

func SortAddresses

func SortAddresses(ipAddrs []net.IP) []net.IP

SortAddresses sorts a set of addresses in the order of ipv4 -> ipv6.

func SplitAndTrim

func SplitAndTrim(input string) (ret []string)

SplitAndTrim splits input separated by a comma and trims excessive white space from the substrings.

func StringToPrivate

func StringToPrivate(s string) (crypto.PrivKey, error)

func StringToPublic

func StringToPublic(s string) (crypto.PubKey, error)

func ToBytes20

func ToBytes20(x []byte) [20]byte

ToBytes20 is a convenience method for converting a byte slice to a fix sized 20 byte array. This method will truncate the input if it is larger than 20 bytes.

func ToBytes32

func ToBytes32(x []byte) [32]byte

ToBytes32 is a convenience method for converting a byte slice to a fix sized 32 byte array. This method will truncate the input if it is larger than 32 bytes.

func ToBytes4

func ToBytes4(x []byte) [4]byte

ToBytes4 is a convenience method for converting a byte slice to a fix sized 4 byte array. This method will truncate the input if it is larger than 4 bytes.

func ToBytes48

func ToBytes48(x []byte) [48]byte

ToBytes48 is a convenience method for converting a byte slice to a fix sized 48 byte array. This method will truncate the input if it is larger than 48 bytes.

func ToBytes64

func ToBytes64(x []byte) [64]byte

ToBytes64 is a convenience method for converting a byte slice to a fix sized 64 byte array. This method will truncate the input if it is larger than 64 bytes.

func ToBytes96

func ToBytes96(x []byte) [96]byte

ToBytes96 is a convenience method for converting a byte slice to a fix sized 96 byte array. This method will truncate the input if it is larger than 96 bytes.

func Uint256sToH256

func Uint256sToH256(u256s []uint256.Int) []*types_pb.H256

Types

type AppInfo

type AppInfo interface {
	ID() string
	Name() string
	Version() string

	Endpoint() []string
	// contains filtered or unexported methods
}

func FromContext

func FromContext(ctx context.Context) (s AppInfo, ok bool)

FromContext returns the Transport value stored in ctx, if any.

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

func NewMultilock

func NewMultilock(locks ...string) *Lock

NewMultilock creates a new multilock for the specified keys

func (*Lock) Lock

func (lk *Lock) Lock()

func (*Lock) Unlock

func (lk *Lock) Unlock()

Unlock unlocks this lock. Must be called after Lock. Can only be invoked if there is a previous call to Lock.

func (*Lock) Yield

func (lk *Lock) Yield()

Yield temporarily unlocks, gives up the cpu time to other goroutine, and attempts to lock again.

Jump to

Keyboard shortcuts

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