Beispiel #1
0
UniValue ValueFromAmount(const Amount &amount) {
    int64_t amt = amount.GetSatoshis();
    bool sign = amt < 0;
    int64_t n_abs = (sign ? -amt : amt);
    int64_t quotient = n_abs / COIN.GetSatoshis();
    int64_t remainder = n_abs % COIN.GetSatoshis();
    return UniValue(UniValue::VNUM, strprintf("%s%d.%08d", sign ? "-" : "",
                                              quotient, remainder));
}
uint64_t CTxOutCompressor::CompressAmount(Amount amt) {
    uint64_t n = amt.GetSatoshis();
    if (n == 0) {
        return 0;
    }
    int e = 0;
    while (((n % 10) == 0) && e < 9) {
        n /= 10;
        e++;
    }
    if (e < 9) {
        int d = (n % 10);
        assert(d >= 1 && d <= 9);
        n /= 10;
        return 1 + (n * 9 + d - 1) * 10 + e;
    } else {
        return 1 + (n - 1) * 10 + 9;
    }
}