Add ledger.sats_on_hand for the current balance per account
This commit is contained in:
1 parent
165c600529
commit
8aa5798cb2
1 file changed
+15
@@ -284,6 +284,21 @@ def sats_in_market(market_id, date, conn=None):
|
||||
conn.close()
|
||||
|
||||
|
||||
def sats_on_hand(conn=None):
|
||||
"""Sats each account holds right now, as the ledger stands."""
|
||||
own = conn is None
|
||||
if own:
|
||||
conn = database.connect()
|
||||
try:
|
||||
rows = conn.execute(
|
||||
"SELECT market_id, SUM(sats_remaining) AS sats FROM lots GROUP BY market_id"
|
||||
).fetchall()
|
||||
return {row["market_id"]: row["sats"] for row in rows}
|
||||
finally:
|
||||
if own:
|
||||
conn.close()
|
||||
|
||||
|
||||
def _split_capped(total, weights):
|
||||
"""Hand out `total` over the weights, in order, never more than a weight."""
|
||||
cuts = []
|
||||
|
||||
Reference in new issue
Block a user