Allocation users can now set worker, detach worker and re-stake

pull/1327/head
David Núñez 2019-09-23 11:22:09 +02:00
parent d6f76c5d93
commit 0da70c8982
2 changed files with 42 additions and 16 deletions

View File

@ -739,7 +739,7 @@ class Staker(NucypherTokenActor):
return receipt
#
# Reward and Collection
# Bonding with Worker
#
@only_me
@ -766,6 +766,20 @@ class Staker(NucypherTokenActor):
return NO_WORKER_ASSIGNED.bool_value(False)
return self.__worker_address
@only_me
@save_receipt
def detach_worker(self) -> str:
if self.is_contract:
receipt = self.user_escrow_agent.release_worker()
else:
receipt = self.staking_agent.release_worker(staker_address=self.checksum_address)
self.__worker_address = BlockchainInterface.NULL_ADDRESS
return receipt
#
# Reward and Collection
#
@only_me
@save_receipt
def mint(self) -> Tuple[str, str]:

View File

@ -19,7 +19,7 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
import click
from web3 import Web3
from nucypher.blockchain.eth.interfaces import BlockchainInterface, BlockchainInterfaceFactory
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import AllocationRegistry
from nucypher.blockchain.eth.token import NU
from nucypher.blockchain.eth.utils import datetime_at_period
@ -196,8 +196,12 @@ def stake(click_config,
elif action == 'set-worker':
if not staking_address:
staking_address = select_stake(stakeholder=STAKEHOLDER, emitter=emitter).staker_address
client_account, staking_address = handle_client_account_for_staking(emitter=emitter,
stakeholder=STAKEHOLDER,
staking_address=staking_address,
is_preallocation_staker=is_preallocation_staker,
beneficiary_address=beneficiary_address,
force=force)
if not worker_address:
worker_address = click.prompt("Enter worker address", type=EIP55_CHECKSUM_ADDRESS)
@ -206,9 +210,9 @@ def stake(click_config,
password = None
if not hw_wallet and not blockchain.client.is_local:
password = get_client_password(checksum_address=staking_address)
password = get_client_password(checksum_address=client_account)
STAKEHOLDER.assimilate(checksum_address=staking_address, password=password)
STAKEHOLDER.assimilate(checksum_address=client_account, password=password)
receipt = STAKEHOLDER.set_worker(worker_address=worker_address)
# TODO: Double-check dates
@ -230,8 +234,12 @@ def stake(click_config,
elif action == 'detach-worker':
if not staking_address:
staking_address = select_stake(stakeholder=STAKEHOLDER, emitter=emitter).staker_address
client_account, staking_address = handle_client_account_for_staking(emitter=emitter,
stakeholder=STAKEHOLDER,
staking_address=staking_address,
is_preallocation_staker=is_preallocation_staker,
beneficiary_address=beneficiary_address,
force=force)
if worker_address:
raise click.BadOptionUsage(message="detach-worker cannot be used together with --worker-address",
@ -243,11 +251,10 @@ def stake(click_config,
password = None
if not hw_wallet and not blockchain.client.is_local:
password = get_client_password(checksum_address=staking_address)
password = get_client_password(checksum_address=client_account)
# TODO: Create Stakeholder.detach_worker() and use it here
STAKEHOLDER.assimilate(checksum_address=staking_address, password=password)
receipt = STAKEHOLDER.set_worker(worker_address=BlockchainInterface.NULL_ADDRESS)
STAKEHOLDER.assimilate(checksum_address=client_account, password=password)
receipt = STAKEHOLDER.detach_worker()
# TODO: Double-check dates
current_period = STAKEHOLDER.staking_agent.get_current_period()
@ -326,12 +333,17 @@ def stake(click_config,
elif action == "restake":
# Authenticate
if not staking_address:
staking_address = select_stake(stakeholder=STAKEHOLDER, emitter=emitter).staker_address
client_account, staking_address = handle_client_account_for_staking(emitter=emitter,
stakeholder=STAKEHOLDER,
staking_address=staking_address,
is_preallocation_staker=is_preallocation_staker,
beneficiary_address=beneficiary_address,
force=force)
password = None
if not hw_wallet and not blockchain.client.is_local:
password = get_client_password(checksum_address=staking_address)
STAKEHOLDER.assimilate(checksum_address=staking_address, password=password)
password = get_client_password(checksum_address=client_account)
STAKEHOLDER.assimilate(checksum_address=client_account, password=password)
# Inner Exclusive Switch
if lock_until: