Skip to content

Commit d513041

Browse files
committed
deduplicate AmountFromValue
1 parent e5a9f2f commit d513041

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/bitcoin-tx.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <key_io.h>
1919
#include <policy/policy.h>
2020
#include <primitives/transaction.h>
21+
#include <rpc/util.h>
2122
#include <script/script.h>
2223
#include <script/sign.h>
2324
#include <script/signingprovider.h>
@@ -550,18 +551,6 @@ static bool findSighashFlags(int& flags, const std::string& flagStr)
550551
return false;
551552
}
552553

553-
static CAmount AmountFromValue(const UniValue& value)
554-
{
555-
if (!value.isNum() && !value.isStr())
556-
throw std::runtime_error("Amount is not a number or string");
557-
CAmount amount;
558-
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
559-
throw std::runtime_error("Invalid amount");
560-
if (!MoneyRange(amount))
561-
throw std::runtime_error("Amount out of range");
562-
return amount;
563-
}
564-
565554
static std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName)
566555
{
567556
std::string strHex;
@@ -645,7 +634,11 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
645634
newcoin.out.scriptPubKey = scriptPubKey;
646635
newcoin.out.nValue = MAX_MONEY;
647636
if (prevOut.exists("amount")) {
648-
newcoin.out.nValue = AmountFromValue(prevOut["amount"]);
637+
try {
638+
newcoin.out.nValue = AmountFromValue(prevOut["amount"]);
639+
} catch (const UniValue& error) {
640+
throw std::runtime_error(error.find_value("message").get_str());
641+
}
649642
}
650643
newcoin.nHeight = 1;
651644
view.AddCoin(out, std::move(newcoin), true);

0 commit comments

Comments
 (0)