reconstructing array of denominations for coins gotten
by melting dynamically; as reported in msg (0010890) of #4576'
This commit is contained in:
parent
0e9651210d
commit
a34a2873ca
@ -87,6 +87,11 @@ struct RefreshRevealCls {
|
|||||||
* Which coin in the list are we melting
|
* Which coin in the list are we melting
|
||||||
*/
|
*/
|
||||||
unsigned int coin_index;
|
unsigned int coin_index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of denominations expected to get from melt
|
||||||
|
*/
|
||||||
|
struct TALER_Amount *denoms;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,16 +226,6 @@ static struct Reserve *reserves;
|
|||||||
*/
|
*/
|
||||||
static struct Coin *coins;
|
static struct Coin *coins;
|
||||||
|
|
||||||
/**
|
|
||||||
* Indices of spent coins
|
|
||||||
*/
|
|
||||||
static unsigned int *spent_coins;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current number of spent coins
|
|
||||||
*/
|
|
||||||
static unsigned int spent_coins_size = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction id counter, used in /deposit's
|
* Transaction id counter, used in /deposit's
|
||||||
*/
|
*/
|
||||||
@ -425,22 +420,20 @@ reveal_cb (void *cls,
|
|||||||
for (i=0; i<num_coins; i++)
|
for (i=0; i<num_coins; i++)
|
||||||
{
|
{
|
||||||
struct Coin fresh_coin;
|
struct Coin fresh_coin;
|
||||||
struct TALER_Amount amount;
|
char *revealed_str;
|
||||||
char *refresh_denom;
|
|
||||||
|
|
||||||
GNUNET_asprintf (&refresh_denom,
|
revealed_str = TALER_amount_to_string (&rrcls->denoms[i]);
|
||||||
"%s:%s",
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
currency,
|
"revealing %s "
|
||||||
refresh_denoms[i]);
|
"# of coins after refresh: %d\n",
|
||||||
|
revealed_str,
|
||||||
|
ncoins);
|
||||||
|
|
||||||
|
GNUNET_free (revealed_str);
|
||||||
fresh_coin.reserve_index = coins[rrcls->coin_index].reserve_index;
|
fresh_coin.reserve_index = coins[rrcls->coin_index].reserve_index;
|
||||||
TALER_string_to_amount (refresh_denom, &amount);
|
fresh_coin.pk = find_pk (keys, &rrcls->denoms[i]);
|
||||||
GNUNET_free (refresh_denom);
|
|
||||||
fresh_coin.pk = find_pk (keys, &amount);
|
|
||||||
fresh_coin.sig = sigs[i];
|
fresh_coin.sig = sigs[i];
|
||||||
GNUNET_array_append (coins, ncoins, fresh_coin);
|
GNUNET_array_append (coins, ncoins, fresh_coin);
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
|
||||||
"# of coins after refresh: %d\n",
|
|
||||||
ncoins);
|
|
||||||
}
|
}
|
||||||
GNUNET_free (rrcls);
|
GNUNET_free (rrcls);
|
||||||
}
|
}
|
||||||
@ -463,8 +456,8 @@ melt_cb (void *cls,
|
|||||||
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
||||||
const json_t *full_response)
|
const json_t *full_response)
|
||||||
{
|
{
|
||||||
|
/* free'd in `reveal_cb` */
|
||||||
struct RefreshRevealCls *rrcls = cls;
|
struct RefreshRevealCls *rrcls = cls;
|
||||||
/* FIXME to be freed */
|
|
||||||
|
|
||||||
coins[rrcls->coin_index].rmh = NULL;
|
coins[rrcls->coin_index].rmh = NULL;
|
||||||
if (MHD_HTTP_OK != http_status)
|
if (MHD_HTTP_OK != http_status)
|
||||||
@ -473,12 +466,13 @@ melt_cb (void *cls,
|
|||||||
fail ("Coin not correctly melted!\n");
|
fail ("Coin not correctly melted!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
coins[rrcls->coin_index].rrh
|
coins[rrcls->coin_index].rrh
|
||||||
= TALER_EXCHANGE_refresh_reveal (exchange,
|
= TALER_EXCHANGE_refresh_reveal (exchange,
|
||||||
rrcls->blob_size,
|
rrcls->blob_size,
|
||||||
rrcls->blob,
|
rrcls->blob,
|
||||||
noreveal_index,
|
noreveal_index,
|
||||||
reveal_cb,
|
&reveal_cb,
|
||||||
rrcls);
|
rrcls);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,30 +519,52 @@ deposit_cb (void *cls,
|
|||||||
fail ("At least one coin has not been deposited, status: %d\n");
|
fail ("At least one coin has not been deposited, status: %d\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Coin #%d correctly spent!\n", coin_index);
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
GNUNET_array_append (spent_coins, spent_coins_size, coin_index);
|
"Coin #%d correctly spent!\n",
|
||||||
spent_coins_size++;
|
coin_index);
|
||||||
if (GNUNET_YES == coins[coin_index].refresh)
|
if (GNUNET_YES == coins[coin_index].refresh)
|
||||||
{
|
{
|
||||||
struct TALER_Amount melt_amount;
|
|
||||||
struct RefreshRevealCls *rrcls;
|
struct RefreshRevealCls *rrcls;
|
||||||
|
|
||||||
TALER_amount_get_zero (currency, &melt_amount);
|
|
||||||
melt_amount.value = 7;
|
|
||||||
char *blob;
|
char *blob;
|
||||||
size_t blob_size;
|
size_t blob_size;
|
||||||
|
const struct TALER_EXCHANGE_Keys *keys;
|
||||||
|
struct TALER_Amount *denoms = NULL;
|
||||||
|
struct TALER_EXCHANGE_DenomPublicKey *dpks = NULL;
|
||||||
|
const struct TALER_EXCHANGE_DenomPublicKey *curr_dpk;
|
||||||
|
struct TALER_Amount curr;
|
||||||
|
unsigned int ndenoms = 0;
|
||||||
|
unsigned int ndenoms2 = 0;
|
||||||
|
unsigned long long acc_value;
|
||||||
|
|
||||||
|
TALER_amount_get_zero (currency, &curr);
|
||||||
|
curr.value = COIN_VALUE >> 1;
|
||||||
|
acc_value = 0;
|
||||||
|
|
||||||
|
keys = TALER_EXCHANGE_get_keys (exchange);
|
||||||
|
for (; curr.value > 0; curr.value = curr.value >> 1)
|
||||||
|
{
|
||||||
|
if (acc_value + curr.value <= coins[coin_index].left.value)
|
||||||
|
{
|
||||||
|
GNUNET_array_append (denoms, ndenoms, curr);
|
||||||
|
GNUNET_assert (NULL != (curr_dpk = find_pk (keys, &curr)));
|
||||||
|
GNUNET_array_append (dpks, ndenoms2, *curr_dpk);
|
||||||
|
acc_value += curr.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"# of coins to get in melt: %d\n",
|
||||||
|
ndenoms2);
|
||||||
blob = TALER_EXCHANGE_refresh_prepare (&coins[coin_index].coin_priv,
|
blob = TALER_EXCHANGE_refresh_prepare (&coins[coin_index].coin_priv,
|
||||||
&melt_amount,
|
&coins[coin_index].left,
|
||||||
&coins[coin_index].sig,
|
&coins[coin_index].sig,
|
||||||
coins[coin_index].pk,
|
coins[coin_index].pk,
|
||||||
GNUNET_YES,
|
GNUNET_YES,
|
||||||
refresh_pk_len,
|
ndenoms2,
|
||||||
refresh_pk,
|
dpks,
|
||||||
&blob_size);
|
&blob_size);
|
||||||
if (NULL == blob)
|
if (NULL == blob)
|
||||||
{
|
{
|
||||||
fail ("Failed to prepare refresh");
|
fail ("Failed to prepare refresh\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
@ -556,14 +572,11 @@ deposit_cb (void *cls,
|
|||||||
(unsigned int) blob_size);
|
(unsigned int) blob_size);
|
||||||
refreshed_once = GNUNET_YES;
|
refreshed_once = GNUNET_YES;
|
||||||
|
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
|
||||||
"# of coins to get in melt: %d\n",
|
|
||||||
refresh_pk_len);
|
|
||||||
rrcls = GNUNET_new (struct RefreshRevealCls);
|
rrcls = GNUNET_new (struct RefreshRevealCls);
|
||||||
rrcls->blob = blob;
|
rrcls->blob = blob;
|
||||||
rrcls->blob_size = blob_size;
|
rrcls->blob_size = blob_size;
|
||||||
rrcls->coin_index = coin_index;
|
rrcls->coin_index = coin_index;
|
||||||
|
rrcls->denoms = denoms;
|
||||||
coins[coin_index].rmh = TALER_EXCHANGE_refresh_melt (exchange,
|
coins[coin_index].rmh = TALER_EXCHANGE_refresh_melt (exchange,
|
||||||
blob_size,
|
blob_size,
|
||||||
blob,
|
blob,
|
||||||
@ -619,7 +632,7 @@ reserve_withdraw_cb (void *cls,
|
|||||||
fail ("At least one coin has not correctly been withdrawn\n");
|
fail ("At least one coin has not correctly been withdrawn\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"%d-th coin withdrawn\n",
|
"%d-th coin withdrawn\n",
|
||||||
coin_index);
|
coin_index);
|
||||||
coins[coin_index].sig.rsa_signature =
|
coins[coin_index].sig.rsa_signature =
|
||||||
@ -652,18 +665,20 @@ reserve_withdraw_cb (void *cls,
|
|||||||
if (GNUNET_YES == eval_probability (REFRESH_PROBABILITY)
|
if (GNUNET_YES == eval_probability (REFRESH_PROBABILITY)
|
||||||
&& GNUNET_NO == refreshed_once)
|
&& GNUNET_NO == refreshed_once)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Always spending 1 out of 8 KUDOS. To be improved by randomly
|
||||||
|
* picking the spent amount
|
||||||
|
*/
|
||||||
struct TALER_Amount one;
|
struct TALER_Amount one;
|
||||||
TALER_amount_get_zero (currency, &one);
|
TALER_amount_get_zero (currency, &one);
|
||||||
one.value = 1;
|
one.value = 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* If the coin is going to be refreshed, only 1 unit
|
|
||||||
* of currency will be spent, since 4 units are going
|
|
||||||
* to be refreshed
|
|
||||||
*/
|
|
||||||
TALER_amount_subtract (&amount,
|
TALER_amount_subtract (&amount,
|
||||||
&one,
|
&one,
|
||||||
&coins[coin_index].pk->fee_deposit);
|
&coins[coin_index].pk->fee_deposit);
|
||||||
|
TALER_amount_subtract (&coins[coin_index].left,
|
||||||
|
&coins[coin_index].pk->value,
|
||||||
|
&one);
|
||||||
coins[coin_index].refresh = GNUNET_YES;
|
coins[coin_index].refresh = GNUNET_YES;
|
||||||
refreshed_once = GNUNET_YES;
|
refreshed_once = GNUNET_YES;
|
||||||
}
|
}
|
||||||
@ -1004,7 +1019,6 @@ do_shutdown (void *cls)
|
|||||||
|
|
||||||
GNUNET_free_non_null (reserves);
|
GNUNET_free_non_null (reserves);
|
||||||
GNUNET_free_non_null (coins);
|
GNUNET_free_non_null (coins);
|
||||||
GNUNET_free_non_null (spent_coins);
|
|
||||||
GNUNET_free_non_null (currency);
|
GNUNET_free_non_null (currency);
|
||||||
|
|
||||||
if (NULL != exchange)
|
if (NULL != exchange)
|
||||||
@ -1095,10 +1109,6 @@ run (void *cls)
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
GNUNET_CONFIGURATION_destroy (cfg);
|
GNUNET_CONFIGURATION_destroy (cfg);
|
||||||
GNUNET_array_append (spent_coins,
|
|
||||||
spent_coins_size,
|
|
||||||
1);
|
|
||||||
spent_coins_size++;
|
|
||||||
reserves = NULL;
|
reserves = NULL;
|
||||||
coins = NULL;
|
coins = NULL;
|
||||||
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
||||||
|
Loading…
Reference in New Issue
Block a user