@@ -5,7 +5,7 @@ use crate::topic::{
5
5
} ;
6
6
use crate :: util:: crossbeam_channel_to_tokio_channel;
7
7
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 } ;
9
9
use std:: env;
10
10
use std:: net:: SocketAddr ;
11
11
use std:: path:: PathBuf ;
@@ -25,10 +25,39 @@ async fn main() {
25
25
log:: info!( "CKBAnalyzer starting" ) ;
26
26
27
27
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
+ } ;
30
59
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) ;
32
61
log:: info!( "CKB Node Subscription: \" {}\" " , subscription_addr) ;
33
62
log:: info!( "Topics: {:?}" , topics) ;
34
63
@@ -317,28 +346,18 @@ pub fn clap_app() -> App<'static, 'static> {
317
346
} ) ,
318
347
)
319
348
. arg (
320
- Arg :: with_name ( "node. rpc" )
321
- . long ( "node. rpc" )
349
+ Arg :: with_name ( "ckb- rpc-url " )
350
+ . long ( "ckb- rpc-url " )
322
351
. 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 ) ,
330
354
)
331
355
. 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 ) ,
342
361
)
343
362
. arg (
344
363
Arg :: with_name ( "topics" )
0 commit comments