clean up link logic
This commit is contained in:
parent
f29a7e3155
commit
efdc91ead4
@ -701,7 +701,7 @@ handle_mhd_request (void *cls,
|
|||||||
* @return #GNUNET_OK on success
|
* @return #GNUNET_OK on success
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
exchange_serve_process_config ()
|
exchange_serve_process_config (void)
|
||||||
{
|
{
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_CONFIGURATION_get_value_number (TEH_cfg,
|
GNUNET_CONFIGURATION_get_value_number (TEH_cfg,
|
||||||
@ -812,7 +812,7 @@ exchange_serve_process_config ()
|
|||||||
* stats if requested.
|
* stats if requested.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
write_stats ()
|
write_stats (void)
|
||||||
{
|
{
|
||||||
struct GNUNET_DISK_FileHandle *fh;
|
struct GNUNET_DISK_FileHandle *fh;
|
||||||
pid_t pid = getpid ();
|
pid_t pid = getpid ();
|
||||||
|
@ -32,13 +32,13 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closure for #handle_transfer_data().
|
* Closure for #handle_link_data().
|
||||||
*/
|
*/
|
||||||
struct HTD_Context
|
struct HTD_Context
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public key of the coin for which we are running /refresh/link.
|
* Public key of the coin for which we are running link.
|
||||||
*/
|
*/
|
||||||
struct TALER_CoinSpendPublicKeyP coin_pub;
|
struct TALER_CoinSpendPublicKeyP coin_pub;
|
||||||
|
|
||||||
@ -70,10 +70,9 @@ handle_link_data (void *cls,
|
|||||||
{
|
{
|
||||||
struct HTD_Context *ctx = cls;
|
struct HTD_Context *ctx = cls;
|
||||||
json_t *list;
|
json_t *list;
|
||||||
json_t *root;
|
|
||||||
|
|
||||||
if (NULL == ctx->mlist)
|
if (NULL == ctx->mlist)
|
||||||
return;
|
return; /* we failed earlier */
|
||||||
if (NULL == (list = json_array ()))
|
if (NULL == (list = json_array ()))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@ -101,16 +100,20 @@ handle_link_data (void *cls,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root = json_pack ("{s:o, s:o}",
|
{
|
||||||
"new_coins",
|
json_t *root;
|
||||||
list,
|
|
||||||
"transfer_pub",
|
root = json_pack ("{s:o, s:o}",
|
||||||
GNUNET_JSON_from_data_auto (transfer_pub));
|
"new_coins",
|
||||||
if ( (NULL == root) ||
|
list,
|
||||||
(0 !=
|
"transfer_pub",
|
||||||
json_array_append_new (ctx->mlist,
|
GNUNET_JSON_from_data_auto (transfer_pub));
|
||||||
root)) )
|
if ( (NULL == root) ||
|
||||||
goto fail;
|
(0 !=
|
||||||
|
json_array_append_new (ctx->mlist,
|
||||||
|
root)) )
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
fail:
|
fail:
|
||||||
ctx->ec = TALER_EC_JSON_ALLOCATION_FAILURE;
|
ctx->ec = TALER_EC_JSON_ALLOCATION_FAILURE;
|
||||||
@ -120,15 +123,13 @@ fail:
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a "/refresh/link". Returns the linkage information that
|
* Execute a link operation. Returns the linkage information that will allow
|
||||||
* will allow the owner of a coin to follow the refresh trail to
|
* the owner of a coin to follow the trail to the refreshed coin.
|
||||||
* the refreshed coin.
|
|
||||||
*
|
*
|
||||||
* If it returns a non-error code, the transaction logic MUST
|
* If it returns a non-error code, the transaction logic MUST NOT queue a MHD
|
||||||
* NOT queue a MHD response. IF it returns an hard error, the
|
* response. IF it returns an hard error, the transaction logic MUST queue a
|
||||||
* transaction logic MUST queue a MHD response and set @a mhd_ret. IF
|
* MHD response and set @a mhd_ret. IF it returns the soft error code, the
|
||||||
* it returns the soft error code, the function MAY be called again to
|
* function MAY be called again to retry and MUST not queue a MHD response.
|
||||||
* retry and MUST not queue a MHD response.
|
|
||||||
*
|
*
|
||||||
* @param cls closure
|
* @param cls closure
|
||||||
* @param connection MHD request which triggered the transaction
|
* @param connection MHD request which triggered the transaction
|
||||||
@ -138,10 +139,10 @@ fail:
|
|||||||
* @return transaction status
|
* @return transaction status
|
||||||
*/
|
*/
|
||||||
static enum GNUNET_DB_QueryStatus
|
static enum GNUNET_DB_QueryStatus
|
||||||
refresh_link_transaction (void *cls,
|
link_transaction (void *cls,
|
||||||
struct MHD_Connection *connection,
|
struct MHD_Connection *connection,
|
||||||
struct TALER_EXCHANGEDB_Session *session,
|
struct TALER_EXCHANGEDB_Session *session,
|
||||||
int *mhd_ret)
|
int *mhd_ret)
|
||||||
{
|
{
|
||||||
struct HTD_Context *ctx = cls;
|
struct HTD_Context *ctx = cls;
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
@ -204,11 +205,19 @@ TEH_handler_link (const struct TEH_RequestHandler *rh,
|
|||||||
"coin public key malformed");
|
"coin public key malformed");
|
||||||
}
|
}
|
||||||
ctx.mlist = json_array ();
|
ctx.mlist = json_array ();
|
||||||
|
if (NULL == ctx.mlist)
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
return TALER_MHD_reply_with_error (connection,
|
||||||
|
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||||
|
TALER_EC_JSON_ALLOCATION_FAILURE,
|
||||||
|
"json_array() call failed");
|
||||||
|
}
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TEH_DB_run_transaction (connection,
|
TEH_DB_run_transaction (connection,
|
||||||
"run link",
|
"run link",
|
||||||
&mhd_ret,
|
&mhd_ret,
|
||||||
&refresh_link_transaction,
|
&link_transaction,
|
||||||
&ctx))
|
&ctx))
|
||||||
{
|
{
|
||||||
if (NULL != ctx.mlist)
|
if (NULL != ctx.mlist)
|
||||||
@ -223,4 +232,4 @@ TEH_handler_link (const struct TEH_RequestHandler *rh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* end of taler-exchange-httpd_refresh_link.c */
|
/* end of taler-exchange-httpd_link.c */
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "taler-exchange-httpd.h"
|
#include "taler-exchange-httpd.h"
|
||||||
#include "taler-exchange-httpd_mhd.h"
|
#include "taler-exchange-httpd_mhd.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to call to handle the request by sending
|
* Function to call to handle the request by sending
|
||||||
* back static data from the @a rh.
|
* back static data from the @a rh.
|
||||||
@ -48,7 +49,6 @@ TEH_handler_static_response (const struct TEH_RequestHandler *rh,
|
|||||||
const char *const args[])
|
const char *const args[])
|
||||||
{
|
{
|
||||||
struct MHD_Response *response;
|
struct MHD_Response *response;
|
||||||
int ret;
|
|
||||||
size_t dlen;
|
size_t dlen;
|
||||||
|
|
||||||
(void) args;
|
(void) args;
|
||||||
@ -68,11 +68,15 @@ TEH_handler_static_response (const struct TEH_RequestHandler *rh,
|
|||||||
(void) MHD_add_response_header (response,
|
(void) MHD_add_response_header (response,
|
||||||
MHD_HTTP_HEADER_CONTENT_TYPE,
|
MHD_HTTP_HEADER_CONTENT_TYPE,
|
||||||
rh->mime_type);
|
rh->mime_type);
|
||||||
ret = MHD_queue_response (connection,
|
{
|
||||||
rh->response_code,
|
int ret;
|
||||||
response);
|
|
||||||
MHD_destroy_response (response);
|
ret = MHD_queue_response (connection,
|
||||||
return ret;
|
rh->response_code,
|
||||||
|
response);
|
||||||
|
MHD_destroy_response (response);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,10 +39,9 @@
|
|||||||
* @return json representation of the @a rh, NULL on error
|
* @return json representation of the @a rh, NULL on error
|
||||||
*/
|
*/
|
||||||
json_t *
|
json_t *
|
||||||
TEH_RESPONSE_compile_transaction_history (const struct
|
TEH_RESPONSE_compile_transaction_history (
|
||||||
TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct
|
const struct TALER_EXCHANGEDB_TransactionList *tl)
|
||||||
TALER_EXCHANGEDB_TransactionList *tl)
|
|
||||||
{
|
{
|
||||||
json_t *history;
|
json_t *history;
|
||||||
|
|
||||||
@ -421,12 +420,11 @@ TEH_RESPONSE_compile_transaction_history (const struct
|
|||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
TEH_RESPONSE_reply_coin_insufficient_funds (struct MHD_Connection *connection,
|
TEH_RESPONSE_reply_coin_insufficient_funds (
|
||||||
enum TALER_ErrorCode ec,
|
struct MHD_Connection *connection,
|
||||||
const struct
|
enum TALER_ErrorCode ec,
|
||||||
TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct
|
const struct TALER_EXCHANGEDB_TransactionList *tl)
|
||||||
TALER_EXCHANGEDB_TransactionList *tl)
|
|
||||||
{
|
{
|
||||||
json_t *history;
|
json_t *history;
|
||||||
|
|
||||||
@ -458,9 +456,9 @@ TEH_RESPONSE_reply_coin_insufficient_funds (struct MHD_Connection *connection,
|
|||||||
* @return json representation of the @a rh, NULL on error
|
* @return json representation of the @a rh, NULL on error
|
||||||
*/
|
*/
|
||||||
json_t *
|
json_t *
|
||||||
TEH_RESPONSE_compile_reserve_history (const struct
|
TEH_RESPONSE_compile_reserve_history (
|
||||||
TALER_EXCHANGEDB_ReserveHistory *rh,
|
const struct TALER_EXCHANGEDB_ReserveHistory *rh,
|
||||||
struct TALER_Amount *balance)
|
struct TALER_Amount *balance)
|
||||||
{
|
{
|
||||||
struct TALER_Amount deposit_total;
|
struct TALER_Amount deposit_total;
|
||||||
struct TALER_Amount withdraw_total;
|
struct TALER_Amount withdraw_total;
|
||||||
|
@ -42,9 +42,9 @@
|
|||||||
* @return json representation of the @a rh, NULL on error
|
* @return json representation of the @a rh, NULL on error
|
||||||
*/
|
*/
|
||||||
json_t *
|
json_t *
|
||||||
TEH_RESPONSE_compile_reserve_history (const struct
|
TEH_RESPONSE_compile_reserve_history (
|
||||||
TALER_EXCHANGEDB_ReserveHistory *rh,
|
const struct TALER_EXCHANGEDB_ReserveHistory *rh,
|
||||||
struct TALER_Amount *balance);
|
struct TALER_Amount *balance);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,12 +60,11 @@ TEH_RESPONSE_compile_reserve_history (const struct
|
|||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
TEH_RESPONSE_reply_coin_insufficient_funds (struct MHD_Connection *connection,
|
TEH_RESPONSE_reply_coin_insufficient_funds (
|
||||||
enum TALER_ErrorCode ec,
|
struct MHD_Connection *connection,
|
||||||
const struct
|
enum TALER_ErrorCode ec,
|
||||||
TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct
|
const struct TALER_EXCHANGEDB_TransactionList *tl);
|
||||||
TALER_EXCHANGEDB_TransactionList *tl);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,10 +75,9 @@ TEH_RESPONSE_reply_coin_insufficient_funds (struct MHD_Connection *connection,
|
|||||||
* @return json representation of the @a rh, NULL on error
|
* @return json representation of the @a rh, NULL on error
|
||||||
*/
|
*/
|
||||||
json_t *
|
json_t *
|
||||||
TEH_RESPONSE_compile_transaction_history (const struct
|
TEH_RESPONSE_compile_transaction_history (
|
||||||
TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
const struct
|
const struct TALER_EXCHANGEDB_TransactionList *tl);
|
||||||
TALER_EXCHANGEDB_TransactionList *tl);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user