Kagome
Polkadot Runtime Engine in C++17
kagome::api::ApiServiceImpl Class Referencefinal

#include <api_service_impl.hpp>

Inheritance diagram for kagome::api::ApiServiceImpl:
Collaboration diagram for kagome::api::ApiServiceImpl:

Classes

struct  ListenerList
 
struct  ProcessorSpan
 
struct  SessionSubscriptions
 

Public Types

template<class T >
using sptr = std::shared_ptr< T >
 
- Public Types inherited from kagome::api::ApiService
using PubsubSubscriptionId = uint32_t
 subscription id for pubsub API methods More...
 
template<class T >
using sptr = std::shared_ptr< T >
 

Public Member Functions

 ApiServiceImpl (const std::shared_ptr< application::AppStateManager > &app_state_manager, std::shared_ptr< api::RpcThreadPool > thread_pool, ListenerList listeners, std::shared_ptr< JRpcServer > server, const ProcessorSpan &processors, StorageSubscriptionEnginePtr storage_sub_engine, ChainSubscriptionEnginePtr chain_sub_engine, ExtrinsicSubscriptionEnginePtr ext_sub_engine, std::shared_ptr< subscription::ExtrinsicEventKeyRepository > extrinsic_event_key_repo, std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< storage::trie::TrieStorage > trie_storage, std::shared_ptr< runtime::Core > core)
 
 ~ApiServiceImpl () override=default
 
bool prepare () override
 
bool start () override
 
void stop () override
 
outcome::result< uint32_t > subscribeSessionToKeys (const std::vector< common::Buffer > &keys) override
 
outcome::result< bool > unsubscribeSessionFromIds (const std::vector< PubsubSubscriptionId > &subscription_id) override
 
outcome::result< PubsubSubscriptionIdsubscribeFinalizedHeads () override
 
outcome::result< bool > unsubscribeFinalizedHeads (PubsubSubscriptionId subscription_id) override
 
outcome::result< PubsubSubscriptionIdsubscribeNewHeads () override
 
outcome::result< bool > unsubscribeNewHeads (PubsubSubscriptionId subscription_id) override
 
outcome::result< PubsubSubscriptionIdsubscribeRuntimeVersion () override
 
outcome::result< bool > unsubscribeRuntimeVersion (PubsubSubscriptionId subscription_id) override
 
outcome::result< PubsubSubscriptionIdsubscribeForExtrinsicLifecycle (const primitives::Transaction::Hash &tx_hash) override
 
outcome::result< bool > unsubscribeFromExtrinsicLifecycle (PubsubSubscriptionId subscription_id) override
 
- Public Member Functions inherited from kagome::api::ApiService
virtual ~ApiService ()=default
 

Private Types

using ChainEventSubscriberPtr = primitives::events::ChainEventSubscriberPtr
 
using StorageEventSubscriberPtr = primitives::events::StorageEventSubscriberPtr
 
using ExtrinsicEventSubscriberPtr = primitives::events::ExtrinsicEventSubscriberPtr
 
using ChainSubscriptionEnginePtr = primitives::events::ChainSubscriptionEnginePtr
 
using StorageSubscriptionEnginePtr = primitives::events::StorageSubscriptionEnginePtr
 
using ExtrinsicSubscriptionEnginePtr = primitives::events::ExtrinsicSubscriptionEnginePtr
 
using ChainEventSubscriber = primitives::events::ChainEventSubscriber
 
using ExtrinsicEventSubscriber = primitives::events::ExtrinsicEventSubscriber
 
using StorageEventSubscriber = primitives::events::StorageEventSubscriber
 
using ExtrinsicSubscriptionEngine = primitives::events::ExtrinsicSubscriptionEngine
 
using SessionPtr = std::shared_ptr< Session >
 
using SubscriptionSetId = subscription::SubscriptionSetId
 subscription set id from subscription::SubscriptionEngine More...
 
using PubsubSubscriptionId = uint32_t
 subscription id for pubsub API methods More...
 
using Buffer = common::Buffer
 

Private Member Functions

jsonrpc::Value createStateStorageEvent (const std::vector< std::pair< common::Buffer, std::optional< common::Buffer >>> &key_value_pairs, const primitives::BlockHash &block)
 
std::optional< std::shared_ptr< SessionSubscriptions > > findSessionById (Session::SessionId id)
 
void removeSessionById (Session::SessionId id)
 
