Mirror kroner and write no pair for a withdrawal
This commit is contained in:
1 parent
1436b275a6
commit
5a773b9071
1 file changed
+12
-10
@@ -235,13 +235,12 @@ def _write_transaction(conn, tx_id, tx, picks):
|
|||||||
def _sync_transfer_pair(conn, tx_id, previous, tx):
|
def _sync_transfer_pair(conn, tx_id, previous, tx):
|
||||||
"""Keep the generated transfer_in in step with its transfer_out."""
|
"""Keep the generated transfer_in in step with its transfer_out."""
|
||||||
group = previous["transfer_group"] if previous else None
|
group = previous["transfer_group"] if previous else None
|
||||||
if tx["type"] == "transfer_out":
|
if tx["type"] == "transfer_out" and tx["to_market_id"]:
|
||||||
if not group:
|
if not group:
|
||||||
group = uuid.uuid4().hex
|
group = uuid.uuid4().hex
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"UPDATE transactions SET transfer_group = ? WHERE id = ?", (group, tx_id)
|
"UPDATE transactions SET transfer_group = ? WHERE id = ?", (group, tx_id)
|
||||||
)
|
)
|
||||||
arrived = tx["leg_out_sats"] or 0
|
|
||||||
now = _now_stamp()
|
now = _now_stamp()
|
||||||
row = conn.execute(
|
row = conn.execute(
|
||||||
"SELECT id FROM transactions WHERE type = 'transfer_in' AND transfer_group = ?",
|
"SELECT id FROM transactions WHERE type = 'transfer_in' AND transfer_group = ?",
|
||||||
@@ -250,20 +249,23 @@ def _sync_transfer_pair(conn, tx_id, previous, tx):
|
|||||||
if row is None:
|
if row is None:
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"INSERT INTO transactions (date, type, market_id, taxable, note, leg_in_sats,"
|
"INSERT INTO transactions (date, type, market_id, taxable, note, leg_in_sats,"
|
||||||
" fee_sats, fee_ore, to_market_id, transfer_group, generated, created_at,"
|
" leg_in_ore, fee_sats, fee_ore, to_market_id, transfer_group, generated,"
|
||||||
" updated_at) VALUES (?, 'transfer_in', ?, ?, '', ?, 0, 0, ?, ?, 1, ?, ?)",
|
" created_at, updated_at)"
|
||||||
(tx["date"], tx["to_market_id"], tx["taxable"], arrived,
|
" VALUES (?, 'transfer_in', ?, ?, '', ?, ?, 0, 0, ?, ?, 1, ?, ?)",
|
||||||
tx["market_id"], group, now, now),
|
(tx["date"], tx["to_market_id"], tx["taxable"], tx["leg_out_sats"],
|
||||||
|
tx["leg_out_ore"], tx["market_id"], group, now, now),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"UPDATE transactions SET date = ?, market_id = ?, taxable = ?,"
|
"UPDATE transactions SET date = ?, market_id = ?, taxable = ?,"
|
||||||
" leg_in_sats = ?, fee_sats = 0, fee_ore = 0, to_market_id = ?,"
|
" leg_in_sats = ?, leg_in_ore = ?, fee_sats = 0, fee_ore = 0,"
|
||||||
" generated = 1, updated_at = ? WHERE id = ?",
|
" to_market_id = ?, generated = 1, updated_at = ? WHERE id = ?",
|
||||||
(tx["date"], tx["to_market_id"], tx["taxable"], arrived,
|
(tx["date"], tx["to_market_id"], tx["taxable"], tx["leg_out_sats"],
|
||||||
tx["market_id"], now, row["id"]),
|
tx["leg_out_ore"], tx["market_id"], now, row["id"]),
|
||||||
)
|
)
|
||||||
elif group:
|
elif group:
|
||||||
|
# The transaction is no longer a transfer with a destination: an empty
|
||||||
|
# `Til` is a withdrawal, and it leaves no pair behind (section 3.11).
|
||||||
_drop_ledger(conn)
|
_drop_ledger(conn)
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"DELETE FROM transactions WHERE type = 'transfer_in' AND transfer_group = ?",
|
"DELETE FROM transactions WHERE type = 'transfer_in' AND transfer_group = ?",
|
||||||
|
|||||||
Reference in new issue
Block a user