forked from Bitcoin-ABC/bitcoin-abc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamount.cpp
38 lines (31 loc) · 1.33 KB
/
amount.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Copyright (c) 2017-2019 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <consensus/amount.h>
#include <currencyunit.h>
#include <univalue.h>
#include <util/system.h>
#include <tinyformat.h>
static const Currency BCHA{COIN, SATOSHI, 8, "BCHA"};
static const Currency XEC{100 * SATOSHI, SATOSHI, 2, "XEC"};
const Currency &Currency::get() {
return gArgs.GetBoolArg("-ecash", DEFAULT_ECASH) ? XEC : BCHA;
}
std::string Amount::ToString() const {
const auto currency = Currency::get();
return strprintf("%d.%0*d %s", *this / currency.baseunit, currency.decimals,
(*this % currency.baseunit) / currency.subunit,
currency.ticker);
}
Amount::operator UniValue() const {
bool sign = *this < Amount::zero();
Amount n_abs(sign ? -amount : amount);
const auto currency = Currency::get();
int64_t quotient = n_abs / currency.baseunit;
int64_t remainder = (n_abs % currency.baseunit) / currency.subunit;
return UniValue(UniValue::VNUM,
strprintf("%s%d.%0*d", sign ? "-" : "", quotient,
currency.decimals, remainder));
}