## Description

CalcWork calculates a work value from difficulty bits. Bitcoin increases the difficulty for generating a block by decreasing the value which the generated hash must be less than. This difficulty target is stored in each block header using a compact representation as described in the documentation for CompactToBig. The main chain is selected by choosing the chain that has the most proof of work (highest difficulty). Since a lower target difficulty value equates to higher actual difficulty, the work value which will be accumulated must be the inverse of the difficulty. Also, in order to avoid potential division by zero and really small floating point numbers, the result adds 1 to the denominator and multiplies the numerator by 2^256.

## Examples

maxTimestamp = minTimestamp } else { totalWork.Add(totalWork, blockchain.CalcWork(header.Bits)) if minTimestamp.After(header.Timestamp) {

bits := uint32(test.in) r := blockchain.CalcWork(bits) if r.Int64() != test.out { t.Errorf("TestCalcWork test #%d failed: got %v want %d\n",

hash: blockHash, parentHash: &prevHash, workSum: CalcWork(blockHeader.Bits), height: height, version: blockHeader.Version,

## CalcWork is referenced in 3 repositories

**github.com/btcsuite/btcd**

- 2 references in blockchain/chainio_test.go
- 1 reference in blockchain/chain.go
- 1 reference in blockchain/difficulty_test.go
- 1 reference in rpcserver.go

**github.com/OpenBazaar/spvwallet**

- 1 reference in blockchain.go

...