-work on P2P payment details

This commit is contained in:
Christian Grothoff 2022-06-02 21:55:21 +02:00
parent 5dd03fe359
commit 04c32eafb9
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 102 additions and 13 deletions

View File

@ -361,7 +361,7 @@ TEH_RESPONSE_compile_transaction_history (
hash and the denomination key's RSA signature over coin_pub, but as
the wallet should really already have this information (and cannot
check or do anything with it anyway if it doesn't), it seems
strictly unnecessary. *///
strictly unnecessary. */
if (0 !=
json_array_append_new (
history,
@ -420,6 +420,56 @@ 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;
@ -797,7 +847,9 @@ TEH_RESPONSE_compile_reserve_history (
TALER_JSON_pack_amount ("amount",
&amount),
TALER_JSON_pack_amount ("purse_fee",
&merge->purse_fee))))
&merge->purse_fee),
GNUNET_JSON_pack_bool ("merged",
merge->merged))))
{
GNUNET_break (0);
json_decref (json_history);

View File

@ -3464,7 +3464,7 @@ BEGIN
SET
current_balance_frac=current_balance_frac-in_history_fee_frac
+ CASE
WHEN reserve_frac < in_history_fee_frac
WHEN current_balance_frac < in_history_fee_frac
THEN 100000000
ELSE 0
END,

View File

@ -2157,6 +2157,8 @@ prepare_statements (struct PostgresClosure *pg)
"SELECT"
" pr.amount_with_fee_val"
",pr.amount_with_fee_frac"
",pr.balance_val"
",pr.balance_frac"
",pr.purse_fee_val"
",pr.purse_fee_frac"
",pr.h_contract_terms"
@ -6515,9 +6517,12 @@ add_p2p_merge (void *cls,
merge = GNUNET_new (struct TALER_EXCHANGEDB_PurseMerge);
{
uint32_t flags32;
struct TALER_Amount balance;
struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
&merge->purse_fee),
TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
&balance),
TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
&merge->amount_with_fee),
GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
@ -6550,15 +6555,21 @@ add_p2p_merge (void *cls,
return;
}
merge->flags = (enum TALER_WalletAccountMergeFlags) flags32;
if ( (! GNUNET_TIME_absolute_is_future (
merge->merge_timestamp.abs_time)) &&
(-1 != TALER_amount_cmp (&balance,
&merge->amount_with_fee)) )
merge->merged = true;
}
if (merge->merged)
GNUNET_assert (0 <=
TALER_amount_add (&rhc->balance_in,
&rhc->balance_in,
&merge->amount_with_fee));
GNUNET_assert (0 <=
TALER_amount_add (&rhc->balance_in,
&rhc->balance_in,
&merge->amount_with_fee));
GNUNET_assert (0 <=
TALER_amount_subtract (&rhc->balance_out,
&rhc->balance_out,
&merge->purse_fee));
TALER_amount_add (&rhc->balance_out,
&rhc->balance_out,
&merge->purse_fee));
merge->reserve_pub = *rhc->reserve_pub;
tail = append_rh (rhc);
tail->type = TALER_EXCHANGEDB_RO_PURSE_MERGE;

View File

@ -1535,6 +1535,12 @@ struct TALER_EXCHANGE_ReserveHistoryEntry
*/
enum TALER_WalletAccountMergeFlags flags;
/**
* True if the purse was actually merged, false
* if only the @e purse_fee was charged.
*/
bool merged;
} merge_details;
} details;

View File

@ -1144,6 +1144,12 @@ struct TALER_EXCHANGEDB_PurseMerge
*/
enum TALER_WalletAccountMergeFlags flags;
/**
* true if the purse was actually successfully merged,
* false if the @e purse_fee was charged but the
* @e amount was not credited to the reserve.
*/
bool merged;
};

View File

@ -417,6 +417,8 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
&rh->details.merge_details.merge_timestamp),
GNUNET_JSON_spec_timestamp ("purse_expiration",
&rh->details.merge_details.purse_expiration),
GNUNET_JSON_spec_bool ("merged",
&rh->details.merge_details.merged),
GNUNET_JSON_spec_end ()
};
@ -447,10 +449,22 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
if (rh->details.merge_details.merged)
{
if (0 >
TALER_amount_add (uc->total_in,
uc->total_in,
&rh->amount))
{
/* overflow in history already!? inconceivable! Bad exchange! */
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
}
if (0 >
TALER_amount_add (uc->total_in,
uc->total_in,
&rh->amount))
TALER_amount_add (uc->total_out,
uc->total_out,
&rh->details.merge_details.purse_fee))
{
/* overflow in history already!? inconceivable! Bad exchange! */
GNUNET_break_op (0);