Skip to content

Commit

Permalink
ref: use helpers in crawler bin
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaslong committed Sep 16, 2021
1 parent f18c86c commit e9db8a0
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions bin/crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use snarkos::{
config::{Config, ConfigCli},
display::{initialize_logger, print_welcome},
errors::NodeError,
init::{init_node, init_rpc},
};
use snarkos_network::{config::Config as NodeConfig, Node, NodeType};
use snarkos_rpc::start_rpc_server;
Expand All @@ -42,47 +43,18 @@ async fn start_server(config: Config) -> anyhow::Result<()> {

print_welcome(&config);

let address = format!("{}:{}", config.node.ip, config.node.port);
let desired_address = address.parse::<SocketAddr>()?;

let node_config = NodeConfig::new(
None,
config.node.kind,
desired_address,
config.p2p.min_peers,
config.p2p.max_peers,
config.p2p.beacons.clone(),
// Set sync intervals for peers.
Duration::from_secs(config.p2p.peer_sync_interval.into()),
)?;

// Construct the node instance. Note this does not start the network services.
// This is done early on, so that the local address can be discovered
// before any other object (RPC) needs to use it.

let storage = Arc::new(AsyncStorage::new(SqliteStorage::new_ephemeral().unwrap()));

let node = Node::new(node_config, storage.clone()).await?;
let node = init_node(&config, storage.clone()).await?;

// Initialize metrics framework.
node.initialize_metrics().await?;

// Start RPC thread, if the RPC configuration is enabled.
if config.rpc.json_rpc {
let rpc_address = format!("{}:{}", config.rpc.ip, config.rpc.port)
.parse()
.expect("Invalid RPC server address!");

let rpc_handle = start_rpc_server(
rpc_address,
storage,
node.clone(),
config.rpc.username,
config.rpc.password,
);
node.register_task(rpc_handle);

info!("Listening for RPC requests on port {}", config.rpc.port);
let rpc_handle = init_rpc(&config, node.clone(), storage);
}

// Start the network services.
Expand Down

0 comments on commit e9db8a0

Please sign in to comment.