usawa

Signed, immutable accounting.
Log | Files | Refs | Submodules | LICENSE

commit b3490b42dca1b84a4daada2e83611f6c1a77ae0f
parent 099c2f74e1564c6e554e2fdb79ea2e50332b5ff0
Author: lash <dev@holbrook.no>
Date:   Thu, 26 Mar 2026 14:44:08 -0600

WIP Add fs store option

Diffstat:
Mdummy/setup.py | 3++-
Mdummy/usawa/core/chain_manager.py | 4++--
Mdummy/usawa/data/usawa.ini | 3+++
Mdummy/usawa/gui/__init__.py | 5+++--
Mdummy/usawa/gui/main_window.py | 22+++++++++++++++++-----
Mdummy/usawa/runnable/asset.py | 5++++-
Mdummy/usawa/runnable/entry.py | 19++++---------------
Mdummy/usawa/runnable/setup_wallet.py | 41+++++++++++++++++++++++++++++++++++++----
8 files changed, 72 insertions(+), 30 deletions(-)

diff --git a/dummy/setup.py b/dummy/setup.py @@ -10,12 +10,13 @@ varints_dir = os.path.join(aux_dir, 'varints', 'varints') setup( install_requires=[ "filemagic~=1.6", - "wheepy[valkey]~=0.0.3", + "wheepy[valkey,fs]~=0.0.5a2", "confini~=0.6.5", "lxml~=6.0.2", "PyNaCl~=1.6.0", "rencode~=1.0.8", "hexathon~=0.1.7", + "xdg-base-dirs~=6.0.2", "varints@file://" + varints_dir, ], ) diff --git a/dummy/usawa/core/chain_manager.py b/dummy/usawa/core/chain_manager.py @@ -123,6 +123,7 @@ class LedgerChainManager: """ next_path = self.derive_next() + raise NotImplementedError('not sure if we need this') db = ValkeyStore('') store = LedgerStore(db, ledger) @@ -154,4 +155,4 @@ class LedgerChainManager: def __repr__(self): - return 'LedgerChainManager(depth={}, current={})'.format(self.depth(), self.current()) -\ No newline at end of file + return 'LedgerChainManager(depth={}, current={})'.format(self.depth(), self.current()) diff --git a/dummy/usawa/data/usawa.ini b/dummy/usawa/data/usawa.ini @@ -22,3 +22,6 @@ store_path= [store] type = valkey + +[fsstore] +base = diff --git a/dummy/usawa/gui/__init__.py b/dummy/usawa/gui/__init__.py @@ -50,6 +50,8 @@ class Usawa(Adw.Application): else: filtered_args.append(args[i]) i += 1 + self.cfg = load_config(config_dir=config_dir) + logg.debug('config-dump:\n{}'.format(self.cfg)) if len(filtered_args) == 0: logg.error("missing ledger file argument") @@ -57,11 +59,10 @@ class Usawa(Adw.Application): if filtered_args[0] == "setup-wallet": wallet_dir = filtered_args[1] if len(filtered_args) > 1 else None - setup_wallet(wallet_dir=wallet_dir) + setup_wallet(self.cfg, wallet_dir=wallet_dir) return 0 self.ledger_file = filtered_args[0] - self.cfg = load_config(config_dir=config_dir) for k in self.cfg.all(): logg.debug("config {} => {}".format(k, self.cfg.get(k))) self.activate() diff --git a/dummy/usawa/gui/main_window.py b/dummy/usawa/gui/main_window.py @@ -18,6 +18,7 @@ from usawa.gui.views.entry_list_view import EntryListView from datetime import datetime from usawa.store import LedgerStore from whee.valkey import ValkeyStore +from whee.fs import FsStore logg = logging.getLogger("gui.mainwindow") @@ -48,9 +49,20 @@ class UsawaMainWindow(Adw.ApplicationWindow): self.cfg = self.get_application().cfg self.unix_client = UnixClient(path=self.cfg.get("SERVER_SOCKET_FILE_PATH")) - self.valkey_store = ValkeyStore( - "", host=self.cfg.get("VALKEY_HOST"), port=self.cfg.get("VALKEY_PORT") - ) + store_type = self.cfg.get('STORE_TYPE') + if store_type == 'valkey': + self.store = ValkeyStore( + "", + host=self.cfg.get("VALKEY_HOST"), + port=self.cfg.get("VALKEY_PORT"), + ) + elif store_type == 'fs': + self.store = FsStore( + base=self.cfg.get('FSSTORE_BASE'), + ) + else: + raise ValueError('invalid store type: ' + store_type) + self.ledger_path = ledger_path self.nav_view = Adw.NavigationView() @@ -141,7 +153,7 @@ class UsawaMainWindow(Adw.ApplicationWindow): else: ledger_tree = load(self.ledger_path) ledger = Ledger.from_tree(ledger_tree) - store = LedgerStore(self.valkey_store, ledger) + store = LedgerStore(self.store, ledger) dialog = PassphraseDialog( store=store, wallet_class=DemoWallet, @@ -159,7 +171,7 @@ class UsawaMainWindow(Adw.ApplicationWindow): repository = LedgerRepository( ledger_path=self.ledger_path, unix_client=self.unix_client, - valkey_store=self.valkey_store, + valkey_store=self.store, cfg=self.cfg, wallet=self.wallet, ) diff --git a/dummy/usawa/runnable/asset.py b/dummy/usawa/runnable/asset.py @@ -24,7 +24,10 @@ class Context: host = self.cfg.get('VALKEY_HOST') port = self.cfg.get('VALKEY_PORT') self.db = ValkeyStore('', host=host, port=port) - self.store = AssetStore(self.db) + elif self.cfg.get('STORE_TYPE') == 'fs': + base = self.cfg.get('FSSTORE_BASE') + self.db = FsStore(base=base, dbname='usawa') + self.store = LedgerStore(self.db, self.ledger) if args.f: self.asset = Asset.from_file(args.f, extref=args.e, mimetype=args.m, slug=args.n) diff --git a/dummy/usawa/runnable/entry.py b/dummy/usawa/runnable/entry.py @@ -7,6 +7,7 @@ import sys import shutil from whee.valkey import ValkeyStore +from whee.fs import FsStore import usawa.config from usawa import Entry, Ledger, EntryPart, Asset, DemoWallet @@ -72,6 +73,9 @@ class Context: host = self.cfg.get('VALKEY_HOST') port = self.cfg.get('VALKEY_PORT') self.db = ValkeyStore('', host=host, port=port) + elif self.cfg.get('STORE_TYPE') == 'fs': + base = self.cfg.get('FSSTORE_BASE') + self.db = FsStore(base=base, dbname='usawa') self.store = LedgerStore(self.db, self.ledger) self.wallet = self.store.get_key(DemoWallet, passphrase=self.cfg.get('WALLET_KEY_PASSPHRASE')) self.ledger.set_wallet(self.wallet) @@ -87,15 +91,6 @@ class Context: self.havedst = False self.i = 0 -# -# def open(self, output): -# if output == '<stdout>': -# self.f = sys.stdout -# logg.debug('output is stdout') -# else: -# self.f = open(output, 'w') -# return self - def parse_type(self, v): v = v.lower() @@ -150,12 +145,6 @@ class Context: raise ValueError('invalid ref') -# def close(self): -# if self.f and self.f != sys.stdout: -# self.f.close() -# - - argp = argparse.ArgumentParser() argp.add_argument('-e', type=str, help='unique reference of entry') argp.add_argument('-x', type=str, action='append', default=[], help='unique reference of attachment') diff --git a/dummy/usawa/runnable/setup_wallet.py b/dummy/usawa/runnable/setup_wallet.py @@ -1,3 +1,4 @@ +import argparse import getpass import logging import os @@ -6,15 +7,20 @@ from nacl.signing import SigningKey from nacl.secret import SecretBox from nacl.pwhash import argon2i from whee.valkey import ValkeyStore +from whee.fs import FsStore +from xdg_base_dirs import xdg_data_home from usawa.store import KeyStore from usawa.crypto import DemoWallet +from usawa.config import load_config -logg = logging.getLogger("core.setup_wallet") +logging.basicConfig(level=logging.WARNING) +logg = logging.getLogger() PRIVATEKEY_FILE = "privatekey.box" PUBLICKEY_FILE = "publickey.bin" +# TODO: change to xdg_data_dir DEFAULT_WALLET_DIR = ( Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local/share")) / "usawa" ) @@ -34,8 +40,23 @@ def encrypt_seed(seed: bytes, passphrase: str) -> bytes: return salt + encrypted -def setup_wallet(wallet_dir=None): - db = ValkeyStore('') +def setup_wallet(cfg, wallet_dir=None): + db = None + store_type = cfg.get('STORE_TYPE') + if store_type == 'valkey': + db = ValkeyStore( + "", + host=cfg.get("VALKEY_HOST"), + port=cfg.get("VALKEY_PORT"), + ) + elif store_type == 'fs': + db = FsStore( + base=cfg.get('FSSTORE_BASE', xdg_data_home()), + dbname='usawa', + ) + else: + raise ValueError('invalid store type: ' + store_type) + store = KeyStore(db) wallet_dir = Path(wallet_dir) if wallet_dir else DEFAULT_WALLET_DIR @@ -72,5 +93,17 @@ def setup_wallet(wallet_dir=None): logg.info("setup complete.") logg.info("your 32-byte public key (hex): %s", pk.encode().hex()) - return 0 + + +if __name__ == '__main__': + argp = argparse.ArgumentParser() + argp.add_argument('-c', type=str, help='override config dir') + argp.add_argument('-v', type=str, choices=['info','debug','warning','error'], help='be verbose') + args = argp.parse_args() + + if args.v: + logg.setLevel(getattr(logging, args.v.upper())) + + cfg = load_config(config_dir=args.c) + setup_wallet(cfg)