Skip to content

Commit 86a8c70

Browse files
committed
add default values directly to modules
1 parent 597dcba commit 86a8c70

File tree

10 files changed

+43
-17
lines changed

10 files changed

+43
-17
lines changed

modules/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import typing
2+
3+
from .module import MtcModule
4+
from .pool import PoolModule
5+
from .nominator_pool import NominatorPoolModule
6+
from .single_pool import SingleNominatorModule
7+
from .validator import ValidatorModule
8+
from .controller import ControllerModule
9+
10+
11+
MODES = {
12+
'validator': ValidatorModule,
13+
'nominator-pool': NominatorPoolModule,
14+
'single-nominator': SingleNominatorModule,
15+
'liquid-staking': ControllerModule,
16+
}
17+
18+
19+
def get_mode(mode_name: str) -> typing.Optional[MtcModule]:
20+
return MODES.get(mode_name)

modules/controller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class ControllerModule(MtcModule):
1212

1313
description = 'Liquid staking controllers.'
14+
default_value = False
1415

1516
def do_create_controllers(self):
1617
new_controllers = self.ton.GetControllers()

modules/module.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from abc import ABC, abstractmethod
2-
from mytoncore.mytoncore import MyTonCore
32

43

54
class MtcModule(ABC):
65

7-
description = ''
6+
description = '' # module text description
7+
default_value = True # is module enabled by default
88

99
def __init__(self, ton, local, *args, **kwargs):
10+
from mytoncore.mytoncore import MyTonCore
1011
self.ton: MyTonCore = ton
1112
self.local = local
1213

modules/nominator_pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class NominatorPoolModule(PoolModule):
99

1010
description = 'Standard nominator pools.'
11+
default_value = False
1112

1213
def do_create_pool(self, pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake,
1314
min_nominator_stake):

modules/pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class PoolModule(MtcModule):
88

99
description = 'Basic pools functions.'
10+
default_value = False
1011

1112
def print_pools_list(self, args):
1213
table = list()

modules/single_pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class SingleNominatorModule(PoolModule):
1010

1111
description = 'Orbs\'s single nominator pools.'
12+
default_value = False
1213

1314
def do_create_single_pool(self, pool_name, owner_address):
1415
self.ton.local.add_log("start create_single_pool function", "debug")

modules/validator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class ValidatorModule(MtcModule):
99
description = ('Validator functions. Activates participating in elections and staking. '
1010
'If pools and l/s modes are disabled stakes from validator wallet.')
1111

12+
default_value = True
13+
1214
def vote_offer(self, args):
1315
if len(args) == 0:
1416
color_print("{red}Bad args. Usage:{endc} vo <offer-hash>")

mytoncore/modes.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

mytoncore/mytoncore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import requests
1212
from fastcrc import crc16
1313

14-
from mytoncore.modes import MODES
14+
from modules import MODES
1515
from mytoncore.utils import xhex2hex, ng2g
1616
from mytoncore.liteclient import LiteClient
1717
from mytoncore.validator_console import ValidatorConsole
@@ -3172,9 +3172,9 @@ def get_modes(self):
31723172
if 'modes' not in self.local.db:
31733173
self.local.db['modes'] = current_modes
31743174
self.migrate_to_modes()
3175-
for mode in MODES:
3176-
if mode not in current_modes:
3177-
current_modes[mode] = MODES[mode] # assign default mode value
3175+
for name, mode in MODES.items():
3176+
if name not in current_modes:
3177+
current_modes[name] = mode.default_value # assign default mode value
31783178
return current_modes
31793179

31803180
def enable_mode(self, name):

mytonctrl/mytonctrl.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,18 @@ def sl(ton, args):
424424
Slashing(ton.local, ton)
425425
#end define
426426

427+
427428
def mode_status(ton, args):
429+
from modules import get_mode
428430
modes = ton.get_modes()
429-
text = "########## {bold}Modes{endc} ########## \n"
430-
for mode in modes:
431-
status = '{green}enabled{endc}' if modes[mode] else '{red}disabled{endc}'
432-
text += f"{mode}: {status}\n"
433-
color_print(text)
431+
table = [["Name", "Status", "Description"]]
432+
for mode_name in modes:
433+
mode = get_mode(mode_name)
434+
status = color_text('{green}enabled{endc}' if modes[mode_name] else '{red}disabled{endc}')
435+
table.append([mode_name, status, mode.description])
436+
print_table(table)
437+
#end define
438+
434439

435440
def PrintStatus(local, ton, args):
436441
opt = None

0 commit comments

Comments
 (0)