Skip to content

Commit

Permalink
Merge pull request #28 from GeniusVentures/dev_cleanup
Browse files Browse the repository at this point in the history
Compiling node without injector
  • Loading branch information
henriqueaklein authored Feb 25, 2024
2 parents b9d3d6a + 6e4cd2d commit a73b47f
Show file tree
Hide file tree
Showing 49 changed files with 1,089 additions and 296 deletions.
42 changes: 42 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
add_executable (sgns_demo
runner.cpp
SuperGeniusDemoApp.cpp
integration/CComponentFactory.cpp
)

target_link_libraries(sgns_demo
logger
Boost::system
Boost::thread
Boost::filesystem
ipfs_blockservice
validating_node_application
app_state_manager
app_config_impl
local_key_storage
configuration_storage
block_header_repository
clock
rocksdb
hasher
p2p::p2p_basic_host
p2p::p2p_default_network
p2p::p2p_peer_repository
p2p::p2p_inmem_address_repository
p2p::p2p_inmem_key_repository
p2p::p2p_inmem_protocol_repository
p2p::p2p_literals
p2p::p2p_kademlia
p2p::p2p_identify
p2p::p2p_ping
p2p::p2p_peer_address
p2p::p2p_protocol_echo
#protobuf::libprotobuf
#${USER_ENV_LIBRARY} # On windows platform , sr25519 library needs extra library userenv, so folllowing code is added
#${WIN_CRYPT_LIBRARY}
)
if(FORCE_MULTILE)
set_target_properties(sgns_demo PROPERTIES LINK_FLAGS ${MULTIPLE_OPTION})
endif()

supergenius_install(sgns_demo)
80 changes: 80 additions & 0 deletions app/Singleton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//---------------------------------------------------------------------
// File: Singleton.hpp
// Description: template for Singleton objects
// Created: 11/30/03
// Author: Kenneth L. Hurley
/// \note Elemental Engine
/// Copyright (C) 2013 Social Systems Technology, Inc.
///
/// This code is redistributable under the terms of the EE License.
///
/// This code is distributed without warranty or implied warranty of
/// merchantability or fitness for a particular purpose. See the
/// EE License for more details.
///
/// You should have received a copy of the EE License along with this
/// code; If not, write to Social Systems Technology, Inc.,
/// 109 East 17th Street Suite 4210 Cheyenne, WY 82001 USA
//---------------------------------------------------------------------

#ifndef SINGLETON_H
#define SINGLETON_H

//
// this code is so that object can register themselves with
// the system.
//

template <class T>
class CSingleton
{
private:
static bool isInitialized;
static T *_instance; // first initialize memory without constructor
public:
static T *Instance()
{
// start lock for multithreading here
if (_instance == NULL)
{
_instance = new T(_instance);
}

if (!isInitialized)
{
isInitialized = true;
new (_instance) T();
}
return _instance;
};

private:
CSingleton() {};
~CSingleton() {};
// disable copy & assignment
CSingleton( CSingleton const&);
CSingleton& operator=( CSingleton const&);
};

template <class T>
bool CSingleton<T>::isInitialized = false;

template <class T>
T *CSingleton<T>::_instance = NULL;

#define SINGLETONINSTANCE(T) \
CSingleton< T >::Instance()

#define SINGLETON(T) \
protected: \
friend class CSingleton< T >; \
T(T *) {} \
T(){}

#define SINGLETONCONSTRUCTOROVERRIDE(T) \
protected: \
friend class CSingleton< T >; \
T(T *) {}


#endif // #ifndef SINGLETON_H
38 changes: 38 additions & 0 deletions app/SuperGeniusDemoApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file SuperGeniusDemoApp.cpp
* @brief SuperGenius demo source file
* @date 2024-02-21
* @author Henrique A. Klein ([email protected])
*/
#include "SuperGeniusDemoApp.hpp"
#include "base/logger.hpp"
#include "integration/AppConfigurationFactory.hpp"

SuperGeniusDemoApp::SuperGeniusDemoApp()
{
std::cout << "SuperGeniusDemoApp Constructed" << std::endl;
}
SuperGeniusDemoApp::~SuperGeniusDemoApp()
{
std::cout << "SuperGeniusDemoApp Destructed" << std::endl;
}

void SuperGeniusDemoApp::init( int argc, char **argv )
{
std::cout << "SuperGeniusDemoApp Init" << std::endl;

auto logger = sgns::base::createLogger( "SuperGenius block node: " );
//cfg = std::shared_ptr<sgns::application::AppConfiguration>( std::move( AppConfigurationFactory::create( logger ) ) );
cfg = AppConfigurationFactory::create( logger );

cfg->initialize_from_args( sgns::application::AppConfiguration::LoadScheme::kValidating, argc, argv );

validation_node = std::make_shared<sgns::application::ValidatingNodeApplication>( std::move( cfg ) );
}
void SuperGeniusDemoApp::run( void )
{
validation_node->run();
}
void SuperGeniusDemoApp::exit( void )
{
}
29 changes: 29 additions & 0 deletions app/SuperGeniusDemoApp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @file SuperGeniusDemoApp.hpp
* @brief SuperGenius App demo header file
* @date 2024-02-21
* @author Henrique A. Klein ([email protected])
*/

