Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion modules/nominator_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,37 @@

class NominatorPoolModule(PoolModule):

def do_create_pool(self, pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake,
min_nominator_stake):
self.ton.local.add_log("start CreatePool function", "debug")
validator_reward_share = int(validator_reward_share_percent * 100)

self.check_download_pool_contract_scripts()

file_path = self.ton.poolsDir + pool_name
if os.path.isfile(file_path + ".addr"):
self.ton.local.add_log("CreatePool warning: Pool already exists: " + file_path, "warning")
return
# end if

fift_script = self.ton.contractsDir + "nominator-pool/func/new-pool.fif"
wallet = self.ton.GetValidatorWallet()
args = [fift_script, wallet.addrB64, validator_reward_share, max_nominators_count, min_validator_stake,
min_nominator_stake, file_path]
result = self.ton.fift.Run(args)
if "Saved pool" not in result:
raise Exception("CreatePool error: " + result)
# end if

pools = self.ton.GetPools()
new_pool = self.ton.GetLocalPool(pool_name)
for pool in pools:
if pool.name != new_pool.name and pool.addrB64 == new_pool.addrB64:
new_pool.Delete()
raise Exception("CreatePool error: Pool with the same parameters already exists.")
# end for
# end define

def new_pool(self, args):
try:
pool_name = args[0]
Expand All @@ -17,7 +48,7 @@ def new_pool(self, args):
except:
color_print("{red}Bad args. Usage:{endc} new_pool <pool-name> <validator-reward-share-percent> <max-nominators-count> <min-validator-stake> <min-nominator-stake>")
return
self.ton.CreatePool(pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake, min_nominator_stake)
self.do_create_pool(pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake, min_nominator_stake)
color_print("NewPool - {green}OK{endc}")

def do_activate_pool(self, pool, ex=True):
Expand Down
18 changes: 17 additions & 1 deletion modules/pool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from mypylib.mypylib import color_print, print_table
from modules.module import MtcModule

Expand Down Expand Up @@ -28,6 +30,15 @@ def delete_pool(self, args):
pool = self.ton.GetLocalPool(pool_name)
pool.Delete()
color_print("DeletePool - {green}OK{endc}")
# end define

def do_import_pool(self, pool_name, addr_b64):
self.check_download_pool_contract_scripts()
addr_bytes = self.ton.addr_b64_to_bytes(addr_b64)
pool_path = self.ton.poolsDir + pool_name
with open(pool_path + ".addr", 'wb') as file:
file.write(addr_bytes)
# end define

def import_pool(self, args):
try:
Expand All @@ -36,9 +47,14 @@ def import_pool(self, args):
except:
color_print("{red}Bad args. Usage:{endc} import_pool <pool-name> <pool-addr>")
return
self.ton.import_pool(pool_name, pool_addr)
self.do_import_pool(pool_name, pool_addr)
color_print("import_pool - {green}OK{endc}")

def check_download_pool_contract_scripts(self):
contract_path = self.ton.contractsDir + "nominator-pool/"
if not os.path.isdir(contract_path):
self.ton.DownloadContract("https://github.com/ton-blockchain/nominator-pool")

def add_console_commands(self, console):
console.AddItem("pools_list", self.print_pools_list, self.local.translate("pools_list_cmd"))
console.AddItem("delete_pool", self.delete_pool, self.local.translate("delete_pool_cmd"))
Expand Down
2 changes: 2 additions & 0 deletions modules/single_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class SingleNominatorModule(PoolModule):
def do_create_single_pool(self, pool_name, owner_address):
self.ton.local.add_log("start create_single_pool function", "debug")

self.check_download_pool_contract_scripts()

file_path = self.ton.poolsDir + pool_name
if os.path.isfile(file_path + ".addr"):
self.ton.local.add_log("create_single_pool warning: Pool already exists: " + file_path, "warning")
Expand Down
38 changes: 0 additions & 38 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,13 +1733,6 @@ def ExportWallet(self, walletName):
return wallet.addrB64, key
#end define

def import_pool(self, pool_name, addr_b64):
addr_bytes = self.addr_b64_to_bytes(addr_b64)
pool_path = self.poolsDir + pool_name
with open(pool_path + ".addr", 'wb') as file:
file.write(addr_bytes)
#end define

def GetWalletsNameList(self):
self.local.add_log("start GetWalletsNameList function", "debug")
walletsNameList = list()
Expand Down Expand Up @@ -3396,37 +3389,6 @@ def DownloadContract(self, url, branch=None):
#end if
#end define

def CreatePool(self, poolName, validatorRewardSharePercent, maxNominatorsCount, minValidatorStake, minNominatorStake):
self.local.add_log("start CreatePool function", "debug")
validatorRewardShare = int(validatorRewardSharePercent * 100)
contractPath = self.contractsDir + "nominator-pool/"
if not os.path.isdir(contractPath):
self.DownloadContract("https://github.com/ton-blockchain/nominator-pool")
#end if

filePath = self.poolsDir + poolName
if os.path.isfile(filePath + ".addr"):
self.local.add_log("CreatePool warning: Pool already exists: " + filePath, "warning")
return
#end if

fiftScript = self.contractsDir + "nominator-pool/func/new-pool.fif"
wallet = self.GetValidatorWallet()
args = [fiftScript, wallet.addrB64, validatorRewardShare, maxNominatorsCount, minValidatorStake, minNominatorStake, filePath]
result = self.fift.Run(args)
if "Saved pool" not in result:
raise Exception("CreatePool error: " + result)
#end if

pools = self.GetPools()
newPool = self.GetLocalPool(poolName)
for pool in pools:
if pool.name != newPool.name and pool.addrB64 == newPool.addrB64:
newPool.Delete()
raise Exception("CreatePool error: Pool with the same parameters already exists.")
#end for
#end define

def WithdrawFromPoolProcess(self, poolAddr, amount):
self.local.add_log("start WithdrawFromPoolProcess function", "debug")
wallet = self.GetValidatorWallet()
Expand Down