Electroneum
core.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2021, The Electroneum Project
2 // Copyrights(c) 2014-2019, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #pragma once
31 
32 #include "blocks/blocks.h"
35 #include "misc_log_ex.h"
36 
37 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
38 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "daemon"
39 
40 namespace daemonize
41 {
42 
43 class t_core final
44 {
45 public:
46  static void init_options(boost::program_options::options_description & option_spec)
47  {
48  cryptonote::core::init_options(option_spec);
49  }
50 private:
52  cryptonote::core m_core;
53  // TEMPORARY HACK - Yes, this creates a copy, but otherwise the original
54  // variable map could go out of scope before the run method is called
55  boost::program_options::variables_map const m_vm_HACK;
56 public:
58  boost::program_options::variables_map const & vm
59  )
60  : m_core{nullptr}
61  , m_vm_HACK{vm}
62  {
63  }
64 
65  // TODO - get rid of circular dependencies in internals
66  void set_protocol(t_protocol_raw & protocol)
67  {
68  m_core.set_cryptonote_protocol(&protocol);
69  }
70 
71  bool run()
72  {
73  //initialize core here
74  MGINFO("Initializing core...");
75 #if defined(PER_BLOCK_CHECKPOINT)
77 #else
78  const cryptonote::GetCheckpointsCallback& get_checkpoints = nullptr;
79 #endif
80  if (!m_core.init(m_vm_HACK, nullptr, get_checkpoints))
81  {
82  return false;
83  }
84  MGINFO("Core initialized OK");
85  return true;
86  }
87 
89  {
90  return m_core;
91  }
92 
94  {
95  MGINFO("Deinitializing core...");
96  try {
97  m_core.deinit();
98  m_core.set_cryptonote_protocol(nullptr);
99  } catch (...) {
100  MERROR("Failed to deinitialize core...");
101  }
102  }
103 };
104 
105 }
#define MERROR(x)
Definition: misc_log_ex.h:73
bool deinit()
performs safe shutdown steps for core and core components
bool init(const boost::program_options::variables_map &vm, const test_options *test_options=NULL, const GetCheckpointsCallback &get_checkpoints=nullptr)
initializes the core as needed
std::function< const epee::span< const unsigned char >cryptonote::network_type network)> GetCheckpointsCallback
Callback routine that returns checkpoints data for specific network type.
Definition: blockchain.h:92
t_core(boost::program_options::variables_map const &vm)
Definition: core.h:57
#define MGINFO(x)
Definition: misc_log_ex.h:80
void set_cryptonote_protocol(i_cryptonote_protocol *pprotocol)
set the pointer to the cryptonote protocol object to use
void set_protocol(t_protocol_raw &protocol)
Definition: core.h:66
handles core cryptonote functionality
static void init_options(boost::program_options::options_description &desc)
adds command line options to the given options set
This is the orginal cryptonote protocol network-events handler, modified by us.
static void init_options(boost::program_options::options_description &option_spec)
Definition: core.h:46
const epee::span< const unsigned char > GetCheckpointsData(cryptonote::network_type network)
Definition: blocks.cpp:21
bool run()
Definition: core.h:71