difficulty

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2016 License: ISC Imports: 8 Imported by: 0

Documentation

Overview

Implement the Bitcoin difficulty value and its various encodings

Index

Constants

View Source
const (
	OneUint64         uint64  = 0x00ffffffffffffff
	MinimumReciprocal float64 = 1.0
)

the default values

View Source
const HalfLife = 100

number of block times to decay the difficulty by 50%

Variables

View Source
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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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