From 6b470080eb3cbbc1f82d4899ff103204201ec023 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 11 Sep 2022 14:46:23 +0300 Subject: [PATCH] mint start --- mint/app.py | 2 ++ mint/crud.py | 13 +++++++++++++ mint/ledger.py | 7 +++++-- pyproject.toml | 2 +- requirements.txt | 1 - 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mint/app.py b/mint/app.py index 582a43c..f910cea 100644 --- a/mint/app.py +++ b/mint/app.py @@ -21,6 +21,8 @@ class MyFlaskApp(Flask): def __init__(self, *args, **kwargs): async def create_tasks_func(): await asyncio.wait([m001_initial(ledger.db)]) + await ledger.load_used_proofs() + print("Mint started.") loop = asyncio.get_event_loop() loop.run_until_complete(create_tasks_func()) diff --git a/mint/crud.py b/mint/crud.py index c29e3a7..ae82ef8 100644 --- a/mint/crud.py +++ b/mint/crud.py @@ -29,6 +29,19 @@ async def store_promise( ) +async def get_proofs_used( + db: Database, + conn: Optional[Connection] = None, +): + + rows = await (conn or db).fetchall( + """ + SELECT secret from proofs_used + """ + ) + return [row[0] for row in rows] + + async def invalidate_proof( proof: dict, db: Database, diff --git a/mint/ledger.py b/mint/ledger.py index 3a6213b..6dfb705 100644 --- a/mint/ledger.py +++ b/mint/ledger.py @@ -11,16 +11,19 @@ import core.b_dhke as b_dhke from core.db import Database from core.split import amount_split from core.settings import MAX_ORDER -from mint.crud import store_promise, invalidate_proof +from mint.crud import store_promise, invalidate_proof, get_proofs_used class Ledger: def __init__(self, secret_key: str, db: str): self.master_key = secret_key - self.proofs_used = set() # no promise proofs have been used + self.proofs_used = set() self.keys = self._derive_keys(self.master_key) self.db = Database("mint", db) + async def load_used_proofs(self): + self.proofs_used = await get_proofs_used(db=self.db) + @staticmethod def _derive_keys(master_key): """Deterministic derivation of keys for 2^n values.""" diff --git a/pyproject.toml b/pyproject.toml index bedda7d..9cc0d74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ MarkupSafe = "2.1.1" urllib3 = "1.26.9" Werkzeug = "2.0.3" ecc-pycrypto = {git = "https://github.com/lc6chang/ecc-pycrypto.git", rev = "v1.0.1"} -psycopg2-binary = "^2.9.3" +psycopg2 = "^2.9.3" [tool.poetry.dev-dependencies] diff --git a/requirements.txt b/requirements.txt index 7ac7107..7febd7c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ ecc==0.0.1 -ecc_pycrypto==1.0.0 psycopg2==2.9.3 pytest_asyncio==0.19.0 SQLAlchemy==1.3.24