Documentation ¶
Index ¶
- Constants
- Variables
- func BigToCompact(n *big.Int) uint32
- func BigToHashString(bigInt *big.Int) string
- func CalculateCompactDifficulty(pdiff uint64) uint32
- func CalculateDifficulty(diff *big.Int, result *big.Int)
- func CompactToBig(compact uint32) *big.Int
- func DoubleHash(b []byte) [32]byte
- func HashToBig(hash [32]byte, bigInt *big.Int)
- func HashToString(hash [32]byte) string
- func Midstate(b []byte) [32]byte
- type Difficulty
- type NTime
- type Nonce32
- type Nonce64
- type Version
- type Versions
Constants ¶
const MaxRawDifficulty = 1000
Variables ¶
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) )
var DiffOne *big.Int
var PoolDiff *big.Int
Functions ¶
func BigToCompact ¶
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 CompactToBig ¶
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 HashToBig ¶
FastHashToBig converts a chainhash.Hash into a big.Int that can be used to perform math comparisons.
func HashToString ¶
Types ¶
type Difficulty ¶
type Difficulty uint64
func (Difficulty) String ¶
func (d Difficulty) String() string