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())
|
f.write(self.as_json())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, path: str) -> 'Keystore':
|
def from_json(cls, json_dict: Dict[Any, Any]) -> 'Keystore':
|
||||||
with open(path, 'r') as f:
|
|
||||||
json_dict = json.load(f)
|
|
||||||
crypto = KeystoreCrypto.from_json(json_dict['crypto'])
|
crypto = KeystoreCrypto.from_json(json_dict['crypto'])
|
||||||
path = json_dict['path']
|
path = json_dict['path']
|
||||||
uuid = json_dict['uuid']
|
uuid = json_dict['uuid']
|
||||||
@ -109,6 +108,11 @@ class Keystore(BytesDataclass):
|
|||||||
pubkey = json_dict.get('pubkey', '')
|
pubkey = json_dict.get('pubkey', '')
|
||||||
return cls(crypto=crypto, description=description, pubkey=pubkey, path=path, uuid=uuid, version=version)
|
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
|
@staticmethod
|
||||||
def _process_password(password: str) -> bytes:
|
def _process_password(password: str) -> bytes:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user