usawa

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | Submodules | LICENSE

commit fb90efce6f8ea5950fb6cb5bd952d5cd48a4fae2
parent 24247c8d31ef8e85ad3971d455c5fb27640bc395
Author: lash <dev@holbrook.no>
Date:   Thu, 15 Jan 2026 17:09:17 +0000

Use varints for running total allowing negative values

Diffstat:
A.gitmodules | 3+++
Adummy/aux/varints | 1+
Mdummy/setup.py | 14+++++++++++++-
Mdummy/usawa/ledger.py | 10+++++-----
Mdummy/usawa/runnable/add.py | 2+-
5 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dummy/aux/varints"] + path = dummy/aux/varints + url = https://github.com/bright-tools/varints diff --git a/dummy/aux/varints b/dummy/aux/varints @@ -0,0 +1 @@ +Subproject commit 1c74efcfa6e0be9df9916717f863d391339a4c6a diff --git a/dummy/setup.py b/dummy/setup.py @@ -1,8 +1,20 @@ +import os + from setuptools import setup +script_dir = os.path.realpath(os.path.dirname(__file__)) +aux_dir = os.path.join(script_dir, 'aux') +varints_dir = os.path.join(aux_dir, 'varints', 'varints') + + setup( install_requires=[ "wheepy[valkey]~=0.0.3", - "confini~=0.6.5" + "confini~=0.6.5", + "lxml~=6.0.2", + "PyNaCl~=1.6.0", + "python-gnupg~=0.4.9", + "rencode~=1.0.8", + "varints@file://" + varints_dir, ], ) diff --git a/dummy/usawa/ledger.py b/dummy/usawa/ledger.py @@ -6,6 +6,7 @@ import hashlib import lxml import rencode +import varints.leb128s from .crypto import DemoWallet, ACL from .xml import nsmap, XML_FORMAT_VERSION @@ -135,15 +136,14 @@ class RunningTotal: """ - :todo: Use varint in serialization, consider leb128 """ def serialize(self): d = [ self.sym, - self.income.to_bytes(8, byteorder='big'), - self.expense.to_bytes(8, byteorder='big'), - self.asset.to_bytes(8, byteorder='big'), - self.liability.to_bytes(8, byteorder='big'), + varints.leb128s.encode(self.income), + varints.leb128s.encode(self.expense), + varints.leb128s.encode(self.asset), + varints.leb128s.encode(self.liability), ] return rencode.dumps(d) diff --git a/dummy/usawa/runnable/add.py b/dummy/usawa/runnable/add.py @@ -174,7 +174,7 @@ if arg.i: ctx = do_interactive(ctx) ctx.validate() -entry = Entry(ctx.part[0], ctx.part[1], ctx.unit, ledger.serial, dt, parent=ledger.current(), description=ctx.description, ref=ctx.ref) +entry = Entry(ctx.part[0], ctx.part[1], ctx.unit, ledger.next_serial(), dt, parent=ledger.current(), description=ctx.description, ref=ctx.ref) entry.sign(wallet) store.add_entry(entry) ledger.add_entry(entry, modify_tree=True)