Documentation ¶
Overview ¶
Implement the Bitcoin difficulty value and its various encodings
Index ¶
- Constants
- Variables
- type Difficulty
- func (difficulty *Difficulty) Adjust(expectedMinutes float64, actualMinutes float64) float64
- func (difficulty *Difficulty) BigInt() *big.Int
- func (difficulty *Difficulty) Bits() uint64
- func (difficulty *Difficulty) Decay() float64
- func (difficulty *Difficulty) GoString() string
- func (difficulty Difficulty) MarshalText() ([]byte, error)
- func (difficulty *Difficulty) Reciprocal() float64
- func (difficulty *Difficulty) SetBits(u uint64) *Difficulty
- func (difficulty *Difficulty) SetBytes(b []byte) *Difficulty
- func (difficulty *Difficulty) SetReciprocal(f float64)
- func (difficulty *Difficulty) String() string
- func (difficulty *Difficulty) UnmarshalText(s []byte) error
Constants ¶
const ( OneUint64 uint64 = 0x00ffffffffffffff MinimumReciprocal float64 = 1.0 )
the default values
const HalfLife = 100
number of block times to decay the difficulty by 50%
Variables ¶
var Current = New()
current difficulty
Functions ¶
This section is empty.
Types ¶
type Difficulty ¶
type Difficulty struct {
// contains filtered or unexported fields
}
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
create a difficulty with the largest possible value which is the easiest for the miners and has the fewest leading zeros
func (*Difficulty) Adjust ¶
func (difficulty *Difficulty) Adjust(expectedMinutes float64, actualMinutes float64) float64
adjustment based on error from desired cycle time call as difficulty.Adjust(expectedMinutes, actualMinutes)
func (*Difficulty) BigInt ¶
func (difficulty *Difficulty) BigInt() *big.Int
convert a uint64 difficulty value to a big.Int
func (*Difficulty) Bits ¶
func (difficulty *Difficulty) Bits() uint64
Get difficulty as short packed value
func (*Difficulty) Decay ¶
func (difficulty *Difficulty) Decay() float64
exponential decay of difficulty call each expected block period to decay the current difficulty
func (*Difficulty) GoString ¶
func (difficulty *Difficulty) GoString() string
for the %#v format use 256 bit value
func (Difficulty) MarshalText ¶ added in v0.2.0
func (difficulty Difficulty) MarshalText() ([]byte, error)
convert a difficulty to little endian hex for JSON
func (*Difficulty) Reciprocal ¶ added in v0.2.0
func (difficulty *Difficulty) Reciprocal() float64
Get 1/difficulty as normal floating-point value this is the Pdiff value
func (*Difficulty) SetBits ¶
func (difficulty *Difficulty) SetBits(u uint64) *Difficulty
set from a 64 bit word (bits)
func (*Difficulty) SetBytes ¶
func (difficulty *Difficulty) SetBytes(b []byte) *Difficulty
set the difficulty from little endian bytes
func (*Difficulty) SetReciprocal ¶ added in v0.2.0
func (difficulty *Difficulty) SetReciprocal(f float64)
func (*Difficulty) String ¶
func (difficulty *Difficulty) 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
convert a difficulty little endian hex string to difficulty value