utils

package
v0.0.0-...-7781947 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: BSD-3-Clause Imports: 14 Imported by: 5

Documentation

Index

Constants

View Source
const NativeDecimals = 9

Variables

This section is empty.

Functions

func ErrBytes

func ErrBytes(err error) []byte

func FormatBalance

func FormatBalance(bal uint64) string

func GetHost

func GetHost(uri string) (string, error)

func InitSubDirectory

func InitSubDirectory(rootPath string, name string) (string, error)

func NewHandler

func NewHandler(
	name string,
	service interface{},
	lockOption ...common.LockOption,
) (*common.HTTPHandler, error)

NewHandler returns a new Handler for a service where:

  • The handler's functionality is defined by [service] [service] should be a gorilla RPC service (see https://www.gorillatoolkit.org/pkg/rpc/v2)
  • The name of the service is [name]
  • The LockOption is the first element of [lockOption] By default the LockOption is WriteLock [lockOption] should have either 0 or 1 elements. Elements beside the first are ignored.

func Outf

func Outf(format string, args ...interface{})

Outputs to stdout.

e.g.,

Out("{{green}}{{bold}}hi there %q{{/}}", "aa")
Out("{{magenta}}{{bold}}hi therea{{/}} {{cyan}}{{underline}}b{{/}}")

ref. https://github.com/onsi/ginkgo/blob/v2.0.0/formatter/formatter.go#L52-L73

func ParseBalance

func ParseBalance(bal string) (uint64, error)

func Repeat

func Repeat[T any](v T, n int) []T

func ToID

func ToID(bytes []byte) ids.ID

Types

type BoundedBuffer

type BoundedBuffer[K any] struct {
	// contains filtered or unexported fields
}

BoundedBuffer keeps [size] entries of type [K] in a buffer and calls [callback] on any item that is overwritten. This is typically used for dereferencing old roots during block processing.

BoundedBuffer is not thread-safe and requires the caller synchronize usage.

func NewBoundedBuffer

func NewBoundedBuffer[K any](size int, callback func(K)) *BoundedBuffer[K]

NewBoundedBuffer creates a new BoundedBuffer.

func (*BoundedBuffer[K]) Insert

func (b *BoundedBuffer[K]) Insert(h K)

Insert adds a new value to the buffer. If the buffer is full, the oldest value will be overwritten and [callback] will be invoked.

func (*BoundedBuffer[K]) Items

func (b *BoundedBuffer[K]) Items() []K

func (*BoundedBuffer[K]) Last

func (b *BoundedBuffer[K]) Last() (K, bool)

Last retrieves the last item added to the buffer.

If no items have been added to the buffer, Last returns the default value of [K] and [false].

Jump to

Keyboard shortcuts

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