add notification logic on purse deletion
This commit is contained in:
parent
5533bcbf65
commit
880c14909b
@ -1 +1 @@
|
|||||||
Subproject commit f603a795963748040e41693daceae343b3a972ed
|
Subproject commit df1d198918cbdd03c18723d818979c8d09f8f231
|
@ -308,6 +308,14 @@ struct PurseSummary
|
|||||||
*/
|
*/
|
||||||
bool had_pi;
|
bool had_pi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Was the purse deleted? FIXME: Not yet handled (do we need to? purse
|
||||||
|
* might just appear as expired eventually; but in the meantime, exchange
|
||||||
|
* may seem to have refunded the coins for no good reason...), also we do
|
||||||
|
* not yet check the deletion signature.
|
||||||
|
*/
|
||||||
|
bool purse_deleted;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -407,7 +415,8 @@ setup_purse (struct PurseContext *pc,
|
|||||||
&ps->total_value,
|
&ps->total_value,
|
||||||
&ps->exchange_balance,
|
&ps->exchange_balance,
|
||||||
&ps->h_contract_terms,
|
&ps->h_contract_terms,
|
||||||
&ps->merge_timestamp);
|
&ps->merge_timestamp,
|
||||||
|
&ps->purse_deleted);
|
||||||
if (0 >= qs)
|
if (0 >= qs)
|
||||||
{
|
{
|
||||||
GNUNET_free (ps);
|
GNUNET_free (ps);
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <gnunet/gnunet_json_lib.h>
|
#include <gnunet/gnunet_json_lib.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include <microhttpd.h>
|
#include <microhttpd.h>
|
||||||
|
#include "taler_dbevents.h"
|
||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler_mhd_lib.h"
|
#include "taler_mhd_lib.h"
|
||||||
#include "taler-exchange-httpd_common_deposit.h"
|
#include "taler-exchange-httpd_common_deposit.h"
|
||||||
@ -131,6 +132,23 @@ TEH_handler_purses_delete (
|
|||||||
TALER_EC_EXCHANGE_PURSE_DELETE_ALREADY_DECIDED,
|
TALER_EC_EXCHANGE_PURSE_DELETE_ALREADY_DECIDED,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
/* Possible minor optimization: integrate notification with
|
||||||
|
transaction above... */
|
||||||
|
struct TALER_PurseEventP rep = {
|
||||||
|
.header.size = htons (sizeof (rep)),
|
||||||
|
.header.type = htons (TALER_DBEVENT_EXCHANGE_PURSE_DEPOSITED),
|
||||||
|
.purse_pub = purse_pub
|
||||||
|
};
|
||||||
|
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"Notifying about purse deletion %s\n",
|
||||||
|
TALER_B2S (&purse_pub));
|
||||||
|
TEH_plugin->event_notify (TEH_plugin->cls,
|
||||||
|
&rep.header,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
|
}
|
||||||
/* success */
|
/* success */
|
||||||
return TALER_MHD_reply_static (connection,
|
return TALER_MHD_reply_static (connection,
|
||||||
MHD_HTTP_NO_CONTENT,
|
MHD_HTTP_NO_CONTENT,
|
||||||
|
@ -374,6 +374,7 @@ TEH_handler_purses_deposit (
|
|||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
struct GNUNET_TIME_Timestamp create_timestamp;
|
struct GNUNET_TIME_Timestamp create_timestamp;
|
||||||
struct GNUNET_TIME_Timestamp merge_timestamp;
|
struct GNUNET_TIME_Timestamp merge_timestamp;
|
||||||
|
bool was_deleted;
|
||||||
|
|
||||||
qs = TEH_plugin->select_purse (
|
qs = TEH_plugin->select_purse (
|
||||||
TEH_plugin->cls,
|
TEH_plugin->cls,
|
||||||
@ -383,7 +384,8 @@ TEH_handler_purses_deposit (
|
|||||||
&pcc.amount,
|
&pcc.amount,
|
||||||
&pcc.deposit_total,
|
&pcc.deposit_total,
|
||||||
&pcc.h_contract_terms,
|
&pcc.h_contract_terms,
|
||||||
&merge_timestamp);
|
&merge_timestamp,
|
||||||
|
&was_deleted);
|
||||||
switch (qs)
|
switch (qs)
|
||||||
{
|
{
|
||||||
case GNUNET_DB_STATUS_HARD_ERROR:
|
case GNUNET_DB_STATUS_HARD_ERROR:
|
||||||
@ -406,12 +408,16 @@ TEH_handler_purses_deposit (
|
|||||||
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
|
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
|
||||||
break; /* handled below */
|
break; /* handled below */
|
||||||
}
|
}
|
||||||
if (GNUNET_TIME_absolute_is_past (pcc.purse_expiration.abs_time))
|
if (GNUNET_TIME_absolute_is_past (pcc.purse_expiration.abs_time) ||
|
||||||
|
was_deleted)
|
||||||
{
|
{
|
||||||
return TALER_MHD_reply_with_error (connection,
|
return TALER_MHD_reply_with_error (
|
||||||
|
connection,
|
||||||
MHD_HTTP_GONE,
|
MHD_HTTP_GONE,
|
||||||
TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
|
was_deleted
|
||||||
NULL);
|
? TALER_EC_EXCHANGE_GENERIC_PURSE_DELETED
|
||||||
|
: TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
|
||||||
|
GNUNET_TIME_timestamp2s (pcc.purse_expiration));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
|
|||||||
const char *const args[2])
|
const char *const args[2])
|
||||||
{
|
{
|
||||||
struct GetContext *gc = rc->rh_ctx;
|
struct GetContext *gc = rc->rh_ctx;
|
||||||
|
bool purse_deleted;
|
||||||
MHD_RESULT res;
|
MHD_RESULT res;
|
||||||
|
|
||||||
if (NULL == gc)
|
if (NULL == gc)
|
||||||
@ -312,7 +313,8 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
|
|||||||
&gc->amount,
|
&gc->amount,
|
||||||
&gc->deposited,
|
&gc->deposited,
|
||||||
&gc->h_contract,
|
&gc->h_contract,
|
||||||
&gc->merge_timestamp);
|
&gc->merge_timestamp,
|
||||||
|
&purse_deleted);
|
||||||
switch (qs)
|
switch (qs)
|
||||||
{
|
{
|
||||||
case GNUNET_DB_STATUS_HARD_ERROR:
|
case GNUNET_DB_STATUS_HARD_ERROR:
|
||||||
@ -367,11 +369,14 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
|
|||||||
gc->eh = eh2;
|
gc->eh = eh2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GNUNET_TIME_absolute_is_past (gc->purse_expiration.abs_time))
|
if (GNUNET_TIME_absolute_is_past (gc->purse_expiration.abs_time) ||
|
||||||
|
purse_deleted)
|
||||||
{
|
{
|
||||||
return TALER_MHD_reply_with_error (rc->connection,
|
return TALER_MHD_reply_with_error (rc->connection,
|
||||||
MHD_HTTP_GONE,
|
MHD_HTTP_GONE,
|
||||||
TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
|
purse_deleted
|
||||||
|
? TALER_EC_EXCHANGE_GENERIC_PURSE_DELETED
|
||||||
|
: TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
|
||||||
GNUNET_TIME_timestamp2s (
|
GNUNET_TIME_timestamp2s (
|
||||||
gc->purse_expiration));
|
gc->purse_expiration));
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ TEH_PG_select_purse (
|
|||||||
struct TALER_Amount *amount,
|
struct TALER_Amount *amount,
|
||||||
struct TALER_Amount *deposited,
|
struct TALER_Amount *deposited,
|
||||||
struct TALER_PrivateContractHashP *h_contract_terms,
|
struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
struct GNUNET_TIME_Timestamp *merge_timestamp)
|
struct GNUNET_TIME_Timestamp *merge_timestamp,
|
||||||
|
bool *purse_deleted)
|
||||||
{
|
{
|
||||||
struct PostgresClosure *pg = cls;
|
struct PostgresClosure *pg = cls;
|
||||||
struct GNUNET_PQ_QueryParam params[] = {
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
@ -57,6 +58,8 @@ TEH_PG_select_purse (
|
|||||||
GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
|
GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
|
||||||
merge_timestamp),
|
merge_timestamp),
|
||||||
NULL),
|
NULL),
|
||||||
|
GNUNET_PQ_result_spec_bool ("purse_deleted",
|
||||||
|
purse_deleted),
|
||||||
GNUNET_PQ_result_spec_end
|
GNUNET_PQ_result_spec_end
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,8 +75,10 @@ TEH_PG_select_purse (
|
|||||||
",balance_val"
|
",balance_val"
|
||||||
",balance_frac"
|
",balance_frac"
|
||||||
",merge_timestamp"
|
",merge_timestamp"
|
||||||
|
",purse_sig IS NOT NULL AS purse_deleted"
|
||||||
" FROM purse_requests"
|
" FROM purse_requests"
|
||||||
" LEFT JOIN purse_merges USING (purse_pub)"
|
" LEFT JOIN purse_merges USING (purse_pub)"
|
||||||
|
" LEFT JOIN purse_deletion USING (purse_pub)"
|
||||||
" WHERE purse_pub=$1;");
|
" WHERE purse_pub=$1;");
|
||||||
*merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
|
*merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
|
||||||
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
* @param[out] deposited set to actual amount put into the purse so far
|
* @param[out] deposited set to actual amount put into the purse so far
|
||||||
* @param[out] h_contract_terms set to hash of the contract for the purse
|
* @param[out] h_contract_terms set to hash of the contract for the purse
|
||||||
* @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
|
* @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
|
||||||
|
* @param[out] purse_deleted set to true if purse was deleted
|
||||||
* @return transaction status code
|
* @return transaction status code
|
||||||
*/
|
*/
|
||||||
enum GNUNET_DB_QueryStatus
|
enum GNUNET_DB_QueryStatus
|
||||||
@ -48,7 +49,8 @@ TEH_PG_select_purse (
|
|||||||
struct TALER_Amount *amount,
|
struct TALER_Amount *amount,
|
||||||
struct TALER_Amount *deposited,
|
struct TALER_Amount *deposited,
|
||||||
struct TALER_PrivateContractHashP *h_contract_terms,
|
struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
struct GNUNET_TIME_Timestamp *merge_timestamp);
|
struct GNUNET_TIME_Timestamp *merge_timestamp,
|
||||||
|
bool *purse_deleted);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5827,6 +5827,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
* @param[out] deposited set to actual amount put into the purse so far
|
* @param[out] deposited set to actual amount put into the purse so far
|
||||||
* @param[out] h_contract_terms set to hash of the contract for the purse
|
* @param[out] h_contract_terms set to hash of the contract for the purse
|
||||||
* @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
|
* @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
|
||||||
|
* @param[out] purse_deleted set to true if purse was deleted
|
||||||
* @return transaction status code
|
* @return transaction status code
|
||||||
*/
|
*/
|
||||||
enum GNUNET_DB_QueryStatus
|
enum GNUNET_DB_QueryStatus
|
||||||
@ -5838,7 +5839,8 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
struct TALER_Amount *amount,
|
struct TALER_Amount *amount,
|
||||||
struct TALER_Amount *deposited,
|
struct TALER_Amount *deposited,
|
||||||
struct TALER_PrivateContractHashP *h_contract_terms,
|
struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
struct GNUNET_TIME_Timestamp *merge_timestamp);
|
struct GNUNET_TIME_Timestamp *merge_timestamp,
|
||||||
|
bool *purse_deleted);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user