/// Creates a node for the given blockchain and node configuration.
Creates a node for the given blockchain and node configuration.
Creates a node for the given blockchain and node configuration .
fn with_blockchain(
        blockchain: BlockchainMut,
        channel: NodeChannel,
        node_cfg: NodeConfig,
        config_manager: Option<Box<dyn ConfigManager>>,
        plugins: Vec<Box<dyn NodePlugin>>,
    ) -> Self {
        crypto::init();
        let peers = node_cfg.connect_list.addresses();
        let config = Configuration {
            connect_list: ConnectList::from_config(node_cfg.connect_list),
            mempool: node_cfg.mempool,
            network: node_cfg.network,
            peer_discovery: peers,
            keys: node_cfg.keys,
        };
        let api_state = SharedNodeState::new(node_cfg.api.state_update_timeout as u64);
        let mut api_aggregator = ApiAggregator::new();
        let plugin_api_context = PluginApiContext::new(
            blockchain.as_ref(),
            &api_state,
            ApiSender::new(channel.api_requests.0.clone()),
        );
        for plugin in &plugins {
            let endpoints = plugin.wire_api(plugin_api_context.clone());
            api_aggregator.extend(endpoints);
        }
        let system_state = Box::new(DefaultSystemState(node_cfg.listen_address));
        let network_config = config.network;
        let api_cfg = node_cfg.api.clone();
        let mut servers = HashMap::new();
        if let Some(listen_address) = api_cfg.public_api_address {
            let server_config = WebServerConfig {
                listen_address,
                allow_origin: api_cfg.public_allow_origin.clone(),
            };
            servers.insert(ApiAccess::Public, server_config);
        }
        if let Some(listen_address) = api_cfg.private_api_address {
            let server_config = WebServerConfig {
                listen_address,
                allow_origin: api_cfg.private_allow_origin.clone(),
            };
            servers.insert(ApiAccess::Private, server_config);
        }
        let api_runtime_config = ApiManagerConfig {
            servers,
            api_aggregator,
            server_restart_retry_timeout: node_cfg.api.server_restart.retry_timeout,
            server_restart_max_retries: node_cfg.api.server_restart.max_retries,
        };
        let mut handler = NodeHandler::new(
            blockchain,
            &node_cfg.external_address,
            channel.node_sender(),
            system_state,
            config,
            api_state,
            config_manager,
        );
        handler.plugins = plugins;
        Self {
            api_options: api_cfg,
            handler,
            channel,
            network_config,
            max_message_len: node_cfg.consensus.max_message_len,
            thread_pool_size: node_cfg.thread_pool_size,
            api_manager_config: api_runtime_config,
        }
    }
fn with_blockchain ( blockchain : BlockchainMut , channel : NodeChannel , node_cfg : NodeConfig , config_manager : Option < Box < dyn ConfigManager > > , plugins : Vec < Box < dyn NodePlugin > > , ) -> Self { crypto :: init ( ) ; let peers = node_cfg . connect_list . addresses ( ) ; let config = Configuration { connect_list : ConnectList :: from_config ( node_cfg . connect_list ) , mempool : node_cfg . mempool , network : node_cfg . network , peer_discovery : peers , keys : node_cfg . keys , } ; let api_state = SharedNodeState :: new ( node_cfg . api . state_update_timeout as u64 ) ; let mut api_aggregator = ApiAggregator :: new ( ) ; let plugin_api_context = PluginApiContext :: new ( blockchain . as_ref ( ) , & api_state , ApiSender :: new ( channel . api_requests . 0 . clone ( ) ) , ) ; for plugin in & plugins { let endpoints = plugin . wire_api ( plugin_api_context . clone ( ) ) ; api_aggregator . extend ( endpoints ) ; } let system_state = Box :: new ( DefaultSystemState ( node_cfg . listen_address ) ) ; let network_config = config . network ; let api_cfg = node_cfg . api . clone ( ) ; let mut servers = HashMap :: new ( ) ; if let Some ( listen_address ) = api_cfg . public_api_address { let server_config = WebServerConfig { listen_address , allow_origin : api_cfg . public_allow_origin . clone ( ) , } ; servers . insert ( ApiAccess :: Public , server_config ) ; } if let Some ( listen_address ) = api_cfg . private_api_address { let server_config = WebServerConfig { listen_address , allow_origin : api_cfg . private_allow_origin . clone ( ) , } ; servers . insert ( ApiAccess :: Private , server_config ) ; } let api_runtime_config = ApiManagerConfig { servers , api_aggregator , server_restart_retry_timeout : node_cfg . api . server_restart . retry_timeout , server_restart_max_retries : node_cfg . api . server_restart . max_retries , } ; let mut handler = NodeHandler :: new ( blockchain , & node_cfg . external_address , channel . node_sender ( ) , system_state , config , api_state , config_manager , ) ; handler . plugins = plugins ; Self { api_options : api_cfg , handler , channel , network_config , max_message_len : node_cfg . consensus . max_message_len , thread_pool_size : node_cfg . thread_pool_size , api_manager_config : api_runtime_config , } }
Creates a node for the given blockchain and node configuration.
Creates a node for the given blockchain and node configuration .
blockchain
BlockchainMut
channel
NodeChannel
node_cfg
NodeConfig
config_manager
Option<Box<dyn ConfigManager>>
plugins
Vec<Box<dyn NodePlugin>>