Compare commits
No commits in common. "e7aeec04f4eb52caaa61b1ff9362f6fe0ffe0f2d" and "e30989c9303105770504f1bdbf26d843adf19468" have entirely different histories.
e7aeec04f4
...
e30989c930
@ -1896,7 +1896,7 @@ refund_cb (void *cls,
|
|||||||
* @param coin_blind blinding factor used to blind the coin
|
* @param coin_blind blinding factor used to blind the coin
|
||||||
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
|
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
|
||||||
*/
|
*/
|
||||||
static enum GNUNET_GenericReturnValue
|
static int
|
||||||
check_recoup (struct CoinContext *cc,
|
check_recoup (struct CoinContext *cc,
|
||||||
const char *operation,
|
const char *operation,
|
||||||
uint64_t rowid,
|
uint64_t rowid,
|
||||||
@ -1962,6 +1962,7 @@ check_recoup (struct CoinContext *cc,
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_recoup_verify (&coin->denom_pub_hash,
|
TALER_wallet_recoup_verify (&coin->denom_pub_hash,
|
||||||
coin_blind,
|
coin_blind,
|
||||||
|
amount,
|
||||||
&coin->coin_pub,
|
&coin->coin_pub,
|
||||||
coin_sig))
|
coin_sig))
|
||||||
{
|
{
|
||||||
@ -2083,7 +2084,7 @@ recoup_cb (void *cls,
|
|||||||
* @param coin_blind blinding factor used to blind the coin
|
* @param coin_blind blinding factor used to blind the coin
|
||||||
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
|
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
|
||||||
*/
|
*/
|
||||||
static enum GNUNET_GenericReturnValue
|
static int
|
||||||
recoup_refresh_cb (void *cls,
|
recoup_refresh_cb (void *cls,
|
||||||
uint64_t rowid,
|
uint64_t rowid,
|
||||||
struct GNUNET_TIME_Timestamp timestamp,
|
struct GNUNET_TIME_Timestamp timestamp,
|
||||||
|
@ -714,6 +714,7 @@ handle_recoup_by_reserve (
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_recoup_verify (&coin->denom_pub_hash,
|
TALER_wallet_recoup_verify (&coin->denom_pub_hash,
|
||||||
coin_blind,
|
coin_blind,
|
||||||
|
amount,
|
||||||
&coin->coin_pub,
|
&coin->coin_pub,
|
||||||
coin_sig))
|
coin_sig))
|
||||||
{
|
{
|
||||||
|
@ -62,6 +62,11 @@ struct RecoupContext
|
|||||||
*/
|
*/
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig;
|
const struct TALER_CoinSpendSignatureP *coin_sig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount requested to be recouped.
|
||||||
|
*/
|
||||||
|
const struct TALER_Amount *requested_amount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique ID of the coin in the known_coins table.
|
* Unique ID of the coin in the known_coins table.
|
||||||
*/
|
*/
|
||||||
@ -113,6 +118,7 @@ recoup_refresh_transaction (void *cls,
|
|||||||
qs = TEH_plugin->do_recoup_refresh (TEH_plugin->cls,
|
qs = TEH_plugin->do_recoup_refresh (TEH_plugin->cls,
|
||||||
&pc->old_coin_pub,
|
&pc->old_coin_pub,
|
||||||
pc->rrc_serial,
|
pc->rrc_serial,
|
||||||
|
pc->requested_amount,
|
||||||
pc->coin_bks,
|
pc->coin_bks,
|
||||||
&pc->coin->coin_pub,
|
&pc->coin->coin_pub,
|
||||||
pc->known_coin_id,
|
pc->known_coin_id,
|
||||||
@ -164,6 +170,7 @@ recoup_refresh_transaction (void *cls,
|
|||||||
* @param coin information about the coin
|
* @param coin information about the coin
|
||||||
* @param coin_bks blinding data of the coin (to be checked)
|
* @param coin_bks blinding data of the coin (to be checked)
|
||||||
* @param coin_sig signature of the coin
|
* @param coin_sig signature of the coin
|
||||||
|
* @param requested_amount requested amount to be recouped
|
||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
static MHD_RESULT
|
static MHD_RESULT
|
||||||
@ -171,7 +178,8 @@ verify_and_execute_recoup_refresh (
|
|||||||
struct MHD_Connection *connection,
|
struct MHD_Connection *connection,
|
||||||
const struct TALER_CoinPublicInfo *coin,
|
const struct TALER_CoinPublicInfo *coin,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig)
|
const struct TALER_CoinSpendSignatureP *coin_sig,
|
||||||
|
const struct TALER_Amount *requested_amount)
|
||||||
{
|
{
|
||||||
struct RecoupContext pc;
|
struct RecoupContext pc;
|
||||||
const struct TEH_DenominationKey *dk;
|
const struct TEH_DenominationKey *dk;
|
||||||
@ -229,6 +237,7 @@ verify_and_execute_recoup_refresh (
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_recoup_refresh_verify (&coin->denom_pub_hash,
|
TALER_wallet_recoup_refresh_verify (&coin->denom_pub_hash,
|
||||||
coin_bks,
|
coin_bks,
|
||||||
|
requested_amount,
|
||||||
&coin->coin_pub,
|
&coin->coin_pub,
|
||||||
coin_sig))
|
coin_sig))
|
||||||
{
|
{
|
||||||
@ -270,6 +279,7 @@ verify_and_execute_recoup_refresh (
|
|||||||
pc.coin_sig = coin_sig;
|
pc.coin_sig = coin_sig;
|
||||||
pc.coin_bks = coin_bks;
|
pc.coin_bks = coin_bks;
|
||||||
pc.coin = coin;
|
pc.coin = coin;
|
||||||
|
pc.requested_amount = requested_amount;
|
||||||
|
|
||||||
{
|
{
|
||||||
MHD_RESULT mhd_ret = MHD_NO;
|
MHD_RESULT mhd_ret = MHD_NO;
|
||||||
@ -357,6 +367,7 @@ TEH_handler_recoup_refresh (struct MHD_Connection *connection,
|
|||||||
struct TALER_CoinPublicInfo coin;
|
struct TALER_CoinPublicInfo coin;
|
||||||
union TALER_DenominationBlindingKeyP coin_bks;
|
union TALER_DenominationBlindingKeyP coin_bks;
|
||||||
struct TALER_CoinSpendSignatureP coin_sig;
|
struct TALER_CoinSpendSignatureP coin_sig;
|
||||||
|
struct TALER_Amount amount;
|
||||||
struct GNUNET_JSON_Specification spec[] = {
|
struct GNUNET_JSON_Specification spec[] = {
|
||||||
GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
|
GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
|
||||||
&coin.denom_pub_hash),
|
&coin.denom_pub_hash),
|
||||||
@ -366,6 +377,9 @@ TEH_handler_recoup_refresh (struct MHD_Connection *connection,
|
|||||||
&coin_bks),
|
&coin_bks),
|
||||||
GNUNET_JSON_spec_fixed_auto ("coin_sig",
|
GNUNET_JSON_spec_fixed_auto ("coin_sig",
|
||||||
&coin_sig),
|
&coin_sig),
|
||||||
|
TALER_JSON_spec_amount ("amount",
|
||||||
|
TEH_currency,
|
||||||
|
&amount),
|
||||||
GNUNET_JSON_spec_end ()
|
GNUNET_JSON_spec_end ()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -386,7 +400,8 @@ TEH_handler_recoup_refresh (struct MHD_Connection *connection,
|
|||||||
res = verify_and_execute_recoup_refresh (connection,
|
res = verify_and_execute_recoup_refresh (connection,
|
||||||
&coin,
|
&coin,
|
||||||
&coin_bks,
|
&coin_bks,
|
||||||
&coin_sig);
|
&coin_sig,
|
||||||
|
&amount);
|
||||||
GNUNET_JSON_parse_free (spec);
|
GNUNET_JSON_parse_free (spec);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,11 @@ struct RecoupContext
|
|||||||
*/
|
*/
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig;
|
const struct TALER_CoinSpendSignatureP *coin_sig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount requested to be recouped.
|
||||||
|
*/
|
||||||
|
const struct TALER_Amount *requested_amount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique ID of the withdraw operation in the reserves_out table.
|
* Unique ID of the withdraw operation in the reserves_out table.
|
||||||
*/
|
*/
|
||||||
@ -116,6 +121,7 @@ recoup_transaction (void *cls,
|
|||||||
qs = TEH_plugin->do_recoup (TEH_plugin->cls,
|
qs = TEH_plugin->do_recoup (TEH_plugin->cls,
|
||||||
&pc->reserve_pub,
|
&pc->reserve_pub,
|
||||||
pc->reserve_out_serial_id,
|
pc->reserve_out_serial_id,
|
||||||
|
pc->requested_amount,
|
||||||
pc->coin_bks,
|
pc->coin_bks,
|
||||||
&pc->coin->coin_pub,
|
&pc->coin->coin_pub,
|
||||||
pc->known_coin_id,
|
pc->known_coin_id,
|
||||||
@ -167,6 +173,7 @@ recoup_transaction (void *cls,
|
|||||||
* @param coin information about the coin
|
* @param coin information about the coin
|
||||||
* @param coin_bks blinding data of the coin (to be checked)
|
* @param coin_bks blinding data of the coin (to be checked)
|
||||||
* @param coin_sig signature of the coin
|
* @param coin_sig signature of the coin
|
||||||
|
* @param requested_amount requested amount to be recouped
|
||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
static MHD_RESULT
|
static MHD_RESULT
|
||||||
@ -174,7 +181,8 @@ verify_and_execute_recoup (
|
|||||||
struct MHD_Connection *connection,
|
struct MHD_Connection *connection,
|
||||||
const struct TALER_CoinPublicInfo *coin,
|
const struct TALER_CoinPublicInfo *coin,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig)
|
const struct TALER_CoinSpendSignatureP *coin_sig,
|
||||||
|
const struct TALER_Amount *requested_amount)
|
||||||
{
|
{
|
||||||
struct RecoupContext pc;
|
struct RecoupContext pc;
|
||||||
const struct TEH_DenominationKey *dk;
|
const struct TEH_DenominationKey *dk;
|
||||||
@ -231,6 +239,7 @@ verify_and_execute_recoup (
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_recoup_verify (&coin->denom_pub_hash,
|
TALER_wallet_recoup_verify (&coin->denom_pub_hash,
|
||||||
coin_bks,
|
coin_bks,
|
||||||
|
requested_amount,
|
||||||
&coin->coin_pub,
|
&coin->coin_pub,
|
||||||
coin_sig))
|
coin_sig))
|
||||||
{
|
{
|
||||||
@ -272,6 +281,7 @@ verify_and_execute_recoup (
|
|||||||
pc.coin_sig = coin_sig;
|
pc.coin_sig = coin_sig;
|
||||||
pc.coin_bks = coin_bks;
|
pc.coin_bks = coin_bks;
|
||||||
pc.coin = coin;
|
pc.coin = coin;
|
||||||
|
pc.requested_amount = requested_amount;
|
||||||
|
|
||||||
{
|
{
|
||||||
MHD_RESULT mhd_ret = MHD_NO;
|
MHD_RESULT mhd_ret = MHD_NO;
|
||||||
@ -359,6 +369,7 @@ TEH_handler_recoup (struct MHD_Connection *connection,
|
|||||||
struct TALER_CoinPublicInfo coin;
|
struct TALER_CoinPublicInfo coin;
|
||||||
union TALER_DenominationBlindingKeyP coin_bks;
|
union TALER_DenominationBlindingKeyP coin_bks;
|
||||||
struct TALER_CoinSpendSignatureP coin_sig;
|
struct TALER_CoinSpendSignatureP coin_sig;
|
||||||
|
struct TALER_Amount amount;
|
||||||
struct GNUNET_JSON_Specification spec[] = {
|
struct GNUNET_JSON_Specification spec[] = {
|
||||||
GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
|
GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
|
||||||
&coin.denom_pub_hash),
|
&coin.denom_pub_hash),
|
||||||
@ -368,6 +379,9 @@ TEH_handler_recoup (struct MHD_Connection *connection,
|
|||||||
&coin_bks),
|
&coin_bks),
|
||||||
GNUNET_JSON_spec_fixed_auto ("coin_sig",
|
GNUNET_JSON_spec_fixed_auto ("coin_sig",
|
||||||
&coin_sig),
|
&coin_sig),
|
||||||
|
TALER_JSON_spec_amount ("amount",
|
||||||
|
TEH_currency,
|
||||||
|
&amount),
|
||||||
GNUNET_JSON_spec_end ()
|
GNUNET_JSON_spec_end ()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -388,7 +402,8 @@ TEH_handler_recoup (struct MHD_Connection *connection,
|
|||||||
res = verify_and_execute_recoup (connection,
|
res = verify_and_execute_recoup (connection,
|
||||||
&coin,
|
&coin,
|
||||||
&coin_bks,
|
&coin_bks,
|
||||||
&coin_sig);
|
&coin_sig,
|
||||||
|
&amount);
|
||||||
GNUNET_JSON_parse_free (spec);
|
GNUNET_JSON_parse_free (spec);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
*
|
*
|
||||||
* @param connection connection to the client
|
* @param connection connection to the client
|
||||||
* @param ebalance expected balance based on our database
|
* @param ebalance expected balance based on our database
|
||||||
* @param withdraw_amount amount that the client requested to withdraw
|
|
||||||
* @param rh reserve history to return
|
* @param rh reserve history to return
|
||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
@ -48,7 +47,6 @@ static MHD_RESULT
|
|||||||
reply_withdraw_insufficient_funds (
|
reply_withdraw_insufficient_funds (
|
||||||
struct MHD_Connection *connection,
|
struct MHD_Connection *connection,
|
||||||
const struct TALER_Amount *ebalance,
|
const struct TALER_Amount *ebalance,
|
||||||
const struct TALER_Amount *withdraw_amount,
|
|
||||||
const struct TALER_EXCHANGEDB_ReserveHistory *rh)
|
const struct TALER_EXCHANGEDB_ReserveHistory *rh)
|
||||||
{
|
{
|
||||||
json_t *json_history;
|
json_t *json_history;
|
||||||
@ -78,8 +76,6 @@ reply_withdraw_insufficient_funds (
|
|||||||
TALER_JSON_pack_ec (TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS),
|
TALER_JSON_pack_ec (TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS),
|
||||||
TALER_JSON_pack_amount ("balance",
|
TALER_JSON_pack_amount ("balance",
|
||||||
&balance),
|
&balance),
|
||||||
TALER_JSON_pack_amount ("requested_amount",
|
|
||||||
withdraw_amount),
|
|
||||||
GNUNET_JSON_pack_array_steal ("history",
|
GNUNET_JSON_pack_array_steal ("history",
|
||||||
json_history));
|
json_history));
|
||||||
}
|
}
|
||||||
@ -178,7 +174,6 @@ withdraw_transaction (void *cls,
|
|||||||
{
|
{
|
||||||
struct TALER_EXCHANGEDB_ReserveHistory *rh;
|
struct TALER_EXCHANGEDB_ReserveHistory *rh;
|
||||||
struct TALER_Amount balance;
|
struct TALER_Amount balance;
|
||||||
struct TALER_Amount requested_amount;
|
|
||||||
|
|
||||||
TEH_plugin->rollback (TEH_plugin->cls);
|
TEH_plugin->rollback (TEH_plugin->cls);
|
||||||
// FIXME: maybe start read-committed here?
|
// FIXME: maybe start read-committed here?
|
||||||
@ -209,11 +204,8 @@ withdraw_transaction (void *cls,
|
|||||||
"reserve history");
|
"reserve history");
|
||||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
}
|
}
|
||||||
TALER_amount_ntoh (&requested_amount,
|
|
||||||
&wc->wsrd.amount_with_fee);
|
|
||||||
*mhd_ret = reply_withdraw_insufficient_funds (connection,
|
*mhd_ret = reply_withdraw_insufficient_funds (connection,
|
||||||
&balance,
|
&balance,
|
||||||
&requested_amount,
|
|
||||||
rh);
|
rh);
|
||||||
TEH_plugin->free_reserve_history (TEH_plugin->cls,
|
TEH_plugin->free_reserve_history (TEH_plugin->cls,
|
||||||
rh);
|
rh);
|
||||||
|
@ -918,7 +918,7 @@ END IF;
|
|||||||
-- Check reserve balance is sufficient.
|
-- Check reserve balance is sufficient.
|
||||||
IF (reserve_val > amount_val)
|
IF (reserve_val > amount_val)
|
||||||
THEN
|
THEN
|
||||||
IF (reserve_frac >= amount_frac)
|
IF (reserve_frac > amount_frac)
|
||||||
THEN
|
THEN
|
||||||
reserve_val=reserve_val - amount_val;
|
reserve_val=reserve_val - amount_val;
|
||||||
reserve_frac=reserve_frac - amount_frac;
|
reserve_frac=reserve_frac - amount_frac;
|
||||||
@ -1508,6 +1508,8 @@ END $$;
|
|||||||
CREATE OR REPLACE FUNCTION exchange_do_recoup_to_reserve(
|
CREATE OR REPLACE FUNCTION exchange_do_recoup_to_reserve(
|
||||||
IN in_reserve_pub BYTEA,
|
IN in_reserve_pub BYTEA,
|
||||||
IN in_reserve_out_serial_id INT8,
|
IN in_reserve_out_serial_id INT8,
|
||||||
|
IN in_amount_val INT8,
|
||||||
|
IN in_amount_frac INT4,
|
||||||
IN in_coin_blind BYTEA,
|
IN in_coin_blind BYTEA,
|
||||||
IN in_coin_pub BYTEA,
|
IN in_coin_pub BYTEA,
|
||||||
IN in_known_coin_id INT8,
|
IN in_known_coin_id INT8,
|
||||||
@ -1521,71 +1523,76 @@ CREATE OR REPLACE FUNCTION exchange_do_recoup_to_reserve(
|
|||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
tmp_val INT8; -- amount recouped
|
tmp_val INT8; -- previous amount recouped
|
||||||
DECLARE
|
DECLARE
|
||||||
tmp_frac INT8; -- amount recouped
|
tmp_frac INT8; -- previous amount recouped
|
||||||
BEGIN
|
BEGIN
|
||||||
-- Shards: SELECT known_coins (by coin_pub)
|
-- Shards: SELECT known_coins (by coin_pub)
|
||||||
-- SELECT recoup (by known_coin_id)
|
-- SELECT recoup (by known_coin_id)
|
||||||
-- UPDATE known_coins (by coin_pub)
|
|
||||||
-- UPDATE reserves (by reserve_pub)
|
-- UPDATE reserves (by reserve_pub)
|
||||||
-- INSERT recoup (by known_coin_id)
|
-- INSERT recoup (by known_coin_id)
|
||||||
|
|
||||||
out_internal_failure=FALSE;
|
out_internal_failure=FALSE;
|
||||||
|
|
||||||
|
-- Check and update balance of the coin.
|
||||||
-- Check remaining balance of the coin.
|
UPDATE known_coins
|
||||||
SELECT
|
SET
|
||||||
remaining_frac
|
remaining_frac=remaining_frac-in_amount_frac
|
||||||
,remaining_val
|
+ CASE
|
||||||
INTO
|
WHEN remaining_frac < in_amount_frac
|
||||||
tmp_frac
|
THEN 100000000
|
||||||
,tmp_val
|
ELSE 0
|
||||||
FROM known_coins
|
END,
|
||||||
WHERE coin_pub=in_coin_pub;
|
remaining_val=remaining_val-in_amount_val
|
||||||
|
- CASE
|
||||||
|
WHEN remaining_frac < in_amount_frac
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
WHERE coin_pub=in_coin_pub
|
||||||
|
AND ( (remaining_val > in_amount_val) OR
|
||||||
|
( (remaining_frac >= in_amount_frac) AND
|
||||||
|
(remaining_val >= in_amount_val) ) );
|
||||||
|
|
||||||
IF NOT FOUND
|
IF NOT FOUND
|
||||||
THEN
|
THEN
|
||||||
out_internal_failure=TRUE;
|
-- Check if we already recouped this coin before!
|
||||||
out_recoup_ok=FALSE;
|
|
||||||
RETURN;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF tmp_val + tmp_frac = 0
|
|
||||||
THEN
|
|
||||||
-- Check for idempotency
|
|
||||||
SELECT
|
SELECT
|
||||||
recoup_timestamp
|
amount_val
|
||||||
|
,amount_frac
|
||||||
|
,recoup_timestamp
|
||||||
INTO
|
INTO
|
||||||
out_recoup_timestamp
|
tmp_val
|
||||||
|
,tmp_frac
|
||||||
|
,out_recoup_timestamp
|
||||||
FROM recoup
|
FROM recoup
|
||||||
WHERE known_coin_id=in_known_coin_id;
|
WHERE known_coin_id=in_known_coin_id;
|
||||||
|
|
||||||
out_recoup_ok=FOUND;
|
IF FOUND
|
||||||
|
THEN
|
||||||
|
-- Idempotent request, all OK!
|
||||||
|
out_recoup_ok= (tmp_val = in_amount_val) AND
|
||||||
|
(tmp_frac = in_amount_frac);
|
||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
out_recoup_ok=FALSE;
|
||||||
-- Update balance of the coin.
|
RETURN;
|
||||||
UPDATE known_coins
|
END IF;
|
||||||
SET
|
|
||||||
remaining_frac=0
|
|
||||||
,remaining_val=0
|
|
||||||
WHERE coin_pub=in_coin_pub;
|
|
||||||
|
|
||||||
|
|
||||||
-- Credit the reserve and update reserve timers.
|
-- Credit the reserve and update reserve timers.
|
||||||
UPDATE reserves
|
UPDATE reserves
|
||||||
SET
|
SET
|
||||||
current_balance_frac=current_balance_frac+tmp_frac
|
current_balance_frac=current_balance_frac+in_amount_frac
|
||||||
- CASE
|
- CASE
|
||||||
WHEN current_balance_frac+tmp_frac >= 100000000
|
WHEN current_balance_frac+in_amount_frac >= 100000000
|
||||||
THEN 100000000
|
THEN 100000000
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END,
|
END,
|
||||||
current_balance_val=current_balance_val+tmp_val
|
current_balance_val=current_balance_val+in_amount_val
|
||||||
+ CASE
|
+ CASE
|
||||||
WHEN current_balance_frac+tmp_frac >= 100000000
|
WHEN current_balance_frac+in_amount_frac >= 100000000
|
||||||
THEN 1
|
THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END,
|
END,
|
||||||
@ -1597,7 +1604,7 @@ UPDATE reserves
|
|||||||
IF NOT FOUND
|
IF NOT FOUND
|
||||||
THEN
|
THEN
|
||||||
RAISE NOTICE 'failed to increase reserve balance from recoup';
|
RAISE NOTICE 'failed to increase reserve balance from recoup';
|
||||||
out_recoup_ok=TRUE;
|
out_recoup_ok=FALSE;
|
||||||
out_internal_failure=TRUE;
|
out_internal_failure=TRUE;
|
||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
@ -1616,8 +1623,8 @@ VALUES
|
|||||||
(in_known_coin_id
|
(in_known_coin_id
|
||||||
,in_coin_sig
|
,in_coin_sig
|
||||||
,in_coin_blind
|
,in_coin_blind
|
||||||
,tmp_val
|
,in_amount_val
|
||||||
,tmp_frac
|
,in_amount_frac
|
||||||
,in_recoup_timestamp
|
,in_recoup_timestamp
|
||||||
,in_reserve_out_serial_id);
|
,in_reserve_out_serial_id);
|
||||||
|
|
||||||
@ -1638,6 +1645,8 @@ END $$;
|
|||||||
CREATE OR REPLACE FUNCTION exchange_do_recoup_to_coin(
|
CREATE OR REPLACE FUNCTION exchange_do_recoup_to_coin(
|
||||||
IN in_old_coin_pub BYTEA,
|
IN in_old_coin_pub BYTEA,
|
||||||
IN in_rrc_serial INT8,
|
IN in_rrc_serial INT8,
|
||||||
|
IN in_amount_val INT8,
|
||||||
|
IN in_amount_frac INT4,
|
||||||
IN in_coin_blind BYTEA,
|
IN in_coin_blind BYTEA,
|
||||||
IN in_coin_pub BYTEA,
|
IN in_coin_pub BYTEA,
|
||||||
IN in_known_coin_id INT8,
|
IN in_known_coin_id INT8,
|
||||||
@ -1649,9 +1658,9 @@ CREATE OR REPLACE FUNCTION exchange_do_recoup_to_coin(
|
|||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
tmp_val INT8; -- amount recouped
|
tmp_val INT8; -- previous amount recouped
|
||||||
DECLARE
|
DECLARE
|
||||||
tmp_frac INT8; -- amount recouped
|
tmp_frac INT8; -- previous amount recouped
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
-- Shards: UPDATE known_coins (by coin_pub)
|
-- Shards: UPDATE known_coins (by coin_pub)
|
||||||
@ -1662,57 +1671,66 @@ BEGIN
|
|||||||
|
|
||||||
out_internal_failure=FALSE;
|
out_internal_failure=FALSE;
|
||||||
|
|
||||||
|
-- Check and update balance of the coin.
|
||||||
-- Check remaining balance of the coin.
|
UPDATE known_coins
|
||||||
SELECT
|
SET
|
||||||
remaining_frac
|
remaining_frac=remaining_frac-in_amount_frac
|
||||||
,remaining_val
|
+ CASE
|
||||||
INTO
|
WHEN remaining_frac < in_amount_frac
|
||||||
tmp_frac
|
THEN 100000000
|
||||||
,tmp_val
|
ELSE 0
|
||||||
FROM known_coins
|
END,
|
||||||
WHERE coin_pub=in_coin_pub;
|
remaining_val=remaining_val-in_amount_val
|
||||||
|
- CASE
|
||||||
|
WHEN remaining_frac < in_amount_frac
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
WHERE coin_pub=in_coin_pub
|
||||||
|
AND ( (remaining_val > in_amount_val) OR
|
||||||
|
( (remaining_frac >= in_amount_frac) AND
|
||||||
|
(remaining_val >= in_amount_val) ) );
|
||||||
|
|
||||||
IF NOT FOUND
|
IF NOT FOUND
|
||||||
THEN
|
THEN
|
||||||
out_internal_failure=TRUE;
|
-- Check if we already recouped this coin before!
|
||||||
|
SELECT
|
||||||
|
amount_val
|
||||||
|
,amount_frac
|
||||||
|
,recoup_timestamp
|
||||||
|
INTO
|
||||||
|
tmp_val
|
||||||
|
,tmp_frac
|
||||||
|
,out_recoup_timestamp
|
||||||
|
FROM recoup_refresh
|
||||||
|
WHERE known_coin_id=in_known_coin_id;
|
||||||
|
|
||||||
|
IF FOUND
|
||||||
|
THEN
|
||||||
|
-- Idempotent request, all OK!
|
||||||
|
out_recoup_ok= (tmp_val = in_amount_val) AND
|
||||||
|
(tmp_frac = in_amount_frac);
|
||||||
|
RETURN;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Insufficient balance, not idempotent.
|
||||||
out_recoup_ok=FALSE;
|
out_recoup_ok=FALSE;
|
||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF tmp_val + tmp_frac = 0
|
|
||||||
THEN
|
|
||||||
-- Check for idempotency
|
|
||||||
SELECT
|
|
||||||
recoup_timestamp
|
|
||||||
INTO
|
|
||||||
out_recoup_timestamp
|
|
||||||
FROM recoup_refresh
|
|
||||||
WHERE known_coin_id=in_known_coin_id;
|
|
||||||
out_recoup_ok=FOUND;
|
|
||||||
RETURN;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Update balance of the coin.
|
|
||||||
UPDATE known_coins
|
|
||||||
SET
|
|
||||||
remaining_frac=0
|
|
||||||
,remaining_val=0
|
|
||||||
WHERE coin_pub=in_coin_pub;
|
|
||||||
|
|
||||||
|
|
||||||
-- Credit the old coin.
|
-- Credit the old coin.
|
||||||
UPDATE known_coins
|
UPDATE known_coins
|
||||||
SET
|
SET
|
||||||
remaining_frac=remaining_frac+tmp_frac
|
remaining_frac=remaining_frac+in_amount_frac
|
||||||
- CASE
|
- CASE
|
||||||
WHEN remaining_frac+tmp_frac >= 100000000
|
WHEN remaining_frac+in_amount_frac >= 100000000
|
||||||
THEN 100000000
|
THEN 100000000
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END,
|
END,
|
||||||
remaining_val=remaining_val+tmp_val
|
remaining_val=remaining_val+in_amount_val
|
||||||
+ CASE
|
+ CASE
|
||||||
WHEN remaining_frac+tmp_frac >= 100000000
|
WHEN remaining_frac+in_amount_frac >= 100000000
|
||||||
THEN 1
|
THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END
|
END
|
||||||
@ -1722,7 +1740,7 @@ UPDATE known_coins
|
|||||||
IF NOT FOUND
|
IF NOT FOUND
|
||||||
THEN
|
THEN
|
||||||
RAISE NOTICE 'failed to increase old coin balance from recoup';
|
RAISE NOTICE 'failed to increase old coin balance from recoup';
|
||||||
out_recoup_ok=TRUE;
|
out_recoup_ok=FALSE;
|
||||||
out_internal_failure=TRUE;
|
out_internal_failure=TRUE;
|
||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
@ -1741,8 +1759,8 @@ VALUES
|
|||||||
(in_known_coin_id
|
(in_known_coin_id
|
||||||
,in_coin_sig
|
,in_coin_sig
|
||||||
,in_coin_blind
|
,in_coin_blind
|
||||||
,tmp_val
|
,in_amount_val
|
||||||
,tmp_frac
|
,in_amount_frac
|
||||||
,in_recoup_timestamp
|
,in_recoup_timestamp
|
||||||
,in_rrc_serial);
|
,in_rrc_serial);
|
||||||
|
|
||||||
|
@ -636,8 +636,8 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
",out_recoup_ok AS recoup_ok"
|
",out_recoup_ok AS recoup_ok"
|
||||||
",out_internal_failure AS internal_failure"
|
",out_internal_failure AS internal_failure"
|
||||||
" FROM exchange_do_recoup_to_reserve"
|
" FROM exchange_do_recoup_to_reserve"
|
||||||
" ($1,$2,$3,$4,$5,$6,$7,$8,$9);",
|
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);",
|
||||||
9),
|
11),
|
||||||
/* Used in #postgres_do_recoup_refresh() to recoup a coin to a zombie coin. */
|
/* Used in #postgres_do_recoup_refresh() to recoup a coin to a zombie coin. */
|
||||||
GNUNET_PQ_make_prepare (
|
GNUNET_PQ_make_prepare (
|
||||||
"call_recoup_refresh",
|
"call_recoup_refresh",
|
||||||
@ -646,8 +646,8 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
",out_recoup_ok AS recoup_ok"
|
",out_recoup_ok AS recoup_ok"
|
||||||
",out_internal_failure AS internal_failure"
|
",out_internal_failure AS internal_failure"
|
||||||
" FROM exchange_do_recoup_to_coin"
|
" FROM exchange_do_recoup_to_coin"
|
||||||
" ($1,$2,$3,$4,$5,$6,$7);",
|
" ($1,$2,$3,$4,$5,$6,$7,$8,$9);",
|
||||||
7),
|
9),
|
||||||
/* Used in #postgres_get_withdraw_info() to
|
/* Used in #postgres_get_withdraw_info() to
|
||||||
locate the response for a /reserve/withdraw request
|
locate the response for a /reserve/withdraw request
|
||||||
using the hash of the blinded message. Used to
|
using the hash of the blinded message. Used to
|
||||||
@ -4674,6 +4674,7 @@ postgres_do_refund (
|
|||||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
* @param reserve_pub public key of the reserve to credit
|
* @param reserve_pub public key of the reserve to credit
|
||||||
* @param reserve_out_serial_id row in the reserves_out table justifying the recoup
|
* @param reserve_out_serial_id row in the reserves_out table justifying the recoup
|
||||||
|
* @param requested_amount the amount to be recouped
|
||||||
* @param coin_bks coin blinding key secret to persist
|
* @param coin_bks coin blinding key secret to persist
|
||||||
* @param coin_pub public key of the coin being recouped
|
* @param coin_pub public key of the coin being recouped
|
||||||
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
||||||
@ -4688,6 +4689,7 @@ postgres_do_recoup (
|
|||||||
void *cls,
|
void *cls,
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||||
uint64_t reserve_out_serial_id,
|
uint64_t reserve_out_serial_id,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
uint64_t known_coin_id,
|
uint64_t known_coin_id,
|
||||||
@ -4704,6 +4706,7 @@ postgres_do_recoup (
|
|||||||
struct GNUNET_PQ_QueryParam params[] = {
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
|
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
|
||||||
GNUNET_PQ_query_param_uint64 (&reserve_out_serial_id),
|
GNUNET_PQ_query_param_uint64 (&reserve_out_serial_id),
|
||||||
|
TALER_PQ_query_param_amount (requested_amount),
|
||||||
GNUNET_PQ_query_param_auto_from_type (coin_bks),
|
GNUNET_PQ_query_param_auto_from_type (coin_bks),
|
||||||
GNUNET_PQ_query_param_auto_from_type (coin_pub),
|
GNUNET_PQ_query_param_auto_from_type (coin_pub),
|
||||||
GNUNET_PQ_query_param_uint64 (&known_coin_id),
|
GNUNET_PQ_query_param_uint64 (&known_coin_id),
|
||||||
@ -4740,6 +4743,7 @@ postgres_do_recoup (
|
|||||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
* @param old_coin_pub public key of the old coin to credit
|
* @param old_coin_pub public key of the old coin to credit
|
||||||
* @param rrc_serial row in the refresh_revealed_coins table justifying the recoup-refresh
|
* @param rrc_serial row in the refresh_revealed_coins table justifying the recoup-refresh
|
||||||
|
* @param requested_amount the amount to be recouped
|
||||||
* @param coin_bks coin blinding key secret to persist
|
* @param coin_bks coin blinding key secret to persist
|
||||||
* @param coin_pub public key of the coin being recouped
|
* @param coin_pub public key of the coin being recouped
|
||||||
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
||||||
@ -4754,6 +4758,7 @@ postgres_do_recoup_refresh (
|
|||||||
void *cls,
|
void *cls,
|
||||||
const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
|
||||||
uint64_t rrc_serial,
|
uint64_t rrc_serial,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
uint64_t known_coin_id,
|
uint64_t known_coin_id,
|
||||||
@ -4766,6 +4771,7 @@ postgres_do_recoup_refresh (
|
|||||||
struct GNUNET_PQ_QueryParam params[] = {
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
GNUNET_PQ_query_param_auto_from_type (old_coin_pub),
|
GNUNET_PQ_query_param_auto_from_type (old_coin_pub),
|
||||||
GNUNET_PQ_query_param_uint64 (&rrc_serial),
|
GNUNET_PQ_query_param_uint64 (&rrc_serial),
|
||||||
|
TALER_PQ_query_param_amount (requested_amount),
|
||||||
GNUNET_PQ_query_param_auto_from_type (coin_bks),
|
GNUNET_PQ_query_param_auto_from_type (coin_bks),
|
||||||
GNUNET_PQ_query_param_auto_from_type (coin_pub),
|
GNUNET_PQ_query_param_auto_from_type (coin_pub),
|
||||||
GNUNET_PQ_query_param_uint64 (&known_coin_id),
|
GNUNET_PQ_query_param_uint64 (&known_coin_id),
|
||||||
|
@ -1766,6 +1766,7 @@ run (void *cls)
|
|||||||
plugin->do_recoup_refresh (plugin->cls,
|
plugin->do_recoup_refresh (plugin->cls,
|
||||||
&deposit.coin.coin_pub,
|
&deposit.coin.coin_pub,
|
||||||
rrc_serial,
|
rrc_serial,
|
||||||
|
&value,
|
||||||
&coin_bks,
|
&coin_bks,
|
||||||
&new_coin.coin_pub,
|
&new_coin.coin_pub,
|
||||||
new_known_coin_id,
|
new_known_coin_id,
|
||||||
@ -1785,6 +1786,7 @@ run (void *cls)
|
|||||||
struct TALER_EXCHANGEDB_KycStatus kyc;
|
struct TALER_EXCHANGEDB_KycStatus kyc;
|
||||||
bool recoup_ok;
|
bool recoup_ok;
|
||||||
bool internal_failure;
|
bool internal_failure;
|
||||||
|
struct TALER_Amount requested_amount;
|
||||||
struct GNUNET_TIME_Timestamp recoup_timestamp
|
struct GNUNET_TIME_Timestamp recoup_timestamp
|
||||||
= GNUNET_TIME_timestamp_get ();
|
= GNUNET_TIME_timestamp_get ();
|
||||||
|
|
||||||
@ -1793,11 +1795,13 @@ run (void *cls)
|
|||||||
plugin->reserves_get (plugin->cls,
|
plugin->reserves_get (plugin->cls,
|
||||||
&pre_reserve,
|
&pre_reserve,
|
||||||
&kyc));
|
&kyc));
|
||||||
|
requested_amount = value;
|
||||||
FAILIF (! TALER_amount_is_zero (&pre_reserve.balance));
|
FAILIF (! TALER_amount_is_zero (&pre_reserve.balance));
|
||||||
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
||||||
plugin->do_recoup (plugin->cls,
|
plugin->do_recoup (plugin->cls,
|
||||||
&reserve_pub,
|
&reserve_pub,
|
||||||
reserve_out_serial_id,
|
reserve_out_serial_id,
|
||||||
|
&requested_amount,
|
||||||
&coin_blind,
|
&coin_blind,
|
||||||
&deposit.coin.coin_pub,
|
&deposit.coin.coin_pub,
|
||||||
known_coin_id,
|
known_coin_id,
|
||||||
|
@ -1839,6 +1839,7 @@ TALER_wallet_link_sign (const struct TALER_DenominationHash *h_denom_pub,
|
|||||||
*
|
*
|
||||||
* @param h_denom_pub hash of the denomiantion public key of the coin
|
* @param h_denom_pub hash of the denomiantion public key of the coin
|
||||||
* @param coin_bks blinding factor used when withdrawing the coin
|
* @param coin_bks blinding factor used when withdrawing the coin
|
||||||
|
* @param requested_amount amount that is left to be recouped
|
||||||
* @param coin_pub coin key of the coin to be recouped
|
* @param coin_pub coin key of the coin to be recouped
|
||||||
* @param coin_sig resulting signature
|
* @param coin_sig resulting signature
|
||||||
* @return #GNUNET_OK if the signature is valid
|
* @return #GNUNET_OK if the signature is valid
|
||||||
@ -1847,6 +1848,7 @@ enum GNUNET_GenericReturnValue
|
|||||||
TALER_wallet_recoup_verify (
|
TALER_wallet_recoup_verify (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig);
|
const struct TALER_CoinSpendSignatureP *coin_sig);
|
||||||
|
|
||||||
@ -1864,6 +1866,7 @@ void
|
|||||||
TALER_wallet_recoup_sign (
|
TALER_wallet_recoup_sign (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
||||||
struct TALER_CoinSpendSignatureP *coin_sig);
|
struct TALER_CoinSpendSignatureP *coin_sig);
|
||||||
|
|
||||||
@ -1873,6 +1876,7 @@ TALER_wallet_recoup_sign (
|
|||||||
*
|
*
|
||||||
* @param h_denom_pub hash of the denomiantion public key of the coin
|
* @param h_denom_pub hash of the denomiantion public key of the coin
|
||||||
* @param coin_bks blinding factor used when withdrawing the coin
|
* @param coin_bks blinding factor used when withdrawing the coin
|
||||||
|
* @param requested_amount amount that is left to be recouped
|
||||||
* @param coin_pub coin key of the coin to be recouped
|
* @param coin_pub coin key of the coin to be recouped
|
||||||
* @param coin_sig resulting signature
|
* @param coin_sig resulting signature
|
||||||
* @return #GNUNET_OK if the signature is valid
|
* @return #GNUNET_OK if the signature is valid
|
||||||
@ -1881,6 +1885,7 @@ enum GNUNET_GenericReturnValue
|
|||||||
TALER_wallet_recoup_refresh_verify (
|
TALER_wallet_recoup_refresh_verify (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig);
|
const struct TALER_CoinSpendSignatureP *coin_sig);
|
||||||
|
|
||||||
@ -1898,6 +1903,7 @@ void
|
|||||||
TALER_wallet_recoup_refresh_sign (
|
TALER_wallet_recoup_refresh_sign (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
||||||
struct TALER_CoinSpendSignatureP *coin_sig);
|
struct TALER_CoinSpendSignatureP *coin_sig);
|
||||||
|
|
||||||
|
@ -2035,6 +2035,7 @@ typedef void
|
|||||||
* @param pk kind of coin to pay back
|
* @param pk kind of coin to pay back
|
||||||
* @param denom_sig signature over the coin by the exchange using @a pk
|
* @param denom_sig signature over the coin by the exchange using @a pk
|
||||||
* @param ps secret internals of the original planchet
|
* @param ps secret internals of the original planchet
|
||||||
|
* @param amount value remaining on the coin that is being recouped
|
||||||
* @param recoup_cb the callback to call when the final result for this request is available
|
* @param recoup_cb the callback to call when the final result for this request is available
|
||||||
* @param recoup_cb_cls closure for @a recoup_cb
|
* @param recoup_cb_cls closure for @a recoup_cb
|
||||||
* @return NULL
|
* @return NULL
|
||||||
@ -2046,6 +2047,7 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
|
|||||||
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
||||||
const struct TALER_DenominationSignature *denom_sig,
|
const struct TALER_DenominationSignature *denom_sig,
|
||||||
const struct TALER_PlanchetSecretsP *ps,
|
const struct TALER_PlanchetSecretsP *ps,
|
||||||
|
const struct TALER_Amount *amount,
|
||||||
TALER_EXCHANGE_RecoupResultCallback recoup_cb,
|
TALER_EXCHANGE_RecoupResultCallback recoup_cb,
|
||||||
void *recoup_cb_cls);
|
void *recoup_cb_cls);
|
||||||
|
|
||||||
@ -2095,6 +2097,7 @@ typedef void
|
|||||||
* @param pk kind of coin to pay back
|
* @param pk kind of coin to pay back
|
||||||
* @param denom_sig signature over the coin by the exchange using @a pk
|
* @param denom_sig signature over the coin by the exchange using @a pk
|
||||||
* @param ps secret internals of the original planchet
|
* @param ps secret internals of the original planchet
|
||||||
|
* @param amount value remaining on the coin that is being recouped
|
||||||
* @param recoup_cb the callback to call when the final result for this request is available
|
* @param recoup_cb the callback to call when the final result for this request is available
|
||||||
* @param recoup_cb_cls closure for @a recoup_cb
|
* @param recoup_cb_cls closure for @a recoup_cb
|
||||||
* @return NULL
|
* @return NULL
|
||||||
@ -2107,6 +2110,7 @@ TALER_EXCHANGE_recoup_refresh (
|
|||||||
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
||||||
const struct TALER_DenominationSignature *denom_sig,
|
const struct TALER_DenominationSignature *denom_sig,
|
||||||
const struct TALER_PlanchetSecretsP *ps,
|
const struct TALER_PlanchetSecretsP *ps,
|
||||||
|
const struct TALER_Amount *amount,
|
||||||
TALER_EXCHANGE_RecoupRefreshResultCallback recoup_cb,
|
TALER_EXCHANGE_RecoupRefreshResultCallback recoup_cb,
|
||||||
void *recoup_cb_cls);
|
void *recoup_cb_cls);
|
||||||
|
|
||||||
|
@ -2596,6 +2596,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
* @param reserve_pub public key of the reserve to credit
|
* @param reserve_pub public key of the reserve to credit
|
||||||
* @param reserve_out_serial_id row in the reserves_out table justifying the recoup
|
* @param reserve_out_serial_id row in the reserves_out table justifying the recoup
|
||||||
|
* @param requested_amount the amount to be recouped
|
||||||
* @param coin_bks coin blinding key secret to persist
|
* @param coin_bks coin blinding key secret to persist
|
||||||
* @param coin_pub public key of the coin being recouped
|
* @param coin_pub public key of the coin being recouped
|
||||||
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
||||||
@ -2610,6 +2611,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
void *cls,
|
void *cls,
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||||
uint64_t reserve_out_serial_id,
|
uint64_t reserve_out_serial_id,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
uint64_t known_coin_id,
|
uint64_t known_coin_id,
|
||||||
@ -2626,6 +2628,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
* @param old_coin_pub public key of the old coin to credit
|
* @param old_coin_pub public key of the old coin to credit
|
||||||
* @param rrc_serial row in the refresh_revealed_coins table justifying the recoup-refresh
|
* @param rrc_serial row in the refresh_revealed_coins table justifying the recoup-refresh
|
||||||
|
* @param requested_amount the amount to be recouped
|
||||||
* @param coin_bks coin blinding key secret to persist
|
* @param coin_bks coin blinding key secret to persist
|
||||||
* @param coin_pub public key of the coin being recouped
|
* @param coin_pub public key of the coin being recouped
|
||||||
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
* @param known_coin_id row of the @a coin_pub in the known_coins table
|
||||||
@ -2640,6 +2643,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
void *cls,
|
void *cls,
|
||||||
const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
|
||||||
uint64_t rrc_serial,
|
uint64_t rrc_serial,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
uint64_t known_coin_id,
|
uint64_t known_coin_id,
|
||||||
|
@ -1507,7 +1507,6 @@ struct TALER_RecoupRequestPS
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Purpose is #TALER_SIGNATURE_WALLET_COIN_RECOUP
|
* Purpose is #TALER_SIGNATURE_WALLET_COIN_RECOUP
|
||||||
* or #TALER_SIGNATURE_WALLET_COIN_RECOUP_REFRESH.
|
|
||||||
*/
|
*/
|
||||||
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
||||||
|
|
||||||
@ -1521,6 +1520,11 @@ struct TALER_RecoupRequestPS
|
|||||||
*/
|
*/
|
||||||
union TALER_DenominationBlindingKeyP coin_blind;
|
union TALER_DenominationBlindingKeyP coin_blind;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How much of the coin's value will be recouped?
|
||||||
|
*/
|
||||||
|
struct TALER_AmountNBO recoup_amount;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -726,6 +726,7 @@ TALER_EXCHANGE_verify_coin_history (
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_recoup_verify (h_denom_pub,
|
TALER_wallet_recoup_verify (h_denom_pub,
|
||||||
&coin_bks,
|
&coin_bks,
|
||||||
|
&recoup_amount,
|
||||||
coin_pub,
|
coin_pub,
|
||||||
&coin_sig))
|
&coin_sig))
|
||||||
{
|
{
|
||||||
@ -795,6 +796,7 @@ TALER_EXCHANGE_verify_coin_history (
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_recoup_verify (h_denom_pub,
|
TALER_wallet_recoup_verify (h_denom_pub,
|
||||||
&coin_bks,
|
&coin_bks,
|
||||||
|
&recoup_amount,
|
||||||
coin_pub,
|
coin_pub,
|
||||||
&coin_sig))
|
&coin_sig))
|
||||||
{
|
{
|
||||||
|
@ -285,6 +285,7 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
|
|||||||
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
||||||
const struct TALER_DenominationSignature *denom_sig,
|
const struct TALER_DenominationSignature *denom_sig,
|
||||||
const struct TALER_PlanchetSecretsP *ps,
|
const struct TALER_PlanchetSecretsP *ps,
|
||||||
|
const struct TALER_Amount *amount,
|
||||||
TALER_EXCHANGE_RecoupResultCallback recoup_cb,
|
TALER_EXCHANGE_RecoupResultCallback recoup_cb,
|
||||||
void *recoup_cb_cls)
|
void *recoup_cb_cls)
|
||||||
{
|
{
|
||||||
@ -305,6 +306,7 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
|
|||||||
&h_denom_pub);
|
&h_denom_pub);
|
||||||
TALER_wallet_recoup_sign (&h_denom_pub,
|
TALER_wallet_recoup_sign (&h_denom_pub,
|
||||||
&ps->blinding_key,
|
&ps->blinding_key,
|
||||||
|
amount,
|
||||||
&ps->coin_priv,
|
&ps->coin_priv,
|
||||||
&coin_sig);
|
&coin_sig);
|
||||||
recoup_obj = GNUNET_JSON_PACK (
|
recoup_obj = GNUNET_JSON_PACK (
|
||||||
@ -312,6 +314,8 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
|
|||||||
&h_denom_pub),
|
&h_denom_pub),
|
||||||
TALER_JSON_pack_denom_sig ("denom_sig",
|
TALER_JSON_pack_denom_sig ("denom_sig",
|
||||||
denom_sig),
|
denom_sig),
|
||||||
|
TALER_JSON_pack_amount ("amount",
|
||||||
|
amount),
|
||||||
GNUNET_JSON_pack_data_auto ("coin_sig",
|
GNUNET_JSON_pack_data_auto ("coin_sig",
|
||||||
&coin_sig),
|
&coin_sig),
|
||||||
GNUNET_JSON_pack_data_auto ("coin_blind_key_secret",
|
GNUNET_JSON_pack_data_auto ("coin_blind_key_secret",
|
||||||
|
@ -287,6 +287,7 @@ TALER_EXCHANGE_recoup_refresh (
|
|||||||
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
||||||
const struct TALER_DenominationSignature *denom_sig,
|
const struct TALER_DenominationSignature *denom_sig,
|
||||||
const struct TALER_PlanchetSecretsP *ps,
|
const struct TALER_PlanchetSecretsP *ps,
|
||||||
|
const struct TALER_Amount *amount,
|
||||||
TALER_EXCHANGE_RecoupRefreshResultCallback recoup_cb,
|
TALER_EXCHANGE_RecoupRefreshResultCallback recoup_cb,
|
||||||
void *recoup_cb_cls)
|
void *recoup_cb_cls)
|
||||||
{
|
{
|
||||||
@ -307,6 +308,7 @@ TALER_EXCHANGE_recoup_refresh (
|
|||||||
&h_denom_pub);
|
&h_denom_pub);
|
||||||
TALER_wallet_recoup_refresh_sign (&h_denom_pub,
|
TALER_wallet_recoup_refresh_sign (&h_denom_pub,
|
||||||
&ps->blinding_key,
|
&ps->blinding_key,
|
||||||
|
amount,
|
||||||
&ps->coin_priv,
|
&ps->coin_priv,
|
||||||
&coin_sig);
|
&coin_sig);
|
||||||
recoup_obj = GNUNET_JSON_PACK (
|
recoup_obj = GNUNET_JSON_PACK (
|
||||||
@ -314,6 +316,8 @@ TALER_EXCHANGE_recoup_refresh (
|
|||||||
&h_denom_pub),
|
&h_denom_pub),
|
||||||
TALER_JSON_pack_denom_sig ("denom_sig",
|
TALER_JSON_pack_denom_sig ("denom_sig",
|
||||||
denom_sig),
|
denom_sig),
|
||||||
|
TALER_JSON_pack_amount ("amount",
|
||||||
|
amount),
|
||||||
GNUNET_JSON_pack_data_auto ("coin_sig",
|
GNUNET_JSON_pack_data_auto ("coin_sig",
|
||||||
&coin_sig),
|
&coin_sig),
|
||||||
GNUNET_JSON_pack_data_auto ("coin_blind_key_secret",
|
GNUNET_JSON_pack_data_auto ("coin_blind_key_secret",
|
||||||
|
@ -318,6 +318,7 @@ recoup_run (void *cls,
|
|||||||
denom_pub,
|
denom_pub,
|
||||||
coin_sig,
|
coin_sig,
|
||||||
&planchet,
|
&planchet,
|
||||||
|
&ps->reserve_history.amount,
|
||||||
&recoup_cb,
|
&recoup_cb,
|
||||||
ps);
|
ps);
|
||||||
GNUNET_assert (NULL != ps->ph);
|
GNUNET_assert (NULL != ps->ph);
|
||||||
|
@ -309,6 +309,7 @@ recoup_refresh_run (void *cls,
|
|||||||
denom_pub,
|
denom_pub,
|
||||||
coin_sig,
|
coin_sig,
|
||||||
&planchet,
|
&planchet,
|
||||||
|
&ps->amount,
|
||||||
recoup_refresh_cb,
|
recoup_refresh_cb,
|
||||||
ps);
|
ps);
|
||||||
GNUNET_assert (NULL != ps->ph);
|
GNUNET_assert (NULL != ps->ph);
|
||||||
|
@ -157,6 +157,7 @@ enum GNUNET_GenericReturnValue
|
|||||||
TALER_wallet_recoup_verify (
|
TALER_wallet_recoup_verify (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig)
|
const struct TALER_CoinSpendSignatureP *coin_sig)
|
||||||
{
|
{
|
||||||
@ -167,6 +168,8 @@ TALER_wallet_recoup_verify (
|
|||||||
.coin_blind = *coin_bks
|
.coin_blind = *coin_bks
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TALER_amount_hton (&pr.recoup_amount,
|
||||||
|
requested_amount);
|
||||||
return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_RECOUP,
|
return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_RECOUP,
|
||||||
&pr,
|
&pr,
|
||||||
&coin_sig->eddsa_signature,
|
&coin_sig->eddsa_signature,
|
||||||
@ -178,6 +181,7 @@ void
|
|||||||
TALER_wallet_recoup_sign (
|
TALER_wallet_recoup_sign (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
||||||
struct TALER_CoinSpendSignatureP *coin_sig)
|
struct TALER_CoinSpendSignatureP *coin_sig)
|
||||||
{
|
{
|
||||||
@ -188,6 +192,8 @@ TALER_wallet_recoup_sign (
|
|||||||
.coin_blind = *coin_bks
|
.coin_blind = *coin_bks
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TALER_amount_hton (&pr.recoup_amount,
|
||||||
|
requested_amount);
|
||||||
GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv,
|
GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv,
|
||||||
&pr,
|
&pr,
|
||||||
&coin_sig->eddsa_signature);
|
&coin_sig->eddsa_signature);
|
||||||
@ -198,6 +204,7 @@ enum GNUNET_GenericReturnValue
|
|||||||
TALER_wallet_recoup_refresh_verify (
|
TALER_wallet_recoup_refresh_verify (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct TALER_CoinSpendSignatureP *coin_sig)
|
const struct TALER_CoinSpendSignatureP *coin_sig)
|
||||||
{
|
{
|
||||||
@ -208,6 +215,8 @@ TALER_wallet_recoup_refresh_verify (
|
|||||||
.coin_blind = *coin_bks
|
.coin_blind = *coin_bks
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TALER_amount_hton (&pr.recoup_amount,
|
||||||
|
requested_amount);
|
||||||
return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_RECOUP_REFRESH,
|
return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_RECOUP_REFRESH,
|
||||||
&pr,
|
&pr,
|
||||||
&coin_sig->eddsa_signature,
|
&coin_sig->eddsa_signature,
|
||||||
@ -219,6 +228,7 @@ void
|
|||||||
TALER_wallet_recoup_refresh_sign (
|
TALER_wallet_recoup_refresh_sign (
|
||||||
const struct TALER_DenominationHash *h_denom_pub,
|
const struct TALER_DenominationHash *h_denom_pub,
|
||||||
const union TALER_DenominationBlindingKeyP *coin_bks,
|
const union TALER_DenominationBlindingKeyP *coin_bks,
|
||||||
|
const struct TALER_Amount *requested_amount,
|
||||||
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
||||||
struct TALER_CoinSpendSignatureP *coin_sig)
|
struct TALER_CoinSpendSignatureP *coin_sig)
|
||||||
{
|
{
|
||||||
@ -229,6 +239,8 @@ TALER_wallet_recoup_refresh_sign (
|
|||||||
.coin_blind = *coin_bks
|
.coin_blind = *coin_bks
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TALER_amount_hton (&pr.recoup_amount,
|
||||||
|
requested_amount);
|
||||||
GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv,
|
GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv,
|
||||||
&pr,
|
&pr,
|
||||||
&coin_sig->eddsa_signature);
|
&coin_sig->eddsa_signature);
|
||||||
|
Loading…
Reference in New Issue
Block a user