Skip to content

Commit

Permalink
keep track of where money exiting the system came from
Browse files Browse the repository at this point in the history
part of #59
  • Loading branch information
Changaco committed Mar 5, 2016
1 parent 034de67 commit fd4a3b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions liberapay/billing/exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,22 @@ def propagate_exchange(cursor, participant, exchange, route, error, amount):
raise NotEnoughWithdrawableMoney(Money(withdrawable, 'EUR'))
for b in bundles:
if x >= b.amount:
cursor.run("""
INSERT INTO e2e_transfers
(origin, withdrawal, amount)
VALUES (%s, %s, %s)
""", (b.origin, exchange.id, b.amount))
cursor.run("DELETE FROM cash_bundles WHERE id = %s", (b.id,))
x -= b.amount
if x == 0:
break
else:
assert x > 0
cursor.run("""
INSERT INTO e2e_transfers
(origin, withdrawal, amount)
VALUES (%s, %s, %s)
""", (b.origin, exchange.id, x))
cursor.run("""
UPDATE cash_bundles
SET amount = (amount - %s)
Expand Down
6 changes: 6 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE e2e_transfers
( id bigserial PRIMARY KEY
, origin bigint NOT NULL REFERENCES exchanges
, withdrawal bigint NOT NULL REFERENCES exchanges
, amount numeric(35,2) NOT NULL CHECK (amount > 0)
);

0 comments on commit fd4a3b0

Please sign in to comment.