-fix full refund deposit fee computation in aggregator
This commit is contained in:
parent
45f43fcde7
commit
4e5193a21f
@ -1 +1 @@
|
|||||||
Subproject commit 1ed97b23f19c80fa84b21a5eb0c686d5491e8ec6
|
Subproject commit b988d98d4856758484eb23c27bfdc9e602d4235a
|
@ -1778,10 +1778,31 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
" FROM refunds"
|
" FROM refunds"
|
||||||
" WHERE coin_pub IN (SELECT coin_pub FROM dep)"
|
" WHERE coin_pub IN (SELECT coin_pub FROM dep)"
|
||||||
" AND deposit_serial_id IN (SELECT deposit_serial_id FROM dep))"
|
" AND deposit_serial_id IN (SELECT deposit_serial_id FROM dep))"
|
||||||
" ,fees AS (" /* find deposit fees for non-refunded deposits */
|
" ,ref_by_coin AS (" /* total up refunds by coin */
|
||||||
// FIXME: this is wrong, the deposit fee is waived IF the
|
" SELECT"
|
||||||
// refunds were for 100% of the deposit value. This logic
|
" SUM(refund_val) AS sum_refund_val"
|
||||||
// ignores this detail :-(.
|
" ,SUM(refund_frac) AS sum_refund_frac"
|
||||||
|
" ,coin_pub"
|
||||||
|
" ,deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
|
||||||
|
" FROM ref"
|
||||||
|
" GROUP BY coin_pub, deposit_serial_id)"
|
||||||
|
" ,norm_ref_by_coin AS (" /* normalize */
|
||||||
|
" SELECT"
|
||||||
|
" sum_refund_val + sum_refund_frac / 100000000 AS norm_refund_val"
|
||||||
|
" ,sum_refund_frac % 100000000 AS norm_refund_frac"
|
||||||
|
" ,coin_pub"
|
||||||
|
" ,deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
|
||||||
|
" FROM ref_by_coin)"
|
||||||
|
" ,fully_refunded_coins AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
|
||||||
|
" SELECT"
|
||||||
|
" dep.coin_pub"
|
||||||
|
" FROM norm_ref_by_coin norm"
|
||||||
|
" JOIN dep"
|
||||||
|
" ON (norm.coin_pub = dep.coin_pub"
|
||||||
|
" AND norm.deposit_serial_id = dep.deposit_Serial_id"
|
||||||
|
" AND norm.norm_refund_val = dep.amount_val"
|
||||||
|
" AND norm.norm_refund_frac = dep.amount_frac))"
|
||||||
|
" ,fees AS (" /* find deposit fees for not fully refunded deposits */
|
||||||
" SELECT"
|
" SELECT"
|
||||||
" denom.fee_deposit_val AS fee_val"
|
" denom.fee_deposit_val AS fee_val"
|
||||||
" ,denom.fee_deposit_frac AS fee_frac"
|
" ,denom.fee_deposit_frac AS fee_frac"
|
||||||
@ -1790,7 +1811,8 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
" JOIN known_coins kc" /* NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
|
" JOIN known_coins kc" /* NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
|
||||||
" USING (coin_pub)"
|
" USING (coin_pub)"
|
||||||
" JOIN denominations denom"
|
" JOIN denominations denom"
|
||||||
" USING (denominations_serial))"
|
" USING (denominations_serial)"
|
||||||
|
" WHERE coin_pub NOT IN (SELECT coin_pub FROM fully_refunded_coins))"
|
||||||
" ,dummy AS (" /* add deposits to aggregation_tracking */
|
" ,dummy AS (" /* add deposits to aggregation_tracking */
|
||||||
" INSERT INTO aggregation_tracking"
|
" INSERT INTO aggregation_tracking"
|
||||||
" (deposit_serial_id"
|
" (deposit_serial_id"
|
||||||
|
Loading…
Reference in New Issue
Block a user