#ifndef _SUPERGENIUS_DEMO_APP_HPP_
#define _SUPERGENIUS_DEMO_APP_HPP_
#include <memory>

#include "application/app_config.hpp"
#include "application/impl/validating_node_application.hpp"

class SuperGeniusDemoApp
{
public:
SuperGeniusDemoApp();
~SuperGeniusDemoApp();
void init( int argc, char **argv );
void run( void );
void exit( void );

private:
std::shared_ptr<sgns::application::AppConfiguration> cfg;
std::shared_ptr<sgns::application::ValidatingNodeApplication> validation_node;
};

#endif
22 changes: 22 additions & 0 deletions app/integration/AppConfigurationFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file AppConfigurationFactory.hpp
* @brief Factory to create AppConfiguration derived classes
* @date 2024-02-21
* @author Henrique A. Klein ([email protected])
*/

#ifndef _APP_CONFIGURATION_FACTORY_HPP_
#define _APP_CONFIGURATION_FACTORY_HPP_

#include "application/impl/app_config_impl.hpp"

class AppConfigurationFactory
{
public:
static std::shared_ptr<sgns::application::AppConfiguration> create( sgns::base::Logger logger )
{
return std::make_shared<sgns::application::AppConfigurationImpl>( std::move( logger ) );
}
};

#endif
22 changes: 22 additions & 0 deletions app/integration/AppStateManagerFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file AppStateManagerFactory.hpp
* @brief Factory to create AppStateManager derived classes
* @date 2024-02-22
* @author Henrique A. Klein ([email protected])
*/

#ifndef _APP_STATE_MANAGER_FACTORY_HPP_
#define _APP_STATE_MANAGER_FACTORY_HPP_

#include "application/impl/app_state_manager_impl.hpp"

class AppStateManagerFactory
{
public:
static std::shared_ptr<sgns::application::AppStateManager> create()
{
return std::make_shared<sgns::application::AppStateManagerImpl>();
}
};

#endif
39 changes: 39 additions & 0 deletions app/integration/BlockHeaderRepositoryFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

/**
* @file BlockHeaderRepositoryFactory.hpp
* @brief
* @date 2024-02-23
* @author Henrique A. Klein ([email protected])
*/
#ifndef _BLOCK_HEADER_REPOSITORY_FACTORY_HPP_
#define _BLOCK_HEADER_REPOSITORY_FACTORY_HPP_

#include "blockchain/impl/key_value_block_header_repository.hpp"
#include "integration/CComponentFactory.hpp"

class BlockHeaderRepositoryFactory
{
public:
static std::shared_ptr<sgns::blockchain::BlockHeaderRepository> create( const std::string &type )
{
auto component_factory = SINGLETONINSTANCE( CComponentFactory );

auto retval = component_factory->GetComponent( "BufferStorage", type );

if ( !retval )
{
throw std::runtime_error( "Initialize BufferStorage first" );
}
auto buf_storage = std::dynamic_pointer_cast<sgns::storage::BufferStorage>( retval.value() );
retval = component_factory->GetComponent( "Hasher", boost::none );
if ( !retval )
{
throw std::runtime_error( "Initialize Hasher first" );
}
auto hasher = std::dynamic_pointer_cast<sgns::crypto::Hasher>( retval.value() );

return std::make_shared<sgns::blockchain::KeyValueBlockHeaderRepository>( buf_storage, hasher );
}
};

#endif
33 changes: 33 additions & 0 deletions app/integration/BlockTreeFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file BlockTreeFactory.hpp
* @brief
* @date 2024-02-22
* @author Henrique A. Klein ([email protected])
*/
#ifndef _BLOCK_TREE_FACTORY_HPP_
#define _BLOCK_TREE_FACTORY_HPP_

class BlockTreeFactory
{
public:
static std::shared_ptr<sgns::blockchain::BlockTree> create( const std::string &db_path )
{
auto header_repo_ = std::make_shared<sgns::blockchain::KeyValueBlockHeaderRepository>( BufferStorageFactory::create( "rocksdb", db_path ),
HasherFactory::create() );

auto result = sgns::blockchain::BlockTreeImpl::create( //
header_repo_, //
);

if ( result )
{
return result.value();
}
else
{
throw std::runtime_error( "BlockTree not created" );
}
}
}

#endif
39 changes: 39 additions & 0 deletions app/integration/BufferStorageFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @file BufferStorageFactory.hpp
* @brief
* @date 2024-02-22
* @author Henrique A. Klein ([email protected])
*/
#ifndef _BUFFER_STORAGE_HPP_
#define _BUFFER_STORAGE_HPP_

#include "storage/rocksdb/rocksdb.hpp"

class BufferStorageFactory
{
public:
static std::shared_ptr<sgns::storage::BufferStorage> create( const std::string &type, const std::string &path )
{
if ( type == "rocksdb" )
{
auto options = sgns::storage::rocksdb::Options{};
options.create_if_missing = true;
auto result = sgns::storage::rocksdb::create( path, options );
if ( result )
{
return result.value();
}
else
{
throw std::runtime_error( "rocksdb not created" );
}
}
else
{
//TrieStorageBackend
}
throw std::runtime_error( "Invalid BufferStorage type" );
}
};

#endif
Loading

0 comments on commit a73b47f

Please sign in to comment.