utils

package module
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAndReverseHexString added in v1.0.8

func DecodeAndReverseHexString(hexStr string) ([]byte, error)

DecodeAndReverseHexString decodes the given hex string and then reverses the bytes. This is useful for converting Bitcoin hex strings to byte slices in little endian format.

func DisableCanonicalMode added in v1.0.5

func DisableCanonicalMode(optionalLogger ...Logger) *ttyState

DisableCanonicalMode disables canonical mode on the terminal. This allows for reading single characters without pressing enter. The previous state is returned and can be used to restore the previous state. The optionalLogger can be used a preferred logger. If no optionalLogger is provided, a default logger is used.

Usage in main.go: defer utils.RestoreTTY(utils.DisableCanonicalMode())

func GetBitcoinHash added in v1.0.7

func GetBitcoinHash(b []byte) []byte

GetBitcoinHash calculates the Bitcoin hash of the given bytes. The Bitcoin hash is the double SHA-256 hash of the given bytes which is then reversed. For transactions the entire transaction bytes are hashed; for blocks only the header (80 bytes) is hashed.

func HexEncodeAndReverseBytes added in v1.0.14

func HexEncodeAndReverseBytes(b []byte) string

HexEncodeAndReverseBytes encodes the given byte slice to a hex string and then reverses the bytes.

func RestoreTTY added in v1.0.5

func RestoreTTY(state *ttyState)

RestoreTTY restores the previous state of the terminal. The previous state is returned by DisableCanonicalMode. If the ttyState is nil, nothing is done.

func ReverseSlice added in v1.0.6

func ReverseSlice[T any](a []T) []T

ReverseSlice reverses the order of the items in the slice. A copy of the slice is returned.

func ReverseSliceInPlace added in v1.0.14

func ReverseSliceInPlace[T any](a []T)

ReverseSliceInPlace reverses the given slice in place.

func SafeSend

func SafeSend[T any](ch chan T, t T) bool

SafeSend is a helper function that sends a value on a channel and returns. It is safe to use with closed channels. It uses go generics to allow for any type of channel.

func Sha256d

func Sha256d(b []byte) []byte

Sha256d calculates hash(hash(b)) and returns the resulting bytes.

Types

type Logger added in v1.0.5

type Logger interface {
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

type Pair added in v1.0.11

type Pair[F, S any] struct {
	First  F
	Second S
}

Pair is a simple struct that holds two values.

func NewPair added in v1.0.12

func NewPair[F, S any](f F, s S) Pair[F, S]

func (Pair[F, S]) String added in v1.0.12

func (p Pair[F, S]) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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