@@ -12,10 +12,10 @@ use crate::{
1212
1313// Important: don't add slashes or anything here
1414// Todo: find better way to do that
15- const MONEROD_DATA : & str = "monerod-data" ;
16- const BITCOIN_DATA : & str = "bitcoin-data" ;
17- const ELECTRS_DATA : & str = "electrs-data" ;
18- const ASB_DATA : & str = "asb-data" ;
15+ pub const MONEROD_DATA : & str = "monerod-data" ;
16+ pub const BITCOIN_DATA : & str = "bitcoin-data" ;
17+ pub const ELECTRS_DATA : & str = "electrs-data" ;
18+ pub const ASB_DATA : & str = "asb-data" ;
1919
2020/// Add all the services/volumes to the compose config
2121#[ allow( unused_variables) ]
@@ -91,19 +91,28 @@ pub fn monerod(
9191 ( monerod_data, monerod_service, monerod_rpc_port)
9292}
9393
94+ pub struct BitcoindConfig {
95+ enabled : bool ,
96+ container_name : String ,
97+ volume_name : String ,
98+ network : bitcoin:: Network ,
99+ p2p_port : u16 ,
100+ rpc_port : u16 ,
101+ }
102+
94103/// Adds the volume/service to the compose config and returns them + the rpc bind port and p2p bind port
95104pub fn bitcoind (
96105 compose : & mut ComposeConfig ,
97- network : bitcoin:: Network ,
98- enabled : bool ,
106+ config : BitcoindConfig ,
99107) -> ( Arc < Volume > , Arc < Service > , u16 , u16 ) {
100- let ( rpc_port , p2p_port , chain) : ( u16 , u16 , & str ) = match network {
101- bitcoin:: Network :: Bitcoin => ( 8332 , 8333 , "main" ) ,
102- bitcoin:: Network :: Testnet => ( 18332 , 18333 , "test" ) ,
108+ let chain = match config . network {
109+ bitcoin:: Network :: Bitcoin => "main" ,
110+ bitcoin:: Network :: Testnet => "test" ,
103111 _ => panic ! ( "unsupported bitcoin network" ) ,
104112 } ;
113+ let ( rpc_port, p2p_port) = ( config. rpc_port , config. p2p_port ) ;
105114
106- let bitcoind_data = compose. add_volume ( BITCOIN_DATA ) ;
115+ let bitcoind_data = compose. add_volume ( config . volume_name ) ;
107116
108117 let bitcoind_command = command ! (
109118 "bitcoind" ,
@@ -119,38 +128,45 @@ pub fn bitcoind(
119128 ) ;
120129
121130 let bitcoind = Service :: new (
122- "bitcoind" ,
131+ config . container_name ,
123132 ImageSource :: from_registry ( images:: BITCOIND_IMAGE ) ,
124133 )
125134 . with_mount ( Mount :: volume ( & bitcoind_data) )
126135 . with_exposed_port ( rpc_port)
127136 . with_exposed_port ( p2p_port)
128137 . with_command ( bitcoind_command)
129- . with_enabled ( enabled) ;
138+ . with_enabled ( config . enabled ) ;
130139
131140 let bitcoind = compose. add_service ( bitcoind) ;
132141
133142 ( bitcoind_data, bitcoind, rpc_port, p2p_port)
134143}
135144
145+ pub struct ElectrsConfig {
146+ enabled : bool ,
147+ container_name : String ,
148+ volume_name : String ,
149+ network : bitcoin:: Network ,
150+ port : u16 ,
151+ }
152+
136153pub fn electrs (
137154 compose : & mut ComposeConfig ,
138- network : bitcoin:: Network ,
139- enabled : bool ,
140155 bitcoind_rpc_port : u16 ,
141156 bitcoind_p2p_port : u16 ,
142157 bitcoind : Arc < Service > ,
143158 bitcoind_data : Arc < Volume > ,
159+ config : ElectrsConfig ,
144160) -> ( Arc < Volume > , Arc < Service > , u16 ) {
145- let ( port, chain) : ( u16 , & str ) = match network {
161+ let ( port, chain) : ( u16 , & str ) = match config . network {
146162 bitcoin:: Network :: Bitcoin => ( 50001 , "bitcoin" ) ,
147163 bitcoin:: Network :: Testnet => ( 50001 , "testnet" ) ,
148164 _ => panic ! ( "unsupported bitcoin network" ) ,
149165 } ;
150166
151167 let bitcoind_name = bitcoind. name ( ) ;
152168
153- let electrs_data = compose. add_volume ( ELECTRS_DATA ) ;
169+ let electrs_data = compose. add_volume ( config . volume_name ) ;
154170 let command = command ! (
155171 "electrs" ,
156172 flag!( "--network={chain}" ) ,
@@ -164,12 +180,15 @@ pub fn electrs(
164180 flag!( "--electrum-rpc-addr=0.0.0.0:{port}" ) ,
165181 flag!( "--log-filters=INFO" ) ,
166182 ) ;
167- let service = Service :: new ( "electrs" , ImageSource :: from_registry ( images:: ELECTRS_IMAGE ) )
168- . with_dependency ( bitcoind. clone ( ) )
169- . with_exposed_port ( port)
170- . with_command ( command)
171- . with_mount ( Mount :: volume ( & electrs_data) )
172- . with_enabled ( enabled) ;
183+ let service = Service :: new (
184+ config. container_name ,
185+ ImageSource :: from_registry ( images:: ELECTRS_IMAGE ) ,
186+ )
187+ . with_dependency ( bitcoind. clone ( ) )
188+ . with_exposed_port ( port)
189+ . with_command ( command)
190+ . with_mount ( Mount :: volume ( & electrs_data) )
191+ . with_enabled ( config. enabled ) ;
173192
174193 let service = compose. add_service ( service) ;
175194
0 commit comments