std::shared_ptr< SessionSubscriptionsstoreSessionWithId (Session::SessionId id, const std::shared_ptr< Session > &session)
 
void onSessionRequest (std::string_view request, std::shared_ptr< Session > session)
 
void onSessionClose (Session::SessionId id, SessionType)
 
void onStorageEvent (SubscriptionSetId set_id, SessionPtr &session, const Buffer &key, const std::optional< Buffer > &data, const common::Hash256 &block)
 
void onChainEvent (SubscriptionSetId set_id, SessionPtr &session, primitives::events::ChainEventType event_type, const primitives::events::ChainEventParams &params)
 
void onExtrinsicEvent (SubscriptionSetId set_id, SessionPtr &session, primitives::events::SubscribedExtrinsicId id, const primitives::events::ExtrinsicLifecycleEvent &params)
 
template<typename Func >
auto withSession (kagome::api::Session::SessionId id, Func &&f)
 
template<typename T >
SessionSubscriptions::AdditionMessageType uploadFromCache (T &&value)
 
SessionSubscriptions::CachedAdditionMessagesList uploadMessagesListFromCache ()
 

Private Attributes

std::shared_ptr< api::RpcThreadPoolthread_pool_
 
std::vector< sptr< Listener > > listeners_
 
std::shared_ptr< JRpcServerserver_
 
log::Logger logger_
 
std::shared_ptr< blockchain::BlockTreeblock_tree_
 
std::shared_ptr< storage::trie::TrieStoragetrie_storage_
 
std::shared_ptr< runtime::Corecore_
 
std::mutex subscribed_sessions_cs_
 
std::unordered_map< Session::SessionId, std::shared_ptr< SessionSubscriptions > > subscribed_sessions_
 
