def __validate_stake(self, amount: NU, lock_periods: int) -> bool: validate_stake_amount(amount=amount) validate_locktime(lock_periods=lock_periods) if not self.token_balance >= amount: raise self.MinerError("Insufficient miner token balance ({balance})".format(balance=self.token_balance)) else: return True
def divide_stake(self, stake_index: int, target_value: int, additional_periods: int = None, expiration: maya.MayaDT = None) -> dict: """ Modifies the unlocking schedule and value of already locked tokens. This actor requires that is_me is True, and that the expiration datetime is after the existing locking schedule of this miner, or an exception will be raised. :param target_value: The quantity of tokens in the smallest denomination. :param expiration: The new expiration date to set. :return: Returns the blockchain transaction hash """ if additional_periods and expiration: raise ValueError( "Pass the number of lock periods or an expiration MayaDT; not both." ) _first_period, last_period, locked_value = self.miner_agent.get_stake_info( miner_address=self.checksum_public_address, stake_index=stake_index) if expiration: additional_periods = datetime_to_period( datetime=expiration) - last_period if additional_periods <= 0: raise self.MinerError( "Expiration {} must be at least 1 period from now.".format( expiration)) if target_value >= locked_value: raise self.MinerError( "Cannot divide stake; Value must be less than the specified stake value." ) # Ensure both halves are for valid amounts validate_stake_amount(amount=target_value) validate_stake_amount(amount=locked_value - target_value) tx = self.miner_agent.divide_stake( miner_address=self.checksum_public_address, stake_index=stake_index, target_value=target_value, periods=additional_periods) self.blockchain.wait_for_receipt(tx) return tx
def divide_stake(self, stake_index: int, target_value: NU, additional_periods: int = None, expiration: maya.MayaDT = None) -> dict: """ Modifies the unlocking schedule and value of already locked tokens. This actor requires that is_me is True, and that the expiration datetime is after the existing locking schedule of this miner, or an exception will be raised. :param stake_index: The miner's stake index of the stake to divide :param additional_periods: The number of periods to extend the stake by :param target_value: The quantity of tokens in the smallest denomination to divide. :param expiration: The new expiration date to set as an end period for stake division. :return: Returns the blockchain transaction hash """ if additional_periods and expiration: raise ValueError("Pass the number of lock periods or an expiration MayaDT; not both.") stake = self.__stakes[stake_index] if expiration: additional_periods = datetime_to_period(datetime=expiration) - stake.end_period if additional_periods <= 0: raise self.MinerError("Expiration {} must be at least 1 period from now.".format(expiration)) if target_value >= stake.value: raise self.MinerError(f"Cannot divide stake; Value ({target_value}) must be less " f"than the existing stake value {stake.value}.") # Ensure both halves are for valid amounts validate_stake_amount(amount=target_value) validate_stake_amount(amount=stake.value - target_value) tx = self.miner_agent.divide_stake(miner_address=self.checksum_public_address, stake_index=stake_index, target_value=int(target_value), periods=additional_periods) self.blockchain.wait_for_receipt(tx) self.__read_stakes() # update local on-chain stake cache return tx