Bitcoin ABC  0.24.7
P2P Digital Currency
config.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Amaury SÉCHET
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_CONFIG_H
6 #define BITCOIN_CONFIG_H
7 
8 #include <amount.h>
9 #include <feerate.h>
10 
11 #include <cstdint>
12 #include <memory>
13 #include <string>
14 
15 class CChainParams;
16 
17 class Config {
18 public:
19  virtual bool SetMaxBlockSize(uint64_t maxBlockSize) = 0;
20  virtual uint64_t GetMaxBlockSize() const = 0;
21  virtual const CChainParams &GetChainParams() const = 0;
22  virtual void SetCashAddrEncoding(bool) = 0;
23  virtual bool UseCashAddrEncoding() const = 0;
24 
25  virtual void SetExcessUTXOCharge(Amount amt) = 0;
26  virtual Amount GetExcessUTXOCharge() const = 0;
27 
28  Config() = default;
29  Config(const Config &) = delete;
30  Config &operator=(const Config &) = delete;
31 };
32 
33 class GlobalConfig final : public Config {
34 public:
35  GlobalConfig();
36  bool SetMaxBlockSize(uint64_t maxBlockSize) override;
37  uint64_t GetMaxBlockSize() const override;
38  const CChainParams &GetChainParams() const override;
39  void SetCashAddrEncoding(bool) override;
40  bool UseCashAddrEncoding() const override;
41 
42  void SetExcessUTXOCharge(Amount) override;
43  Amount GetExcessUTXOCharge() const override;
44 
45 private:
48 
50  uint64_t nMaxBlockSize;
51 };
52 
53 // Dummy for subclassing in unittests
54 class DummyConfig : public Config {
55 public:
56  DummyConfig();
57  explicit DummyConfig(std::string net);
58  explicit DummyConfig(std::unique_ptr<CChainParams> chainParamsIn);
59  bool SetMaxBlockSize(uint64_t maxBlockSize) override { return false; }
60  uint64_t GetMaxBlockSize() const override { return 0; }
61 
62  void SetChainParams(std::string net);
63  const CChainParams &GetChainParams() const override { return *chainParams; }
64 
65  void SetCashAddrEncoding(bool) override {}
66  bool UseCashAddrEncoding() const override { return false; }
67 
68  void SetExcessUTXOCharge(Amount amt) override {}
69  Amount GetExcessUTXOCharge() const override { return Amount::zero(); }
70 
71 private:
72  std::unique_ptr<CChainParams> chainParams;
73 };
74 
75 // Temporary woraround.
76 const Config &GetConfig();
77 
78 #endif // BITCOIN_CONFIG_H
Config::GetMaxBlockSize
virtual uint64_t GetMaxBlockSize() const =0
feerate.h
Config::GetExcessUTXOCharge
virtual Amount GetExcessUTXOCharge() const =0
DummyConfig::DummyConfig
DummyConfig()
Definition: config.cpp:45
Config::operator=
Config & operator=(const Config &)=delete
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:47
GlobalConfig::SetMaxBlockSize
bool SetMaxBlockSize(uint64_t maxBlockSize) override
Definition: config.cpp:13
Config::Config
Config()=default
DummyConfig::SetChainParams
void SetChainParams(std::string net)
Definition: config.cpp:54
DummyConfig::UseCashAddrEncoding
bool UseCashAddrEncoding() const override
Definition: config.h:66
DummyConfig::SetMaxBlockSize
bool SetMaxBlockSize(uint64_t maxBlockSize) override
Definition: config.h:59
Amount::zero
static constexpr Amount zero()
Definition: amount.h:42
Config::UseCashAddrEncoding
virtual bool UseCashAddrEncoding() const =0
GlobalConfig::excessUTXOCharge
Amount excessUTXOCharge
Definition: config.h:47
GetConfig
const Config & GetConfig()
Definition: config.cpp:34
Config
Definition: config.h:17
GlobalConfig::SetCashAddrEncoding
void SetCashAddrEncoding(bool) override
Definition: config.cpp:38
GlobalConfig::UseCashAddrEncoding
bool UseCashAddrEncoding() const override
Definition: config.cpp:41
GlobalConfig::GlobalConfig
GlobalConfig()
Definition: config.cpp:10
DummyConfig::GetMaxBlockSize
uint64_t GetMaxBlockSize() const override
Definition: config.h:60
GlobalConfig::SetExcessUTXOCharge
void SetExcessUTXOCharge(Amount) override
Definition: config.cpp:58
Amount
Definition: amount.h:19
Config::SetMaxBlockSize
virtual bool SetMaxBlockSize(uint64_t maxBlockSize)=0
GlobalConfig::GetChainParams
const CChainParams & GetChainParams() const override
Definition: config.cpp:28
Config::GetChainParams
virtual const CChainParams & GetChainParams() const =0
DummyConfig::chainParams
std::unique_ptr< CChainParams > chainParams
Definition: config.h:72
DummyConfig::GetChainParams
const CChainParams & GetChainParams() const override
Definition: config.h:63
DummyConfig::SetExcessUTXOCharge
void SetExcessUTXOCharge(Amount amt) override
Definition: config.h:68
DummyConfig::SetCashAddrEncoding
void SetCashAddrEncoding(bool) override
Definition: config.h:65
GlobalConfig::nMaxBlockSize
uint64_t nMaxBlockSize
The largest block size this node will accept.
Definition: config.h:50
GlobalConfig::useCashAddr
bool useCashAddr
Definition: config.h:46
GlobalConfig::GetExcessUTXOCharge
Amount GetExcessUTXOCharge() const override
Definition: config.cpp:62
amount.h
Config::SetExcessUTXOCharge
virtual void SetExcessUTXOCharge(Amount amt)=0
DummyConfig::GetExcessUTXOCharge
Amount GetExcessUTXOCharge() const override
Definition: config.h:69
Config::SetCashAddrEncoding
virtual void SetCashAddrEncoding(bool)=0
GlobalConfig
Definition: config.h:33
GlobalConfig::GetMaxBlockSize
uint64_t GetMaxBlockSize() const override
Definition: config.cpp:24
DummyConfig
Definition: config.h:54