usawa

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

commit f505d46409c997d60582c35562b37a85edf2be50
parent c5336f91fee5ea735ab3ec87b99bf0bfee942a4a
Author: lash <dev@holbrook.no>
Date:   Sun,  8 Mar 2026 14:39:34 -0600

Add events add callback in ledger

Diffstat:
Mdummy/setup.py | 1-
Mdummy/usawa/crypto.py | 4++++
Mdummy/usawa/ledger.py | 17++++++++++++++++-
Mdummy/usawa/resolve/base.py | 1+
4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/dummy/setup.py b/dummy/setup.py @@ -14,7 +14,6 @@ setup( "confini~=0.6.5", "lxml~=6.0.2", "PyNaCl~=1.6.0", - "python-gnupg~=0.4.9", "rencode~=1.0.8", "hexathon~=0.1.7", "varints@file://" + varints_dir, diff --git a/dummy/usawa/crypto.py b/dummy/usawa/crypto.py @@ -162,6 +162,10 @@ class Wallet: return o + def __str__(self): + return self.did_uri() + + class DemoWallet(Wallet): """DemoWallet is an unsafe wallet implementation used during development. It implements the Wallet interface class. diff --git a/dummy/usawa/ledger.py b/dummy/usawa/ledger.py @@ -245,6 +245,7 @@ class Ledger: self.wallet = None self.lookup = None self.lookup_algo = 'sha512' + self.entry_cb = [] for k in self.uidx.syms(): if self.running.get(k) != None: @@ -298,6 +299,17 @@ class Ledger: self.sigs[pubkey] = b'' + """Add callback to be invoked for each entry added to the ledger. + + Callback will be passed entry as the sole argument. + + :param fn: Callback function + :type fn: function + """ + def register_callback(self, fn): + self.entry_cb.append(fn) + + """Retrieve the serial that will be assigned to the next entry, without incrementing it in the object state. :rtype: int @@ -475,7 +487,7 @@ class Ledger: #oldsum = self.cur #self.cur = entry.sum()[0] (k, v) = entry.get_lookup(self.lookup_algo) - logg.debug('addentr entry {} {}'.format(k, v)) + logg.debug('addentr entry for algo {}: {} {}'.format(self.lookup_algo, k, v)) #entry.parent = oldsum entry.parent = self.cur self.cur = bytes.fromhex(k) @@ -485,6 +497,9 @@ class Ledger: # Add entry to the ledger object. self.entries[entry.serial] = entry + for fn in self.entry_cb: + fn(entry) + """Update running total according to the entry. diff --git a/dummy/usawa/resolve/base.py b/dummy/usawa/resolve/base.py @@ -100,6 +100,7 @@ class BaseResolver: def put_entry(self, entry, lookup=None): k = None (k, v) = entry.sum() + logg.debug('putting entry {}'.format(v.decode('utf-8'))) self.put(k, v) if lookup != None: (k, v) = entry.get_lookup(lookup)