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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@ -1621,6 +1631,7 @@ handle_transaction_data (void *cls,
|
||||
{
|
||||
struct WtidTransactionContext *ctx = cls;
|
||||
struct TALER_Amount delta;
|
||||
struct TMH_WireDepositDetail *wdd;
|
||||
|
||||
if (GNUNET_SYSERR == ctx->is_valid)
|
||||
return;
|
||||
@ -1671,17 +1682,15 @@ handle_transaction_data (void *cls,
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* 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) */
|
||||
json_array_append (ctx->deposits,
|
||||
json_pack ("{s:o, s:o, s:o, s:I, s:o}",
|
||||
"deposit_value", TALER_JSON_from_amount (deposit_value),
|
||||
"deposit_fee", TALER_JSON_from_amount (deposit_fee),
|
||||
"H_contract", GNUNET_JSON_from_data (h_contract,
|
||||
sizeof (struct GNUNET_HashCode)),
|
||||
"transaction_id", (json_int_t) transaction_id,
|
||||
"coin_pub", GNUNET_JSON_from_data (coin_pub,
|
||||
sizeof (struct TALER_CoinSpendPublicKeyP))));
|
||||
wdd = GNUNET_new (struct TMH_WireDepositDetail);
|
||||
wdd->deposit_value = *deposit_value;
|
||||
wdd->deposit_fee = *deposit_fee;
|
||||
wdd->h_contract = *h_contract;
|
||||
wdd->transaction_id = transaction_id;
|
||||
wdd->coin_pub = *coin_pub;
|
||||
GNUNET_CONTAINER_DLL_insert (ctx->wdd_head,
|
||||
ctx->wdd_tail,
|
||||
wdd);
|
||||
}
|
||||
|
||||
|
||||
@ -1700,6 +1709,7 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection,
|
||||
int ret;
|
||||
struct WtidTransactionContext ctx;
|
||||
struct TALER_EXCHANGEDB_Session *session;
|
||||
struct TMH_WireDepositDetail *wdd;
|
||||
|
||||
if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls,
|
||||
TMH_test_mode)))
|
||||
@ -1708,7 +1718,6 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection,
|
||||
return TMH_RESPONSE_reply_internal_db_error (connection);
|
||||
}
|
||||
ctx.is_valid = GNUNET_NO;
|
||||
ctx.deposits = json_array ();
|
||||
ret = TMH_plugin->lookup_wire_transfer (TMH_plugin->cls,
|
||||
session,
|
||||
wtid,
|
||||
@ -1717,26 +1726,35 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection,
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (ctx.deposits);
|
||||
return TMH_RESPONSE_reply_internal_db_error (connection);
|
||||
ret = TMH_RESPONSE_reply_internal_db_error (connection);
|
||||
goto cleanup;
|
||||
}
|
||||
if (GNUNET_SYSERR == ctx.is_valid)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (ctx.deposits);
|
||||
return TMH_RESPONSE_reply_internal_db_error (connection);
|
||||
ret = TMH_RESPONSE_reply_internal_db_error (connection);
|
||||
goto cleanup;
|
||||
}
|
||||
if (GNUNET_NO == ctx.is_valid)
|
||||
{
|
||||
json_decref (ctx.deposits);
|
||||
return TMH_RESPONSE_reply_arg_unknown (connection,
|
||||
ret = TMH_RESPONSE_reply_arg_unknown (connection,
|
||||
"wtid");
|
||||
goto cleanup;
|
||||
}
|
||||
return TMH_RESPONSE_reply_wire_deposit_details (connection,
|
||||
ret = TMH_RESPONSE_reply_wire_deposit_details (connection,
|
||||
&ctx.total,
|
||||
&ctx.merchant_pub,
|
||||
&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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1151,7 +1151,7 @@ TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection,
|
||||
* @param total total amount that was transferred
|
||||
* @param merchant_pub public key of the merchant
|
||||
* @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
|
||||
*/
|
||||
int
|
||||
@ -1159,8 +1159,27 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection,
|
||||
const struct TALER_Amount *total,
|
||||
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
||||
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 */
|
||||
return TMH_RESPONSE_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
|
@ -297,6 +297,49 @@ TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection,
|
||||
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.
|
||||
* 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 merchant_pub public key of the merchant
|
||||
* @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
|
||||
*/
|
||||
int
|
||||
@ -313,7 +356,7 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection,
|
||||
const struct TALER_Amount *total,
|
||||
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
||||
const struct GNUNET_HashCode *h_wire,
|
||||
json_t *deposits);
|
||||
const struct TMH_WireDepositDetail *wdd_head);
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user