mirror of https://github.com/nucypher/nucypher.git
Give some attention to layering get missing confirmations via agent and actor; Fixes prolong duration sugestion.
parent
22ccdb4d68
commit
5dceb34207
|
@ -1150,6 +1150,12 @@ class Staker(NucypherTokenActor):
|
|||
raise TypeError("This method can only be used when staking via a contract")
|
||||
return receipt
|
||||
|
||||
@property
|
||||
def missing_confirmations(self) -> int:
|
||||
staker_address = self.checksum_address
|
||||
missing = self.staking_agent.get_missing_confirmations(checksum_address=staker_address)
|
||||
return missing
|
||||
|
||||
|
||||
class Worker(NucypherTokenActor):
|
||||
"""
|
||||
|
@ -1223,20 +1229,11 @@ class Worker(NucypherTokenActor):
|
|||
receipt = self.staking_agent.confirm_activity(worker_address=self.__worker_address)
|
||||
return receipt
|
||||
|
||||
def get_missing_confirmations(self) -> int:
|
||||
@property
|
||||
def missing_confirmations(self) -> int:
|
||||
staker_address = self.checksum_address
|
||||
last_confirmed_period = self.staking_agent.get_last_active_period(staker_address)
|
||||
current_period = self.staking_agent.get_current_period()
|
||||
missing_confirmations = current_period - last_confirmed_period
|
||||
if missing_confirmations in (0, -1):
|
||||
result = 0
|
||||
elif missing_confirmations == current_period: # never confirmed
|
||||
stakes = self.staking_agent.get_all_stakes(staker_address=staker_address)
|
||||
initial_staking_period = min(stakes, key=lambda s: s[0])
|
||||
result = current_period - initial_staking_period
|
||||
else:
|
||||
result = missing_confirmations
|
||||
return result
|
||||
missing = self.staking_agent.get_missing_confirmations(checksum_address=staker_address)
|
||||
return missing
|
||||
|
||||
|
||||
class BlockchainPolicyAuthor(NucypherTokenActor):
|
||||
|
|
|
@ -605,6 +605,22 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
total_completed_work = self.contract.functions.getCompletedWork(bidder_address).call()
|
||||
return total_completed_work
|
||||
|
||||
@validate_checksum_address
|
||||
def get_missing_confirmations(self, checksum_address: str) -> int:
|
||||
# TODO: Move this up one layer, since it utilizes a combination of contract API methods.
|
||||
last_confirmed_period = self.get_last_active_period(checksum_address)
|
||||
current_period = self.get_current_period()
|
||||
missing_confirmations = current_period - last_confirmed_period
|
||||
if missing_confirmations in (0, -1):
|
||||
result = 0
|
||||
elif missing_confirmations == current_period: # never confirmed
|
||||
stakes = list(self.get_all_stakes(staker_address=checksum_address))
|
||||
initial_staking_period = min(stakes, key=lambda s: s[0])[0]
|
||||
result = current_period - initial_staking_period
|
||||
else:
|
||||
result = missing_confirmations
|
||||
return result
|
||||
|
||||
|
||||
class PolicyManagerAgent(EthereumContractAgent):
|
||||
|
||||
|
|
|
@ -703,7 +703,7 @@ def prolong(general_config, transacting_staker_options, config_file, force, lock
|
|||
# Interactive
|
||||
if not lock_periods:
|
||||
stake_extension_range = click.IntRange(min=1, max=economics.maximum_allowed_locked, clamp=False)
|
||||
max_extension = economics.maximum_allowed_locked - current_stake.periods_remaining
|
||||
max_extension = economics.maximum_rewarded_periods - current_stake.periods_remaining
|
||||
lock_periods = click.prompt(f"Enter number of periods to extend (1-{max_extension})", type=stake_extension_range)
|
||||
if not force:
|
||||
click.confirm(f"Publish stake extension of {lock_periods} period(s) to the blockchain?", abort=True)
|
||||
|
|
|
@ -475,7 +475,7 @@ def paint_stakes(emitter, stakeholder, paint_inactive: bool = False, staker_addr
|
|||
fees = staker.policy_agent.get_reward_amount(staker.checksum_address)
|
||||
gwei_fees = f"{Web3.fromWei(fees, 'gwei')} Gwei"
|
||||
last_confirmed = staker.staking_agent.get_last_active_period(staker.checksum_address)
|
||||
missing = staker.staking_agent.get_missing_confirmations(staker_address=staker.checksum_address)
|
||||
missing = staker.missing_confirmations
|
||||
|
||||
staker_data = [f'Missing {missing} confirmation{"s" if missing > 1 else ""}' if missing else f'Confirmed #{last_confirmed}',
|
||||
f'{"Yes" if staker.is_restaking else "No"} ({"Locked" if staker.restaking_lock_enabled else "Unlocked"})',
|
||||
|
|
|
@ -1388,6 +1388,6 @@ class Teacher:
|
|||
if not self.federated_only:
|
||||
payload.update({
|
||||
"balances": dict(eth=float(self.eth_balance), nu=float(self.token_balance.to_tokens())),
|
||||
"missing_confirmations": self.get_missing_confirmations(),
|
||||
"missing_confirmations": self.missing_confirmations,
|
||||
"last_active_period": self.last_active_period})
|
||||
return payload
|
||||
|
|
Loading…
Reference in New Issue