Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
igroman787 committed Aug 30, 2022
1 parent fb3f906 commit f168bb0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 278 deletions.
137 changes: 2 additions & 135 deletions mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,48 +1535,10 @@ def GetMaxFactor(self):
return maxFactor
#end define

def GetNominationControllerLastSentStakeTime(self, addrB64):
cmd = f"runmethodfull {addrB64} all_data"
result = self.liteClient.Run(cmd)
buff = self.Result2List(result)
return buff[-1]
#end define

def IsNominationControllerReadyToStake(self, addrB64):
now = GetTimestamp()
config15 = self.GetConfig15()
lastSentStakeTime = self.GetNominationControllerLastSentStakeTime(addrB64)
stakeFreezeDelay = config15["validatorsElectedFor"] + config15["stakeHeldFor"]
result = lastSentStakeTime + stakeFreezeDelay < now
return result
#end define

def IsNominationControllerReadyToVote(self, addrB64):
vwl = self.GetValidatorsWalletsList()
result = addrB64 in vwl
return result
#end define

def GetNominationController(self, mode):
local.AddLog("start GetNominationController function", "debug")
nominationControllerList = ["nomination_controller_001", "nomination_controller_002"]
for item in nominationControllerList:
wallet = self.GetLocalWallet(item)
if mode == "stake" and self.IsNominationControllerReadyToStake(wallet.addrB64):
return wallet
if mode == "vote" and self.IsNominationControllerReadyToVote(wallet.addrB64):
return wallet
raise Exception("Validator сontroller not found")
#end define

def GetValidatorWallet(self, mode="stake"):
local.AddLog("start GetValidatorWallet function", "debug")
useNominationController = local.db.get("useNominationController")
if useNominationController is True:
wallet = self.GetNominationController(mode)
else:
walletName = local.db.get("validatorWalletName")
wallet = self.GetLocalWallet(walletName)
walletName = local.db.get("validatorWalletName")
wallet = self.GetLocalWallet(walletName)
return wallet
#end define

Expand Down Expand Up @@ -3433,71 +3395,6 @@ def DownloadContract(self, url, branch=None):
#end if
#end define

def CreateNominationController(self, name, nominatorAddr, **kwargs):
workchain = kwargs.get("workchain", -1)
subwalletDefault = 698983191 + workchain # 0x29A9A317 + workchain
subwallet = kwargs.get("subwallet", subwalletDefault)
rewardShare = kwargs.get("rewardShare", 0)
coverAbility = kwargs.get("coverAbility", 0)
local.AddLog("start CreateNominationController function", "debug")
walletPath = self.walletsDir + name
contractPath = self.contractsDir + "nomination-contract/"
if not os.path.isdir(contractPath):
self.DownloadContract("https://github.com/EmelyanenkoK/nomination-contract")
#end if

fiftScript = contractPath + "scripts/new-nomination-controller.fif"
args = [fiftScript, workchain, subwallet, nominatorAddr, rewardShare, coverAbility, walletPath]
result = self.fift.Run(args)
version = "v3r3"
wallet = self.GetLocalWallet(name, version)
self.SetWalletVersion(wallet.addrB64, version)
#end define

def DepositToNominationController(self, walletName, destAddr, amount):
wallet = self.GetLocalWallet(walletName)
bocPath = self.contractsDir + "nomination-contract/scripts/add-stake.boc"
resultFilePath = self.SignBocWithWallet(wallet, bocPath, destAddr, amount)
self.SendFile(resultFilePath, wallet)
#end define

def WithdrawFromNominationController(self, walletName, destAddr, amount):
wallet = self.GetLocalWallet(walletName)
fiftScript = self.contractsDir + "nomination-contract/scripts/request-stake.fif" # withdraw-stake.fif
bocPath = self.contractsDir + "nomination-contract/scripts/withdraw-stake"
args = [fiftScript, amount, bocPath]
result = self.fift.Run(args)
bocPath = Pars(result, "Saved to file ", ")")
resultFilePath = self.SignBocWithWallet(wallet, bocPath, destAddr, 1)
self.SendFile(resultFilePath, wallet)
#end define

def SendRequestToNominationController(self, walletName, destAddr):
wallet = self.GetLocalWallet(walletName)
bocPath = self.contractsDir + "nomination-contract/scripts/elector-refund.boc"
resultFilePath = self.SignBocWithWallet(wallet, bocPath, destAddr, 1.5)
self.SendFile(resultFilePath, wallet)
#end define

def CreateRestrictedWallet(self, name, ownerAddr, **kwargs):
workchain = kwargs.get("workchain", 0)
subwalletDefault = 698983191 + workchain # 0x29A9A317 + workchain
subwallet = kwargs.get("subwallet", subwalletDefault)
local.AddLog("start CreateRestrictedWallet function", "debug")
walletPath = self.walletsDir + name
contractPath = self.contractsDir + "nomination-contract/"
if not os.path.isdir(contractPath):
self.DownloadContract("https://github.com/EmelyanenkoK/nomination-contract")
#end if

