Workaround for #1385. Better logs when activating TransactingPowers

pull/1327/head
David Núñez 2019-10-02 15:25:00 +02:00
parent 91a5db16bb
commit f2e10106ef
4 changed files with 26 additions and 4 deletions

View File

@ -322,8 +322,17 @@ class GethClient(Web3Client):
# Geth --dev accounts are unlocked by default.
return True
debug_message = f"Unlocking account {address}"
if duration is None:
debug_message += f" for 5 minutes"
elif duration == 0:
debug_message += f" indefinitely"
elif duration > 0:
debug_message += f" for {duration} seconds"
if password is None:
debug_message += " with no password."
self.log.debug(debug_message)
return self.w3.geth.personal.unlockAccount(address, password, duration)

View File

@ -1390,6 +1390,7 @@ class StakeHolder(Staker):
self.__get_accounts()
if checksum_address not in self:
raise self.UnknownAccount
# TODO: What if cached TransactingPower is wrongly initialized? See issue #1385
try:
transacting_power = self.__transacting_powers[checksum_address]
except KeyError:
@ -1433,17 +1434,27 @@ class StakeHolder(Staker):
@validate_checksum_address
def assimilate(self, checksum_address: str, password: str = None) -> None:
if self.is_contract:
original_form = f"{self.beneficiary_address[0:8]} (contract {self.checksum_address[0:8]})"
else:
original_form = self.checksum_address
# This handles both regular staking and staking via a contract
staking_contract_address = self.check_if_staking_via_contract(checksum_address)
staking_address = staking_contract_address or checksum_address
self.wallet.activate_account(checksum_address=checksum_address, password=password)
original_form = self.checksum_address
self.checksum_address = staking_address
self.stakes = StakeList(registry=self.registry, checksum_address=staking_address)
self.stakes.refresh()
# TODO: Not sure how to log all this new info (i.e. old or new address may be via contract)
self.log.info(f"Resistance is futile - Assimilating Staker {original_form} -> {checksum_address}.")
if self.is_contract:
new_form = f"{self.beneficiary_address[0:8]} (contract {self.checksum_address[0:8]})"
else:
new_form = self.checksum_address
self.log.info(f"Resistance is futile - Assimilating Staker {original_form} -> {new_form}.")
@property
def all_stakes(self) -> list:

View File

@ -166,8 +166,10 @@ def stake(click_config,
allocation_registry = None
initial_address = staking_address
dummy_password = "Look Away, I'm Hideous" # TODO: See #1385
STAKEHOLDER = stakeholder_config.produce(initial_address=initial_address,
allocation_registry=allocation_registry)
allocation_registry=allocation_registry,
password=dummy_password)
blockchain = BlockchainInterfaceFactory.get_interface(provider_uri=provider_uri) # Eager connection
economics = STAKEHOLDER.economics

View File

@ -123,7 +123,7 @@ class TransactingPower(CryptoPowerUp):
self.blockchain = BlockchainInterfaceFactory.get_or_create_interface(provider_uri=provider_uri)
self.__account = account
# TODO: Is there a better way to design this Flag?
# TODO: Is there a better way to design this Flag? See #1385
self.device = True if not password else False
self.__password = password