Exemple #1
0
 def create_pool(self):
     owner = self.threebot_name
     threebot = get_threebot_config_instance(owner, self.threebot_info["solution_uuid"])
     zos = get_threebot_zos(threebot)
     identity = generate_user_identity(threebot, self.password, zos)
     zos = j.sals.zos.get(identity.instance_name)
     farm_name, existent_pool = self._find_free_pool_in_farm(zos, self.available_farms)
     if existent_pool is not None:
         self.pool_id = existent_pool.pool_id
     else:
         farm = random.choice(self.available_farms)
         farm_name = farm.name
         self.pool_info = deployer.create_3bot_pool(
             farm_name, self.expiration, currency=self.currency, identity_name=identity.instance_name, **self.query,
         )
         if self.pool_info.escrow_information.address.strip() == "":
             raise StopChatFlow(
                 f"provisioning the pool, invalid escrow information probably caused by a misconfigured, pool creation request was {self.pool_info}"
             )
         payment_info = deployer.pay_for_pool(self.pool_info)
         result = deployer.wait_pool_reservation(self.pool_info.reservation_id, bot=self)
         if not result:
             raise StopChatFlow(f"provisioning the pool timed out. pool_id: {self.pool_info.reservation_id}")
         self.md_show_update(
             f"Capacity pool {self.pool_info.reservation_id} created and funded with {payment_info['total_amount_dec']} TFT"
         )
         self.pool_id = self.pool_info.reservation_id
Exemple #2
0
 def _verify_password(self, password):
     instance = USER_THREEBOT_FACTORY.get(f"threebot_{self.threebot_info['solution_uuid']}")
     if not instance.verify_secret(password):
         return False
     zos = get_threebot_zos(instance)
     user = zos._explorer.users.get(instance.identity_tid)
     words = j.data.encryption.key_to_mnemonic(password.encode().zfill(32))
     seed = j.data.encryption.mnemonic_to_key(words)
     pubkey = NACL(seed).get_verify_key_hex()
     return pubkey == user.pubkey
Exemple #3
0
 def create_pool(self):
     owner = self.threebot_name
     threebot = get_threebot_config_instance(owner, self.threebot_info["solution_uuid"])
     zos = get_threebot_zos(threebot)
     identity = generate_user_identity(threebot, self.password, zos)
     zos = j.sals.zos.get(identity.instance_name)
     farm = random.choice(self.available_farms)
     farm_name = farm.name
     self.pool_info = deployer.create_3bot_pool(
         farm_name, self.expiration, currency=self.currency, identity_name=identity.instance_name, **self.query,
     )
     if self.pool_info.escrow_information.address.strip() == "":
         raise StopChatFlow(
             f"provisioning the pool, invalid escrow information probably caused by a misconfigured, pool creation request was {self.pool_info}"
         )
     msg, qr_code = deployer.get_qr_code_payment_info(self.pool_info)
     deployer.msg_payment_info = msg
     result = deployer.wait_pool_payment(self, self.pool_info.reservation_id, qr_code=qr_code)
     if not result:
         raise StopChatFlow(f"provisioning the pool timed out. pool_id: {self.pool_info.reservation_id}")
     self.pool_id = self.pool_info.reservation_id
Exemple #4
0
 def _find_free_pool_in_farm(self, zos, farms):
     owner = self.threebot_name
     threebot = get_threebot_config_instance(owner, self.threebot_info["solution_uuid"])
     zos = get_threebot_zos(threebot)
     identity = generate_user_identity(threebot, self.password, zos)
     zos = j.sals.zos.get(identity.instance_name)
     pools = zos.pools.list()
     max_pool = None
     farm_name = None
     for pool in pools:
         try:
             pool_farm = deployer.get_pool_farm_name(pool=pool)
         except requests.exceptions.HTTPError:
             continue
         if (
             self._empty_pool(pool)
             and self._contains_node(pool, self.selected_node)
             and [1 for farm in farms if farm.name == pool_farm]
         ):
             max_pool = self._max_pool(max_pool, pool)
             farm_name = pool_farm
     return farm_name, max_pool