Skip to content

Commit 5bb21ba

Browse files
committed
add validator mode
1 parent 62cfb02 commit 5bb21ba

File tree

4 files changed

+75
-58
lines changed

4 files changed

+75
-58
lines changed

mytoncore/functions.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ def Elections(local, ton):
8282
use_pool = ton.using_pool()
8383
if use_pool:
8484
ton.PoolsUpdateValidatorSet()
85-
ton.RecoverStake()
85+
ton.RecoverStake()
86+
if ton.using_validator():
8687
ton.ElectionEntry()
87-
else:
88-
ton.RecoverStake()
89-
ton.ElectionEntry()
90-
# end define
9188

9289

9390
def Statistics(local):
@@ -516,10 +513,10 @@ def Complaints(local, ton):
516513

517514

518515
def Slashing(local, ton):
519-
isSlashing = local.db.get("isSlashing")
520-
if isSlashing is not True:
516+
is_slashing = local.db.get("isSlashing")
517+
is_validator = ton.using_validator()
518+
if is_slashing is not True or is_validator:
521519
return
522-
# end if
523520

524521
# Creating complaints
525522
slash_time = local.buffer.slash_time

mytoncore/mytoncore.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ def ProcessRecoverStake(self):
12931293
def GetStake(self, account, args=None):
12941294
stake = self.local.db.get("stake")
12951295
usePool = self.using_pool()
1296-
useController = self.local.db.get("useController")
1296+
useController = self.local.db.get("useController") or self.using_liquid_staking()
12971297
stakePercent = self.local.db.get("stakePercent", 99)
12981298
vconfig = self.GetValidatorConfig()
12991299
validators = vconfig.get("validators")
@@ -1372,7 +1372,7 @@ def GetValidatorWallet(self, mode="stake"):
13721372

13731373
def ElectionEntry(self, args=None):
13741374
usePool = self.using_pool()
1375-
useController = self.local.db.get("useController")
1375+
useController = self.local.db.get("useController") or self.using_liquid_staking()
13761376
wallet = self.GetValidatorWallet()
13771377
addrB64 = wallet.addrB64
13781378
if wallet is None:
@@ -3203,8 +3203,17 @@ def using_nominator_pool(self):
32033203
return (self.local.db.get("usePool") or # for backward compatibility
32043204
self.get_mode_value('nominator-pool'))
32053205

3206+
def using_single_nominator(self):
3207+
return self.get_mode_value('single-nominator')
3208+
3209+
def using_liquid_staking(self):
3210+
return self.get_mode_value('liquid-staking')
3211+
32063212
def using_pool(self) -> bool:
3207-
return self.using_nominator_pool() or self.get_mode_value('single-nominator')
3213+
return self.using_nominator_pool() or self.using_single_nominator()
3214+
3215+
def using_validator(self):
3216+
return self.get_mode_value('validator')
32083217

32093218
def Tlb2Json(self, text):
32103219
# Заменить скобки

mytonctrl/modules/validator.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from mypylib.mypylib import color_print
2+
from mytonctrl.modules.module import MtcModule
3+
4+
from mytoncore.functions import Elections
5+
6+
7+
class ValidatorModule(MtcModule):
8+
9+
def vote_offer(self, args):
10+
if len(args) == 0:
11+
color_print("{red}Bad args. Usage:{endc} vo <offer-hash>")
12+
return
13+
for offerHash in args:
14+
self.ton.VoteOffer(offerHash)
15+
color_print("VoteOffer - {green}OK{endc}")
16+
17+
def vote_election_entry(self, args):
18+
Elections(self.ton.local, self.ton)
19+
color_print("VoteElectionEntry - {green}OK{endc}")
20+
21+
def vote_complaint(self, args):
22+
try:
23+
election_id = args[0]
24+
complaint_hash = args[1]
25+
except:
26+
color_print("{red}Bad args. Usage:{endc} vc <election-id> <complaint-hash>")
27+
return
28+
self.ton.VoteComplaint(election_id, complaint_hash)
29+
color_print("VoteComplaint - {green}OK{endc}")
30+
31+
def add_console_commands(self, console):
32+
console.AddItem("vo", self.vote_offer, self.local.translate("vo_cmd"))
33+
console.AddItem("ve", self.vote_election_entry, self.local.translate("ve_cmd"))
34+
console.AddItem("vc", self.vote_complaint, self.local.translate("vc_cmd"))

mytonctrl/mytonctrl.py

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ def inject_globals(func):
7474
console.AddItem("status_modes", inject_globals(mode_status), local.translate("status_modes_cmd"))
7575
console.AddItem("enable_mode", inject_globals(enable_mode), local.translate("enable_mode_cmd"))
7676
console.AddItem("disable_mode", inject_globals(disable_mode), local.translate("disable_mode_cmd"))
77+
console.AddItem("get", inject_globals(GetSettings), local.translate("get_cmd"))
78+
console.AddItem("set", inject_globals(SetSettings), local.translate("set_cmd"))
79+
7780
console.AddItem("seqno", inject_globals(Seqno), local.translate("seqno_cmd"))
7881
console.AddItem("getconfig", inject_globals(GetConfig), local.translate("getconfig_cmd"))
82+
console.AddItem("get_pool_data", inject_globals(GetPoolData), local.translate("get_pool_data_cmd"))
7983

8084
console.AddItem("nw", inject_globals(CreatNewWallet), local.translate("nw_cmd"))
8185
console.AddItem("aw", inject_globals(ActivateWallet), local.translate("aw_cmd"))
@@ -105,44 +109,42 @@ def inject_globals(func):
105109
# console.AddItem("gdfa", inject_globals(GetDomainFromAuction), local.translate("gdfa_cmd"))
106110

