We recently made our U256 type private and using it to expose Target and Work. Doing so stopped folks from doing arbitrary math with large numbers, one thing that is no longer possible is calculating the next difficulty target.
Add implementation of CalculateNextWorkRequired (incl. logic from GetNextWorkRequired) from Bitcoin Core (both in bitcoin/src/pow.cpp).
For bonus points:
- Comment the div/mul by 4 so readers of the code know why that is done.
- Make it rusty instead of a direct copy of the C++.