diff --git a/docker/.env.example b/docker/.env.example deleted file mode 100644 index ded0559..0000000 --- a/docker/.env.example +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -# Used in https://github.com/timescale/timescaledb-docker -POSTGRES_DB=ckb -POSTGRES_USER=ckb -POSTGRES_PASSWORD=ckb - -# Used when render Grafana configuration file -GRAFANA_DOMAIN=127.0.0.1 diff --git a/docker/collector.yaml b/docker/collector.yaml index 1a6c3b5..508f418 100644 --- a/docker/collector.yaml +++ b/docker/collector.yaml @@ -41,12 +41,10 @@ services: - ckb-mainnet command: - "/bin/ckb-analyzer" - - "--node.rpc" + - "--ckb-rpc-url" - "http://ckb-mainnet:8114" - - "--node.subscription" + - "--ckb-subscription-addr" - "127.0.0.1:18114" - - "--topics" - - "ChainCrawler" extra_hosts: # use `host.docker.internal` as host DNS name - "host.docker.internal:host-gateway" @@ -59,12 +57,10 @@ services: - ckb-testnet command: - "/bin/ckb-analyzer" - - "--node.rpc" + - "--ckb-rpc-url" - "http://ckb-testnet:8114" - - "--node.subscription" + - "--ckb-subscription-addr" - "127.0.0.1:18114" - - "--topics" - - "ChainCrawler" extra_hosts: # use `host.docker.internal` as host DNS name - "host.docker.internal:host-gateway" diff --git a/src/main.rs b/src/main.rs index 3cd9511..4213117 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use crate::topic::{ }; use crate::util::crossbeam_channel_to_tokio_channel; use ckb_testkit::{connector::SharedState, ConnectorBuilder, Node}; -use clap::{crate_version, value_t_or_exit, values_t_or_exit, App, Arg}; +use clap::{crate_version, values_t_or_exit, App, Arg}; use std::env; use std::net::SocketAddr; use std::path::PathBuf; @@ -25,10 +25,39 @@ async fn main() { log::info!("CKBAnalyzer starting"); let matches = clap_app().get_matches(); - let rpc_url = value_t_or_exit!(matches, "node.rpc", String); - let subscription_addr = value_t_or_exit!(matches, "node.subscription", SocketAddr); + let rpc_url = { + let raw = match matches.value_of("ckb-rpc-url") { + Some(raw) => raw.to_string(), + None => match env::var_os("CKB_RPC_URL") { + Some(raw) => raw.to_string_lossy().to_string(), + None => { + panic!("Miss CKB Rpc url via neither --ckb-rpc-url nor environment variable \"CKB_RPC_URL\""); + } + }, + }; + let _ = url::Url::parse(&raw) + .map_err(|err| panic!("Invalid CKB RPC url, url: \"{}\", error: {:?}", raw, err)); + raw + }; + let subscription_addr = { + let raw = match matches.value_of("ckb-subscription-addr") { + Some(raw) => raw.to_string(), + None => match env::var_os("CKB_SUBSCRIPTION_ADDR") { + Some(raw) => raw.to_string_lossy().to_string(), + None => { + panic!("Miss CKB subscription addr via neither --ckb-subscription-addr nor environment variable \"CKB_SUBSCRIPTION_ADDR\""); + } + }, + }; + raw.parse::().unwrap_or_else(|err| { + panic!( + "Invalid CKB subscription addr, addr: \"{}\", error: {:?}", + raw, err + ) + }) + }; let topics = values_t_or_exit!(matches, "topics", String); - log::info!("CKB Node RPC: \"{}\"", rpc_url); + log::info!("CKB CKB RPC: \"{}\"", rpc_url); log::info!("CKB Node Subscription: \"{}\"", subscription_addr); log::info!("Topics: {:?}", topics); @@ -317,28 +346,18 @@ pub fn clap_app() -> App<'static, 'static> { }), ) .arg( - Arg::with_name("node.rpc") - .long("node.rpc") + Arg::with_name("ckb-rpc-url") + .long("ckb-rpc-url") .value_name("URL") - .required(true) - .takes_value(true) - .validator(|s| { - url::Url::parse(&s) - .map(|_| ()) - .map_err(|err| err.to_string()) - }), + .required(false) + .takes_value(true), ) .arg( - Arg::with_name("node.subscription") - .long("node.subscription") - .value_name("HOSTPORT") - .required(true) - .takes_value(true) - .validator(|s| { - s.parse::() - .map(|_| ()) - .map_err(|err| err.to_string()) - }), + Arg::with_name("ckb-subscription-addr") + .long("ckb-subscription-addr") + .value_name("HOST:PORT") + .required(false) + .takes_value(true), ) .arg( Arg::with_name("topics")