diff --git a/src/amount.h b/src/amount.h --- a/src/amount.h +++ b/src/amount.h @@ -14,6 +14,8 @@ #include #include +class UniValue; + struct Amount { private: int64_t amount; @@ -24,6 +26,11 @@ constexpr Amount() : amount(0) {} constexpr Amount(const Amount &other) : amount(other.amount) {} + /** + * Convenient implicit UniValue conversion operator + */ + operator UniValue() const; + /** * Assignement operator. */ diff --git a/src/amount.cpp b/src/amount.cpp --- a/src/amount.cpp +++ b/src/amount.cpp @@ -7,6 +7,7 @@ #include #include +#include #include @@ -14,3 +15,12 @@ return strprintf("%d.%08d %s", *this / COIN, (*this % COIN) / SATOSHI, CURRENCY_UNIT); } + +Amount::operator UniValue() const { + bool sign = *this < Amount::zero(); + Amount n_abs(sign ? -amount : amount); + int64_t quotient = n_abs / COIN; + int64_t remainder = (n_abs % COIN) / SATOSHI; + return UniValue(UniValue::VNUM, strprintf("%s%d.%08d", sign ? "-" : "", + quotient, remainder)); +} diff --git a/src/core_io.h b/src/core_io.h --- a/src/core_io.h +++ b/src/core_io.h @@ -42,7 +42,6 @@ SigHashType ParseSighashString(const UniValue &sighash); // core_write.cpp -UniValue ValueFromAmount(const Amount &amount); std::string FormatScript(const CScript &script); std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags = 0); std::string SighashToStr(uint8_t sighash_type); diff --git a/src/core_write.cpp b/src/core_write.cpp --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -17,15 +17,6 @@ #include -UniValue ValueFromAmount(const Amount &amount) { - bool sign = amount < Amount::zero(); - Amount n_abs(sign ? -amount : amount); - int64_t quotient = n_abs / COIN; - int64_t remainder = (n_abs % COIN) / SATOSHI; - return UniValue(UniValue::VNUM, strprintf("%s%d.%08d", sign ? "-" : "", - quotient, remainder)); -} - std::string FormatScript(const CScript &script) { std::string ret; CScript::const_iterator it = script.begin(); @@ -256,7 +247,7 @@ UniValue out(UniValue::VOBJ); - out.pushKV("value", ValueFromAmount(txout.nValue)); + out.pushKV("value", txout.nValue); out.pushKV("n", int64_t(i)); UniValue o(UniValue::VOBJ); diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -667,7 +667,7 @@ for (const CCoin &coin : outs) { UniValue utxo(UniValue::VOBJ); utxo.pushKV("height", int32_t(coin.nHeight)); - utxo.pushKV("value", ValueFromAmount(coin.out.nValue)); + utxo.pushKV("value", coin.out.nValue); // include the script in a json output UniValue o(UniValue::VOBJ); diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -281,7 +281,7 @@ UniValue stake(UniValue::VOBJ); stake.pushKV("txid", utxo.GetTxId().ToString()); stake.pushKV("vout", uint64_t(utxo.GetN())); - stake.pushKV("amount", ValueFromAmount(s.getStake().getAmount())); + stake.pushKV("amount", s.getStake().getAmount()); stake.pushKV("height", uint64_t(s.getStake().getHeight())); stake.pushKV("iscoinbase", s.getStake().isCoinbase()); stake.pushKV("pubkey", HexStr(s.getStake().getPubkey())); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -535,15 +535,15 @@ AssertLockHeld(pool.cs); UniValue fees(UniValue::VOBJ); - fees.pushKV("base", ValueFromAmount(e.GetFee())); - fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee())); - fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors())); - fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants())); + fees.pushKV("base", e.GetFee()); + fees.pushKV("modified", e.GetModifiedFee()); + fees.pushKV("ancestor", e.GetModFeesWithAncestors()); + fees.pushKV("descendant", e.GetModFeesWithDescendants()); info.pushKV("fees", fees); info.pushKV("size", (int)e.GetTxSize()); - info.pushKV("fee", ValueFromAmount(e.GetFee())); - info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee())); + info.pushKV("fee", e.GetFee()); + info.pushKV("modifiedfee", e.GetModifiedFee()); info.pushKV("time", count_seconds(e.GetTime())); info.pushKV("height", (int)e.GetHeight()); info.pushKV("descendantcount", e.GetCountWithDescendants()); @@ -1222,7 +1222,7 @@ ret.pushKV("bogosize", int64_t(stats.nBogoSize)); ret.pushKV("hash_serialized", stats.hashSerialized.GetHex()); ret.pushKV("disk_size", stats.nDiskSize); - ret.pushKV("total_amount", ValueFromAmount(stats.nTotalAmount)); + ret.pushKV("total_amount", stats.nTotalAmount); } else { throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set"); } @@ -1313,7 +1313,7 @@ ret.pushKV("confirmations", int64_t(pindex->nHeight - coin.GetHeight() + 1)); } - ret.pushKV("value", ValueFromAmount(coin.GetTxOut().nValue)); + ret.pushKV("value", coin.GetTxOut().nValue); UniValue o(UniValue::VOBJ); ScriptPubKeyToUniv(coin.GetTxOut().scriptPubKey, o, true); ret.pushKV("scriptPubKey", o); @@ -1728,9 +1728,8 @@ ret.pushKV("maxmempool", (int64_t)maxmempool); ret.pushKV( "mempoolminfee", - ValueFromAmount(std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee) - .GetFeePerK())); - ret.pushKV("minrelaytxfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); + std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee).GetFeePerK()); + ret.pushKV("minrelaytxfee", ::minRelayTxFee.GetFeePerK()); ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()}); return ret; } @@ -2375,42 +2374,35 @@ } UniValue ret_all(UniValue::VOBJ); - ret_all.pushKV("avgfee", - ValueFromAmount((block.vtx.size() > 1) - ? totalfee / int((block.vtx.size() - 1)) - : Amount::zero())); + ret_all.pushKV("avgfee", block.vtx.size() > 1 + ? (totalfee / int((block.vtx.size() - 1))) + : Amount::zero()); ret_all.pushKV("avgfeerate", - ValueFromAmount((total_size > 0) ? totalfee / total_size - : Amount::zero())); + total_size > 0 ? (totalfee / total_size) : Amount::zero()); ret_all.pushKV("avgtxsize", (block.vtx.size() > 1) ? total_size / (block.vtx.size() - 1) : 0); ret_all.pushKV("blockhash", pindex->GetBlockHash().GetHex()); ret_all.pushKV("height", (int64_t)pindex->nHeight); ret_all.pushKV("ins", inputs); - ret_all.pushKV("maxfee", ValueFromAmount(maxfee)); - ret_all.pushKV("maxfeerate", ValueFromAmount(maxfeerate)); + ret_all.pushKV("maxfee", maxfee); + ret_all.pushKV("maxfeerate", maxfeerate); ret_all.pushKV("maxtxsize", maxtxsize); - ret_all.pushKV("medianfee", - ValueFromAmount(CalculateTruncatedMedian(fee_array))); - ret_all.pushKV("medianfeerate", - ValueFromAmount(CalculateTruncatedMedian(feerate_array))); + ret_all.pushKV("medianfee", CalculateTruncatedMedian(fee_array)); + ret_all.pushKV("medianfeerate", CalculateTruncatedMedian(feerate_array)); ret_all.pushKV("mediantime", pindex->GetMedianTimePast()); ret_all.pushKV("mediantxsize", CalculateTruncatedMedian(txsize_array)); - ret_all.pushKV( - "minfee", - ValueFromAmount((minfee == MAX_MONEY) ? Amount::zero() : minfee)); + ret_all.pushKV("minfee", minfee == MAX_MONEY ? Amount::zero() : minfee); ret_all.pushKV("minfeerate", - ValueFromAmount((minfeerate == MAX_MONEY) ? Amount::zero() - : minfeerate)); + minfeerate == MAX_MONEY ? Amount::zero() : minfeerate); ret_all.pushKV("mintxsize", mintxsize == blockMaxSize ? 0 : mintxsize); ret_all.pushKV("outs", outputs); - ret_all.pushKV("subsidy", ValueFromAmount(GetBlockSubsidy( - pindex->nHeight, Params().GetConsensus()))); + ret_all.pushKV("subsidy", + GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())); ret_all.pushKV("time", pindex->GetBlockTime()); - ret_all.pushKV("total_out", ValueFromAmount(total_out)); + ret_all.pushKV("total_out", total_out); ret_all.pushKV("total_size", total_size); - ret_all.pushKV("totalfee", ValueFromAmount(totalfee)); + ret_all.pushKV("totalfee", totalfee); ret_all.pushKV("txs", (int64_t)block.vtx.size()); ret_all.pushKV("utxo_increase", outputs - inputs); ret_all.pushKV("utxo_size_inc", utxo_size_inc); @@ -2720,13 +2712,13 @@ unspent.pushKV("vout", int32_t(outpoint.GetN())); unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey)); unspent.pushKV("desc", descriptors[txo.scriptPubKey]); - unspent.pushKV("amount", ValueFromAmount(txo.nValue)); + unspent.pushKV("amount", txo.nValue); unspent.pushKV("height", int32_t(coin.GetHeight())); unspents.push_back(unspent); } result.pushKV("unspents", unspents); - result.pushKV("total_amount", ValueFromAmount(total_in)); + result.pushKV("total_amount", total_in); } else { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid command"); } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1142,7 +1142,7 @@ .Check(request); const CTxMemPool &mempool = EnsureMemPool(request.context); - return ValueFromAmount(mempool.estimateFee().GetFeePerK()); + return mempool.estimateFee().GetFeePerK(); } void RegisterMiningRPCCommands(CRPCTable &t) { diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -272,7 +272,7 @@ permissions.push_back(permission); } obj.pushKV("permissions", permissions); - obj.pushKV("minfeefilter", ValueFromAmount(stats.minFeeFilter)); + obj.pushKV("minfeefilter", stats.minFeeFilter); UniValue sendPerMsgCmd(UniValue::VOBJ); for (const auto &i : stats.mapSendBytesPerMsgCmd) { @@ -691,9 +691,8 @@ int(node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); } obj.pushKV("networks", GetNetworksInfo()); - obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); - obj.pushKV("excessutxocharge", - ValueFromAmount(config.GetExcessUTXOCharge())); + obj.pushKV("relayfee", ::minRelayTxFee.GetFeePerK()); + obj.pushKV("excessutxocharge", config.GetExcessUTXOCharge()); UniValue localAddresses(UniValue::VARR); { LOCK(cs_mapLocalHost); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1363,7 +1363,7 @@ UniValue out(UniValue::VOBJ); - out.pushKV("amount", ValueFromAmount(txout.nValue)); + out.pushKV("amount", txout.nValue); if (MoneyRange(txout.nValue) && MoneyRange(total_in + txout.nValue)) { total_in += txout.nValue; @@ -1491,7 +1491,7 @@ } result.pushKV("outputs", outputs); if (have_all_utxos) { - result.pushKV("fee", ValueFromAmount(total_in - output_value)); + result.pushKV("fee", total_in - output_value); } return result; @@ -2133,10 +2133,10 @@ } if (psbta.estimated_feerate != std::nullopt) { result.pushKV("estimated_feerate", - ValueFromAmount(psbta.estimated_feerate->GetFeePerK())); + psbta.estimated_feerate->GetFeePerK()); } if (psbta.fee != std::nullopt) { - result.pushKV("fee", ValueFromAmount(*psbta.fee)); + result.pushKV("fee", *psbta.fee); } result.pushKV("next", PSBTRoleName(psbta.next)); if (!psbta.error.empty()) { diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp --- a/src/test/fuzz/integer.cpp +++ b/src/test/fuzz/integer.cpp @@ -148,12 +148,11 @@ (void)SipHashUint256Extra(u64, u64, u256, u32); (void)ToLower(ch); (void)ToUpper(ch); - // ValueFromAmount(i) not defined when i == + // Amount::operator UniValue() not defined when Amount::amount == // std::numeric_limits::min() if (i64 != std::numeric_limits::min()) { Amount parsed_money; - if (ParseMoney(ValueFromAmount(i64 * SATOSHI).getValStr(), - parsed_money)) { + if (ParseMoney(UniValue(i64 * SATOSHI).getValStr(), parsed_money)) { assert(parsed_money == i64 * SATOSHI); } } diff --git a/src/test/fuzz/transaction.cpp b/src/test/fuzz/transaction.cpp --- a/src/test/fuzz/transaction.cpp +++ b/src/test/fuzz/transaction.cpp @@ -95,7 +95,7 @@ (void)AreInputsStandard(tx, coins_view_cache, STANDARD_SCRIPT_VERIFY_FLAGS); UniValue u(UniValue::VOBJ); - // ValueFromAmount(i) not defined when i == + // Amount::operator UniValue() not defined when Amount.amount == // std::numeric_limits::min() bool skip_tx_to_univ = false; for (const CTxOut &txout : tx.vout) { diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -237,44 +237,40 @@ } BOOST_AUTO_TEST_CASE(rpc_format_monetary_values) { - BOOST_CHECK(ValueFromAmount(Amount::zero()).write() == "0.00000000"); - BOOST_CHECK(ValueFromAmount(SATOSHI).write() == "0.00000001"); - BOOST_CHECK(ValueFromAmount(17622195 * SATOSHI).write() == "0.17622195"); - BOOST_CHECK(ValueFromAmount(50000000 * SATOSHI).write() == "0.50000000"); - BOOST_CHECK(ValueFromAmount(89898989 * SATOSHI).write() == "0.89898989"); - BOOST_CHECK(ValueFromAmount(100000000 * SATOSHI).write() == "1.00000000"); - BOOST_CHECK(ValueFromAmount(int64_t(2099999999999990) * SATOSHI).write() == + BOOST_CHECK(UniValue(Amount::zero()).write() == "0.00000000"); + BOOST_CHECK(UniValue(SATOSHI).write() == "0.00000001"); + BOOST_CHECK(UniValue(17622195 * SATOSHI).write() == "0.17622195"); + BOOST_CHECK(UniValue(50000000 * SATOSHI).write() == "0.50000000"); + BOOST_CHECK(UniValue(89898989 * SATOSHI).write() == "0.89898989"); + BOOST_CHECK(UniValue(100000000 * SATOSHI).write() == "1.00000000"); + BOOST_CHECK(UniValue(int64_t(2099999999999990) * SATOSHI).write() == "20999999.99999990"); - BOOST_CHECK(ValueFromAmount(int64_t(2099999999999999) * SATOSHI).write() == + BOOST_CHECK(UniValue(int64_t(2099999999999999) * SATOSHI).write() == "20999999.99999999"); - BOOST_CHECK_EQUAL(ValueFromAmount(Amount::zero()).write(), "0.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(123456789 * (COIN / 10000)).write(), + BOOST_CHECK_EQUAL(UniValue(Amount::zero()).write(), "0.00000000"); + BOOST_CHECK_EQUAL(UniValue(123456789 * (COIN / 10000)).write(), "12345.67890000"); - BOOST_CHECK_EQUAL(ValueFromAmount(-1 * COIN).write(), "-1.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(-1 * COIN / 10).write(), "-0.10000000"); - - BOOST_CHECK_EQUAL(ValueFromAmount(100000000 * COIN).write(), - "100000000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(10000000 * COIN).write(), - "10000000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(1000000 * COIN).write(), - "1000000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(100000 * COIN).write(), - "100000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(10000 * COIN).write(), "10000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(1000 * COIN).write(), "1000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(100 * COIN).write(), "100.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(10 * COIN).write(), "10.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN).write(), "1.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 10).write(), "0.10000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 100).write(), "0.01000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 1000).write(), "0.00100000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 10000).write(), "0.00010000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 100000).write(), "0.00001000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 1000000).write(), "0.00000100"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 10000000).write(), "0.00000010"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 100000000).write(), "0.00000001"); + BOOST_CHECK_EQUAL(UniValue(-1 * COIN).write(), "-1.00000000"); + BOOST_CHECK_EQUAL(UniValue(-1 * COIN / 10).write(), "-0.10000000"); + + BOOST_CHECK_EQUAL(UniValue(100000000 * COIN).write(), "100000000.00000000"); + BOOST_CHECK_EQUAL(UniValue(10000000 * COIN).write(), "10000000.00000000"); + BOOST_CHECK_EQUAL(UniValue(1000000 * COIN).write(), "1000000.00000000"); + BOOST_CHECK_EQUAL(UniValue(100000 * COIN).write(), "100000.00000000"); + BOOST_CHECK_EQUAL(UniValue(10000 * COIN).write(), "10000.00000000"); + BOOST_CHECK_EQUAL(UniValue(1000 * COIN).write(), "1000.00000000"); + BOOST_CHECK_EQUAL(UniValue(100 * COIN).write(), "100.00000000"); + BOOST_CHECK_EQUAL(UniValue(10 * COIN).write(), "10.00000000"); + BOOST_CHECK_EQUAL(UniValue(COIN).write(), "1.00000000"); + BOOST_CHECK_EQUAL(UniValue(COIN / 10).write(), "0.10000000"); + BOOST_CHECK_EQUAL(UniValue(COIN / 100).write(), "0.01000000"); + BOOST_CHECK_EQUAL(UniValue(COIN / 1000).write(), "0.00100000"); + BOOST_CHECK_EQUAL(UniValue(COIN / 10000).write(), "0.00010000"); + BOOST_CHECK_EQUAL(UniValue(COIN / 100000).write(), "0.00001000"); + BOOST_CHECK_EQUAL(UniValue(COIN / 1000000).write(), "0.00000100"); + BOOST_CHECK_EQUAL(UniValue(COIN / 10000000).write(), "0.00000010"); + BOOST_CHECK_EQUAL(UniValue(COIN / 100000000).write(), "0.00000001"); } static UniValue ValueFromString(const std::string &str) { diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -508,7 +508,7 @@ UniValue array(UniValue::VARR); if (nValue != Amount::zero()) { UniValue amount(UniValue::VARR); - amount.push_back(ValueFromAmount(nValue)); + amount.push_back(nValue); array.push_back(amount); } diff --git a/src/util/moneystr.h b/src/util/moneystr.h --- a/src/util/moneystr.h +++ b/src/util/moneystr.h @@ -16,7 +16,7 @@ /** * Do not use these functions to represent or parse monetary amounts to or from - * JSON but use AmountFromValue and ValueFromAmount for that. + * JSON but use AmountFromValue and the Amount::operator UniValue() for that. */ std::string FormatMoney(const Amount n); /** diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1076,7 +1076,7 @@ utxo.pushKV("txid", o.tx->GetId().ToString()); utxo.pushKV("vout", o.i); utxo.pushKV("depth", o.nDepth); - utxo.pushKV("value", ValueFromAmount(o.tx->tx->vout[o.i].nValue)); + utxo.pushKV("value", o.tx->tx->vout[o.i].nValue); coins.push_back(std::move(utxo)); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -553,7 +553,7 @@ for (const CTxDestination &address : grouping) { UniValue addressInfo(UniValue::VARR); addressInfo.push_back(EncodeDestination(address, config)); - addressInfo.push_back(ValueFromAmount(balances[address])); + addressInfo.push_back(balances[address]); const auto *address_book_entry = pwallet->FindAddressBookEntry(address); @@ -733,8 +733,8 @@ LOCK(pwallet->cs_wallet); - return ValueFromAmount(GetReceived(*pwallet, request.params, - /* by_label */ false)); + return GetReceived(*pwallet, request.params, + /* by_label */ false); } static UniValue getreceivedbylabel(const Config &config, @@ -777,8 +777,8 @@ LOCK(pwallet->cs_wallet); - return ValueFromAmount(GetReceived(*pwallet, request.params, - /* by_label */ true)); + return GetReceived(*pwallet, request.params, + /* by_label */ true); } static UniValue getbalance(const Config &config, @@ -848,9 +848,8 @@ const auto bal = pwallet->GetBalance(min_depth, avoid_reuse); - return ValueFromAmount(bal.m_mine_trusted + (include_watchonly - ? bal.m_watchonly_trusted - : Amount::zero())); + return bal.m_mine_trusted + + (include_watchonly ? bal.m_watchonly_trusted : Amount::zero()); } static UniValue getunconfirmedbalance(const Config &config, @@ -876,7 +875,7 @@ LOCK(pwallet->cs_wallet); - return ValueFromAmount(pwallet->GetBalance().m_mine_untrusted_pending); + return pwallet->GetBalance().m_mine_untrusted_pending; } static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { @@ -1286,7 +1285,7 @@ obj.pushKV("involvesWatchonly", true); } obj.pushKV("address", EncodeDestination(address, config)); - obj.pushKV("amount", ValueFromAmount(nAmount)); + obj.pushKV("amount", nAmount); obj.pushKV("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf)); obj.pushKV("label", label); @@ -1309,7 +1308,7 @@ if (entry.second.fIsWatchonly) { obj.pushKV("involvesWatchonly", true); } - obj.pushKV("amount", ValueFromAmount(nAmount)); + obj.pushKV("amount", nAmount); obj.pushKV("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf)); obj.pushKV("label", entry.first); @@ -1494,14 +1493,14 @@ } MaybePushAddress(entry, s.destination); entry.pushKV("category", "send"); - entry.pushKV("amount", ValueFromAmount(-s.amount)); + entry.pushKV("amount", -s.amount); const auto *address_book_entry = pwallet->FindAddressBookEntry(s.destination); if (address_book_entry) { entry.pushKV("label", address_book_entry->GetLabel()); } entry.pushKV("vout", s.vout); - entry.pushKV("fee", ValueFromAmount(-1 * nFee)); + entry.pushKV("fee", -1 * nFee); if (fLong) { WalletTxToJSON(pwallet->chain(), wtx, entry); } @@ -1539,7 +1538,7 @@ } else { entry.pushKV("category", "receive"); } - entry.pushKV("amount", ValueFromAmount(r.amount)); + entry.pushKV("amount", r.amount); if (address_book_entry) { entry.pushKV("label", label); } @@ -2099,9 +2098,9 @@ Amount nFee = (wtx.IsFromMe(filter) ? wtx.tx->GetValueOut() - nDebit : Amount::zero()); - entry.pushKV("amount", ValueFromAmount(nNet - nFee)); + entry.pushKV("amount", nNet - nFee); if (wtx.IsFromMe(filter)) { - entry.pushKV("fee", ValueFromAmount(nFee)); + entry.pushKV("fee", nFee); } WalletTxToJSON(pwallet->chain(), wtx, entry); @@ -2900,33 +2899,28 @@ UniValue balances{UniValue::VOBJ}; { UniValue balances_mine{UniValue::VOBJ}; - balances_mine.pushKV("trusted", ValueFromAmount(bal.m_mine_trusted)); - balances_mine.pushKV("untrusted_pending", - ValueFromAmount(bal.m_mine_untrusted_pending)); - balances_mine.pushKV("immature", ValueFromAmount(bal.m_mine_immature)); + balances_mine.pushKV("trusted", bal.m_mine_trusted); + balances_mine.pushKV("untrusted_pending", bal.m_mine_untrusted_pending); + balances_mine.pushKV("immature", bal.m_mine_immature); if (wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) { // If the AVOID_REUSE flag is set, bal has been set to just the // un-reused address balance. Get the total balance, and then // subtract bal to get the reused address balance. const auto full_bal = wallet.GetBalance(0, false); - balances_mine.pushKV( - "used", ValueFromAmount(full_bal.m_mine_trusted + - full_bal.m_mine_untrusted_pending - - bal.m_mine_trusted - - bal.m_mine_untrusted_pending)); + balances_mine.pushKV("used", full_bal.m_mine_trusted + + full_bal.m_mine_untrusted_pending - + bal.m_mine_trusted - + bal.m_mine_untrusted_pending); } balances.pushKV("mine", balances_mine); } auto spk_man = wallet.GetLegacyScriptPubKeyMan(); if (spk_man && spk_man->HaveWatchOnly()) { UniValue balances_watchonly{UniValue::VOBJ}; - balances_watchonly.pushKV("trusted", - ValueFromAmount(bal.m_watchonly_trusted)); - balances_watchonly.pushKV( - "untrusted_pending", - ValueFromAmount(bal.m_watchonly_untrusted_pending)); - balances_watchonly.pushKV("immature", - ValueFromAmount(bal.m_watchonly_immature)); + balances_watchonly.pushKV("trusted", bal.m_watchonly_trusted); + balances_watchonly.pushKV("untrusted_pending", + bal.m_watchonly_untrusted_pending); + balances_watchonly.pushKV("immature", bal.m_watchonly_immature); balances.pushKV("watchonly", balances_watchonly); } return balances; @@ -3019,10 +3013,9 @@ int64_t kp_oldest = pwallet->GetOldestKeyPoolTime(); obj.pushKV("walletname", pwallet->GetName()); obj.pushKV("walletversion", pwallet->GetVersion()); - obj.pushKV("balance", ValueFromAmount(bal.m_mine_trusted)); - obj.pushKV("unconfirmed_balance", - ValueFromAmount(bal.m_mine_untrusted_pending)); - obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature)); + obj.pushKV("balance", bal.m_mine_trusted); + obj.pushKV("unconfirmed_balance", bal.m_mine_untrusted_pending); + obj.pushKV("immature_balance", bal.m_mine_immature); obj.pushKV("txcount", (int)pwallet->mapWallet.size()); if (kp_oldest > 0) { obj.pushKV("keypoololdest", kp_oldest); @@ -3044,7 +3037,7 @@ if (pwallet->IsCrypted()) { obj.pushKV("unlocked_until", pwallet->nRelockTime); } - obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); + obj.pushKV("paytxfee", pwallet->m_pay_tx_fee.GetFeePerK()); obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); if (pwallet->IsScanning()) { @@ -3646,7 +3639,7 @@ } entry.pushKV("scriptPubKey", HexStr(scriptPubKey)); - entry.pushKV("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue)); + entry.pushKV("amount", out.tx->tx->vout[out.i].nValue); entry.pushKV("confirmations", out.nDepth); entry.pushKV("spendable", out.fSpendable); entry.pushKV("solvable", out.fSolvable); @@ -3913,7 +3906,7 @@ UniValue result(UniValue::VOBJ); result.pushKV("hex", EncodeHexTx(CTransaction(tx))); - result.pushKV("fee", ValueFromAmount(fee)); + result.pushKV("fee", fee); result.pushKV("changepos", change_position); return result; @@ -4934,7 +4927,7 @@ UniValue result(UniValue::VOBJ); result.pushKV("psbt", EncodeBase64(ssTx.str())); - result.pushKV("fee", ValueFromAmount(fee)); + result.pushKV("fee", fee); result.pushKV("changepos", change_position); return result; }