mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2025-01-10 21:11:21 +00:00
Proposed tweak to from_json and from_file
This feels to me like it would be more intuitive behavior; the `from_json` behaves the same way for Keystore and KeystoreCrypto, and it exposes a way for people to use the library with json that is not saved in a file anywhere.
This commit is contained in:
parent
9310de0ff3
commit
0bfb657894
@ -98,9 +98,8 @@ class Keystore(BytesDataclass):
|
||||
f.write(self.as_json())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, path: str) -> 'Keystore':
|
||||
with open(path, 'r') as f:
|
||||
json_dict = json.load(f)
|
||||
def from_json(cls, json_dict: Dict[Any, Any]) -> 'Keystore':
|
||||
|
||||
crypto = KeystoreCrypto.from_json(json_dict['crypto'])
|
||||
path = json_dict['path']
|
||||
uuid = json_dict['uuid']
|
||||
@ -108,6 +107,11 @@ class Keystore(BytesDataclass):
|
||||
description = json_dict.get('description', '')
|
||||
pubkey = json_dict.get('pubkey', '')
|
||||
return cls(crypto=crypto, description=description, pubkey=pubkey, path=path, uuid=uuid, version=version)
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, path: str) -> 'KeyStore':
|
||||
with open(path, 'r') as f:
|
||||
return cls.from_json(json.load(f))
|
||||
|
||||
@staticmethod
|
||||
def _process_password(password: str) -> bytes:
|
||||
|
Loading…
Reference in New Issue
Block a user