util

package
v0.0.0-...-a9f2047 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeToBytes

func EncodeToBytes(i uint64) []byte

Get big-endian bytes encoding of i Result is 1 to 8 bytes long. 0x0 bytes is returned for 0

func GetDifficulty

func GetDifficulty(p float64) uint

solve for l the equation: p := 1 / 2^ l

func GetMask

func GetMask(l uint, c uint) *big.Int

Create an l bytes long bit mask with the c MSB bits set to 0 and the other bits set to 1 c*8 must be <= l

func GetMaxNonce

func GetMaxNonce(l int) *big.Int

Returns the max nonce that is l bits long. e.g. for l=256, nonce should be 2^256-1

func GetNthBit

func GetNthBit(b byte, bit uint64) bool

Get the bool value of the nth bit of a value of a byte bit is defined from right to left so the LSB bit is at 0 and the MSB it is at 7. e.g. byte is bits at indexes [7|6|5|4|3|2|1|0] and 0x1 is 00000001, 0x2 is 00000010

func GetProbability

func GetProbability(l uint) float64

Get the prob (0...1) of a difficulty param l p := 1 / 2^l

func GetSimpleMask

func GetSimpleMask(l uint) *big.Int

Returns an int representing l bits set to 1

func Rnd

func Rnd(t *testing.T, l uint) []byte

test helper - generate l random bytes

func Rnd1

func Rnd1(l uint) []byte

test helper - generate l random bytes

func String

func String(b bitarray.BitArray, size uint64) (string, error)

Get string representation of a BitArray

func Uint64Value

func Uint64Value(b bitarray.BitArray, length uint64) (uint64, error)

Decode a big-endian uint64 from its binary encoding of up to length bits

Types

type Writer

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

Writer implements buffering for an io.Writer object. If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes, and Flush, will return the error. After all data has been written, the client should call the Flush method to guarantee all data has been forwarded to the underlying io.Writer.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a new Writer whose buffer has the default size.

func NewWriterSize

func NewWriterSize(w io.Writer, size int) *Writer

NewWriterSize returns a new Writer whose buffer has at least the specified size. If the argument io.Writer is already a Writer with large enough size, it returns the underlying Writer.

func (*Writer) Available

func (b *Writer) Available() int

Available returns how many bytes are unused in the buffer.

func (*Writer) Buffered

func (b *Writer) Buffered() int

Buffered returns the number of bytes that have been written into the current buffer.

func (*Writer) Flush

func (b *Writer) Flush() error

Flush writes any buffered data to the underlying io.Writer.

func (*Writer) GetBuffer

func (b *Writer) GetBuffer() []byte

get the underlying buffer slice

func (*Writer) Reset

func (b *Writer) Reset(w io.Writer)

Reset discards any unflushed buffered data, clears any error, and resets b to write its output to w.

func (*Writer) Size

func (b *Writer) Size() int

Size returns the size of the underlying buffer in bytes.

func (*Writer) Write

func (b *Writer) Write(p []byte) (nn int, err error)

Write writes the contents of p into the buffer. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short.

func (*Writer) WriteByte

func (b *Writer) WriteByte(c byte) error

WriteByte writes a single byte.

Jump to

Keyboard shortcuts

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