Skip to content

Commit c651f6e

Browse files
committed
add download pool scripts for single-nom, import-pool; move CreatePool to modules
1 parent 549fde2 commit c651f6e

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

modules/nominator_pool.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@
77

88
class NominatorPoolModule(PoolModule):
99

10+
def do_create_pool(self, pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake,
11+
min_nominator_stake):
12+
self.ton.local.add_log("start CreatePool function", "debug")
13+
validator_reward_share = int(validator_reward_share_percent * 100)
14+
15+
self.check_download_pool_contract_scripts()
16+
17+
file_path = self.ton.poolsDir + pool_name
18+
if os.path.isfile(file_path + ".addr"):
19+
self.ton.local.add_log("CreatePool warning: Pool already exists: " + file_path, "warning")
20+
return
21+
# end if
22+
23+
fift_script = self.ton.contractsDir + "nominator-pool/func/new-pool.fif"
24+
wallet = self.ton.GetValidatorWallet()
25+
args = [fift_script, wallet.addrB64, validator_reward_share, max_nominators_count, min_validator_stake,
26+
min_nominator_stake, file_path]
27+
result = self.ton.fift.Run(args)
28+
if "Saved pool" not in result:
29+
raise Exception("CreatePool error: " + result)
30+
# end if
31+
32+
pools = self.ton.GetPools()
33+
new_pool = self.ton.GetLocalPool(pool_name)
34+
for pool in pools:
35+
if pool.name != new_pool.name and pool.addrB64 == new_pool.addrB64:
36+
new_pool.Delete()
37+
raise Exception("CreatePool error: Pool with the same parameters already exists.")
38+
# end for
39+
# end define
40+
1041
def new_pool(self, args):
1142
try:
1243
pool_name = args[0]
@@ -17,7 +48,7 @@ def new_pool(self, args):
1748
except:
1849
color_print("{red}Bad args. Usage:{endc} new_pool <pool-name> <validator-reward-share-percent> <max-nominators-count> <min-validator-stake> <min-nominator-stake>")
1950
return
20-
self.ton.CreatePool(pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake, min_nominator_stake)
51+
self.do_create_pool(pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake, min_nominator_stake)
2152
color_print("NewPool - {green}OK{endc}")
2253

2354
def do_activate_pool(self, pool, ex=True):

modules/pool.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from mypylib.mypylib import color_print, print_table
24
from modules.module import MtcModule
35

@@ -28,6 +30,15 @@ def delete_pool(self, args):
2830
pool = self.ton.GetLocalPool(pool_name)
2931
pool.Delete()
3032
color_print("DeletePool - {green}OK{endc}")
33+
# end define
34+
35+
def do_import_pool(self, pool_name, addr_b64):
36+
self.check_download_pool_contract_scripts()
37+
addr_bytes = self.ton.addr_b64_to_bytes(addr_b64)
38+
pool_path = self.ton.poolsDir + pool_name
39+
with open(pool_path + ".addr", 'wb') as file:
40+
file.write(addr_bytes)
41+
# end define
3142

3243
def import_pool(self, args):
3344
try:
@@ -36,9 +47,14 @@ def import_pool(self, args):
3647
except:
3748
color_print("{red}Bad args. Usage:{endc} import_pool <pool-name> <pool-addr>")
3849
return
39-
self.ton.import_pool(pool_name, pool_addr)
50+
self.do_import_pool(pool_name, pool_addr)
4051
color_print("import_pool - {green}OK{endc}")
4152

53+
def check_download_pool_contract_scripts(self):
54+
contract_path = self.ton.contractsDir + "nominator-pool/"
55+
if not os.path.isdir(contract_path):
56+
self.ton.DownloadContract("https://github.com/ton-blockchain/nominator-pool")
57+
4258
def add_console_commands(self, console):
4359
console.AddItem("pools_list", self.print_pools_list, self.local.translate("pools_list_cmd"))
4460
console.AddItem("delete_pool", self.delete_pool, self.local.translate("delete_pool_cmd"))

modules/single_pool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class SingleNominatorModule(PoolModule):
1111
def do_create_single_pool(self, pool_name, owner_address):
1212
self.ton.local.add_log("start create_single_pool function", "debug")
1313

14+
self.check_download_pool_contract_scripts()
15+
1416
file_path = self.ton.poolsDir + pool_name
1517
if os.path.isfile(file_path + ".addr"):
1618
self.ton.local.add_log("create_single_pool warning: Pool already exists: " + file_path, "warning")

mytoncore/mytoncore.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,13 +1733,6 @@ def ExportWallet(self, walletName):
17331733
return wallet.addrB64, key
17341734
#end define
17351735

1736-
def import_pool(self, pool_name, addr_b64):
1737-
addr_bytes = self.addr_b64_to_bytes(addr_b64)
1738-
pool_path = self.poolsDir + pool_name
1739-
with open(pool_path + ".addr", 'wb') as file:
1740-
file.write(addr_bytes)
1741-
#end define
1742-
17431736
def GetWalletsNameList(self):
17441737
self.local.add_log("start GetWalletsNameList function", "debug")
17451738
walletsNameList = list()
@@ -3396,37 +3389,6 @@ def DownloadContract(self, url, branch=None):
33963389
#end if
33973390
#end define
33983391

3399-
def CreatePool(self, poolName, validatorRewardSharePercent, maxNominatorsCount, minValidatorStake, minNominatorStake):
3400-
self.local.add_log("start CreatePool function", "debug")
3401-
validatorRewardShare = int(validatorRewardSharePercent * 100)
3402-
contractPath = self.contractsDir + "nominator-pool/"
3403-
if not os.path.isdir(contractPath):
3404-
self.DownloadContract("https://github.com/ton-blockchain/nominator-pool")
3405-
#end if
3406-
3407-
filePath = self.poolsDir + poolName
3408-
if os.path.isfile(filePath + ".addr"):
3409-
self.local.add_log("CreatePool warning: Pool already exists: " + filePath, "warning")
3410-
return
3411-
#end if
3412-
3413-
fiftScript = self.contractsDir + "nominator-pool/func/new-pool.fif"
3414-
wallet = self.GetValidatorWallet()
3415-
args = [fiftScript, wallet.addrB64, validatorRewardShare, maxNominatorsCount, minValidatorStake, minNominatorStake, filePath]
3416-
result = self.fift.Run(args)
3417-
if "Saved pool" not in result:
3418-
raise Exception("CreatePool error: " + result)
3419-
#end if
3420-
3421-
pools = self.GetPools()
3422-
newPool = self.GetLocalPool(poolName)
3423-
for pool in pools:
3424-
if pool.name != newPool.name and pool.addrB64 == newPool.addrB64:
3425-
newPool.Delete()
3426-
raise Exception("CreatePool error: Pool with the same parameters already exists.")
3427-
#end for
3428-
#end define
3429-
34303392
def WithdrawFromPoolProcess(self, poolAddr, amount):
34313393
self.local.add_log("start WithdrawFromPoolProcess function", "debug")
34323394
wallet = self.GetValidatorWallet()

0 commit comments

Comments
 (0)