diff --git a/doc/prebuilt b/doc/prebuilt index 1ed97b23f..b988d98d4 160000 --- a/doc/prebuilt +++ b/doc/prebuilt @@ -1 +1 @@ -Subproject commit 1ed97b23f19c80fa84b21a5eb0c686d5491e8ec6 +Subproject commit b988d98d4856758484eb23c27bfdc9e602d4235a diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index ee120a01c..277e3bc4f 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -1778,10 +1778,31 @@ prepare_statements (struct PostgresClosure *pg) " FROM refunds" " WHERE coin_pub IN (SELECT coin_pub FROM dep)" " AND deposit_serial_id IN (SELECT deposit_serial_id FROM dep))" - " ,fees AS (" /* find deposit fees for non-refunded deposits */ - // FIXME: this is wrong, the deposit fee is waived IF the - // refunds were for 100% of the deposit value. This logic - // ignores this detail :-(. + " ,ref_by_coin AS (" /* total up refunds by coin */ + " SELECT" + " SUM(refund_val) AS sum_refund_val" + " ,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" " denom.fee_deposit_val AS fee_val" " ,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? */ " USING (coin_pub)" " 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 */ " INSERT INTO aggregation_tracking" " (deposit_serial_id"