mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
partial bitcoin#15638: Add several util units
This commit is contained in:
parent
680319643f
commit
138997c8e6
@ -261,6 +261,8 @@ BITCOIN_CORE_H = \
|
||||
undo.h \
|
||||
unordered_lru_cache.h \
|
||||
util/bytevectorhash.h \
|
||||
util/error.h \
|
||||
util/fees.h \
|
||||
util/system.h \
|
||||
util/asmap.h \
|
||||
util/memory.h \
|
||||
@ -269,6 +271,8 @@ BITCOIN_CORE_H = \
|
||||
util/time.h \
|
||||
util/threadnames.h \
|
||||
util/vector.h \
|
||||
util/url.h \
|
||||
util/validation.h \
|
||||
validation.h \
|
||||
validationinterface.h \
|
||||
versionbits.h \
|
||||
@ -593,6 +597,8 @@ libdash_util_a_SOURCES = \
|
||||
sync.cpp \
|
||||
threadinterrupt.cpp \
|
||||
util/bytevectorhash.cpp \
|
||||
util/error.cpp \
|
||||
util/fees.cpp \
|
||||
util/system.cpp \
|
||||
util/asmap.cpp \
|
||||
util/moneystr.cpp \
|
||||
@ -600,6 +606,8 @@ libdash_util_a_SOURCES = \
|
||||
util/time.cpp \
|
||||
util/string.cpp \
|
||||
util/threadnames.cpp \
|
||||
util/url.cpp \
|
||||
util/validation.cpp \
|
||||
$(BITCOIN_CORE_H)
|
||||
|
||||
if GLIBC_BACK_COMPAT
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <chain.h>
|
||||
#include <coins.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <version.h>
|
||||
|
||||
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
|
||||
{
|
||||
|
@ -667,15 +667,3 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
|
||||
pathHandlers.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string urlDecode(const std::string &urlEncoded) {
|
||||
std::string res;
|
||||
if (!urlEncoded.empty()) {
|
||||
char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, nullptr);
|
||||
if (decoded) {
|
||||
res = std::string(decoded);
|
||||
free(decoded);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -148,6 +148,4 @@ private:
|
||||
struct event* ev;
|
||||
};
|
||||
|
||||
std::string urlDecode(const std::string &urlEncoded);
|
||||
|
||||
#endif // BITCOIN_HTTPSERVER_H
|
||||
|
@ -45,9 +45,11 @@
|
||||
#include <txmempool.h>
|
||||
#include <torcontrol.h>
|
||||
#include <ui_interface.h>
|
||||
#include <util/system.h>
|
||||
#include <util/asmap.h>
|
||||
#include <util/error.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/system.h>
|
||||
#include <util/validation.h>
|
||||
#include <validationinterface.h>
|
||||
|
||||
#include <masternode/activemasternode.h>
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <scheduler.h>
|
||||
#include <spork.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/validation.h>
|
||||
|
||||
namespace llmq
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <net_processing.h>
|
||||
#include <spork.h>
|
||||
#include <validation.h>
|
||||
#include <util/validation.h>
|
||||
|
||||
#include <cxxtimer.hpp>
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <timedata.h>
|
||||
#include <util/system.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/validation.h>
|
||||
#include <masternode/masternode-payments.h>
|
||||
#include <masternode/masternode-sync.h>
|
||||
#include <validationinterface.h>
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <util/system.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/validation.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
@ -13,7 +13,8 @@
|
||||
#include <init.h>
|
||||
#include <key_io.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <validation.h> // For strMessageMagic
|
||||
#include <util/validation.h> // For strMessageMagic
|
||||
#include <validation.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <txmempool.h>
|
||||
#include <util/system.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/validation.h>
|
||||
#include <hash.h>
|
||||
#include <validationinterface.h>
|
||||
#include <warnings.h>
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <consensus/validation.h>
|
||||
#include <core_io.h>
|
||||
#include <init.h>
|
||||
#include <validation.h>
|
||||
#include <key_io.h>
|
||||
#include <miner.h>
|
||||
#include <net.h>
|
||||
@ -22,8 +21,11 @@
|
||||
#include <rpc/mining.h>
|
||||
#include <rpc/server.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/system.h>
|
||||
#include <util/fees.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
#include <util/validation.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
#include <warnings.h>
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <util/system.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <validation.h>
|
||||
#include <util/validation.h>
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <wallet/rpcwallet.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <script/standard.h>
|
||||
#include <txmempool.h>
|
||||
#include <uint256.h>
|
||||
#include <util/validation.h>
|
||||
#include <util/strencodings.h>
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <wallet/rpcwallet.h>
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <rpc/server.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/validation.h>
|
||||
#include <validation.h>
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/register.h>
|
||||
#include <script/sigcache.h>
|
||||
#include <util/validation.h>
|
||||
|
||||
#include <coinjoin/coinjoin.h>
|
||||
#include <evo/specialtx.h>
|
||||
|
@ -17,13 +17,3 @@ void InitWarning(const std::string& str)
|
||||
{
|
||||
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
|
||||
}
|
||||
|
||||
std::string AmountHighWarn(const std::string& optname)
|
||||
{
|
||||
return strprintf(_("%s is set very high!"), optname);
|
||||
}
|
||||
|
||||
std::string AmountErrMsg(const char* const optname, const std::string& strValue)
|
||||
{
|
||||
return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
|
||||
}
|
||||
|
@ -124,10 +124,6 @@ void InitWarning(const std::string& str);
|
||||
/** Show error message **/
|
||||
bool InitError(const std::string& str);
|
||||
|
||||
std::string AmountHighWarn(const std::string& optname);
|
||||
|
||||
std::string AmountErrMsg(const char* const optname, const std::string& strValue);
|
||||
|
||||
extern CClientUIInterface uiInterface;
|
||||
|
||||
#endif // BITCOIN_UI_INTERFACE_H
|
||||
|
17
src/util/error.cpp
Normal file
17
src/util/error.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2010-2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <util/error.h>
|
||||
|
||||
#include <util/system.h>
|
||||
|
||||
std::string AmountHighWarn(const std::string& optname)
|
||||
{
|
||||
return strprintf(_("%s is set very high!"), optname);
|
||||
}
|
||||
|
||||
std::string AmountErrMsg(const char* const optname, const std::string& strValue)
|
||||
{
|
||||
return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
|
||||
}
|
23
src/util/error.h
Normal file
23
src/util/error.h
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2010-2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_UTIL_ERROR_H
|
||||
#define BITCOIN_UTIL_ERROR_H
|
||||
|
||||
/**
|
||||
* util/error.h is a common place for definitions of simple error types and
|
||||
* string functions. Types and functions defined here should not require any
|
||||
* outside dependencies.
|
||||
*
|
||||
* Error types defined here can be used in different parts of the bitcoin
|
||||
* codebase, to avoid the need to write boilerplate code catching and
|
||||
* translating errors passed across wallet/node/rpc/gui code boundaries.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string AmountHighWarn(const std::string& optname);
|
||||
std::string AmountErrMsg(const char* const optname, const std::string& strValue);
|
||||
|
||||
#endif // BITCOIN_UTIL_ERROR_H
|
42
src/util/fees.cpp
Normal file
42
src/util/fees.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <policy/fees.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string StringForFeeReason(FeeReason reason) {
|
||||
static const std::map<FeeReason, std::string> fee_reason_strings = {
|
||||
{FeeReason::NONE, "None"},
|
||||
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
|
||||
{FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
|
||||
{FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
|
||||
{FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
|
||||
{FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
|
||||
{FeeReason::PAYTXFEE, "PayTxFee set"},
|
||||
{FeeReason::FALLBACK, "Fallback fee"},
|
||||
{FeeReason::REQUIRED, "Minimum Required Fee"},
|
||||
{FeeReason::MAXTXFEE, "MaxTxFee limit"}
|
||||
};
|
||||
auto reason_string = fee_reason_strings.find(reason);
|
||||
|
||||
if (reason_string == fee_reason_strings.end()) return "Unknown";
|
||||
|
||||
return reason_string->second;
|
||||
}
|
||||
|
||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) {
|
||||
static const std::map<std::string, FeeEstimateMode> fee_modes = {
|
||||
{"UNSET", FeeEstimateMode::UNSET},
|
||||
{"ECONOMICAL", FeeEstimateMode::ECONOMICAL},
|
||||
{"CONSERVATIVE", FeeEstimateMode::CONSERVATIVE},
|
||||
};
|
||||
auto mode = fee_modes.find(mode_string);
|
||||
|
||||
if (mode == fee_modes.end()) return false;
|
||||
|
||||
fee_estimate_mode = mode->second;
|
||||
return true;
|
||||
}
|
16
src/util/fees.h
Normal file
16
src/util/fees.h
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_UTIL_FEES_H
|
||||
#define BITCOIN_UTIL_FEES_H
|
||||
|
||||
#include <string>
|
||||
|
||||
enum class FeeEstimateMode;
|
||||
enum class FeeReason;
|
||||
|
||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
|
||||
std::string StringForFeeReason(FeeReason reason);
|
||||
|
||||
#endif // BITCOIN_UTIL_FEES_H
|
21
src/util/url.cpp
Normal file
21
src/util/url.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2015-2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <util/url.h>
|
||||
|
||||
#include <event2/http.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
std::string urlDecode(const std::string &urlEncoded) {
|
||||
std::string res;
|
||||
if (!urlEncoded.empty()) {
|
||||
char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, nullptr);
|
||||
if (decoded) {
|
||||
res = std::string(decoded);
|
||||
free(decoded);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
12
src/util/url.h
Normal file
12
src/util/url.h
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2015-2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_UTIL_URL_H
|
||||
#define BITCOIN_UTIL_URL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string urlDecode(const std::string &urlEncoded);
|
||||
|
||||
#endif // BITCOIN_UTIL_URL_H
|
20
src/util/validation.cpp
Normal file
20
src/util/validation.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <util/validation.h>
|
||||
|
||||
#include <consensus/validation.h>
|
||||
#include <tinyformat.h>
|
||||
|
||||
/** Convert CValidationState to a human-readable message for logging */
|
||||
std::string FormatStateMessage(const CValidationState &state)
|
||||
{
|
||||
return strprintf("%s%s (code %i)",
|
||||
state.GetRejectReason(),
|
||||
state.GetDebugMessage().empty() ? "" : ", "+state.GetDebugMessage(),
|
||||
state.GetRejectCode());
|
||||
}
|
||||
|
||||
const std::string strMessageMagic = "DarkCoin Signed Message:\n";
|
18
src/util/validation.h
Normal file
18
src/util/validation.h
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_UTIL_VALIDATION_H
|
||||
#define BITCOIN_UTIL_VALIDATION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class CValidationState;
|
||||
|
||||
/** Convert CValidationState to a human-readable message for logging */
|
||||
std::string FormatStateMessage(const CValidationState &state);
|
||||
|
||||
extern const std::string strMessageMagic;
|
||||
|
||||
#endif // BITCOIN_UTIL_VALIDATION_H
|
@ -39,6 +39,7 @@
|
||||
#include <util/system.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/validation.h>
|
||||
#include <validationinterface.h>
|
||||
#include <warnings.h>
|
||||
|
||||
@ -269,8 +270,6 @@ static void CheckBlockIndex(const Consensus::Params& consensusParams);
|
||||
/** Constant stuff for coinbase transactions we create: */
|
||||
CScript COINBASE_FLAGS;
|
||||
|
||||
const std::string strMessageMagic = "DarkCoin Signed Message:\n";
|
||||
|
||||
// Internal stuff
|
||||
namespace {
|
||||
CBlockIndex *&pindexBestInvalid = g_chainstate.pindexBestInvalid;
|
||||
@ -525,16 +524,7 @@ static void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age)
|
||||
pcoinsTip->Uncache(removed);
|
||||
}
|
||||
|
||||
/** Convert CValidationState to a human-readable message for logging */
|
||||
std::string FormatStateMessage(const CValidationState &state)
|
||||
{
|
||||
return strprintf("%s%s (code %i)",
|
||||
state.GetRejectReason(),
|
||||
state.GetDebugMessage().empty() ? "" : ", "+state.GetDebugMessage(),
|
||||
state.GetRejectCode());
|
||||
}
|
||||
|
||||
static bool IsCurrentForFeeEstimation()
|
||||
static bool IsCurrentForFeeEstimation() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
if (IsInitialBlockDownload())
|
||||
|
@ -152,7 +152,7 @@ extern CTxMemPool mempool;
|
||||
extern std::atomic_bool g_is_mempool_loaded;
|
||||
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
|
||||
typedef std::unordered_multimap<uint256, CBlockIndex*, BlockHasher> PrevBlockMap;
|
||||
extern BlockMap& mapBlockIndex;
|
||||
extern BlockMap& mapBlockIndex GUARDED_BY(cs_main);
|
||||
extern PrevBlockMap& mapPrevBlockIndex;
|
||||
extern uint64_t nLastBlockTx;
|
||||
extern uint64_t nLastBlockSize;
|
||||
@ -332,9 +332,6 @@ bool GetUTXOCoin(const COutPoint& outpoint, Coin& coin);
|
||||
int GetUTXOHeight(const COutPoint& outpoint);
|
||||
int GetUTXOConfirmations(const COutPoint& outpoint);
|
||||
|
||||
/** Convert CValidationState to a human-readable message for logging */
|
||||
std::string FormatStateMessage(const CValidationState &state);
|
||||
|
||||
/** Get the BIP9 state for a given deployment at the current tip. */
|
||||
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <keepass.h>
|
||||
#include <net.h>
|
||||
#include <scheduler.h>
|
||||
#include <util/error.h>
|
||||
#include <util/system.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <validation.h>
|
||||
|
@ -19,8 +19,11 @@
|
||||
#include <rpc/util.h>
|
||||
#include <timedata.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/fees.h>
|
||||
#include <util/system.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/url.h>
|
||||
#include <util/validation.h>
|
||||
#include <validation.h>
|
||||
#include <wallet/coincontrol.h>
|
||||
#include <wallet/rpcwallet.h>
|
||||
|
@ -26,7 +26,10 @@
|
||||
#include <script/sign.h>
|
||||
#include <timedata.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/error.h>
|
||||
#include <util/fees.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/validation.h>
|
||||
#include <wallet/fees.h>
|
||||
#include <warnings.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user