Build out BlockchainPower with unlock_account method

pull/327/head
tuxxy 2018-06-21 16:30:32 -06:00
parent c185f66485
commit b7215a6b0c
1 changed files with 23 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import inspect
import web3
from typing import List, Union
from nucypher.keystore import keypairs
@ -61,6 +62,28 @@ class CryptoPowerUp(object):
confers_public_key = False
class BlockchainPower(CryptoPowerUp):
"""
Allows for transacting on a Blockchain via web3 backend.
"""
def __init__(self, account: str):
"""
Instantiates a BlockchainPower for the given account id.
"""
self.account = account
def unlock_account(self, password: str, duration: int = None):
"""
Unlocks the account for the specified duration. If no duration is
provided, it will remain unlocked indefinitely.
"""
is_unlocked = web3.personal.unlockAccount(self.account, password,
duration=duration)
if not is_unlocked:
raise PowerUpError("Account failed to unlock for {}".format(self.account))
class KeyPairBasedPower(CryptoPowerUp):
confers_public_key = True
_keypair_class = keypairs.Keypair