Bitcoin ABC  0.26.3
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 <consensus/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
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
Definition: config.h:17
virtual bool UseCashAddrEncoding() const =0
virtual uint64_t GetMaxBlockSize() const =0
Config()=default
Config & operator=(const Config &)=delete
Config(const Config &)=delete
virtual Amount GetExcessUTXOCharge() const =0
virtual const CChainParams & GetChainParams() const =0
virtual bool SetMaxBlockSize(uint64_t maxBlockSize)=0
virtual void SetExcessUTXOCharge(Amount amt)=0
virtual void SetCashAddrEncoding(bool)=0
const CChainParams & GetChainParams() const override
Definition: config.h:63
std::unique_ptr< CChainParams > chainParams
Definition: config.h:72
void SetCashAddrEncoding(bool) override
Definition: config.h:65
uint64_t GetMaxBlockSize() const override
Definition: config.h:60
bool SetMaxBlockSize(uint64_t maxBlockSize) override
Definition: config.h:59
void SetChainParams(std::string net)
Definition: config.cpp:54
bool UseCashAddrEncoding() const override
Definition: config.h:66
DummyConfig()
Definition: config.cpp:45
void SetExcessUTXOCharge(Amount amt) override
Definition: config.h:68
Amount GetExcessUTXOCharge() const override
Definition: config.h:69
void SetExcessUTXOCharge(Amount) override
Definition: config.cpp:58
bool UseCashAddrEncoding() const override
Definition: config.cpp:41
bool useCashAddr
Definition: config.h:46
bool SetMaxBlockSize(uint64_t maxBlockSize) override
Definition: config.cpp:13
Amount GetExcessUTXOCharge() const override
Definition: config.cpp:62
Amount excessUTXOCharge
Definition: config.h:47
uint64_t nMaxBlockSize
The largest block size this node will accept.
Definition: config.h:50
const CChainParams & GetChainParams() const override
Definition: config.cpp:28
void SetCashAddrEncoding(bool) override
Definition: config.cpp:38
uint64_t GetMaxBlockSize() const override
Definition: config.cpp:24
GlobalConfig()
Definition: config.cpp:10
const Config & GetConfig()
Definition: config.cpp:34
Definition: amount.h:19
static constexpr Amount zero()
Definition: amount.h:42