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

Commit e05b96e

Browse files
committed
wip
1 parent 9b9ea74 commit e05b96e

File tree

4 files changed

+55
-36
lines changed

4 files changed

+55
-36
lines changed

docker/.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
# Used in https://github.com/timescale/timescaledb-docker
44
POSTGRES_DB=ckb
5-
POSTGRES_USER=ckb
6-
POSTGRES_PASSWORD=ckb
5+
POSTGRES_USER=postgres
6+
POSTGRES_PASSWORD=postgres
7+
8+
# Used in ckb-analyzer
9+
POSTGRES_HOST=host.docker.internal
10+
# POSTGRES_HOST=127.0.0.1
711

812
# Used when render Grafana configuration file
913
GRAFANA_DOMAIN=127.0.0.1

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ubuntu:20.04
33
RUN apt update \
44
&& apt install -y wget
55

6-
RUN wget https://github.com/cryptape/ckb-analyzer/releases/download/v0.1.2/ckb-analyzer-linux-x86_64.tar.gz \
6+
RUN wget https://github.com/cryptape/ckb-analyzer/releases/download/rc-v0.1.3/ckb-analyzer-linux-x86_64.tar.gz \
77
&& tar xzf ckb-analyzer-linux-x86_64.tar.gz \
88
&& mv target/release/ckb-analyzer /bin/ckb-analyzer \
99
&& chmod +x /bin/ckb-analyzer \

docker/collector.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ services:
4141
- ckb-mainnet
4242
command:
4343
- "/bin/ckb-analyzer"
44-
- "--node.rpc"
44+
- "--ckb-rpc-url"
4545
- "http://ckb-mainnet:8114"
46-
- "--node.subscription"
47-
- "127.0.0.1:18114"
48-
- "--topics"
49-
- "ChainCrawler"
46+
- "--ckb-subscription-addr"
47+
- "ckb-mainnet:18114"
5048
extra_hosts:
5149
# use `host.docker.internal` as host DNS name
5250
- "host.docker.internal:host-gateway"
@@ -59,12 +57,10 @@ services:
5957
- ckb-testnet
6058
command:
6159
- "/bin/ckb-analyzer"
62-
- "--node.rpc"
60+
- "--ckb-rpc-url"
6361
- "http://ckb-testnet:8114"
64-
- "--node.subscription"
65-
- "127.0.0.1:18114"
66-
- "--topics"
67-
- "ChainCrawler"
62+
- "--ckb-subscription-addr"
63+
- "ckb-testnet:18114"
6864
extra_hosts:
6965
# use `host.docker.internal` as host DNS name
7066
- "host.docker.internal:host-gateway"

src/main.rs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::topic::{
55
};
66
use crate::util::crossbeam_channel_to_tokio_channel;
77
use ckb_testkit::{connector::SharedState, ConnectorBuilder, Node};
8-
use clap::{crate_version, value_t_or_exit, values_t_or_exit, App, Arg};
8+
use clap::{crate_version, values_t_or_exit, App, Arg};
99
use std::env;
1010
use std::net::SocketAddr;
1111
use std::path::PathBuf;
@@ -25,10 +25,39 @@ async fn main() {
2525
log::info!("CKBAnalyzer starting");
2626

2727
let matches = clap_app().get_matches();
28-
let rpc_url = value_t_or_exit!(matches, "node.rpc", String);
29-
let subscription_addr = value_t_or_exit!(matches, "node.subscription", SocketAddr);
28+
let rpc_url = {
29+
let raw = match matches.value_of("ckb-rpc-url") {
30+
Some(raw) => raw.to_string(),
31+
None => match env::var_os("CKB_RPC_URL") {
32+
Some(raw) => raw.to_string_lossy().to_string(),
33+
None => {
34+
panic!("Miss CKB Rpc url via neither --ckb-rpc-url nor environment variable \"CKB_RPC_URL\"");
35+
}
36+
},
37+
};
38+
let _ = url::Url::parse(&raw)
39+
.map_err(|err| panic!("Invalid CKB RPC url, url: \"{}\", error: {:?}", raw, err));
40+
raw
41+
};
42+
let subscription_addr = {
43+
let raw = match matches.value_of("ckb-subscription-addr") {
44+
Some(raw) => raw.to_string(),
45+
None => match env::var_os("CKB_SUBSCRIPTION_ADDR") {
46+
Some(raw) => raw.to_string_lossy().to_string(),
47+
None => {
48+
panic!("Miss CKB subscription addr via neither --ckb-subscription-addr nor environment variable \"CKB_SUBSCRIPTION_ADDR\"");
49+
}
50+
},
51+
};
52+
raw.parse::<SocketAddr>().unwrap_or_else(|err| {
53+
panic!(
54+
"Invalid CKB subscription addr, addr: \"{}\", error: {:?}",
55+
raw, err
56+
)
57+
})
58+
};
3059
let topics = values_t_or_exit!(matches, "topics", String);
31-
log::info!("CKB Node RPC: \"{}\"", rpc_url);
60+
log::info!("CKB CKB RPC: \"{}\"", rpc_url);
3261
log::info!("CKB Node Subscription: \"{}\"", subscription_addr);
3362
log::info!("Topics: {:?}", topics);
3463

@@ -317,28 +346,18 @@ pub fn clap_app() -> App<'static, 'static> {
317346
}),
318347
)
319348
.arg(
320-
Arg::with_name("node.rpc")
321-
.long("node.rpc")
349+
Arg::with_name("ckb-rpc-url")
350+
.long("ckb-rpc-url")
322351
.value_name("URL")
323-
.required(true)
324-
.takes_value(true)
325-
.validator(|s| {
326-
url::Url::parse(&s)
327-
.map(|_| ())
328-
.map_err(|err| err.to_string())
329-
}),
352+
.required(false)
353+
.takes_value(true),
330354
)
331355
.arg(
332-
Arg::with_name("node.subscription")
333-
.long("node.subscription")
334-
.value_name("HOSTPORT")
335-
.required(true)
336-
.takes_value(true)
337-
.validator(|s| {
338-
s.parse::<SocketAddr>()
339-
.map(|_| ())
340-
.map_err(|err| err.to_string())
341-
}),
356+
Arg::with_name("ckb-subscription-addr")
357+
.long("ckb-subscription-addr")
358+
.value_name("HOST:PORT")
359+
.required(false)
360+
.takes_value(true),
342361
)
343362
.arg(
344363
Arg::with_name("topics")

0 commit comments

Comments
 (0)