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.
This commit is contained in:
Wladimir J. van der Laan 2017-08-07 14:38:39 +02:00
parent dac37823d4
commit 46347add43
7 changed files with 16 additions and 11 deletions

View File

@ -5,6 +5,8 @@
#ifndef BITCOIN_CORE_IO_H #ifndef BITCOIN_CORE_IO_H
#define BITCOIN_CORE_IO_H #define BITCOIN_CORE_IO_H
#include "amount.h"
#include <string> #include <string>
#include <vector> #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); std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName);
// core_write.cpp // core_write.cpp
UniValue ValueFromAmount(const CAmount& amount);
std::string FormatScript(const CScript& script); std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0); std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);

View File

@ -16,6 +16,16 @@
#include "utilmoneystr.h" #include "utilmoneystr.h"
#include "utilstrencodings.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 FormatScript(const CScript& script)
{ {
std::string ret; std::string ret;

View File

@ -6,6 +6,7 @@
#include "base58.h" #include "base58.h"
#include "chain.h" #include "chain.h"
#include "clientversion.h" #include "clientversion.h"
#include "core_io.h"
#include "init.h" #include "init.h"
#include "validation.h" #include "validation.h"
#include "httpserver.h" #include "httpserver.h"

View File

@ -6,6 +6,7 @@
#include "chainparams.h" #include "chainparams.h"
#include "clientversion.h" #include "clientversion.h"
#include "core_io.h"
#include "validation.h" #include "validation.h"
#include "net.h" #include "net.h"
#include "net_processing.h" #include "net_processing.h"

View File

@ -123,16 +123,6 @@ CAmount AmountFromValue(const UniValue& value)
return amount; 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) uint256 ParseHashV(const UniValue& v, std::string strName)
{ {
std::string strHex; std::string strHex;

View File

@ -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 std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
extern CAmount AmountFromValue(const UniValue& value); 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 HelpExampleCli(const std::string& methodname, const std::string& args);
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);

View File

@ -6,6 +6,7 @@
#include "rpc/client.h" #include "rpc/client.h"
#include "base58.h" #include "base58.h"
#include "core_io.h"
#include "netbase.h" #include "netbase.h"
#include "test/test_bitcoin.h" #include "test/test_bitcoin.h"