modify TALER_EXCHANGE_deposits_get() API to combine returned arguments into a struct (simplifies merchant later)
This commit is contained in:
parent
35bfdbef19
commit
1ed77a9f2e
@ -1682,27 +1682,57 @@ TALER_EXCHANGE_transfers_get_cancel (
|
|||||||
struct TALER_EXCHANGE_DepositGetHandle;
|
struct TALER_EXCHANGE_DepositGetHandle;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data returned for a successful GET /deposits/ request. Note that
|
||||||
|
* most fields are only set if the status is #MHD_HTTP_OK. Only
|
||||||
|
* the @e execution_time is available if the status is #MHD_HTTP_ACCEPTED.
|
||||||
|
*/
|
||||||
|
struct TALER_EXCHANGE_DepositData
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* exchange key used to sign, NULL if exchange did not
|
||||||
|
* yet execute the transaction
|
||||||
|
*/
|
||||||
|
const struct TALER_ExchangePublicKeyP *exchange_pub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signature from the exchange over the deposit data, NULL if exchange did not
|
||||||
|
* yet execute the transaction
|
||||||
|
*/
|
||||||
|
const struct TALER_ExchangeSignatureP *exchange_sig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wire transfer identifier used by the exchange, NULL if exchange did not
|
||||||
|
* yet execute the transaction
|
||||||
|
*/
|
||||||
|
const struct TALER_WireTransferIdentifierRawP *wtid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* actual or planned execution time for the wire transfer
|
||||||
|
*/
|
||||||
|
struct GNUNET_TIME_Absolute execution_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contribution to the total amount by this coin, NULL if exchange did not
|
||||||
|
* yet execute the transaction
|
||||||
|
*/
|
||||||
|
const struct TALER_Amount *coin_contribution;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function called with detailed wire transfer data.
|
* Function called with detailed wire transfer data.
|
||||||
*
|
*
|
||||||
* @param cls closure
|
* @param cls closure
|
||||||
* @param hr HTTP response data
|
* @param hr HTTP response data
|
||||||
* @param exchange_pub exchange key used to sign @a json, or NULL
|
* @param dd details about the deposit (NULL on errors)
|
||||||
* @param wtid wire transfer identifier used by the exchange, NULL if exchange did not
|
|
||||||
* yet execute the transaction
|
|
||||||
* @param execution_time actual or planned execution time for the wire transfer
|
|
||||||
* @param coin_contribution contribution to the total amount by this coin (can be NULL)
|
|
||||||
* // FIXME: also return the exchange signature
|
|
||||||
* // FIXME: combine all of the above (except cls,hr) into a 'struct'! => DepositData
|
|
||||||
*/
|
*/
|
||||||
typedef void
|
typedef void
|
||||||
(*TALER_EXCHANGE_DepositGetCallback)(
|
(*TALER_EXCHANGE_DepositGetCallback)(
|
||||||
void *cls,
|
void *cls,
|
||||||
const struct TALER_EXCHANGE_HttpResponse *hr,
|
const struct TALER_EXCHANGE_HttpResponse *hr,
|
||||||
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
const struct TALER_EXCHANGE_DepositData *dd);
|
||||||
const struct TALER_WireTransferIdentifierRawP *wtid,
|
|
||||||
struct GNUNET_TIME_Absolute execution_time,
|
|
||||||
const struct TALER_Amount *coin_contribution);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A Deposit Wtid Handle
|
* @brief A Deposit Get Handle
|
||||||
*/
|
*/
|
||||||
struct TALER_EXCHANGE_DepositGetHandle
|
struct TALER_EXCHANGE_DepositGetHandle
|
||||||
{
|
{
|
||||||
@ -84,31 +84,19 @@ struct TALER_EXCHANGE_DepositGetHandle
|
|||||||
*
|
*
|
||||||
* @param dwh deposit wtid handle
|
* @param dwh deposit wtid handle
|
||||||
* @param json json reply with the signature
|
* @param json json reply with the signature
|
||||||
* @param[out] exchange_pub set to the exchange's public key
|
* @param exchange_pub the exchange's public key
|
||||||
|
* @param exchange_sig the exchange's signature
|
||||||
* @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not
|
* @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
verify_deposit_wtid_signature_ok (
|
verify_deposit_wtid_signature_ok (
|
||||||
const struct TALER_EXCHANGE_DepositGetHandle *dwh,
|
const struct TALER_EXCHANGE_DepositGetHandle *dwh,
|
||||||
const json_t *json,
|
const json_t *json,
|
||||||
struct TALER_ExchangePublicKeyP *exchange_pub)
|
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
||||||
|
const struct TALER_ExchangeSignatureP *exchange_sig)
|
||||||
{
|
{
|
||||||
struct TALER_ExchangeSignatureP exchange_sig;
|
|
||||||
const struct TALER_EXCHANGE_Keys *key_state;
|
const struct TALER_EXCHANGE_Keys *key_state;
|
||||||
struct GNUNET_JSON_Specification spec[] = {
|
|
||||||
GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig),
|
|
||||||
GNUNET_JSON_spec_fixed_auto ("exchange_pub", exchange_pub),
|
|
||||||
GNUNET_JSON_spec_end ()
|
|
||||||
};
|
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
|
||||||
GNUNET_JSON_parse (json,
|
|
||||||
spec,
|
|
||||||
NULL, NULL))
|
|
||||||
{
|
|
||||||
GNUNET_break_op (0);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
key_state = TALER_EXCHANGE_get_keys (dwh->exchange);
|
key_state = TALER_EXCHANGE_get_keys (dwh->exchange);
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_EXCHANGE_test_signing_key (key_state,
|
TALER_EXCHANGE_test_signing_key (key_state,
|
||||||
@ -120,7 +108,7 @@ verify_deposit_wtid_signature_ok (
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE,
|
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE,
|
||||||
&dwh->depconf,
|
&dwh->depconf,
|
||||||
&exchange_sig.eddsa_signature,
|
&exchange_sig->eddsa_signature,
|
||||||
&exchange_pub->eddsa_pub))
|
&exchange_pub->eddsa_pub))
|
||||||
{
|
{
|
||||||
GNUNET_break_op (0);
|
GNUNET_break_op (0);
|
||||||
@ -144,12 +132,6 @@ handle_deposit_wtid_finished (void *cls,
|
|||||||
const void *response)
|
const void *response)
|
||||||
{
|
{
|
||||||
struct TALER_EXCHANGE_DepositGetHandle *dwh = cls;
|
struct TALER_EXCHANGE_DepositGetHandle *dwh = cls;
|
||||||
const struct TALER_WireTransferIdentifierRawP *wtid = NULL;
|
|
||||||
struct GNUNET_TIME_Absolute execution_time = GNUNET_TIME_UNIT_FOREVER_ABS;
|
|
||||||
const struct TALER_Amount *coin_contribution = NULL;
|
|
||||||
struct TALER_Amount coin_contribution_s;
|
|
||||||
struct TALER_ExchangePublicKeyP exchange_pub;
|
|
||||||
struct TALER_ExchangePublicKeyP *ep = NULL;
|
|
||||||
const json_t *j = response;
|
const json_t *j = response;
|
||||||
struct TALER_EXCHANGE_HttpResponse hr = {
|
struct TALER_EXCHANGE_HttpResponse hr = {
|
||||||
.reply = j,
|
.reply = j,
|
||||||
@ -164,10 +146,16 @@ handle_deposit_wtid_finished (void *cls,
|
|||||||
break;
|
break;
|
||||||
case MHD_HTTP_OK:
|
case MHD_HTTP_OK:
|
||||||
{
|
{
|
||||||
|
struct GNUNET_TIME_Absolute execution_time;
|
||||||
|
struct TALER_Amount coin_contribution;
|
||||||
|
struct TALER_ExchangePublicKeyP exchange_pub;
|
||||||
|
struct TALER_ExchangeSignatureP exchange_sig;
|
||||||
struct GNUNET_JSON_Specification spec[] = {
|
struct GNUNET_JSON_Specification spec[] = {
|
||||||
GNUNET_JSON_spec_fixed_auto ("wtid", &dwh->depconf.wtid),
|
GNUNET_JSON_spec_fixed_auto ("wtid", &dwh->depconf.wtid),
|
||||||
GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time),
|
GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time),
|
||||||
TALER_JSON_spec_amount ("coin_contribution", &coin_contribution_s),
|
TALER_JSON_spec_amount ("coin_contribution", &coin_contribution),
|
||||||
|
GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig),
|
||||||
|
GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub),
|
||||||
GNUNET_JSON_spec_end ()
|
GNUNET_JSON_spec_end ()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -181,15 +169,14 @@ handle_deposit_wtid_finished (void *cls,
|
|||||||
hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
|
hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wtid = &dwh->depconf.wtid;
|
|
||||||
dwh->depconf.execution_time = GNUNET_TIME_absolute_hton (execution_time);
|
dwh->depconf.execution_time = GNUNET_TIME_absolute_hton (execution_time);
|
||||||
TALER_amount_hton (&dwh->depconf.coin_contribution,
|
TALER_amount_hton (&dwh->depconf.coin_contribution,
|
||||||
&coin_contribution_s);
|
&coin_contribution);
|
||||||
coin_contribution = &coin_contribution_s;
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
verify_deposit_wtid_signature_ok (dwh,
|
verify_deposit_wtid_signature_ok (dwh,
|
||||||
j,
|
j,
|
||||||
&exchange_pub))
|
&exchange_pub,
|
||||||
|
&exchange_sig))
|
||||||
{
|
{
|
||||||
GNUNET_break_op (0);
|
GNUNET_break_op (0);
|
||||||
hr.http_status = 0;
|
hr.http_status = 0;
|
||||||
@ -197,13 +184,26 @@ handle_deposit_wtid_finished (void *cls,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ep = &exchange_pub;
|
struct TALER_EXCHANGE_DepositData dd = {
|
||||||
|
.exchange_pub = &exchange_pub,
|
||||||
|
.exchange_sig = &exchange_sig,
|
||||||
|
.wtid = &dwh->depconf.wtid,
|
||||||
|
.execution_time = execution_time,
|
||||||
|
.coin_contribution = &coin_contribution
|
||||||
|
};
|
||||||
|
|
||||||
|
dwh->cb (dwh->cb_cls,
|
||||||
|
&hr,
|
||||||
|
&dd);
|
||||||
|
TALER_EXCHANGE_deposits_get_cancel (dwh);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MHD_HTTP_ACCEPTED:
|
case MHD_HTTP_ACCEPTED:
|
||||||
{
|
{
|
||||||
/* Transaction known, but not executed yet */
|
/* Transaction known, but not executed yet */
|
||||||
|
struct GNUNET_TIME_Absolute execution_time;
|
||||||
struct GNUNET_JSON_Specification spec[] = {
|
struct GNUNET_JSON_Specification spec[] = {
|
||||||
GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time),
|
GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time),
|
||||||
GNUNET_JSON_spec_end ()
|
GNUNET_JSON_spec_end ()
|
||||||
@ -219,6 +219,18 @@ handle_deposit_wtid_finished (void *cls,
|
|||||||
hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
|
hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct TALER_EXCHANGE_DepositData dd = {
|
||||||
|
.execution_time = execution_time
|
||||||
|
};
|
||||||
|
|
||||||
|
dwh->cb (dwh->cb_cls,
|
||||||
|
&hr,
|
||||||
|
&dd);
|
||||||
|
TALER_EXCHANGE_deposits_get_cancel (dwh);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MHD_HTTP_BAD_REQUEST:
|
case MHD_HTTP_BAD_REQUEST:
|
||||||
@ -259,10 +271,7 @@ handle_deposit_wtid_finished (void *cls,
|
|||||||
}
|
}
|
||||||
dwh->cb (dwh->cb_cls,
|
dwh->cb (dwh->cb_cls,
|
||||||
&hr,
|
&hr,
|
||||||
ep,
|
NULL);
|
||||||
wtid,
|
|
||||||
execution_time,
|
|
||||||
coin_contribution);
|
|
||||||
TALER_EXCHANGE_deposits_get_cancel (dwh);
|
TALER_EXCHANGE_deposits_get_cancel (dwh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,29 +81,17 @@ struct TrackTransactionState
|
|||||||
*
|
*
|
||||||
* @param cls closure.
|
* @param cls closure.
|
||||||
* @param hr HTTP response details
|
* @param hr HTTP response details
|
||||||
* @param exchange_pub public key of the exchange
|
* @param dd data about the wire transfer associated with the deposit
|
||||||
* @param wtid wire transfer identifier, NULL if exchange did not
|
|
||||||
* execute the transaction yet.
|
|
||||||
* @param execution_time actual or planned execution time for the
|
|
||||||
* wire transfer.
|
|
||||||
* @param coin_contribution contribution to the total amount of
|
|
||||||
* the deposited coin (can be NULL).
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
deposit_wtid_cb (void *cls,
|
deposit_wtid_cb (void *cls,
|
||||||
const struct TALER_EXCHANGE_HttpResponse *hr,
|
const struct TALER_EXCHANGE_HttpResponse *hr,
|
||||||
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
const struct TALER_EXCHANGE_DepositData *dd)
|
||||||
const struct TALER_WireTransferIdentifierRawP *wtid,
|
|
||||||
struct GNUNET_TIME_Absolute execution_time,
|
|
||||||
const struct TALER_Amount *coin_contribution)
|
|
||||||
{
|
{
|
||||||
struct TrackTransactionState *tts = cls;
|
struct TrackTransactionState *tts = cls;
|
||||||
struct TALER_TESTING_Interpreter *is = tts->is;
|
struct TALER_TESTING_Interpreter *is = tts->is;
|
||||||
struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
|
struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
|
||||||
|
|
||||||
(void) coin_contribution;
|
|
||||||
(void) exchange_pub;
|
|
||||||
(void) execution_time;
|
|
||||||
tts->tth = NULL;
|
tts->tth = NULL;
|
||||||
if (tts->expected_response_code != hr->http_status)
|
if (tts->expected_response_code != hr->http_status)
|
||||||
{
|
{
|
||||||
@ -123,7 +111,8 @@ deposit_wtid_cb (void *cls,
|
|||||||
switch (hr->http_status)
|
switch (hr->http_status)
|
||||||
{
|
{
|
||||||
case MHD_HTTP_OK:
|
case MHD_HTTP_OK:
|
||||||
tts->wtid = *wtid;
|
GNUNET_assert (NULL != dd->wtid);
|
||||||
|
tts->wtid = *dd->wtid;
|
||||||
if (NULL != tts->bank_transfer_reference)
|
if (NULL != tts->bank_transfer_reference)
|
||||||
{
|
{
|
||||||
const struct TALER_TESTING_Command *bank_transfer_cmd;
|
const struct TALER_TESTING_Command *bank_transfer_cmd;
|
||||||
@ -151,7 +140,7 @@ deposit_wtid_cb (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compare that expected and gotten subjects match. */
|
/* Compare that expected and gotten subjects match. */
|
||||||
if (0 != GNUNET_memcmp (wtid,
|
if (0 != GNUNET_memcmp (dd->wtid,
|
||||||
wtid_want))
|
wtid_want))
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
|
Loading…
Reference in New Issue
Block a user