refactor /wire/deposit response generation to do all JSON logic in httpd_responses.c
This commit is contained in:
parent
58373f2a92
commit
a2bb69910a
@ -1579,6 +1579,16 @@ struct WtidTransactionContext
|
|||||||
*/
|
*/
|
||||||
struct GNUNET_HashCode h_wire;
|
struct GNUNET_HashCode h_wire;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Head of DLL with details for /wire/deposit response.
|
||||||
|
*/
|
||||||
|
struct TMH_WireDepositDetail *wdd_head;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Head of DLL with details for /wire/deposit response.
|
||||||
|
*/
|
||||||
|
struct TMH_WireDepositDetail *wdd_tail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON array with details about the individual deposits.
|
* JSON array with details about the individual deposits.
|
||||||
*/
|
*/
|
||||||
@ -1621,6 +1631,7 @@ handle_transaction_data (void *cls,
|
|||||||
{
|
{
|
||||||
struct WtidTransactionContext *ctx = cls;
|
struct WtidTransactionContext *ctx = cls;
|
||||||
struct TALER_Amount delta;
|
struct TALER_Amount delta;
|
||||||
|
struct TMH_WireDepositDetail *wdd;
|
||||||
|
|
||||||
if (GNUNET_SYSERR == ctx->is_valid)
|
if (GNUNET_SYSERR == ctx->is_valid)
|
||||||
return;
|
return;
|
||||||
@ -1671,17 +1682,15 @@ handle_transaction_data (void *cls,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* NOTE: We usually keep JSON stuff out of the _DB file, and this
|
wdd = GNUNET_new (struct TMH_WireDepositDetail);
|
||||||
is also ugly if we ever add signatures over this data. (#4135) */
|
wdd->deposit_value = *deposit_value;
|
||||||
json_array_append (ctx->deposits,
|
wdd->deposit_fee = *deposit_fee;
|
||||||
json_pack ("{s:o, s:o, s:o, s:I, s:o}",
|
wdd->h_contract = *h_contract;
|
||||||
"deposit_value", TALER_JSON_from_amount (deposit_value),
|
wdd->transaction_id = transaction_id;
|
||||||
"deposit_fee", TALER_JSON_from_amount (deposit_fee),
|
wdd->coin_pub = *coin_pub;
|
||||||
"H_contract", GNUNET_JSON_from_data (h_contract,
|
GNUNET_CONTAINER_DLL_insert (ctx->wdd_head,
|
||||||
sizeof (struct GNUNET_HashCode)),
|
ctx->wdd_tail,
|
||||||
"transaction_id", (json_int_t) transaction_id,
|
wdd);
|
||||||
"coin_pub", GNUNET_JSON_from_data (coin_pub,
|
|
||||||
sizeof (struct TALER_CoinSpendPublicKeyP))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1700,6 +1709,7 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection,
|
|||||||
int ret;
|
int ret;
|
||||||
struct WtidTransactionContext ctx;
|
struct WtidTransactionContext ctx;
|
||||||
struct TALER_EXCHANGEDB_Session *session;
|
struct TALER_EXCHANGEDB_Session *session;
|
||||||
|
struct TMH_WireDepositDetail *wdd;
|
||||||
|
|
||||||
if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls,
|
if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls,
|
||||||
TMH_test_mode)))
|
TMH_test_mode)))
|
||||||
@ -1708,7 +1718,6 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection,
|
|||||||
return TMH_RESPONSE_reply_internal_db_error (connection);
|
return TMH_RESPONSE_reply_internal_db_error (connection);
|
||||||
}
|
}
|
||||||
ctx.is_valid = GNUNET_NO;
|
ctx.is_valid = GNUNET_NO;
|
||||||
ctx.deposits = json_array ();
|
|
||||||
ret = TMH_plugin->lookup_wire_transfer (TMH_plugin->cls,
|
ret = TMH_plugin->lookup_wire_transfer (TMH_plugin->cls,
|
||||||
session,
|
session,
|
||||||
wtid,
|
wtid,
|
||||||
@ -1717,26 +1726,35 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection,
|
|||||||
if (GNUNET_SYSERR == ret)
|
if (GNUNET_SYSERR == ret)
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
json_decref (ctx.deposits);
|
ret = TMH_RESPONSE_reply_internal_db_error (connection);
|
||||||
return TMH_RESPONSE_reply_internal_db_error (connection);
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (GNUNET_SYSERR == ctx.is_valid)
|
if (GNUNET_SYSERR == ctx.is_valid)
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
json_decref (ctx.deposits);
|
ret = TMH_RESPONSE_reply_internal_db_error (connection);
|
||||||
return TMH_RESPONSE_reply_internal_db_error (connection);
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (GNUNET_NO == ctx.is_valid)
|
if (GNUNET_NO == ctx.is_valid)
|
||||||
{
|
{
|
||||||
json_decref (ctx.deposits);
|
ret = TMH_RESPONSE_reply_arg_unknown (connection,
|
||||||
return TMH_RESPONSE_reply_arg_unknown (connection,
|
"wtid");
|
||||||
"wtid");
|
goto cleanup;
|
||||||
}
|
}
|
||||||
return TMH_RESPONSE_reply_wire_deposit_details (connection,
|
ret = TMH_RESPONSE_reply_wire_deposit_details (connection,
|
||||||
&ctx.total,
|
&ctx.total,
|
||||||
&ctx.merchant_pub,
|
&ctx.merchant_pub,
|
||||||
&ctx.h_wire,
|
&ctx.h_wire,
|
||||||
ctx.deposits);
|
ctx.wdd_head);
|
||||||
|
cleanup:
|
||||||
|
while (NULL != (wdd = ctx.wdd_head))
|
||||||
|
{
|
||||||
|
GNUNET_CONTAINER_DLL_remove (ctx.wdd_head,
|
||||||
|
ctx.wdd_tail,
|
||||||
|
wdd);
|
||||||
|
GNUNET_free (wdd);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1133,13 +1133,13 @@ TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection,
|
|||||||
MHD_HTTP_OK,
|
MHD_HTTP_OK,
|
||||||
"{s:o, s:o, s:o, s:o, s:o, s:o}",
|
"{s:o, s:o, s:o, s:o, s:o, s:o}",
|
||||||
"wtid", GNUNET_JSON_from_data (wtid,
|
"wtid", GNUNET_JSON_from_data (wtid,
|
||||||
sizeof (*wtid)),
|
sizeof (*wtid)),
|
||||||
"execution_time", GNUNET_JSON_from_time_abs (exec_time),
|
"execution_time", GNUNET_JSON_from_time_abs (exec_time),
|
||||||
"coin_contribution", TALER_JSON_from_amount (coin_contribution),
|
"coin_contribution", TALER_JSON_from_amount (coin_contribution),
|
||||||
"exchange_sig", GNUNET_JSON_from_data (&sig,
|
"exchange_sig", GNUNET_JSON_from_data (&sig,
|
||||||
sizeof (sig)),
|
sizeof (sig)),
|
||||||
"exchange_pub", GNUNET_JSON_from_data (&pub,
|
"exchange_pub", GNUNET_JSON_from_data (&pub,
|
||||||
sizeof (pub)));
|
sizeof (pub)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1151,7 +1151,7 @@ TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection,
|
|||||||
* @param total total amount that was transferred
|
* @param total total amount that was transferred
|
||||||
* @param merchant_pub public key of the merchant
|
* @param merchant_pub public key of the merchant
|
||||||
* @param h_wire destination account
|
* @param h_wire destination account
|
||||||
* @param deposits details about the combined deposits
|
* @param wdd_head linked list with details about the combined deposits
|
||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@ -1159,8 +1159,27 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection,
|
|||||||
const struct TALER_Amount *total,
|
const struct TALER_Amount *total,
|
||||||
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
||||||
const struct GNUNET_HashCode *h_wire,
|
const struct GNUNET_HashCode *h_wire,
|
||||||
json_t *deposits)
|
const struct TMH_WireDepositDetail *wdd_head)
|
||||||
{
|
{
|
||||||
|
const struct TMH_WireDepositDetail *wdd_pos;
|
||||||
|
json_t *deposits;
|
||||||
|
|
||||||
|
deposits = json_array ();
|
||||||
|
|
||||||
|
/* NOTE: We usually keep JSON stuff out of the _DB file, and this
|
||||||
|
is also ugly if we ever add signatures over this data. (#4135) */
|
||||||
|
for (wdd_pos = wdd_head; NULL != wdd_pos; wdd_pos = wdd_pos->next)
|
||||||
|
{
|
||||||
|
json_array_append (deposits,
|
||||||
|
json_pack ("{s:o, s:o, s:o, s:I, s:o}",
|
||||||
|
"deposit_value", TALER_JSON_from_amount (&wdd_pos->deposit_value),
|
||||||
|
"deposit_fee", TALER_JSON_from_amount (&wdd_pos->deposit_fee),
|
||||||
|
"H_contract", GNUNET_JSON_from_data (&wdd_pos->h_contract,
|
||||||
|
sizeof (struct GNUNET_HashCode)),
|
||||||
|
"transaction_id", (json_int_t) wdd_pos->transaction_id,
|
||||||
|
"coin_pub", GNUNET_JSON_from_data (&wdd_pos->coin_pub,
|
||||||
|
sizeof (struct TALER_CoinSpendPublicKeyP))));
|
||||||
|
}
|
||||||
/* FIXME: #4135: signing not implemented here */
|
/* FIXME: #4135: signing not implemented here */
|
||||||
return TMH_RESPONSE_reply_json_pack (connection,
|
return TMH_RESPONSE_reply_json_pack (connection,
|
||||||
MHD_HTTP_OK,
|
MHD_HTTP_OK,
|
||||||
|
@ -297,6 +297,49 @@ TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection,
|
|||||||
struct GNUNET_TIME_Absolute exec_time);
|
struct GNUNET_TIME_Absolute exec_time);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detail for /wire/deposit response.
|
||||||
|
*/
|
||||||
|
struct TMH_WireDepositDetail
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We keep deposit details in a DLL.
|
||||||
|
*/
|
||||||
|
struct TMH_WireDepositDetail *next;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We keep deposit details in a DLL.
|
||||||
|
*/
|
||||||
|
struct TMH_WireDepositDetail *prev;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash of the contract
|
||||||
|
*/
|
||||||
|
struct GNUNET_HashCode h_contract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merchant's transaction ID.
|
||||||
|
*/
|
||||||
|
uint64_t transaction_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coin's public key.
|
||||||
|
*/
|
||||||
|
struct TALER_CoinSpendPublicKeyP coin_pub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Total value of the coin.
|
||||||
|
*/
|
||||||
|
struct TALER_Amount deposit_value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fees charged by the exchange for the deposit.
|
||||||
|
*/
|
||||||
|
struct TALER_Amount deposit_fee;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A merchant asked for transaction details about a wire transfer.
|
* A merchant asked for transaction details about a wire transfer.
|
||||||
* Provide them. Generates the 200 reply.
|
* Provide them. Generates the 200 reply.
|
||||||
@ -305,7 +348,7 @@ TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection,
|
|||||||
* @param total total amount that was transferred
|
* @param total total amount that was transferred
|
||||||
* @param merchant_pub public key of the merchant
|
* @param merchant_pub public key of the merchant
|
||||||
* @param h_wire destination account
|
* @param h_wire destination account
|
||||||
* @param deposits details about the combined deposits
|
* @param wdd_head linked list with details about the combined deposits
|
||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@ -313,7 +356,7 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection,
|
|||||||
const struct TALER_Amount *total,
|
const struct TALER_Amount *total,
|
||||||
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
||||||
const struct GNUNET_HashCode *h_wire,
|
const struct GNUNET_HashCode *h_wire,
|
||||||
json_t *deposits);
|
const struct TMH_WireDepositDetail *wdd_head);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user