107111
console.AddItem("ol", inject_globals(PrintOffersList), local.translate("ol_cmd"))
108-
console.AddItem("vo", inject_globals(VoteOffer), local.translate("vo_cmd"))
109112
console.AddItem("od", inject_globals(OfferDiff), local.translate("od_cmd"))
110113

111114
console.AddItem("el", inject_globals(PrintElectionEntriesList), local.translate("el_cmd"))
112-
console.AddItem("ve", inject_globals(VoteElectionEntry), local.translate("ve_cmd"))
113115
console.AddItem("vl", inject_globals(PrintValidatorList), local.translate("vl_cmd"))
114116
console.AddItem("cl", inject_globals(PrintComplaintsList), local.translate("cl_cmd"))
115-
console.AddItem("vc", inject_globals(VoteComplaint), local.translate("vc_cmd"))
116117

117-
console.AddItem("get", inject_globals(GetSettings), local.translate("get_cmd"))
118-
console.AddItem("set", inject_globals(SetSettings), local.translate("set_cmd"))
119118
#console.AddItem("xrestart", inject_globals(Xrestart), local.translate("xrestart_cmd"))
120119
#console.AddItem("xlist", inject_globals(Xlist), local.translate("xlist_cmd"))
121120
#console.AddItem("gpk", inject_globals(GetPubKey), local.translate("gpk_cmd"))
122121
#console.AddItem("ssoc", inject_globals(SignShardOverlayCert), local.translate("ssoc_cmd"))
123122
#console.AddItem("isoc", inject_globals(ImportShardOverlayCert), local.translate("isoc_cmd"))
124123

125-
console.AddItem("get_pool_data", inject_globals(GetPoolData), local.translate("get_pool_data_cmd"))
126-
127-
if ton.using_pool():
128-
from mytonctrl.modules.pool import PoolModule
129-
module = PoolModule(ton, local)
124+
if ton.get_mode_value('validator'):
125+
from mytonctrl.modules.validator import ValidatorModule
126+
module = ValidatorModule(ton, local)
130127
module.add_console_commands(console)
131128

132-
if ton.using_nominator_pool():
133-
from mytonctrl.modules.nominator_pool import NominatorPoolModule
134-
module = NominatorPoolModule(ton, local)
135-
module.add_console_commands(console)
129+
if ton.using_pool(): # add basic pool functions (pools_list, delete_pool, import_pool)
130+
from mytonctrl.modules.pool import PoolModule
131+
module = PoolModule(ton, local)
132+
module.add_console_commands(console)
136133

137-
if ton.get_mode_value('single-nominator'):
138-
from mytonctrl.modules.single_pool import SingleNominatorModule
139-
module = SingleNominatorModule(ton, local)
140-
module.add_console_commands(console)
134+
if ton.using_nominator_pool():
135+
from mytonctrl.modules.nominator_pool import NominatorPoolModule
136+
module = NominatorPoolModule(ton, local)
137+
module.add_console_commands(console)
141138

142-
if ton.get_mode_value('liquid-staking'):
143-
from mytonctrl.modules.controller import ControllerModule
144-
module = ControllerModule(ton, local)
145-
module.add_console_commands(console)
139+
if ton.get_mode_value('single-nominator'):
140+
from mytonctrl.modules.single_pool import SingleNominatorModule
141+
module = SingleNominatorModule(ton, local)
142+
module.add_console_commands(console)
143+
144+
if ton.using_liquid_staking():
145+
from mytonctrl.modules.controller import ControllerModule
146+
module = ControllerModule(ton, local)
147+
module.add_console_commands(console)
146148

147149
console.AddItem("cleanup", inject_globals(cleanup_validator_db), local.translate("cleanup_cmd"))
148150
console.AddItem("benchmark", inject_globals(run_benchmark), local.translate("benchmark_cmd"))
@@ -1000,15 +1002,6 @@ def PrintOffersList(ton, args):
10001002
print_table(table)
10011003
#end define
10021004

1003-
def VoteOffer(ton, args):
1004-
if len(args) == 0:
1005-
color_print("{red}Bad args. Usage:{endc} vo <offer-hash>")
1006-
return
1007-
for offerHash in args:
1008-
ton.VoteOffer(offerHash)
1009-
color_print("VoteOffer - {green}OK{endc}")
1010-
#end define
1011-
10121005
def OfferDiff(ton, args):
10131006
try:
10141007
offerHash = args[0]
@@ -1063,17 +1056,6 @@ def PrintComplaintsList(ton, args):
10631056
print_table(table)
10641057
#end define
10651058

1066-
def VoteComplaint(ton, args):
1067-
try:
1068-
electionId = args[0]
1069-
complaintHash = args[1]
1070-
except:
1071-
color_print("{red}Bad args. Usage:{endc} vc <election-id> <complaint-hash>")
1072-
return
1073-
ton.VoteComplaint(electionId, complaintHash)
1074-
color_print("VoteComplaint - {green}OK{endc}")
1075-
#end define
1076-
10771059
def NewDomain(ton, args):
10781060
try:
10791061
domainName = args[0]
@@ -1172,11 +1154,6 @@ def PrintElectionEntriesList(ton, args):
11721154
print_table(table)
11731155
#end define
11741156

1175-
def VoteElectionEntry(ton, args):
1176-
Elections(ton.local, ton)
1177-
color_print("VoteElectionEntry - {green}OK{endc}")
1178-
#end define
1179-
11801157
def PrintValidatorList(ton, args):
11811158
past = "past" in args
11821159
data = ton.GetValidatorsList(past=past)

0 commit comments

Comments
 (0)