diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-08-07 14:38:39 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-08-07 17:01:21 +0200 |
commit | 46347add438d49a69f34a3f2ab755feda7daff10 (patch) | |
tree | 24025b570a23124335f6ce839a797bfc291102f7 /src | |
parent | dac37823d4799477b19434d4d53c74c4af455c76 (diff) |
rpc: Move ValueFromAmount to core_write
This is necessary because core_write has to write amounts in
TxToUniv, and mistakingly uses FormatMoney for that
(which is only for debugging).
We don't move AmountFromValue at the same time, as
this is more challenging due to the RPCError depencency
there.
Diffstat (limited to 'src')
-rw-r--r-- | src/core_io.h | 3 | ||||
-rw-r--r-- | src/core_write.cpp | 10 | ||||
-rw-r--r-- | src/rpc/misc.cpp | 1 | ||||
-rw-r--r-- | src/rpc/net.cpp | 1 | ||||
-rw-r--r-- | src/rpc/server.cpp | 10 | ||||
-rw-r--r-- | src/rpc/server.h | 1 | ||||
-rw-r--r-- | src/test/rpc_tests.cpp | 1 |
7 files changed, 16 insertions, 11 deletions
diff --git a/src/core_io.h b/src/core_io.h index 2d63be5fc4..3f25faf0ec 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_CORE_IO_H #define BITCOIN_CORE_IO_H +#include "amount.h" + #include <string> #include <vector> @@ -25,6 +27,7 @@ uint256 ParseHashStr(const std::string&, const std::string& strName); std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName); // core_write.cpp +UniValue ValueFromAmount(const CAmount& amount); std::string FormatScript(const CScript& script); std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0); void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); diff --git a/src/core_write.cpp b/src/core_write.cpp index a366ef933c..2bf28a1506 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -16,6 +16,16 @@ #include "utilmoneystr.h" #include "utilstrencodings.h" +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)); +} + std::string FormatScript(const CScript& script) { std::string ret; diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index f3c86038a3..cd93919eb5 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -6,6 +6,7 @@ #include "base58.h" #include "chain.h" #include "clientversion.h" +#include "core_io.h" #include "init.h" #include "validation.h" #include "httpserver.h" diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index b4d6795e62..6271e0cc83 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -6,6 +6,7 @@ #include "chainparams.h" #include "clientversion.h" +#include "core_io.h" #include "validation.h" #include "net.h" #include "net_processing.h" diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 63e4e9c630..58640d69d6 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -123,16 +123,6 @@ CAmount AmountFromValue(const UniValue& value) return amount; } -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)); -} - uint256 ParseHashV(const UniValue& v, std::string strName) { std::string strHex; diff --git a/src/rpc/server.h b/src/rpc/server.h index b20c827727..dd6f763245 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -185,7 +185,6 @@ extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strNa extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey); extern CAmount AmountFromValue(const UniValue& value); -extern UniValue ValueFromAmount(const CAmount& amount); extern std::string HelpExampleCli(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args); diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 134bd7c609..c6643be7a7 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -6,6 +6,7 @@ #include "rpc/client.h" #include "base58.h" +#include "core_io.h" #include "netbase.h" #include "test/test_bitcoin.h" |