handle case where purse expiration refunded the coin's deposited amount

This commit is contained in:
Christian Grothoff 2022-06-04 14:04:27 +02:00
parent 04c32eafb9
commit d04769b729
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 32 additions and 50 deletions

View File

@ -411,6 +411,8 @@ TEH_RESPONSE_compile_transaction_history (
: pd->exchange_base_url),
GNUNET_JSON_pack_data_auto ("purse_pub",
&pd->purse_pub),
GNUNET_JSON_pack_bool ("refunded",
pd->refunded),
GNUNET_JSON_pack_data_auto ("coin_sig",
&pd->coin_sig))))
{
@ -420,56 +422,6 @@ TEH_RESPONSE_compile_transaction_history (
}
break;
}
#if FIXME_PURSE_REFUND
case TALER_EXCHANGEDB_TT_PURSE_REFUND:
{
struct TALER_EXCHANGEDB_PurseRefundListEntry *pr
= pos->details.purse_refund;
struct TALER_ExchangePublicKeyP epub;
struct TALER_ExchangeSignatureP esig;
if (TALER_EC_NONE !=
TALER_exchange_online_purse_refund_sign (
&TEH_keys_exchange_sign_,
&pr->amount,
&pr->refund_fee,
&pr->purse_share_fee,
&pr->purse_pub,
coin_pub,
&epub,
&esig))
{
GNUNET_break (0);
json_decref (history);
return NULL;
}
if (0 !=
json_array_append_new (
history,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("type",
"PURSE-REFUND"),
TALER_JSON_pack_amount ("amount",
&pd->amount),
TALER_JSON_pack_amount ("refund_fee",
&pd->refund_fee),
TALER_JSON_pack_amount ("purse_share_fee",
&pd->purse_share_fee),
GNUNET_JSON_pack_data_auto ("purse_pub",
&pd->purse_pub),
GNUNET_JSON_pack_data_auto ("exchange_sig",
&esig),
GNUNET_JSON_pack_data_auto ("exchange_pub",
&epub))))
{
GNUNET_break (0);
json_decref (history);
return NULL;
}
break;
}
#endif
}
}
return history;

View File

@ -1269,9 +1269,12 @@ prepare_statements (struct PostgresClosure *pg)
",purse_pub"
",coin_sig"
",purse_deposit_serial_id"
",pr.refunded"
" FROM purse_deposits pd"
" LEFT JOIN partners"
" USING (partner_serial_id)"
" JOIN purse_requests pr"
" USING (purse_pub)"
" JOIN known_coins kc"
" ON (pd.coin_pub = kc.coin_pub)"
" JOIN denominations denoms"
@ -8314,6 +8317,8 @@ add_coin_purse_deposit (void *cls,
NULL),
GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
&deposit->coin_sig),
GNUNET_PQ_result_spec_bool ("refunded",
&deposit->refunded),
GNUNET_PQ_result_spec_end
};

View File

@ -1679,6 +1679,11 @@ struct TALER_EXCHANGEDB_PurseDepositListEntry
*/
struct TALER_CoinSpendSignatureP coin_sig;
/**
* Set to true if the coin was refunded.
*/
bool refunded;
};
/**

View File

@ -1185,6 +1185,7 @@ help_purse_deposit (struct CoinHistoryParseContext *pc,
struct TALER_PurseContractPublicKeyP purse_pub;
struct TALER_CoinSpendSignatureP coin_sig;
const char *exchange_base_url;
bool refunded;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("purse_pub",
&purse_pub),
@ -1192,6 +1193,8 @@ help_purse_deposit (struct CoinHistoryParseContext *pc,
&coin_sig),
GNUNET_JSON_spec_string ("exchange_base_url",
&exchange_base_url),
GNUNET_JSON_spec_bool ("refunded",
&refunded),
GNUNET_JSON_spec_end ()
};
@ -1214,6 +1217,23 @@ help_purse_deposit (struct CoinHistoryParseContext *pc,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
if (refunded)
{
/* We add the amount to refunds here, the original
deposit will be added to the balance later because
we still return GNUNET_YES, thus effectively
cancelling out this operation with respect to
the final balance. */
if (0 >
TALER_amount_add (&pc->rtotal,
&pc->rtotal,
amount))
{
/* overflow in refund history? inconceivable! Bad exchange! */
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
}
return GNUNET_YES;
}