fiftScript = contractPath + "scripts/new-restricted-wallet.fif"
args = [fiftScript, workchain, subwallet, ownerAddr, walletPath]
result = self.fift.Run(args)
version = "v3r4"
wallet = self.GetLocalWallet(name, version)
self.SetWalletVersion(wallet.addrB64, version)
#end define

def CreatePool(self, poolName, validatorRewardSharePercent, maxNominatorsCount, minValidatorStake, minNominatorStake):
local.AddLog("start CreatePool function", "debug")
validatorRewardShare = int(validatorRewardSharePercent * 100)
Expand Down Expand Up @@ -3613,36 +3510,6 @@ def PoolProcessRecoverStake(self):
return resultFilePath
#end define

def GetControllerData(self, addrB64):
local.AddLog("start GetControllerData function", "debug")
account = self.GetAccount(addrB64)
if account.status != "active":
return
cmd = "runmethodfull {addrB64} all_data".format(addrB64=addrB64)
result = self.liteClient.Run(cmd)
data = self.Result2List(result)
controllerData = dict()
wallet_data = dict()
wallet_data["seqno"] = data[0][0]
wallet_data["subwallet_id"] = data[0][1]
wallet_data["controller_pubkey"] = data[0][2]
wallet_data["last_used"] = data[0][3]
static_data = dict()
static_data["nominator_address"] = data[1][0]
static_data["controller_reward_share"] = data[1][1]
static_data["controller_cover_ability"] = data[1][2]
balances = dict()
balances["nominator_total_balance"] = data[2][0]
balances["nominator_elector_balance"] = data[2][1]
balances["nominator_withdrawal_request"] = data[2][2]
balances["total_stake_on_elector"] = data[2][3]
controllerData["wallet_data"] = wallet_data
controllerData["static_data"] = static_data
controllerData["balances"] = balances
controllerData["last_sent_stake_time"] = data[3]
return controllerData
#end define

def GetLocalPool(self, poolName):
local.AddLog("start GetLocalPool function", "debug")
if poolName is None:
Expand Down
143 changes: 0 additions & 143 deletions mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def Init(argv):
console.AddItem("bl", PrintBookmarksList, local.Translate("bl_cmd"))
console.AddItem("db", DeleteBookmark, local.Translate("db_cmd"))

# console.AddItem("nr", CreatNewAutoTransferRule, local.Translate("nr_cmd")) # "Добавить правило автопереводов в расписание / Create new auto transfer rule"
# console.AddItem("rl", PrintAutoTransferRulesList, local.Translate("rl_cmd")) # "Показать правила автопереводов / Show auto transfer rule list"
# console.AddItem("dr", DeleteAutoTransferRule, local.Translate("dr_cmd")) # "Удалить правило автопереводов из расписания / Delete auto transfer rule"

console.AddItem("nd", NewDomain, local.Translate("nd_cmd"))
console.AddItem("dl", PrintDomainsList, local.Translate("dl_cmd"))
console.AddItem("vds", ViewDomainStatus, local.Translate("vds_cmd"))
Expand All @@ -65,16 +61,6 @@ def Init(argv):
console.AddItem("set", SetSettings, local.Translate("set_cmd"))
console.AddItem("xrestart", Xrestart, local.Translate("xrestart_cmd"))
console.AddItem("xlist", Xlist, local.Translate("xlist_cmd"))
#console.AddItem("gpk", GetPubKey, local.Translate("gpk_cmd"))
#console.AddItem("ssoc", SignShardOverlayCert, local.Translate("ssoc_cmd"))
#console.AddItem("isoc", ImportShardOverlayCert, local.Translate("isoc_cmd"))

#console.AddItem("new_nomination_controller", NewNominationController, local.Translate("new_controller_cmd"))
#console.AddItem("get_nomination_controller_data", GetNominationControllerData, local.Translate("get_nomination_controller_data_cmd"))
#console.AddItem("deposit_to_nomination_controller", DepositToNominationController, local.Translate("deposit_to_controller_cmd"))
#console.AddItem("withdraw_from_nomination_controller", WithdrawFromNominationController, local.Translate("withdraw_from_nomination_controller_cmd"))
#console.AddItem("request_to_nomination_controller", SendRequestToNominationController, local.Translate("request_to_nomination_controller_cmd"))
#console.AddItem("new_restricted_wallet", NewRestrictedWallet, local.Translate("new_restricted_wallet_cmd"))

console.AddItem("new_pool", NewPool, local.Translate("new_pool_cmd"))
console.AddItem("pools_list", PrintPoolsList, local.Translate("pools_list_cmd"))
Expand All @@ -83,10 +69,6 @@ def Init(argv):
console.AddItem("deposit_to_pool", DepositToPool, local.Translate("deposit_to_pool_cmd"))
console.AddItem("withdraw_from_pool", WithdrawFromPool, local.Translate("withdraw_from_pool_cmd"))
console.AddItem("delete_pool", DeletePool, local.Translate("delete_pool_cmd"))
#console.AddItem("update_validator_set", UpdateValidatorSet, local.Translate("update_validator_set_cmd"))

