Difficulty is a fraught metric. It is derived from the network target, where the
difficulty equals the current network target divided by the network target defined in the genesis block.
The target principally represents a 256-bit number but the block header
contains a compact representation called nbits (or CompactTarget). This is inherently lossy.
Furthermore difficulty, which used to be only for human consumption has made itself into the
stratum protocol to define the target (inverse of difficulty) a miner’s share has to meet. It
is used to tune the frequency of a miner’s share submission and for accounting how much work
has been completed. This struct aims to define it’s edges and make it easier to work with but
it is inherently lossy and imprecise. If someone stumbles accross this comment and sees a
better way to reconcile these different types, please open an issue or PR.
Stratum uses the the natural big-endian hex encoding of a hash but for some reason
all double sha256d::Hash are displayed in little-endian hex in Bitcoin. To ensure correct
serialization/deserialization and display this wrapper type was created.
Calculates the merkle root by reassembling the coinbase transaction and rebuilding
the merkle tree from the merkle branches. This is definitely a target for some
optimization in the future.