utils

package
v0.0.0-...-4feef75 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRawDifficulty = 1000

Variables

View Source
var (
	LOG_ERR     = color.New(color.FgRed).PrintfFunc()
	LOG_INFO    = color.New(color.FgBlue)
	LOG_WARN    = color.New(color.FgYellow).PrintfFunc()
	LOG_SUCCESS = color.New(color.FgGreen)
)
View Source
var DiffOne *big.Int
View Source
var PoolDiff *big.Int

Functions

func BigToCompact

func BigToCompact(n *big.Int) uint32

BigToCompact converts a whole number N to a compact representation using an unsigned 32-bit number. The compact representation only provides 23 bits of precision, so values larger than (2^23 - 1) only encode the most significant digits of the number. See CompactToBig for details.

func BigToHashString

func BigToHashString(bigInt *big.Int) string

func CalculateCompactDifficulty

func CalculateCompactDifficulty(pdiff uint64) uint32

func CalculateDifficulty

func CalculateDifficulty(diff *big.Int, result *big.Int)

func CompactToBig

func CompactToBig(compact uint32) *big.Int

CompactToBig converts a compact representation of a whole number N to an unsigned 32-bit number. The representation is similar to IEEE754 floating point numbers.

Like IEEE754 floating point, there are three basic components: the sign, the exponent, and the mantissa. They are broken out as follows:

  • the most significant 8 bits represent the unsigned base 256 exponent

  • bit 23 (the 24th bit) represents the sign bit

  • the least significant 23 bits represent the mantissa

    ------------------------------------------------- | Exponent | Sign | Mantissa | ------------------------------------------------- | 8 bits [31-24] | 1 bit [23] | 23 bits [22-00] | -------------------------------------------------

The formula to calculate N is:

N = (-1^sign) * mantissa * 256^(exponent-3)

This compact form is only used in bitcoin to encode unsigned 256-bit numbers which represent difficulty targets, thus there really is not a need for a sign bit, but it is implemented here to stay consistent with bitcoind.

func DoubleHash

func DoubleHash(b []byte) [32]byte

func HashToBig

func HashToBig(hash [32]byte, bigInt *big.Int)

FastHashToBig converts a chainhash.Hash into a big.Int that can be used to perform math comparisons.

func HashToString

func HashToString(hash [32]byte) string

func Midstate

func Midstate(b []byte) [32]byte

Types

type Difficulty

type Difficulty uint64

func (Difficulty) String

func (d Difficulty) String() string

type NTime

type NTime uint32

func (NTime) String

func (n NTime) String() string

type Nonce32

type Nonce32 uint32

func (Nonce32) String

func (n Nonce32) String() string

type Nonce64

type Nonce64 uint64

func (Nonce64) String

func (n Nonce64) String() string

type Version

type Version uint32

func (Version) String

func (v Version) String() string

func (Version) ZeroPositions

func (v Version) ZeroPositions() []int

type Versions

type Versions [4]Version

func (*Versions) Len

func (v *Versions) Len() int

func (*Versions) Less

func (v *Versions) Less(i, j int) bool

func (*Versions) Swap

func (v *Versions) Swap(i, j int)

Jump to

Keyboard shortcuts

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