add logic to return information about purse refunds in coin histories
This commit is contained in:
parent
5f333f817c
commit
eebc030f6c
@ -131,6 +131,26 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
|
||||
}
|
||||
deposit_fee = pos->details.purse_deposit->deposit_fee;
|
||||
break;
|
||||
case TALER_EXCHANGEDB_TT_PURSE_REFUND:
|
||||
/* refunded += pos->refund_amount - pos->refund_fee */
|
||||
if (0 >
|
||||
TALER_amount_add (&refunded,
|
||||
&refunded,
|
||||
&pos->details.purse_refund->refund_amount))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (0 >
|
||||
TALER_amount_add (&spent,
|
||||
&spent,
|
||||
&pos->details.purse_refund->refund_fee))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
have_refund = true;
|
||||
break;
|
||||
case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
|
||||
/* spent += pos->amount_with_fee */
|
||||
if (0 >
|
||||
|
@ -343,6 +343,63 @@ add_coin_refund (void *cls,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to be called with the results of a SELECT statement
|
||||
* that has returned @a num_results results.
|
||||
*
|
||||
* @param cls closure of type `struct CoinHistoryContext`
|
||||
* @param result the postgres result
|
||||
* @param num_results the number of results in @a result
|
||||
*/
|
||||
static void
|
||||
add_coin_purse_refund (void *cls,
|
||||
PGresult *result,
|
||||
unsigned int num_results)
|
||||
{
|
||||
struct CoinHistoryContext *chc = cls;
|
||||
struct PostgresClosure *pg = chc->pg;
|
||||
|
||||
for (unsigned int i = 0; i<num_results; i++)
|
||||
{
|
||||
struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund;
|
||||
struct TALER_EXCHANGEDB_TransactionList *tl;
|
||||
uint64_t serial_id;
|
||||
|
||||
prefund = GNUNET_new (struct TALER_EXCHANGEDB_PurseRefundListEntry);
|
||||
{
|
||||
struct GNUNET_PQ_ResultSpec rs[] = {
|
||||
GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
|
||||
&prefund->purse_pub),
|
||||
TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
|
||||
&prefund->refund_amount),
|
||||
TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
|
||||
&prefund->refund_fee),
|
||||
GNUNET_PQ_result_spec_uint64 ("purse_refunds_serial_id",
|
||||
&serial_id),
|
||||
GNUNET_PQ_result_spec_end
|
||||
};
|
||||
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_PQ_extract_result (result,
|
||||
rs,
|
||||
i))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
GNUNET_free (prefund);
|
||||
chc->failed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
|
||||
tl->next = chc->head;
|
||||
tl->type = TALER_EXCHANGEDB_TT_PURSE_REFUND;
|
||||
tl->details.purse_refund = prefund;
|
||||
tl->serial_id = serial_id;
|
||||
chc->head = tl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to be called with the results of a SELECT statement
|
||||
* that has returned @a num_results results.
|
||||
@ -629,6 +686,9 @@ TEH_PG_get_coin_transactions (
|
||||
/** #TALER_EXCHANGEDB_TT_PURSE_DEPOSIT */
|
||||
{ "get_purse_deposit_by_coin_pub",
|
||||
&add_coin_purse_deposit },
|
||||
/** #TALER_EXCHANGEDB_TT_PURSE_REFUND */
|
||||
{ "get_purse_refund_by_coin_pub",
|
||||
&add_coin_purse_refund },
|
||||
/** #TALER_EXCHANGEDB_TT_REFUND */
|
||||
{ "get_refunds_by_coin",
|
||||
&add_coin_refund },
|
||||
@ -748,6 +808,23 @@ TEH_PG_get_coin_transactions (
|
||||
" JOIN denominations denom"
|
||||
" USING (denominations_serial)"
|
||||
" WHERE ref.coin_pub=$1;");
|
||||
PREPARE (pg,
|
||||
"get_purse_refund_by_coin",
|
||||
"SELECT"
|
||||
" pr.purse_pub"
|
||||
",pd.amount_with_fee_val"
|
||||
",pd.amount_with_fee_frac"
|
||||
",denom.fee_refund_val "
|
||||
",denom.fee_refund_frac "
|
||||
",pr.purse_refunds_serial_id"
|
||||
" FROM purse_deposits pd"
|
||||
" JOIN purse_refunds pr"
|
||||
" USING (purse_pub)"
|
||||
" JOIN known_coins kc"
|
||||
" ON (pd.coin_pub = kc.coin_pub)"
|
||||
" JOIN denominations denom"
|
||||
" USING (denominations_serial)"
|
||||
" WHERE pd.coin_pub=$1;");
|
||||
PREPARE (pg,
|
||||
"recoup_by_old_coin",
|
||||
"SELECT"
|
||||
|
@ -152,6 +152,14 @@ TEH_COMMON_free_coin_transaction_list (
|
||||
GNUNET_free (deposit);
|
||||
break;
|
||||
}
|
||||
case TALER_EXCHANGEDB_TT_PURSE_REFUND:
|
||||
{
|
||||
struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund;
|
||||
|
||||
prefund = tl->details.purse_refund;
|
||||
GNUNET_free (prefund);
|
||||
break;
|
||||
}
|
||||
case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
|
||||
{
|
||||
struct TALER_EXCHANGEDB_ReserveOpenListEntry *role;
|
||||
|
@ -1788,6 +1788,31 @@ struct TALER_EXCHANGEDB_PurseDepositListEntry
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specification for a purse refund operation in a coin's transaction list.
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_PurseRefundListEntry
|
||||
{
|
||||
|
||||
/**
|
||||
* Public key of the purse.
|
||||
*/
|
||||
struct TALER_PurseContractPublicKeyP purse_pub;
|
||||
|
||||
/**
|
||||
* Fraction of the original deposit's value to be refunded, including
|
||||
* refund fee (if any). The coin is identified by @e coin_pub.
|
||||
*/
|
||||
struct TALER_Amount refund_amount;
|
||||
|
||||
/**
|
||||
* Refund fee to be covered by the customer.
|
||||
*/
|
||||
struct TALER_Amount refund_fee;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Information about a /reserves/$RID/open operation in a coin transaction history.
|
||||
*/
|
||||
@ -1974,10 +1999,15 @@ enum TALER_EXCHANGEDB_TransactionType
|
||||
*/
|
||||
TALER_EXCHANGEDB_TT_PURSE_DEPOSIT = 6,
|
||||
|
||||
/**
|
||||
* Purse deposit operation.
|
||||
*/
|
||||
TALER_EXCHANGEDB_TT_PURSE_REFUND = 7,
|
||||
|
||||
/**
|
||||
* Reserve open deposit operation.
|
||||
*/
|
||||
TALER_EXCHANGEDB_TT_RESERVE_OPEN = 7
|
||||
TALER_EXCHANGEDB_TT_RESERVE_OPEN = 8
|
||||
|
||||
};
|
||||
|
||||
@ -2053,6 +2083,12 @@ struct TALER_EXCHANGEDB_TransactionList
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_PurseDepositListEntry *purse_deposit;
|
||||
|
||||
/**
|
||||
* Coin was refunded upon purse expiration
|
||||
* (#TALER_EXCHANGEDB_TT_PURSE_REFUND)
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_PurseRefundListEntry *purse_refund;
|
||||
|
||||
/**
|
||||
* Coin was used to pay to open a reserve.
|
||||
* (#TALER_EXCHANGEDB_TT_RESERVE_OPEN)
|
||||
|
Loading…
Reference in New Issue
Block a user