Kagome
Polkadot Runtime Engine in C++17
chain_spec.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CHAIN_SPEC_HPP
7 #define KAGOME_CHAIN_SPEC_HPP
8 
9 #include <libp2p/peer/peer_info.hpp>
10 
11 #include "crypto/ed25519_types.hpp"
12 #include "crypto/sr25519_types.hpp"
13 #include "primitives/block.hpp"
15 
16 namespace kagome::application {
17 
18  using GenesisRawData = std::vector<std::pair<common::Buffer, common::Buffer>>;
19  using ChildrenDefaultRawData = std::map<common::Buffer, GenesisRawData>;
20 
25  class ChainSpec {
26  public:
27  virtual ~ChainSpec() = default;
28 
29  virtual const std::string &name() const = 0;
30 
31  virtual const std::string &id() const = 0;
32 
33  virtual const std::string &chainType() const = 0;
34 
36  virtual const std::vector<libp2p::multi::Multiaddress> &bootNodes()
37  const = 0;
38 
39  virtual const std::vector<std::pair<std::string, size_t>>
40  &telemetryEndpoints() const = 0;
41 
42  virtual const std::string &protocolId() const = 0;
43 
44  virtual const std::map<std::string, std::string> &properties() const = 0;
45 
46  virtual std::optional<std::reference_wrapper<const std::string>>
47  getProperty(const std::string &property) const = 0;
48 
49  virtual const std::set<primitives::BlockHash> &forkBlocks() const = 0;
50 
51  virtual const std::set<primitives::BlockHash> &badBlocks() const = 0;
52 
53  virtual std::optional<std::string> consensusEngine() const = 0;
54 
58  virtual outcome::result<common::Buffer> fetchCodeSubstituteByBlockInfo(
59  const primitives::BlockInfo &block_info) const = 0;
60 
64  virtual std::shared_ptr<const primitives::CodeSubstituteBlockIds>
65  codeSubstitutes() const = 0;
66 
70  virtual const GenesisRawData &getGenesisTopSection() const = 0;
71 
76  const = 0;
77 
78  bool idStartsWith(std::string_view prefix) const {
79  return id().rfind(prefix, 0) == 0;
80  }
81 
82  bool isKusama() const {
83  return idStartsWith("kusama") || idStartsWith("ksm");
84  }
85 
86  bool isRococo() const {
87  return idStartsWith("rococo") || idStartsWith("rco");
88  }
89 
90  bool isWococo() const {
91  return idStartsWith("wococo") || idStartsWith("wco");
92  }
93 
94  bool isVersi() const {
95  return idStartsWith("versi") || idStartsWith("vrs");
96  }
97  };
98 
99 } // namespace kagome::application
100 
101 #endif // KAGOME_CHAIN_SPEC_HPP
virtual const std::string & name() const =0
virtual const std::set< primitives::BlockHash > & badBlocks() const =0
virtual std::shared_ptr< const primitives::CodeSubstituteBlockIds > codeSubstitutes() const =0
virtual const std::string & chainType() const =0
virtual const std::map< std::string, std::string > & properties() const =0
virtual outcome::result< common::Buffer > fetchCodeSubstituteByBlockInfo(const primitives::BlockInfo &block_info) const =0
std::vector< std::pair< common::Buffer, common::Buffer >> GenesisRawData
Definition: chain_spec.hpp:18
virtual const std::vector< libp2p::multi::Multiaddress > & bootNodes() const =0
Return ids of peer nodes of the current node.
virtual std::optional< std::reference_wrapper< const std::string > > getProperty(const std::string &property) const =0
virtual const std::string & protocolId() const =0
bool idStartsWith(std::string_view prefix) const
Definition: chain_spec.hpp:78
virtual const std::set< primitives::BlockHash > & forkBlocks() const =0
virtual const std::string & id() const =0
virtual std::optional< std::string > consensusEngine() const =0
std::map< common::Buffer, GenesisRawData > ChildrenDefaultRawData
Definition: chain_spec.hpp:19
virtual const GenesisRawData & getGenesisTopSection() const =0
virtual const std::vector< std::pair< std::string, size_t > > & telemetryEndpoints() const =0
virtual const ChildrenDefaultRawData & getGenesisChildrenDefaultSection() const =0
virtual ~ChainSpec()=default