Skip to content

app/integration/ChainApiFactory.hpp

More...

Namespaces

Name
sgns

Classes

Name
class sgns::ChainApiFactory

Detailed Description

Date: 2024-03-05 Henrique A. Klein ([email protected])

Source code

#ifndef _CHAIN_API_FACTORY_HPP_
#define _CHAIN_API_FACTORY_HPP_

#include "api/service/chain/impl/chain_api_impl.hpp"
#include "blockchain/block_header_repository.hpp"
#include "blockchain/block_tree.hpp"

class CComponentFactory;
namespace sgns
{
    class ChainApiFactory
    {
    public:
        std::shared_ptr<api::ChainApi> create()
        {
            auto component_factory = SINGLETONINSTANCE( CComponentFactory );
            auto result            = component_factory->GetComponent( "BlockHeaderRepository", boost::none );

            if ( !result )
            {
                throw std::runtime_error( "Initialize BlockHeaderRepository first" );
            }
            auto block_header_repo = std::dynamic_pointer_cast<blockchain::BlockHeaderRepository>( result.value() );

            result            = component_factory->GetComponent( "BlockTree", boost::none );
            if ( !result )
            {
                throw std::runtime_error( "Initialize BlockTree first" );
            }
            auto block_tree = std::dynamic_pointer_cast<blockchain::BlockTree>( result.value() );

            return std::make_shared<api::ChainApiImpl>(block_header_repo, block_tree);
        }
    };
}

#endif

Updated on 2026-03-04 at 13:10:44 -0800