1111class BtcTeleportModule (MtcModule ):
1212
1313 COORDINATOR_ADDRESS = 'EQD43RtdAQ_Y8nl86SqzxjlL_-rAvdZiBDk_s7OTF-oRxmwo'
14- CONFIGURATOR_ADDRESS = 'kQBV_cc8tD2lr2oogPOp1VCyP5m1xzdAZ77H3oM_Tix60dPP '
14+ CONFIGURATOR_ADDRESS = 'EQCPL1AFRXtvqIxaYK05EzSCnz5QQRb6UGXp6PAJurFeVQYC '
1515
1616 def __init__ (self , ton , local , * args , ** kwargs ):
1717 super ().__init__ (ton , local , * args , ** kwargs )
@@ -82,21 +82,44 @@ def run_remove_btc_teleport(args):
8282 script_path = pkg_resources .resource_filename ('mytonctrl' , 'scripts/remove_btc_teleport.sh' )
8383 return run_as_root (["bash" , script_path ] + args )
8484
85- def get_offers_btc_teleport (self ):
85+ def get_save_offers (self ):
86+ bname = "saveOffersBtcTeleport"
87+ save_offers = self .ton .local .db .get (bname )
88+ if save_offers is None :
89+ save_offers = dict ()
90+ self .ton .local .db [bname ] = save_offers
91+ return save_offers
92+
93+ def auto_vote_offers (self ):
94+ save_offers = self .get_save_offers ()
95+ if not save_offers :
96+ return
97+ current_offers = self .get_offers ()
98+ for save_offer in list (save_offers .values ()):
99+ offer_hash = save_offer ['hash' ]
100+ if offer_hash not in current_offers :
101+ continue
102+ offer = current_offers [save_offer ['hash' ]]
103+ if offer ['isPassed' ]:
104+ save_offers .pop (offer_hash )
105+ continue
106+ self .vote_offer_btc_teleport ([offer ['hash' ]])
107+
108+ def get_offers (self ):
86109 self .local .add_log ("start get_offers_btc_teleport function" , "debug" )
87110 cmd = f"runmethodfull { self .CONFIGURATOR_ADDRESS } list_proposals"
88111 result = self .ton .liteClient .Run (cmd )
89112 raw_offers = self .ton .Result2List (result )
90113 raw_offers = raw_offers [0 ]
91114 config34 = self .ton .GetConfig34 ()
92115 total_weight = config34 .get ("totalWeight" )
93- offers = []
116+ offers = {}
94117 for offer in raw_offers :
95118 if len (offer ) == 0 :
96119 continue
97120 item = {}
98- hash = str (offer [0 ])
99- item ["hash" ] = hash
121+ o_hash = str (offer [0 ])
122+ item ["hash" ] = o_hash
100123 item ["price" ] = offer [1 ]
101124 item ["proposal" ] = offer [2 ]
102125 item ["votedValidators" ] = offer [3 ]
@@ -108,10 +131,9 @@ def get_offers_btc_teleport(self):
108131 if len (item ["votedValidators" ]) == 0 :
109132 weight_remaining = required_weight
110133 available_weight = required_weight - weight_remaining
111- item ["weightRemaining" ] = weight_remaining
112134 item ["approvedPercent" ] = round (available_weight / total_weight * 100 , 3 )
113135 item ["isPassed" ] = (weight_remaining < 0 )
114- offers . append ( item )
136+ offers [ o_hash ] = item
115137 return offers
116138
117139 def vote_offer_btc_teleport (self , args ):
@@ -123,10 +145,16 @@ def vote_offer_btc_teleport(self, args):
123145 validator_pubkey_b64 = self .ton .GetPubKeyBase64 (validator_key )
124146 validator_index = self .ton .GetValidatorIndex ()
125147 for offer_hash in args :
126- # offer = self.GetOffer(offerHash)
127- # if validatorIndex in offer.get("votedValidators"):
128- # self.local.add_log("Proposal already has been voted", "debug")
129- # return
148+ current_offers = self .get_offers ()
149+ if offer_hash not in current_offers :
150+ self .local .add_log ("Offer not found, skip" , "warning" )
151+ return
152+ offer = current_offers [offer_hash ]
153+ if validator_index in offer .get ("votedValidators" ):
154+ self .local .add_log ("Proposal already has been voted" , "debug" )
155+ return
156+ self .get_save_offers ()[offer_hash ] = offer
157+ self .ton .local .save ()
130158 request_hash = self .ton .CreateConfigProposalRequest (offer_hash , validator_index )
131159 validator_signature = self .ton .GetValidatorSignature (validator_key , request_hash )
132160 path = self .ton .SignProposalVoteRequestWithValidator (offer_hash , validator_index , validator_pubkey_b64 ,
@@ -135,7 +163,7 @@ def vote_offer_btc_teleport(self, args):
135163 self .ton .SendFile (path , wallet )
136164
137165 def print_offers_btc_teleport_list (self , args ):
138- data = self .get_offers_btc_teleport ()
166+ data = self .get_offers ()
139167 if not data :
140168 print ("No data" )
141169 return
@@ -144,19 +172,19 @@ def print_offers_btc_teleport_list(self, args):
144172 print (text )
145173 return
146174 table = [["Hash" , "Votes" , "Approved" , "Is passed" ]]
147- for item in data :
148- hash = item .get ("hash" )
175+ for item in data . values () :
176+ o_hash = item .get ("hash" )
149177 voted_validators = len (item .get ("votedValidators" ))
150178 approved_percent_text = f"{ item .get ('approvedPercent' )} %"
151179 is_passed = item .get ("isPassed" )
152180 if "hash" not in args :
153181 from modules .utilities import UtilitiesModule
154- hash = UtilitiesModule .reduct (hash )
182+ o_hash = UtilitiesModule .reduct (o_hash )
155183 if is_passed is True :
156184 is_passed = bcolors .green_text ("true" )
157185 if is_passed is False :
158186 is_passed = bcolors .red_text ("false" )
159- table += [[hash , voted_validators , approved_percent_text , is_passed ]]
187+ table += [[o_hash , voted_validators , approved_percent_text , is_passed ]]
160188 print_table (table )
161189
162190 def remove_btc_teleport (self , args : list ):
@@ -175,4 +203,4 @@ def remove_btc_teleport(self, args: list):
175203 def add_console_commands (self , console ):
176204 console .AddItem ("remove_btc_teleport" , self .remove_btc_teleport , self .local .translate ("remove_btc_teleport_cmd" ))
177205 console .AddItem ("vote_offer_btc_teleport" , self .vote_offer_btc_teleport , self .local .translate ("vote_offer_btc_teleport_cmd" ))
178- console .AddItem ("print_offers_btc_teleport_list" , self .print_offers_btc_teleport_list , self .local .translate ("print_offers_btc_teleport_list_cmd" ))
206+ console .AddItem ("print_offers_btc_teleport_list" , self .print_offers_btc_teleport_list , self .local .translate ("print_offers_btc_teleport_list_cmd" ))
0 commit comments