@@ -25,7 +25,7 @@ def custom_graph(
2525 fork_obs_query_interval : int ,
2626 caddy : bool ,
2727 logging : bool ,
28- force_pull : bool
28+ force_pull : bool ,
2929):
3030 try :
3131 datadir .mkdir (parents = False , exist_ok = False )
@@ -98,119 +98,90 @@ def custom_graph(
9898
9999def inquirer_create_network (project_path : Path ):
100100 # Custom network configuration
101- questions = [
102- inquirer .Text (
103- "network_name" ,
104- message = click .style ("Enter your network name" , fg = "blue" , bold = True ),
105- validate = lambda _ , x : len (x ) > 0 ,
106- ),
107- inquirer .List (
108- "nodes" ,
109- message = click .style ("How many nodes would you like?" , fg = "blue" , bold = True ),
110- choices = ["8" , "12" , "20" , "50" , "other" ],
111- default = "12" ,
112- ),
113- inquirer .List (
114- "connections" ,
115- message = click .style (
116- "How many connections would you like each node to have?" ,
117- fg = "blue" ,
118- bold = True ,
119- ),
120- choices = ["0" , "1" , "2" , "8" , "12" , "other" ],
121- default = "8" ,
101+ network_name = inquirer .text (
102+ message = click .style ("Enter your network name" , fg = "blue" , bold = True ),
103+ validate = lambda _ , x : len (x ) > 0 ,
104+ )
105+ nodes = inquirer .list_input (
106+ message = click .style ("How many nodes would you like?" , fg = "blue" , bold = True ),
107+ choices = ["8" , "12" , "20" , "50" , "other" ],
108+ default = "12" ,
109+ )
110+ if nodes == "other" :
111+ nodes = inquirer .text (
112+ message = click .style ("Enter the number of nodes" , fg = "blue" , bold = True ),
113+ validate = lambda _ , x : int (x ) > 0 ,
114+ )
115+ connections = inquirer .list_input (
116+ message = click .style (
117+ "How many connections would you like each node to have?" ,
118+ fg = "blue" ,
119+ bold = True ,
122120 ),
123- inquirer .List (
124- "version" ,
125- message = click .style (
126- "Which version would you like nodes to run by default?" , fg = "blue" , bold = True
127- ),
128- choices = SUPPORTED_TAGS ,
129- default = DEFAULT_TAG ,
121+ choices = ["0" , "1" , "2" , "8" , "12" , "other" ],
122+ default = "8" ,
123+ )
124+ if connections == "other" :
125+ connections = inquirer .text (
126+ message = click .style ("Enter the number of connections" , fg = "blue" , bold = True ),
127+ validate = lambda _ , x : int (x ) >= 0 ,
128+ )
129+ version = inquirer .list_input (
130+ message = click .style (
131+ "Which version would you like nodes to run by default?" , fg = "blue" , bold = True
130132 ),
131-
132- inquirer .Confirm (
133- "force_pull" ,
134- message = click .style (
135- "Would you like to force-pull bitcoin node images from dockerhub?" , fg = "blue" , bold = True
136- ),
137- default = False ,
133+ choices = SUPPORTED_TAGS ,
134+ default = DEFAULT_TAG ,
135+ )
136+ force_pull = inquirer .confirm (
137+ message = click .style (
138+ "Would you like to force-pull bitcoin node images from dockerhub?" , fg = "blue" , bold = True
138139 ),
139- ]
140-
141- net_answers = inquirer .prompt (questions )
142- if net_answers is None :
143- click .secho ("Setup cancelled by user." , fg = "yellow" )
144- return False
140+ default = False ,
141+ )
145142
146- if net_answers ["nodes" ] == "other" :
147- custom_nodes = inquirer .prompt (
148- [
149- inquirer .Text (
150- "nodes" ,
151- message = click .style ("Enter the number of nodes" , fg = "blue" , bold = True ),
152- validate = lambda _ , x : int (x ) > 0 ,
153- )
154- ]
155- )
156- if custom_nodes is None :
157- click .secho ("Setup cancelled by user." , fg = "yellow" )
158- return False
159- net_answers ["nodes" ] = custom_nodes ["nodes" ]
160-
161- if net_answers ["connections" ] == "other" :
162- custom_connections = inquirer .prompt (
163- [
164- inquirer .Text (
165- "connections" ,
166- message = click .style ("Enter the number of connections" , fg = "blue" , bold = True ),
167- validate = lambda _ , x : int (x ) >= 0 ,
168- )
169- ]
170- )
171- if custom_connections is None :
172- click .secho ("Setup cancelled by user." , fg = "yellow" )
173- return False
174- net_answers ["connections" ] = custom_connections ["connections" ]
175- fork_observer = click .prompt (
176- click .style (
177- "\n Would you like to enable fork-observer on the network?" , fg = "blue" , bold = True
143+ # Inquire about fork observer
144+ fork_observer = inquirer .confirm (
145+ message = click .style (
146+ "Would you like to enable fork-observer on the network?" , fg = "blue" , bold = True
178147 ),
179- type = bool ,
180148 default = True ,
181149 )
182150 fork_observer_query_interval = 20
183151 if fork_observer :
184- fork_observer_query_interval = click .prompt (
185- click .style (
186- "\n How often would you like fork-observer to query node status (seconds)?" ,
187- fg = "blue" ,
188- bold = True ,
189- ),
190- type = int ,
191- default = 20 ,
152+ fork_observer_query_interval = int (
153+ inquirer .text (
154+ message = click .style (
155+ "How often would you like fork-observer to query node status (seconds)?" ,
156+ fg = "blue" ,
157+ bold = True ,
158+ ),
159+ validate = lambda _ , x : int (x ) > 0 ,
160+ default = fork_observer_query_interval ,
161+ )
192162 )
193163
194- logging = click .prompt (
195- click .style (
196- "\n Would you like to enable grafana logging on the network?" , fg = "blue" , bold = True
164+ # Inquire about logging
165+ logging = inquirer .confirm (
166+ message = click .style (
167+ "Would you like to enable grafana logging on the network?" , fg = "blue" , bold = True
197168 ),
198- type = bool ,
199169 default = False ,
200170 )
171+
201172 caddy = fork_observer | logging
202- custom_network_path = project_path / "networks" / net_answers [ " network_name" ]
173+ custom_network_path = project_path / "networks" / network_name
203174 click .secho ("\n Generating custom network..." , fg = "yellow" , bold = True )
204175 custom_graph (
205- int (net_answers [ " nodes" ] ),
206- int (net_answers [ " connections" ] ),
207- net_answers [ " version" ] ,
176+ int (nodes ),
177+ int (connections ),
178+ version ,
208179 custom_network_path ,
209180 fork_observer ,
210181 fork_observer_query_interval ,
211182 caddy ,
212183 logging ,
213- net_answers [ " force_pull" ] ,
184+ force_pull ,
214185 )
215186 return custom_network_path
216187
0 commit comments