struct {
StorageSubscriptionEnginePtr storage
 
ChainSubscriptionEnginePtr chain
 
ExtrinsicSubscriptionEnginePtr ext
 
subscription_engines_
 
std::shared_ptr< subscription::ExtrinsicEventKeyRepositoryextrinsic_event_key_repo_
 

Detailed Description

Service listening for incoming JSON RPC request

Definition at line 69 of file api_service_impl.hpp.


Class Documentation

struct kagome::api::ApiServiceImpl::ListenerList

Definition at line 117 of file api_service_impl.hpp.

Collaboration diagram for kagome::api::ApiServiceImpl::ListenerList:
Class Members
vector< sptr< Listener > > listeners
struct kagome::api::ApiServiceImpl::ProcessorSpan

Definition at line 120 of file api_service_impl.hpp.

Collaboration diagram for kagome::api::ApiServiceImpl::ProcessorSpan:
Class Members
span< sptr< JRpcProcessor > > processors
struct kagome::api::ApiServiceImpl::SessionSubscriptions

Definition at line 100 of file api_service_impl.hpp.

Collaboration diagram for kagome::api::ApiServiceImpl::SessionSubscriptions:
Class Members
typedef vector
< AdditionMessageType >
AdditionMessagesList
typedef decltype(KAGOME_EXTRACT_UNIQUE_CACHE(api_service,
string))
AdditionMessageType
typedef decltype(KAGOME_EXTRACT_SHARED_CACHE(api_service,
AdditionMessagesList))
CachedAdditionMessagesList
Class Members
ChainEventSubscriberPtr chain_sub
ExtrinsicEventSubscriberPtr ext_sub
CachedAdditionMessagesList messages
StorageEventSubscriberPtr storage_sub

Member Typedef Documentation

Definition at line 98 of file api_service_impl.hpp.

subscription id for pubsub API methods

Definition at line 96 of file api_service_impl.hpp.

using kagome::api::ApiServiceImpl::SessionPtr = std::shared_ptr<Session>
private

Definition at line 90 of file api_service_impl.hpp.

template<class T >
using kagome::api::ApiServiceImpl::sptr = std::shared_ptr<T>

Definition at line 115 of file api_service_impl.hpp.

Constructor & Destructor Documentation

kagome::api::ApiServiceImpl::ApiServiceImpl ( const std::shared_ptr< application::AppStateManager > &  app_state_manager,
std::shared_ptr< api::RpcThreadPool thread_pool,
ListenerList  listeners,
std::shared_ptr< JRpcServer server,
const ProcessorSpan processors,
StorageSubscriptionEnginePtr  storage_sub_engine,
ChainSubscriptionEnginePtr  chain_sub_engine,
ExtrinsicSubscriptionEnginePtr  ext_sub_engine,
std::shared_ptr< subscription::ExtrinsicEventKeyRepository extrinsic_event_key_repo,
std::shared_ptr< blockchain::BlockTree block_tree,
std::shared_ptr< storage::trie::TrieStorage trie_storage,
std::shared_ptr< runtime::Core core 
)
Parameters
context- reference to the io context
listener- a shared ptr to the endpoint listener instance
processors- shared ptrs to JSON processor instances

Definition at line 119 of file api_service_impl.cpp.

kagome::api::ApiServiceImpl::~ApiServiceImpl ( )
overridedefault

Member Function Documentation

jsonrpc::Value kagome::api::ApiServiceImpl::createStateStorageEvent ( const std::vector< std::pair< common::Buffer, std::optional< common::Buffer >>> &  key_value_pairs,
const primitives::BlockHash block 
)
private

TODO(iceseer): PRE-475 make event notification depending in packs blocks, to batch them in a single message Because of a spec, we can send an array of changes in a single message. We can receive here a pack of events and format them in a single json message.

Definition at line 166 of file api_service_impl.cpp.

std::optional<std::shared_ptr<SessionSubscriptions> > kagome::api::ApiServiceImpl::findSessionById ( Session::SessionId  id)
inlineprivate

Definition at line 185 of file api_service_impl.hpp.

void kagome::api::ApiServiceImpl::onChainEvent ( SubscriptionSetId  set_id,
SessionPtr session,
primitives::events::ChainEventType  event_type,
const primitives::events::ChainEventParams params 
)
private

Definition at line 533 of file api_service_impl.cpp.

void kagome::api::ApiServiceImpl::onExtrinsicEvent ( SubscriptionSetId  set_id,
SessionPtr session,
primitives::events::SubscribedExtrinsicId  id,
const primitives::events::ExtrinsicLifecycleEvent params 
)
private

Definition at line 561 of file api_service_impl.cpp.

void kagome::api::ApiServiceImpl::onSessionClose ( Session::SessionId  id,
SessionType   
)
private

Definition at line 516 of file api_service_impl.cpp.

void kagome::api::ApiServiceImpl::onSessionRequest ( std::string_view  request,
std::shared_ptr< Session session 
)
private

Unique ptr object to autorelease sessions. 0xff if a random not null value to jump internal nullptr check.

Definition at line 474 of file api_service_impl.cpp.

void kagome::api::ApiServiceImpl::onStorageEvent ( SubscriptionSetId  set_id,
SessionPtr session,
const Buffer key,
const std::optional< Buffer > &  data,
const common::Hash256 block 
)
private

Definition at line 520 of file api_service_impl.cpp.

bool kagome::api::ApiServiceImpl::prepare ( )
overridevirtual
See also
AppStateManager::takeControl

Implements kagome::api::ApiService.

Definition at line 193 of file api_service_impl.cpp.

void kagome::api::ApiServiceImpl::removeSessionById ( Session::SessionId  id)
private

Definition at line 262 of file api_service_impl.cpp.

bool kagome::api::ApiServiceImpl::start ( )
overridevirtual
See also
AppStateManager::takeControl

Implements kagome::api::ApiService.

Definition at line 231 of file api_service_impl.cpp.

void kagome::api::ApiServiceImpl::stop ( )
overridevirtual
See also
AppStateManager::takeControl

Implements kagome::api::ApiService.

Definition at line 237 of file api_service_impl.cpp.

std::shared_ptr< ApiServiceImpl::SessionSubscriptions > kagome::api::ApiServiceImpl::storeSessionWithId ( Session::SessionId  id,
const std::shared_ptr< Session > &  session 
)
private

Definition at line 243 of file api_service_impl.cpp.

outcome::result< ApiServiceImpl::PubsubSubscriptionId > kagome::api::ApiServiceImpl::subscribeFinalizedHeads ( )
overridevirtual

Implements kagome::api::ApiService.

Definition at line 316 of file api_service_impl.cpp.

outcome::result< ApiServiceImpl::PubsubSubscriptionId > kagome::api::ApiServiceImpl::subscribeForExtrinsicLifecycle ( const primitives::Transaction::Hash tx_hash)
overridevirtual

Implements kagome::api::ApiService.

Definition at line 439 of file api_service_impl.cpp.

outcome::result< ApiServiceImpl::PubsubSubscriptionId > kagome::api::ApiServiceImpl::subscribeNewHeads ( )
overridevirtual

Implements kagome::api::ApiService.

Definition at line 360 of file api_service_impl.cpp.

outcome::result< ApiServiceImpl::PubsubSubscriptionId > kagome::api::ApiServiceImpl::subscribeRuntimeVersion ( )
overridevirtual

Implements kagome::api::ApiService.

Definition at line 401 of file api_service_impl.cpp.

outcome::result< ApiServiceImpl::PubsubSubscriptionId > kagome::api::ApiServiceImpl::subscribeSessionToKeys ( const std::vector< common::Buffer > &  keys)
overridevirtual

Implements kagome::api::ApiService.

Definition at line 268 of file api_service_impl.cpp.

outcome::result< bool > kagome::api::ApiServiceImpl::unsubscribeFinalizedHeads ( PubsubSubscriptionId  subscription_id)
overridevirtual

Implements kagome::api::ApiService.

Definition at line 349 of file api_service_impl.cpp.

outcome::result< bool > kagome::api::ApiServiceImpl::unsubscribeFromExtrinsicLifecycle ( PubsubSubscriptionId  subscription_id)
overridevirtual

Implements kagome::api::ApiService.

Definition at line 453 of file api_service_impl.cpp.

outcome::result< bool > kagome::api::ApiServiceImpl::unsubscribeNewHeads ( PubsubSubscriptionId  subscription_id)
overridevirtual

Implements kagome::api::ApiService.

Definition at line 390 of file api_service_impl.cpp.

outcome::result< bool > kagome::api::ApiServiceImpl::unsubscribeRuntimeVersion ( PubsubSubscriptionId  subscription_id)
overridevirtual

Implements kagome::api::ApiService.

Definition at line 428 of file api_service_impl.cpp.

outcome::result< bool > kagome::api::ApiServiceImpl::unsubscribeSessionFromIds ( const std::vector< PubsubSubscriptionId > &  subscription_id)
overridevirtual

Implements kagome::api::ApiService.

Definition at line 463 of file api_service_impl.cpp.

template<typename T >
SessionSubscriptions::AdditionMessageType kagome::api::ApiServiceImpl::uploadFromCache ( T &&  value)
inlineprivate

Definition at line 228 of file api_service_impl.hpp.

SessionSubscriptions::CachedAdditionMessagesList kagome::api::ApiServiceImpl::uploadMessagesListFromCache ( )
inlineprivate

Definition at line 235 of file api_service_impl.hpp.

template<typename Func >
auto kagome::api::ApiServiceImpl::withSession ( kagome::api::Session::SessionId  id,
Func &&  f 
)
inlineprivate

Definition at line 217 of file api_service_impl.hpp.

Member Data Documentation

std::shared_ptr<blockchain::BlockTree> kagome::api::ApiServiceImpl::block_tree_
private

Definition at line 246 of file api_service_impl.hpp.

std::shared_ptr<runtime::Core> kagome::api::ApiServiceImpl::core_
private

Definition at line 248 of file api_service_impl.hpp.

std::shared_ptr<subscription::ExtrinsicEventKeyRepository> kagome::api::ApiServiceImpl::extrinsic_event_key_repo_
private

Definition at line 261 of file api_service_impl.hpp.

std::vector<sptr<Listener> > kagome::api::ApiServiceImpl::listeners_
private

Definition at line 243 of file api_service_impl.hpp.

log::Logger kagome::api::ApiServiceImpl::logger_
private

Definition at line 245 of file api_service_impl.hpp.

std::shared_ptr<JRpcServer> kagome::api::ApiServiceImpl::server_
private

Definition at line 244 of file api_service_impl.hpp.

std::unordered_map<Session::SessionId, std::shared_ptr<SessionSubscriptions> > kagome::api::ApiServiceImpl::subscribed_sessions_
private

Definition at line 253 of file api_service_impl.hpp.

std::mutex kagome::api::ApiServiceImpl::subscribed_sessions_cs_
private

Definition at line 250 of file api_service_impl.hpp.

struct { ... } kagome::api::ApiServiceImpl::subscription_engines_
std::shared_ptr<api::RpcThreadPool> kagome::api::ApiServiceImpl::thread_pool_
private

Definition at line 242 of file api_service_impl.hpp.

std::shared_ptr<storage::trie::TrieStorage> kagome::api::ApiServiceImpl::trie_storage_
private

Definition at line 247 of file api_service_impl.hpp.


The documentation for this class was generated from the following files: