10
10
11
11
12
12
def read_env ():
13
- can_apply_for_validators = os .environ .get ('CAN_ADD_VALIDATORS' , True ).lower () in ('true' , '1' , 't' )
14
- can_apply_for_bonds = os .environ .get ('CAN_ADD_BONDS' , True ).lower () in ('true' , '1' , 't' )
15
- can_apply_for_accounts = os .environ .get ('CAN_ADD_ACCOUNTS' , True ).lower () in ('true' , '1' , 't' )
13
+ can_apply_for_validators = os .environ .get ('CAN_ADD_VALIDATORS' , 'true' ).lower () in ('true' , '1' , 't' )
14
+ can_apply_for_bonds = os .environ .get ('CAN_ADD_BONDS' , 'true' ).lower () in ('true' , '1' , 't' )
15
+ can_apply_for_accounts = os .environ .get ('CAN_ADD_ACCOUNTS' , 'true' ).lower () in ('true' , '1' , 't' )
16
16
17
17
print ("Can add validators: {}" .format (can_apply_for_validators ))
18
18
print ("Can add bonds: {}" .format (can_apply_for_bonds ))
@@ -188,35 +188,41 @@ def check_if_bond_is_valid(bonds_toml: List[Dict], balances: Dict[str, Dict]):
188
188
return True
189
189
190
190
191
- def validate_toml (file , can_apply_for_validators , can_apply_for_bonds , can_apply_for_accounts ):
191
+ def validate_toml (file , can_apply_for_validators , can_apply_for_bonds , can_apply_for_accounts ) -> bool :
192
192
balances = toml .load (open ("genesis/balances.toml" , "r" ))
193
193
nam_balances = balances ['token' ]['NAM' ]
194
194
195
195
if '-account.toml' in file and can_apply_for_accounts :
196
196
accounts_toml = read_unsafe_toml (file )
197
197
if accounts_toml is None :
198
198
print ("{} is NOT valid." .format (file ))
199
+ return False
199
200
is_valid = check_if_account_is_valid (accounts_toml )
200
201
if not is_valid :
201
202
print ("{} is NOT valid." .format (file ))
203
+ return False
202
204
elif '-validator.toml' in file and can_apply_for_validators :
203
205
validators_toml = read_unsafe_toml (file )
204
206
if validators_toml is None :
205
207
print ("{} is NOT valid." .format (file ))
208
+ return False
206
209
is_valid = check_if_validator_is_valid (validators_toml )
207
210
if not is_valid :
208
211
print ("{} is NOT valid." .format (file ))
212
+ return False
209
213
elif '-bond.toml' in file and can_apply_for_bonds :
210
214
bonds_toml = read_unsafe_toml (file )
211
215
if not bonds_toml :
212
216
print ("{} is NOT valid." .format (file ))
217
+ return False
213
218
is_valid = check_if_bond_is_valid (bonds_toml , nam_balances )
214
219
if not is_valid :
215
220
print ("{} is NOT valid." .format (file ))
221
+ return False
216
222
else :
217
223
return False
218
-
219
- print ( "{} is valid." . format ( file ))
224
+
225
+ return True
220
226
221
227
def main ():
222
228
alias = get_alias_from_env ()
@@ -236,11 +242,17 @@ def main():
236
242
237
243
file_alias = get_alias_from_file (file )
238
244
if not alias .lower () in file_alias .lower ():
245
+ print ("alias {} doesn't correspond" .format (alias .lower ()))
239
246
exit (1 )
240
247
241
248
print ("{} is allowed, checking if its valid..." .format (file ))
242
249
243
- validate_toml (file , can_apply_for_validators , can_apply_for_bonds , can_apply_for_accounts )
250
+ res = validate_toml (file , can_apply_for_validators , can_apply_for_bonds , can_apply_for_accounts )
251
+ if res :
252
+ print ("{} is valid." .format (file ))
253
+ else :
254
+ print ("{} is NOT valid" .format (file ))
255
+ exit (1 )
244
256
245
257
246
258
if __name__ == "__main__" :
0 commit comments