Page MenuHomePhabricator

[refactor] replace duplicated AmountFromValue function with Amount::Amount(UniValue T)

Authored by majcosta on Sun, Jun 6, 06:01.


Group Reviewers
Restricted Project

The AmountFromValue function is defined twice, one of which is only used in bitcoin-tx, once.

The difference between them is that in rpc/util.cpp it throws a UniValue and the bitcoin-tx version throws a std::runtime_error. This deduplicates the code and makes it into a user-defined conversion on the Amount class which throws 'UniValue' as that was the one most used.

Tests are updated to conform to the simpler syntax.
Added a catch block in bitcoin-tx to handle possible UniValue throw there.

Test Plan
ninja all check-all
cmake .. -GNinja -DENABLE_SANITIZERS='undefined,address,fuzzer' -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
ninja bitcoin-fuzzers && ./src/test/fuzz/parse_univalue

Diff Detail