diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index d6ff642ae1..c291eb231f 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -906,6 +907,25 @@ static void ParseError(const UniValue& error, std::string& strPrint, int& nRet) nRet = abs(error["code"].getInt()); } +static CAmount AmountFromValue(const UniValue& value) +{ + CAmount amount{0}; + if (!ParseFixedPoint(value.getValStr(), 8, &amount)) + throw std::runtime_error("Invalid amount"); + if (!MoneyRange(amount)) + throw std::runtime_error("Amount out of range"); + return amount; +} + +static UniValue ValueFromAmount(const CAmount& amount) +{ + bool sign{amount < 0}; + int64_t n_abs{sign ? -amount : amount}; + int64_t quotient{n_abs / COIN}; + int64_t remainder{n_abs % COIN}; + return UniValue(UniValue::VNUM, strprintf("%s%d.%08d", sign ? "-" : "", quotient, remainder)); +} + /** * GetWalletBalances calls listwallets; if more than one wallet is loaded, it then * fetches mine.trusted balances for each loaded wallet and pushes them to `result`.