def __init__(self, datadir): keyfile = path.join(datadir, 'ethkey.json') if path.exists(keyfile): data = json.load(open(keyfile, 'r')) self.priv = keys.decode_keystore_json(data, "FIXME: password!") else: self.priv = os.urandom(32) data = keys.make_keystore_json(self.priv, "FIXME: password!") json.dump(data, open(keyfile, 'w')) self.address = keys.privtoaddr(self.priv)
def new(cls, password, key=None, uuid=None, path=None): """Create a new account. Note that this creates the account in memory and does not store it on disk. :param password: the password used to encrypt the private key :param key: the private key, or `None` to generate a random one :param uuid: an optional id """ if key is None: key = mk_random_privkey() keystore = keys.make_keystore_json(key, password) keystore['id'] = uuid return Account(keystore, password, path)