@@ -11,8 +11,8 @@ use error_handling::handle_result;
11
11
use job_declarator:: JobDeclarator ;
12
12
use mempool:: error:: JdsMempoolError ;
13
13
use roles_logic_sv2:: { parsers:: AnyMessage as JdsMessages , utils:: Mutex } ;
14
- use std :: { ops :: Sub , sync :: Arc } ;
15
- use stratum_common :: url :: is_valid_url ;
14
+ pub use rpc_sv2 :: Uri ;
15
+ use std :: { ops :: Sub , str :: FromStr , sync :: Arc } ;
16
16
use tokio:: { select, task} ;
17
17
use tracing:: { error, info, warn} ;
18
18
@@ -26,23 +26,25 @@ pub struct JobDeclaratorServer {
26
26
}
27
27
28
28
impl JobDeclaratorServer {
29
- pub fn new ( config : JobDeclaratorServerConfig ) -> Result < Self , Box < JdsError > > {
30
- let url = config. core_rpc_url ( ) . to_string ( ) + ":" + & config. core_rpc_port ( ) . to_string ( ) ;
31
- if !is_valid_url ( & url) {
32
- return Err ( Box :: new ( JdsError :: InvalidRPCUrl ) ) ;
33
- }
34
- Ok ( Self { config } )
29
+ pub fn new ( config : JobDeclaratorServerConfig ) -> Self {
30
+ Self { config }
35
31
}
36
32
pub async fn start ( & self ) -> Result < ( ) , JdsError > {
37
- let config = self . config . clone ( ) ;
33
+ let mut config = self . config . clone ( ) ;
34
+ // In case the url came with a trailing slash, we remove it to make sure we end up with
35
+ // `{scheme}://{host}:{port}` format.
36
+ if config. core_rpc_url ( ) . ends_with ( '/' ) {
37
+ config. set_core_rpc_url ( config. core_rpc_url ( ) . trim_end_matches ( '/' ) . to_string ( ) ) ;
38
+ }
38
39
let url = config. core_rpc_url ( ) . to_string ( ) + ":" + & config. core_rpc_port ( ) . to_string ( ) ;
39
40
let username = config. core_rpc_user ( ) ;
40
41
let password = config. core_rpc_pass ( ) ;
41
42
// TODO should we manage what to do when the limit is reaced?
42
43
let ( new_block_sender, new_block_receiver) : ( Sender < String > , Receiver < String > ) =
43
44
bounded ( 10 ) ;
45
+ let url = Uri :: from_str ( & url. clone ( ) ) . expect ( "Invalid core rpc url" ) ;
44
46
let mempool = Arc :: new ( Mutex :: new ( mempool:: JDsMempool :: new (
45
- url. clone ( ) ,
47
+ url,
46
48
username. to_string ( ) ,
47
49
password. to_string ( ) ,
48
50
new_block_receiver,
@@ -51,7 +53,7 @@ impl JobDeclaratorServer {
51
53
let mempool_cloned_ = mempool. clone ( ) ;
52
54
let mempool_cloned_1 = mempool. clone ( ) ;
53
55
if let Err ( e) = mempool:: JDsMempool :: health ( mempool_cloned_1. clone ( ) ) . await {
54
- error ! ( "{:?}" , e) ;
56
+ error ! ( "JDS Connection with bitcoin core failed {:?}" , e) ;
55
57
return Err ( JdsError :: MempoolError ( e) ) ;
56
58
}
57
59
let ( status_tx, status_rx) = unbounded ( ) ;
0 commit comments