Add CashAddr Address Format

Ported from Bitcoin Unlimited, Bitcoin ABC
This commit is contained in:
lateminer
2018-01-14 22:32:08 +03:00
parent 7cd5894690
commit 323a6750c2
85 changed files with 3107 additions and 780 deletions

View File

@@ -130,4 +130,44 @@ bool TimingResistantEqual(const T& a, const T& b)
*/
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out);
/**
* Convert from one power-of-2 number base to another.
*
* If padding is enabled, this always return true. If not, then it returns true
* of all the bits of the input are encoded in the output.
*/
template <int frombits, int tobits, bool pad, typename O, typename I>
bool ConvertBits(O &out, I it, I end)
{
size_t acc = 0;
size_t bits = 0;
constexpr size_t maxv = (1 << tobits) - 1;
constexpr size_t max_acc = (1 << (frombits + tobits - 1)) - 1;
while (it != end)
{
acc = ((acc << frombits) | *it) & max_acc;
bits += frombits;
while (bits >= tobits)
{
bits -= tobits;
out.push_back((acc >> bits) & maxv);
}
++it;
}
// We have remaining bits to encode but do not pad.
if (!pad && bits)
{
return false;
}
// We have remaining bits to encode so we do pad.
if (pad && bits)
{
out.push_back((acc << (tobits - bits)) & maxv);
}
return true;
}
#endif // BITCOIN_UTILSTRENCODINGS_H