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  Config() = default;
26  Config(const Config &) = delete;
27  Config &operator=(const Config &) = delete;
28 };
29 
30 class GlobalConfig final : public Config {
31 public:
32  GlobalConfig();
33  bool SetMaxBlockSize(uint64_t maxBlockSize) override;
34  uint64_t GetMaxBlockSize() const override;
35  const CChainParams &GetChainParams() const override;
36  void SetCashAddrEncoding(bool) override;
37  bool UseCashAddrEncoding() const override;
38 
39 private:
41 
43  uint64_t nMaxBlockSize;
44 };
45 
46 // Dummy for subclassing in unittests
47 class DummyConfig : public Config {
48 public:
49  DummyConfig();
50  explicit DummyConfig(std::string net);
51  bool SetMaxBlockSize(uint64_t maxBlockSize) override { return false; }
52  uint64_t GetMaxBlockSize() const override { return 32'000'000; }
53 
54  const CChainParams &GetChainParams() const override { return *chainParams; }
55 
56  void SetCashAddrEncoding(bool) override {}
57  bool UseCashAddrEncoding() const override { return false; }
58 
59 private:
60  std::unique_ptr<CChainParams> chainParams;
61 };
62 
63 // Temporary woraround.
64 const Config &GetConfig();
65 
66 #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 const CChainParams & GetChainParams() const =0
virtual bool SetMaxBlockSize(uint64_t maxBlockSize)=0
virtual void SetCashAddrEncoding(bool)=0
const CChainParams & GetChainParams() const override
Definition: config.h:54
std::unique_ptr< CChainParams > chainParams
Definition: config.h:60
void SetCashAddrEncoding(bool) override
Definition: config.h:56
uint64_t GetMaxBlockSize() const override
Definition: config.h:52
bool SetMaxBlockSize(uint64_t maxBlockSize) override
Definition: config.h:51
bool UseCashAddrEncoding() const override
Definition: config.h:57
DummyConfig()
Definition: config.cpp:45
bool UseCashAddrEncoding() const override
Definition: config.cpp:41
bool useCashAddr
Definition: config.h:40
bool SetMaxBlockSize(uint64_t maxBlockSize) override
Definition: config.cpp:13
uint64_t nMaxBlockSize
The largest block size this node will accept.
Definition: config.h:43
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