utils

package
v0.0.0-...-59e56fa Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigTo256

func BigTo256(b *big.Int) common.Hash

BigTo256 converts big number to 32 bytes array

func CheckPid

func CheckPid(pidfileName string) error

func FreePort

func FreePort(network string) (port uint16)

FreePort gets free network port on host.

func GetUnusedNetAddr

func GetUnusedNetAddr(n int, t testing.TB) []string

GetUnusedNetAddr return array of n unused ports starting with base port NB: addresses 1-1024 are reserved for non-root users;

func HashFromHex

func HashFromHex(s string) []byte

HashFromHex converts hex string to bytes.

func I64to256

func I64to256(i64 int64) common.Hash

I64to256 converts int64 to 32 bytes array

func NameOf

func NameOf(p idx.StakerID) string

NameOf returns human readable string representation.

func PaddedBigBytes

func PaddedBigBytes(bigint *big.Int, n int) []byte

PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.

func ReadBits

func ReadBits(bigint *big.Int, buf []byte)

ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.

func TextColumns

func TextColumns(texts ...string) string

TextColumns join side-by-side.

func ToFtm

func ToFtm(ftm uint64) *big.Int

ToFtm number of FTM to Wei

func U64to256

func U64to256(u64 uint64) common.Hash

U64to256 converts uint64 to 32 bytes array

func WeightedPermutation

func WeightedPermutation(size int, weights []pos.Stake, seed common.Hash) []int

WeightedPermutation builds weighted random permutation Returns first {size} entries of {weights} permutation. Call with {size} == len(weights) to get the whole permutation.

Types

type BitArray

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

BitArray stores only first <bits> of each of <count> numbers.

func NewBitArray

func NewBitArray(bits, count uint) *BitArray

NewBitArray makes bits array of int.

func (*BitArray) Reader

func (a *BitArray) Reader(r []byte) *BitArrayReader

Reader is a number unpacker.

func (*BitArray) Size

func (a *BitArray) Size() int

Size is a bytes count.

func (*BitArray) Writer

func (a *BitArray) Writer(w []byte) *BitArrayWriter

Writer is a number packer.

type BitArrayReader

type BitArrayReader struct {
	BitArray
	// contains filtered or unexported fields
}

BitArrayReader of numbers from BitArray.

func (*BitArrayReader) Pop

func (a *BitArrayReader) Pop() int

Pop number from array.

type BitArrayWriter

type BitArrayWriter struct {
	BitArray
	// contains filtered or unexported fields
}

BitArrayWriter of numbers to BitArray.

func (*BitArrayWriter) Push

func (a *BitArrayWriter) Push(v int)

Push bits of number into array.

type SpinLock

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

SpinLock implements a simple atomic spin lock, the zero value for a SpinLock is an unlocked spinlock.

func (*SpinLock) Lock

func (sl *SpinLock) Lock()

Lock locks sl. If the lock is already in use, the caller blocks until Unlock is called

func (*SpinLock) String

func (sl *SpinLock) String() string

String is human readable lock state

func (*SpinLock) TryLock

func (sl *SpinLock) TryLock() bool

TryLock will try to lock sl and return whether it succeed or not without blocking.

func (*SpinLock) Unlock

func (sl *SpinLock) Unlock()

Unlock unlocks sl, unlike [Mutex.Unlock](http://golang.org/pkg/sync/#Mutex.Unlock), there's no harm calling it on an unlocked SpinLock

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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