Documentation ¶
Overview ¶
Package difficulty - implement the difficulty value and its various encodings
Index ¶
- Constants
- Variables
- func Hashrate() float64
- func NextDifficultyByPreviousTimespan(prevTimespanSecond uint64, currentDifficulty float64) float64
- func PrevTimespanBlockBeginAndEnd(height uint64) (uint64, uint64)
- type Difficulty
- func (difficulty *Difficulty) BigInt() *big.Int
- func (difficulty *Difficulty) Bits() uint64
- func (difficulty *Difficulty) GoString() string
- func (difficulty Difficulty) MarshalText() ([]byte, error)
- func (difficulty *Difficulty) Set(f float64)
- func (difficulty *Difficulty) SetBits(u uint64) *Difficulty
- func (difficulty *Difficulty) SetBytes(b []byte) *Difficulty
- func (difficulty *Difficulty) String() string
- func (difficulty *Difficulty) UnmarshalText(s []byte) error
- func (difficulty *Difficulty) Value() float64
Constants ¶
const ( OneUint64 uint64 = 0x00ffffffffffffff ExpectedBlockSpacingInSecond = 2 * 60 AdjustTimespanInBlocks = 200 )
the default values
Variables ¶
var Current = New()
Current - current difficulty
Functions ¶
func Hashrate ¶ added in v0.11.0
func Hashrate() float64
Hashrate - calculate hashrate from current difficulty, rounded to 3 digits
func NextDifficultyByPreviousTimespan ¶ added in v0.11.0
NextDifficultyByPreviousTimespan - next difficulty calculated by previous timespan
func PrevTimespanBlockBeginAndEnd ¶ added in v0.11.0
PrevTimespanBlockBeginAndEnd - previous begin & end block of difficulty timespan
Types ¶
type Difficulty ¶
type Difficulty struct {
// contains filtered or unexported fields
}
Difficulty - Type for difficulty
bits is encoded as:
8 bit exponent, 57 bit mantissa normalised so msb is '1' and omitted
mantissa is shifted by exponent+8 examples:
the "One" value: 00 ff ff ff ff ff ff ff represents the 256 bit value: 00ff ffff ffff ffff 8000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 value: 01 ff ff ff ff ff ff ff represents the 256 bit value: 007f ffff ffff ffff c000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
func New ¶
func New() *Difficulty
New - create a difficulty with the largest possible value which is the easiest for the miners and has the fewest leading zeros
func (*Difficulty) BigInt ¶
func (difficulty *Difficulty) BigInt() *big.Int
BigInt - convert a uint64 difficulty value to a big.Int
func (*Difficulty) Bits ¶
func (difficulty *Difficulty) Bits() uint64
Bits - Get difficulty as short packed value
func (*Difficulty) GoString ¶
func (difficulty *Difficulty) GoString() string
GoString - for the %#v format use 256 bit value
func (Difficulty) MarshalText ¶ added in v0.2.0
func (difficulty Difficulty) MarshalText() ([]byte, error)
MarshalText - convert a difficulty to little endian hex for JSON
func (*Difficulty) Set ¶ added in v0.11.0
func (difficulty *Difficulty) Set(f float64)
Set - set difficulty value
func (*Difficulty) SetBits ¶
func (difficulty *Difficulty) SetBits(u uint64) *Difficulty
SetBits - set from a 64 bit word (bits)
func (*Difficulty) SetBytes ¶
func (difficulty *Difficulty) SetBytes(b []byte) *Difficulty
SetBytes - set the difficulty from little endian bytes
func (*Difficulty) String ¶
func (difficulty *Difficulty) String() string
String - Get difficulty as the big endian hex encodes short packed value
func (*Difficulty) UnmarshalText ¶ added in v0.2.0
func (difficulty *Difficulty) UnmarshalText(s []byte) error
UnmarshalText - convert a difficulty little endian hex string to difficulty value
func (*Difficulty) Value ¶ added in v0.11.0
func (difficulty *Difficulty) Value() float64
Value - difficulty value (floating point, it's Pdiff value) This value is a reciprocal, difficulty.value = 1 / difficulty.bits