11from modules .module import MtcModule
22from mypylib import color_print , print_table
33from mytoncore import b642hex , signed_int_to_hex64 , shard_prefix_len , hex_shard_to_int , shard_prefix , shard_is_ancestor
4+ from mytonctrl .console_cmd import check_usage_args_min_len , add_command , check_usage_no_args , check_usage_args_lens
45from mytonctrl .utils import pop_arg_from_args
56
67
@@ -44,9 +45,7 @@ def _check_input_shards(node_shards: list, shards_need_to_add: list, monitor_min
4445 def setup_collator (self , args : list ):
4546 from mytoninstaller .mytoninstaller import set_node_argument
4647 from mytoninstaller .node_args import get_node_args
47-
48- if not args :
49- color_print ("{red}Bad args. Usage:{endc} setup_collator [--force] [--adnl <ADNL address>] <shard1> [shard2] ..." )
48+ if not check_usage_args_min_len ("setup_collator" , args , 1 ):
5049 return
5150 force = '--force' in args
5251 args .remove ('--force' ) if '--force' in args else None
@@ -81,6 +80,8 @@ def setup_collator(self, args: list):
8180 color_print ("setup_collator - {green}OK{endc}" )
8281
8382 def stop_collator (self , args : list ):
83+ if not check_usage_args_lens ("stop_collator" , args , [0 , 2 ]):
84+ return
8485 if not args :
8586 text = f"{{red}}WARNING: This action will stop and delete all local collation broadcasts from this node for all shards.{{endc}}\n "
8687 color_print (text )
@@ -104,17 +105,12 @@ def stop_collator(self, args: list):
104105 color_print ("stop_collator - {green}OK{endc}" )
105106 return
106107
107- if len (args ) == 2 :
108- adnl_addr , shard_str = args
109- if ':' not in shard_str :
110- color_print ("{red}Bad args. Usage:{endc} stop_collator <adnl_id> <workchain>:<shard_hex>" )
111- return
112- shard_id = hex_shard_to_int (shard_str )
113- workchain = int (shard_id ['workchain' ])
114- shard_int = int (shard_id ['shard' ])
115- else :
116- color_print ("{red}Bad args. Usage:{endc} stop_collator <adnl_id> <workchain>:<shard_hex>" )
117- return
108+ adnl_addr , shard_str = args
109+ if ':' not in shard_str :
110+ raise Exception (f"Invalid shard: { shard_str } , use format <workchain>:<shard_hex>" )
111+ shard_id = hex_shard_to_int (shard_str )
112+ workchain = int (shard_id ['workchain' ])
113+ shard_int = int (shard_id ['shard' ])
118114
119115 res = self .ton .validatorConsole .Run (f"del-collator { adnl_addr } { workchain } { shard_int } " )
120116 if 'successfully removed collator' not in res .lower ():
@@ -136,8 +132,7 @@ def print_collators(self, args: list = None):
136132 print_table (table )
137133
138134 def add_validator_to_collation_wl (self , args : list ):
139- if len (args ) < 1 :
140- color_print ("{red}Bad args. Usage:{endc} add_validator_to_collation_wl <adnl> [adnl2] [adnl3] ..." )
135+ if not check_usage_args_min_len ("add_validator_to_collation_wl" , args , 1 ):
141136 return
142137 self .ton .validatorConsole .Run (f"collator-whitelist-enable 1" )
143138 self .local .add_log ("Collation whitelist enabled" )
@@ -148,8 +143,7 @@ def add_validator_to_collation_wl(self, args: list):
148143 color_print ("add_validator_to_collation_wl - {green}OK{endc}" )
149144
150145 def delete_validator_from_collation_wl (self , args : list ):
151- if len (args ) < 1 :
152- color_print ("{red}Bad args. Usage:{endc} delete_validator_from_collation_wl <adnl> [adnl2] [adnl3] ..." )
146+ if not check_usage_args_min_len ("delete_validator_from_collation_wl" , args , 1 ):
153147 return
154148 for adnl_addr in args :
155149 result = self .ton .validatorConsole .Run (f"collator-whitelist-del { adnl_addr } " )
@@ -158,8 +152,7 @@ def delete_validator_from_collation_wl(self, args: list):
158152 color_print ("delete_validator_from_collation_wl - {green}OK{endc}" )
159153
160154 def disable_collation_validator_wl (self , args : list ):
161- if len (args ) != 0 :
162- color_print ("{red}Bad args. Usage:{endc} disable_collation_validator_wl" )
155+ if not check_usage_no_args ("disable_collation_wl" , args ):
163156 return
164157 result = self .ton .validatorConsole .Run (f"collator-whitelist-enable 0" )
165158 if 'success' not in result :
@@ -186,10 +179,10 @@ def check_disable(self):
186179
187180
188181 def add_console_commands (self , console ):
189- console . AddItem ( "setup_collator" , self .setup_collator , self . local . translate ( "setup_collator_cmd" ) )
190- console . AddItem ( "print_local_collators" , self .print_collators , self . local . translate ( "print_local_collators_cmd" ) )
191- console . AddItem ( "add_validator_to_collation_wl" , self .add_validator_to_collation_wl , self . local . translate ( "add_validator_to_collation_wl_cmd" ) )
192- console . AddItem ( "delete_validator_from_collation_wl" , self .delete_validator_from_collation_wl , self . local . translate ( "delete_validator_from_collation_wl_cmd" ) )
193- console . AddItem ( "disable_collation_wl" , self .disable_collation_validator_wl , self . local . translate ( "disable_collation_validator_wl_cmd" ) )
194- console . AddItem ( "print_collation_whitelist" , self .print_collation_validators_whitelist , self . local . translate ( "print_collation_validators_whitelist_cmd" ) )
195- console . AddItem ( "stop_collator" , self .stop_collator , self . local . translate ( "stop_collator_cmd" ) )
182+ add_command ( self . local , console , "setup_collator" , self .setup_collator )
183+ add_command ( self . local , console , "print_local_collators" , self .print_collators )
184+ add_command ( self . local , console , "add_validator_to_collation_wl" , self .add_validator_to_collation_wl )
185+ add_command ( self . local , console , "delete_validator_from_collation_wl" , self .delete_validator_from_collation_wl )
186+ add_command ( self . local , console , "disable_collation_wl" , self .disable_collation_validator_wl )
187+ add_command ( self . local , console , "print_collation_whitelist" , self .print_collation_validators_whitelist )
188+ add_command ( self . local , console , "stop_collator" , self .stop_collator )
0 commit comments