# console.AddItem("pt", PrintTest, "PrintTest")
# console.AddItem("sl", sl, "sl")

# Process input parameters
opts, args = getopt.getopt(argv,"hc:w:",["config=","wallets="])
Expand Down Expand Up @@ -802,36 +784,6 @@ def DeleteBookmark(args):
ColorPrint("DeleteBookmark - {green}OK{endc}")
#end define

# def CreatNewAutoTransferRule(args):
# try:
# name = args[0]
# addr = args[1]
# except:
# ColorPrint("{red}Bad args. Usage:{endc} nr <rule-name> <account-addr | domain-name>")
# return
# rule = dict()
# rule["name"] = name
# rule["addr"] = addr
# ton.AddAutoTransferRule(rule)
# ColorPrint("CreatNewAutoTransferRule - {green}OK{endc}")
# #end define

# def PrintAutoTransferRulesList(args):
# data = ton.GetRules()
# if (data is None or len(data) == 0):
# print("No data")
# return
# table = list()
# table += [["Name", "fix me"]]
# for item in data:
# table += [[item.get("name"), item.get("fix me")]]
# PrintTable(table)
# #end define

# def DeleteAutoTransferRule(args):
# print("fix me")
# #end define

def PrintOffersList(args):
offers = ton.GetOffers()
if "--json" in args:
Expand Down Expand Up @@ -1100,101 +1052,6 @@ def Xlist(args):
ColorPrint("Xlist - {green}OK{endc}")
#end define

def GetPubKey(args):
adnlAddr = ton.GetAdnlAddr()
pubkey = ton.GetPubKey(adnlAddr)
print("pubkey:", pubkey)
#end define

def SignShardOverlayCert(args):
try:
adnl = args[0]
pubkey = args[0]
except:
ColorPrint("{red}Bad args. Usage:{endc} ssoc <pubkey>")
return
ton.SignShardOverlayCert(adnl, pubkey)
#end define

def ImportShardOverlayCert(args):
ton.ImportShardOverlayCert()
#end define

def NewNominationController(args):
try:
name = args[0]
nominatorAddr = args[1]
rewardShare = args[2]
coverAbility = args[3]
except:
ColorPrint("{red}Bad args. Usage:{endc} new_controller <controller-name> <nominator-addr> <reward-share> <cover-ability>")
return
ton.CreateNominationController(name, nominatorAddr, rewardShare=rewardShare, coverAbility=coverAbility)
ColorPrint("NewNominationController - {green}OK{endc}")
#end define

def GetNominationControllerData(args):
try:
addrB64 = args[0]
except:
ColorPrint("{red}Bad args. Usage:{endc} get_nomination_controller_data <controller-name | controller-addr>")
return
addrB64 = ton.GetDestinationAddr(addrB64)
controllerData = ton.GetControllerData(addrB64)
print(json.dumps(controllerData, indent=4))
#end define

def DepositToNominationController(args):
try:
walletName = args[0]
destination = args[1]
amount = float(args[2])
except:
ColorPrint("{red}Bad args. Usage:{endc} add_to_nomination_controller <wallet-name> <controller-addr> <amount>")
return
destination = ton.GetDestinationAddr(destination)
ton.DepositToNominationController(walletName, destination, amount)
ColorPrint("DepositToNominationController - {green}OK{endc}")
#end define

def WithdrawFromNominationController(args):
try:
walletName = args[0]
destination = args[1]
amount = float(args[2])
except:
ColorPrint("{red}Bad args. Usage:{endc} withdraw_from_nomination_controller <wallet-name> <controller-addr> <amount>")
return
destination = ton.GetDestinationAddr(destination)
ton.WithdrawFromNominationController(walletName, destination, amount)
ColorPrint("WithdrawFromNominationController - {green}OK{endc}")
#end define

def SendRequestToNominationController(args):
try:
walletName = args[0]
destination = args[1]
except:
ColorPrint("{red}Bad args. Usage:{endc} request_to_nomination_controller <wallet-name> <controller-addr>")
return
destination = ton.GetDestinationAddr(destination)
ton.SendRequestToNominationController(walletName, destination)
ColorPrint("SendRequestToNominationController - {green}OK{endc}")
#end define

def NewRestrictedWallet(args):
try:
workchain = int(args[0])
name = args[1]
ownerAddr = args[2]
#subwallet = args[3]
except:
ColorPrint("{red}Bad args. Usage:{endc} new_restricted_wallet <workchain-id> <wallet-name> <owner-addr>")
return
ton.CreateRestrictedWallet(name, ownerAddr, workchain)
ColorPrint("NewRestrictedWallet - {green}OK{endc}")
#end define

def NewPool(args):
try:
poolName = args[0]
Expand Down

0 comments on commit f168bb0

Please sign in to comment.