-more traits for reserve history checking

This commit is contained in:
Christian Grothoff 2022-05-23 12:17:41 +02:00
parent f1a58b0fd8
commit 2035294adb
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 110 additions and 12 deletions

View File

@ -4509,6 +4509,12 @@ struct TALER_EXCHANGE_PurseCreateMergeResponse
*/
struct TALER_EXCHANGE_HttpResponse hr;
/**
* Reserve signature generated for the request
* (client-side).
*/
const struct TALER_ReserveSignatureP *reserve_sig;
/**
* Details depending on the HTTP status.
*/

View File

@ -964,10 +964,9 @@ TALER_TESTING_parse_coin_reference (
* @return 0 if @a h1 and @a h2 are equal
*/
int
TALER_TESTING_history_entry_cmp (const struct
TALER_EXCHANGE_ReserveHistoryEntry *h1,
const struct
TALER_EXCHANGE_ReserveHistoryEntry *h2);
TALER_TESTING_history_entry_cmp (
const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
const struct TALER_EXCHANGE_ReserveHistoryEntry *h2);
/* ************** Specific interpreter commands ************ */
@ -2721,6 +2720,7 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
op (merge_pub, const struct TALER_PurseMergePublicKeyP) \
op (contract_priv, const struct TALER_ContractDiffiePrivateP) \
op (reserve_priv, const struct TALER_ReservePrivateKeyP) \
op (reserve_sig, const struct TALER_ReserveSignatureP) \
op (h_payto, const struct TALER_PaytoHashP) \
op (planchet_secret, const struct TALER_PlanchetMasterSecretP) \
op (refresh_secret, const struct TALER_RefreshMasterSecretP) \

View File

@ -80,6 +80,11 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle
*/
struct TALER_ReservePublicKeyP reserve_pub;
/**
* Reserve signature affirming our merge.
*/
struct TALER_ReserveSignatureP reserve_sig;
/**
* Public key of the purse.
*/
@ -119,7 +124,8 @@ handle_purse_create_with_merge_finished (void *cls,
const json_t *j = response;
struct TALER_EXCHANGE_PurseCreateMergeResponse dr = {
.hr.reply = j,
.hr.http_status = (unsigned int) response_code
.hr.http_status = (unsigned int) response_code,
.reserve_sig = &pcm->reserve_sig
};
pcm->job = NULL;
@ -259,7 +265,6 @@ TALER_EXCHANGE_purse_create_with_merge (
struct GNUNET_CURL_Context *ctx;
json_t *create_with_merge_obj;
CURL *eh;
struct TALER_ReserveSignatureP reserve_sig;
char arg_str[sizeof (pcm->reserve_pub) * 2 + 32];
uint32_t min_age = 0;
struct TALER_PurseMergePublicKeyP merge_pub;
@ -381,7 +386,7 @@ TALER_EXCHANGE_purse_create_with_merge (
min_age,
flags,
reserve_priv,
&reserve_sig);
&pcm->reserve_sig);
if (upload_contract)
{
TALER_CRYPTO_contract_encrypt_for_deposit (
@ -429,7 +434,7 @@ TALER_EXCHANGE_purse_create_with_merge (
GNUNET_JSON_pack_data_auto ("merge_sig",
&merge_sig),
GNUNET_JSON_pack_data_auto ("reserve_sig",
&reserve_sig),
&pcm->reserve_sig),
GNUNET_JSON_pack_data_auto ("purse_pub",
&pcm->purse_pub),
GNUNET_JSON_pack_data_auto ("purse_sig",

View File

@ -87,6 +87,12 @@ struct PurseDepositState
*/
const char *purse_ref;
/**
* Reserve history entry that corresponds to this operation.
* Will be of type #TALER_EXCHANGE_RTT_MERGE.
* Only valid if @e purse_complete is true.
*/
struct TALER_EXCHANGE_ReserveHistoryEntry reserve_history;
/**
* Expected HTTP response code.
*/
@ -101,6 +107,11 @@ struct PurseDepositState
* Minimum age to apply to all deposits.
*/
uint8_t min_age;
/**
* Set to true if this deposit filled the purse.
*/
bool purse_complete;
};
@ -134,7 +145,71 @@ deposit_cb (void *cls,
}
if (MHD_HTTP_OK == dr->hr.http_status)
{
// FIXME: any data to keep from reply?
if (-1 !=
TALER_amount_cmp (&dr->details.success.total_deposited,
&dr->details.success.purse_value_after_fees))
{
const struct TALER_TESTING_Command *purse_cmd;
const struct TALER_ReserveSignatureP *reserve_sig;
const struct GNUNET_TIME_Timestamp *merge_timestamp;
purse_cmd = TALER_TESTING_interpreter_lookup_command (ds->is,
ds->purse_ref);
if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_sig (purse_cmd,
&reserve_sig))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
return;
}
if (GNUNET_OK !=
TALER_TESTING_get_trait_timestamp (purse_cmd,
0,
&merge_timestamp))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
return;
}
/* Deposits complete, create trait! */
ds->reserve_history.type = TALER_EXCHANGE_RTT_MERGE;
ds->reserve_history.amount
= dr->details.success.purse_value_after_fees;
#if 0
{
const struct TALER_EXCHANGE_Keys *keys;
const struct TALER_EXCHANGE_GlobalFee *gf;
keys = TALER_EXCHANGE_get_keys (ds->is->exchange);
GNUNET_assert (NULL != keys);
gf = TALER_EXCHANGE_get_global_fee (keys,
*merge_timestamp);
GNUNET_assert (NULL != gf);
}
#endif
/* Note: change when flags below changes! */
TALER_amount_set_zero (
ds->reserve_history.amount.currency,
&ds->reserve_history.details.merge_details.purse_fee);
ds->reserve_history.details.merge_details.h_contract_terms
= dr->details.success.h_contract_terms;
ds->reserve_history.details.merge_details.merge_pub
= dr->details.success.merge_pub;
ds->reserve_history.details.merge_details.reserve_sig
= *reserve_sig;
ds->reserve_history.details.merge_details.merge_timestamp
= *merge_timestamp;
ds->reserve_history.details.merge_details.purse_expiration
= dr->details.success.purse_expiration;
ds->reserve_history.details.merge_details.min_age
= ds->min_age;
ds->reserve_history.details.merge_details.flags
= TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA;
ds->purse_complete = true;
}
}
TALER_TESTING_interpreter_next (ds->is);
}
@ -293,11 +368,15 @@ deposit_traits (void *cls,
{
struct PurseDepositState *ds = cls;
struct TALER_TESTING_Trait traits[] = {
/* history entry MUST be first due to response code logic below! */
TALER_TESTING_make_trait_reserve_history (&ds->reserve_history),
TALER_TESTING_make_trait_purse_pub (&ds->purse_pub),
TALER_TESTING_trait_end ()
};
return TALER_TESTING_get_trait (traits,
return TALER_TESTING_get_trait (ds->purse_complete
? &traits[0] /* we have reserve history */
: &traits[1], /* skip reserve history */
ret,
trait,
index);

View File

@ -140,7 +140,7 @@ merge_cb (void *cls,
gf = TALER_EXCHANGE_get_global_fee (keys,
ds->merge_timestamp);
GNUNET_assert (NULL != gf);
ds->reserve_history.amount = gf->fees.purse;
ds->reserve_history.amount = ds->value_after_fees;
ds->reserve_history.details.merge_details.purse_fee = gf->fees.purse;
ds->reserve_history.details.merge_details.h_contract_terms
= ds->h_contract_terms;

View File

@ -46,6 +46,12 @@ struct ReservePurseState
*/
struct TALER_ReservePrivateKeyP reserve_priv;
/**
* Reserve signature generated for the request
* (client-side).
*/
struct TALER_ReserveSignatureP reserve_sig;
/**
* Private key of the purse.
*/
@ -118,6 +124,7 @@ purse_cb (void *cls,
struct ReservePurseState *ds = cls;
ds->dh = NULL;
ds->reserve_sig = *dr->reserve_sig;
if (ds->expected_response_code != dr->hr.http_status)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -187,7 +194,7 @@ purse_run (void *cls,
&ds->contract_priv,
ds->contract_terms,
true /* upload contract */,
false /* do not pay purse fee -- FIXME: make this a choice to test this case! */,
false /* do not pay purse fee -- FIXME: make this a choice to test this case; then update testing_api_cmd_purse_deposit flags logic to match! */,
ds->merge_timestamp,
&purse_cb,
ds);
@ -254,6 +261,7 @@ purse_traits (void *cls,
TALER_TESTING_make_trait_merge_priv (&ds->merge_priv),
TALER_TESTING_make_trait_contract_priv (&ds->contract_priv),
TALER_TESTING_make_trait_reserve_priv (&ds->reserve_priv),
TALER_TESTING_make_trait_reserve_sig (&ds->reserve_sig),
TALER_TESTING_trait_end ()
};