-complete purses_get draft implementation
This commit is contained in:
parent
efb8c8037b
commit
932cef3d8c
@ -71,11 +71,6 @@ struct GetContext
|
||||
*/
|
||||
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?
|
||||
*/
|
||||
@ -304,8 +299,7 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
|
||||
&gc->amount,
|
||||
&gc->deposited,
|
||||
&gc->h_contract,
|
||||
&gc->merge_timestamp,
|
||||
&gc->deposit_timestamp);
|
||||
&gc->merge_timestamp);
|
||||
switch (qs)
|
||||
{
|
||||
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) &&
|
||||
( ((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) &&
|
||||
GNUNET_TIME_absolute_is_zero (gc->deposit_timestamp.abs_time)) ))
|
||||
(0 <
|
||||
TALER_amount_cmp (&gc->amount,
|
||||
&gc->deposited))) ) )
|
||||
{
|
||||
gc->suspended = true;
|
||||
GNUNET_CONTAINER_DLL_insert (gc_head,
|
||||
@ -355,16 +351,24 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
|
||||
return MHD_YES;
|
||||
}
|
||||
|
||||
// FIXME: add exchange signature!?
|
||||
// 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",
|
||||
gc->deposit_timestamp)
|
||||
);
|
||||
{
|
||||
struct GNUNET_TIME_Timestamp dt = GNUNET_TIME_timestamp_get ();
|
||||
|
||||
if (GNUNET_TIME_timestamp_cmp (dt,
|
||||
>,
|
||||
gc->purse_expiration))
|
||||
dt = gc->purse_expiration;
|
||||
// FIXME: add exchange signature!?
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -3470,6 +3470,22 @@ prepare_statements (struct PostgresClosure *pg)
|
||||
" ($1, $2, $3, $4, $5, $6, $7, $8)"
|
||||
" ON CONFLICT DO NOTHING;",
|
||||
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 */
|
||||
GNUNET_PQ_make_prepare (
|
||||
"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] 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] deposit_timestamp set to time when the deposited amount reached the target amount, or NEVER if not
|
||||
* @return transaction status code
|
||||
*/
|
||||
static enum GNUNET_DB_QueryStatus
|
||||
@ -13372,8 +13387,7 @@ postgres_select_purse (
|
||||
struct TALER_Amount *amount,
|
||||
struct TALER_Amount *deposited,
|
||||
struct TALER_PrivateContractHashP *h_contract_terms,
|
||||
struct GNUNET_TIME_Timestamp *merge_timestamp,
|
||||
struct GNUNET_TIME_Timestamp *deposit_timestamp)
|
||||
struct GNUNET_TIME_Timestamp *merge_timestamp)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
@ -13393,29 +13407,14 @@ postgres_select_purse (
|
||||
GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
|
||||
merge_timestamp),
|
||||
NULL),
|
||||
GNUNET_PQ_result_spec_allow_null (
|
||||
GNUNET_PQ_result_spec_timestamp ("deposit_timestamp",
|
||||
deposit_timestamp),
|
||||
NULL),
|
||||
GNUNET_PQ_result_spec_end
|
||||
};
|
||||
enum GNUNET_DB_QueryStatus qs;
|
||||
|
||||
*merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
|
||||
*deposit_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
|
||||
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
||||
"select_purse_request",
|
||||
params,
|
||||
rs);
|
||||
if ( (qs > 0) &&
|
||||
(0 <
|
||||
TALER_amount_cmp (amount,
|
||||
deposited)) )
|
||||
{
|
||||
/* not yet enough */
|
||||
*deposit_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
|
||||
}
|
||||
return qs;
|
||||
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
||||
"select_purse",
|
||||
params,
|
||||
rs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4556,7 +4556,6 @@ struct TALER_EXCHANGEDB_Plugin
|
||||
* @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] 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
|
||||
*/
|
||||
enum GNUNET_DB_QueryStatus
|
||||
@ -4567,8 +4566,7 @@ struct TALER_EXCHANGEDB_Plugin
|
||||
struct TALER_Amount *amount,
|
||||
struct TALER_Amount *deposited,
|
||||
struct TALER_PrivateContractHashP *h_contract_terms,
|
||||
struct GNUNET_TIME_Timestamp *merge_timestamp,
|
||||
struct GNUNET_TIME_Timestamp *deposit_timestamp);
|
||||
struct GNUNET_TIME_Timestamp *merge_timestamp);
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user