From fd4a3b07c225bbfea5964faea1a80efffb27c569 Mon Sep 17 00:00:00 2001 From: Changaco Date: Sat, 5 Mar 2016 18:45:29 +0100 Subject: [PATCH] keep track of where money exiting the system came from part of #59 --- liberapay/billing/exchanges.py | 10 ++++++++++ sql/branch.sql | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 sql/branch.sql diff --git a/liberapay/billing/exchanges.py b/liberapay/billing/exchanges.py index 9a4725c15b..35dcd4bc3b 100644 --- a/liberapay/billing/exchanges.py +++ b/liberapay/billing/exchanges.py @@ -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) diff --git a/sql/branch.sql b/sql/branch.sql new file mode 100644 index 0000000000..11101907e3 --- /dev/null +++ b/sql/branch.sql @@ -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) +);