-complete purses_get draft implementation

This commit is contained in:
Christian Grothoff 2022-04-26 13:34:18 +02:00
parent efb8c8037b
commit 932cef3d8c
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 45 additions and 44 deletions

View File

@ -71,11 +71,6 @@ struct GetContext
*/ */
struct GNUNET_TIME_Timestamp merge_timestamp; struct GNUNET_TIME_Timestamp merge_timestamp;
/**
* When was the full amount deposited into this purse?
*/
struct GNUNET_TIME_Timestamp deposit_timestamp;
/** /**
* How much is the purse (supposed) to be worth? * How much is the purse (supposed) to be worth?
*/ */
@ -304,8 +299,7 @@ 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);
&gc->deposit_timestamp);
switch (qs) switch (qs)
{ {
case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_HARD_ERROR:
@ -343,9 +337,11 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
if (GNUNET_TIME_absolute_is_future (gc->timeout) && if (GNUNET_TIME_absolute_is_future (gc->timeout) &&
( ((gc->wait_for_merge) && ( ((gc->wait_for_merge) &&
GNUNET_TIME_absolute_is_zero (gc->merge_timestamp.abs_time)) || GNUNET_TIME_absolute_is_never (gc->merge_timestamp.abs_time)) ||
((! gc->wait_for_merge) && ((! gc->wait_for_merge) &&
GNUNET_TIME_absolute_is_zero (gc->deposit_timestamp.abs_time)) )) (0 <
TALER_amount_cmp (&gc->amount,
&gc->deposited))) ) )
{ {
gc->suspended = true; gc->suspended = true;
GNUNET_CONTAINER_DLL_insert (gc_head, GNUNET_CONTAINER_DLL_insert (gc_head,
@ -355,16 +351,24 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
return MHD_YES; return MHD_YES;
} }
// FIXME: add exchange signature!? {
// FIXME: return amount? struct GNUNET_TIME_Timestamp dt = GNUNET_TIME_timestamp_get ();
res = TALER_MHD_REPLY_JSON_PACK (
rc->connection, if (GNUNET_TIME_timestamp_cmp (dt,
MHD_HTTP_OK, >,
GNUNET_JSON_pack_timestamp ("merge_timestamp", gc->purse_expiration))
gc->merge_timestamp), dt = gc->purse_expiration;
GNUNET_JSON_pack_timestamp ("deposit_timestamp", // FIXME: add exchange signature!?
gc->deposit_timestamp) // FIXME: return amount?
); res = TALER_MHD_REPLY_JSON_PACK (
rc->connection,
MHD_HTTP_OK,
GNUNET_JSON_pack_timestamp ("merge_timestamp",
gc->merge_timestamp),
GNUNET_JSON_pack_timestamp ("deposit_timestamp",
dt)
);
}
return res; return res;
} }

View File

@ -3470,6 +3470,22 @@ prepare_statements (struct PostgresClosure *pg)
" ($1, $2, $3, $4, $5, $6, $7, $8)" " ($1, $2, $3, $4, $5, $6, $7, $8)"
" ON CONFLICT DO NOTHING;", " ON CONFLICT DO NOTHING;",
8), 8),
/* Used in #postgres_select_purse */
GNUNET_PQ_make_prepare (
"select_purse",
"SELECT "
" merge_pub"
",purse_expiration"
",h_contract_terms"
",amount_with_fee_val"
",amount_with_fee_frac"
",balance_val"
",balance_frac"
",merge_timestamp"
" FROM purse_requests"
" WHERE purse_pub=$1"
" LEFT JOIN purse_merges ON (purse_pub);",
1),
/* Used in #postgres_select_purse_request */ /* Used in #postgres_select_purse_request */
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"select_purse_request", "select_purse_request",
@ -13361,7 +13377,6 @@ postgres_insert_purse_request (
* @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] deposit_timestamp set to time when the deposited amount reached the target amount, or NEVER if not
* @return transaction status code * @return transaction status code
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
@ -13372,8 +13387,7 @@ postgres_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)
struct GNUNET_TIME_Timestamp *deposit_timestamp)
{ {
struct PostgresClosure *pg = cls; struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -13393,29 +13407,14 @@ postgres_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_allow_null (
GNUNET_PQ_result_spec_timestamp ("deposit_timestamp",
deposit_timestamp),
NULL),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
enum GNUNET_DB_QueryStatus qs;
*merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS; *merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
*deposit_timestamp = GNUNET_TIME_UNIT_FOREVER_TS; return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "select_purse",
"select_purse_request", params,
params, rs);
rs);
if ( (qs > 0) &&
(0 <
TALER_amount_cmp (amount,
deposited)) )
{
/* not yet enough */
*deposit_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
}
return qs;
} }

View File

@ -4556,7 +4556,6 @@ 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] deposit_timestamp set to time when the deposited amount reached the target amount, or NEVER if not
* @return transaction status code * @return transaction status code
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
@ -4567,8 +4566,7 @@ 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);
struct GNUNET_TIME_Timestamp *deposit_timestamp);
/** /**