Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Jan 30, 2022
1 parent 9b9ea74 commit 5d180e3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
9 changes: 0 additions & 9 deletions docker/.env.example

This file was deleted.

12 changes: 4 additions & 8 deletions docker/collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
65 changes: 42 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<SocketAddr>().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);

Expand Down Expand Up @@ -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::<SocketAddr>()
.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")
Expand Down

0 comments on commit 5d180e3

Please sign in to comment.