1+ import json
12import os
23import subprocess
34
45import pkg_resources
56
67from modules .module import MtcModule
7- from mypylib .mypylib import run_as_root , color_print
8+ from mypylib .mypylib import run_as_root , color_print , bcolors , print_table
89
910
1011class BtcTeleportModule (MtcModule ):
@@ -81,6 +82,83 @@ def run_remove_btc_teleport(args):
8182 script_path = pkg_resources .resource_filename ('mytonctrl' , 'scripts/remove_btc_teleport.sh' )
8283 return run_as_root (["bash" , script_path ] + args )
8384
85+ def get_offers_btc_teleport (self ):
86+ self .local .add_log ("start get_offers_btc_teleport function" , "debug" )
87+ cmd = f"runmethodfull { self .CONFIGURATOR_ADDRESS } list_proposals"
88+ result = self .ton .liteClient .Run (cmd )
89+ raw_offers = self .ton .Result2List (result )
90+ raw_offers = raw_offers [0 ]
91+ config34 = self .ton .GetConfig34 ()
92+ total_weight = config34 .get ("totalWeight" )
93+ offers = []
94+ for offer in raw_offers :
95+ if len (offer ) == 0 :
96+ continue
97+ item = {}
98+ hash = str (offer [0 ])
99+ item ["hash" ] = hash
100+ item ["price" ] = offer [1 ]
101+ item ["proposal" ] = offer [2 ]
102+ item ["votedValidators" ] = offer [3 ]
103+ weight_remaining = offer [4 ]
104+ item ["weightRemaining" ] = weight_remaining
105+ item ["vset_id" ] = offer [5 ]
106+ item ["creator" ] = offer [6 ]
107+ required_weight = total_weight * 3 / 4
108+ if len (item ["votedValidators" ]) == 0 :
109+ weight_remaining = required_weight
110+ available_weight = required_weight - weight_remaining
111+ item ["weightRemaining" ] = weight_remaining
112+ item ["approvedPercent" ] = round (available_weight / total_weight * 100 , 3 )
113+ item ["isPassed" ] = (weight_remaining < 0 )
114+ offers .append (item )
115+ return offers
116+
117+ def vote_offer_btc_teleport (self , args ):
118+ if len (args ) == 0 :
119+ color_print ("{red}Bad args. Usage:{endc} vote_offer_btc_teleport <offer-hash> [offer-hash-2 offer-hash-3 ...]" )
120+ return
121+ wallet = self .ton .GetValidatorWallet (mode = "vote" )
122+ validator_key = self .ton .GetValidatorKey ()
123+ validator_pubkey_b64 = self .ton .GetPubKeyBase64 (validator_key )
124+ validator_index = self .ton .GetValidatorIndex ()
125+ 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
130+ request_hash = self .ton .CreateConfigProposalRequest (offer_hash , validator_index )
131+ validator_signature = self .ton .GetValidatorSignature (validator_key , request_hash )
132+ path = self .ton .SignProposalVoteRequestWithValidator (offer_hash , validator_index , validator_pubkey_b64 ,
133+ validator_signature )
134+ path = self .ton .SignBocWithWallet (wallet , path , self .CONFIGURATOR_ADDRESS , 1.5 )
135+ self .ton .SendFile (path , wallet )
136+
137+ def print_offers_btc_teleport_list (self , args ):
138+ data = self .get_offers_btc_teleport ()
139+ if not data :
140+ print ("No data" )
141+ return
142+ if "--json" in args :
143+ text = json .dumps (data , indent = 2 )
144+ print (text )
145+ return
146+ table = [["Hash" , "Votes" , "Approved" , "Is passed" ]]
147+ for item in data :
148+ hash = item .get ("hash" )
149+ voted_validators = len (item .get ("votedValidators" ))
150+ approved_percent_text = f"{ item .get ('approvedPercent' )} %"
151+ is_passed = item .get ("isPassed" )
152+ if "hash" not in args :
153+ from modules .utilities import UtilitiesModule
154+ hash = UtilitiesModule .reduct (hash )
155+ if is_passed is True :
156+ is_passed = bcolors .green_text ("true" )
157+ if is_passed is False :
158+ is_passed = bcolors .red_text ("false" )
159+ table += [[hash , voted_validators , approved_percent_text , is_passed ]]
160+ print_table (table )
161+
84162 def remove_btc_teleport (self , args : list ):
85163 if len (args ) > 1 :
86164 color_print ("{red}Bad args. Usage:{endc} remove_btc_teleport [--force]" )
@@ -96,3 +174,5 @@ def remove_btc_teleport(self, args: list):
96174
97175 def add_console_commands (self , console ):
98176 console .AddItem ("remove_btc_teleport" , self .remove_btc_teleport , self .local .translate ("remove_btc_teleport_cmd" ))
177+ 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" ))
0 commit comments