-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepository.py
More file actions
42 lines (33 loc) · 1.23 KB
/
repository.py
File metadata and controls
42 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import bdkpython as bdk
import pickle
from typing import Type
class Repository(object):
_instance = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(Repository, cls).__new__(cls)
return cls._instance
def __init__(self, pkl_file, data=None) -> None:
if data:
self.data = data
else:
self.data = {}
self.pkl_file = pkl_file
def persist(self) -> None:
with open(self.pkl_file, "wb") as f:
pickle.dump(self.data, f)
@staticmethod
def load(pkl_file) -> Type["Repository"]:
with open(pkl_file, "rb") as f:
data = pickle.load(f)
return Repository(pkl_file=pkl_file, data=data)
def save_wallet(
self, external_descriptor: bdk.Descriptor, internal_descriptor: bdk.Descriptor
) -> None:
self.data["wallet_initialized"] = True
self.data["external_descriptor"] = external_descriptor.as_string()
self.data["internal_descriptor"] = internal_descriptor.as_string()
def save_mnemonic(self, mnemonic: str) -> None:
self.data["mnemonic"] = mnemonic.as_string()
def get_mnemonic(self) -> str:
return self.data["mnemonic"]