reduce code duplication
This commit is contained in:
parent
6066ffcb9b
commit
30903b9386
@ -42,7 +42,6 @@ TALER_EXCHANGE_verify_coin_history (const char *currency,
|
||||
struct TALER_Amount *total)
|
||||
{
|
||||
size_t len;
|
||||
int add;
|
||||
struct TALER_Amount rtotal;
|
||||
|
||||
if (NULL == history)
|
||||
@ -64,6 +63,7 @@ TALER_EXCHANGE_verify_coin_history (const char *currency,
|
||||
&rtotal));
|
||||
for (size_t off=0;off<len;off++)
|
||||
{
|
||||
int add;
|
||||
json_t *transaction;
|
||||
struct TALER_Amount amount;
|
||||
const char *type;
|
||||
|
@ -873,12 +873,10 @@ refresh_melt_run (void *cls,
|
||||
{
|
||||
struct RefreshMeltState *rms = cls;
|
||||
unsigned int num_fresh_coins;
|
||||
const struct TALER_TESTING_Command *coin_command;
|
||||
/* FIXME: this should be dynamic */
|
||||
const char *melt_fresh_amounts[] = {
|
||||
"EUR:1", "EUR:1", "EUR:1", "EUR:0.1",
|
||||
NULL};
|
||||
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk;
|
||||
|
||||
rms->is = is;
|
||||
rms->noreveal_index = UINT16_MAX;
|
||||
@ -895,8 +893,9 @@ refresh_melt_run (void *cls,
|
||||
struct TALER_Amount fresh_amount;
|
||||
const struct TALER_DenominationSignature *melt_sig;
|
||||
const struct TALER_EXCHANGE_DenomPublicKey *melt_denom_pub;
|
||||
|
||||
const struct TALER_TESTING_Command *coin_command;
|
||||
const struct MeltDetails *md = &rms->melted_coin;
|
||||
|
||||
if (NULL == (coin_command
|
||||
= TALER_TESTING_interpreter_lookup_command
|
||||
(is, md->coin_reference)))
|
||||
@ -945,6 +944,8 @@ refresh_melt_run (void *cls,
|
||||
|
||||
for (unsigned int i=0;i<num_fresh_coins;i++)
|
||||
{
|
||||
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk;
|
||||
|
||||
if (GNUNET_OK != TALER_string_to_amount
|
||||
(melt_fresh_amounts[i], &fresh_amount))
|
||||
{
|
||||
|
@ -263,7 +263,23 @@ deposit_confirmation_run (void *cls,
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
TALER_string_to_amount (dcs->amount_without_fee,
|
||||
&amount_without_fee));
|
||||
{
|
||||
struct GNUNET_JSON_Specification spec[] = {
|
||||
GNUNET_JSON_spec_absolute_time ("timestamp", ×tamp),
|
||||
GNUNET_JSON_spec_absolute_time ("refund_deadline", &refund_deadline),
|
||||
GNUNET_JSON_spec_end()
|
||||
};
|
||||
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_JSON_parse (contract_terms,
|
||||
spec,
|
||||
NULL, NULL))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
TALER_TESTING_interpreter_fail (is);
|
||||
return;
|
||||
}
|
||||
}
|
||||
dcs->dc = TALER_AUDITOR_deposit_confirmation
|
||||
(dcs->auditor,
|
||||
&h_wire,
|
||||
|
@ -538,6 +538,29 @@ TALER_amount_normalize (struct TALER_Amount *amount)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the fraction of @a amount to a string
|
||||
* in decimals.
|
||||
*
|
||||
* @param amount value to convert
|
||||
* @param tail[out] where to write the reesult
|
||||
*/
|
||||
static void
|
||||
amount_to_tail (const struct TALER_Amount *amount,
|
||||
char tail[TALER_AMOUNT_FRAC_LEN + 1])
|
||||
{
|
||||
uint32_t n = amount->fraction;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; (i < TALER_AMOUNT_FRAC_LEN) && (0 != n); i++)
|
||||
{
|
||||
tail[i] = '0' + (n / (TALER_AMOUNT_FRAC_BASE / 10));
|
||||
n = (n * 10) % (TALER_AMOUNT_FRAC_BASE);
|
||||
}
|
||||
tail[i] = '\0';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert amount to string.
|
||||
*
|
||||
@ -548,9 +571,6 @@ char *
|
||||
TALER_amount_to_string (const struct TALER_Amount *amount)
|
||||
{
|
||||
char *result;
|
||||
unsigned int i;
|
||||
uint32_t n;
|
||||
char tail[TALER_AMOUNT_FRAC_LEN + 1];
|
||||
struct TALER_Amount norm;
|
||||
|
||||
if (GNUNET_YES != TALER_amount_is_valid (amount))
|
||||
@ -558,14 +578,12 @@ TALER_amount_to_string (const struct TALER_Amount *amount)
|
||||
norm = *amount;
|
||||
GNUNET_break (GNUNET_SYSERR !=
|
||||
TALER_amount_normalize (&norm));
|
||||
if (0 != (n = norm.fraction))
|
||||
if (0 != norm.fraction)
|
||||
{
|
||||
for (i = 0; (i < TALER_AMOUNT_FRAC_LEN) && (0 != n); i++)
|
||||
{
|
||||
tail[i] = '0' + (n / (TALER_AMOUNT_FRAC_BASE / 10));
|
||||
n = (n * 10) % (TALER_AMOUNT_FRAC_BASE);
|
||||
}
|
||||
tail[i] = '\0';
|
||||
char tail[TALER_AMOUNT_FRAC_LEN + 1];
|
||||
|
||||
amount_to_tail (&norm,
|
||||
tail);
|
||||
GNUNET_asprintf (&result,
|
||||
"%s:%llu.%s",
|
||||
norm.currency,
|
||||
@ -594,9 +612,6 @@ const char *
|
||||
TALER_amount2s (const struct TALER_Amount *amount)
|
||||
{
|
||||
static char result[TALER_AMOUNT_FRAC_LEN + TALER_CURRENCY_LEN + 3 + 12];
|
||||
unsigned int i;
|
||||
uint32_t n;
|
||||
char tail[TALER_AMOUNT_FRAC_LEN + 1];
|
||||
struct TALER_Amount norm;
|
||||
|
||||
if (GNUNET_YES != TALER_amount_is_valid (amount))
|
||||
@ -604,14 +619,12 @@ TALER_amount2s (const struct TALER_Amount *amount)
|
||||
norm = *amount;
|
||||
GNUNET_break (GNUNET_SYSERR !=
|
||||
TALER_amount_normalize (&norm));
|
||||
if (0 != (n = norm.fraction))
|
||||
if (0 != norm.fraction)
|
||||
{
|
||||
for (i = 0; (i < TALER_AMOUNT_FRAC_LEN) && (0 != n); i++)
|
||||
{
|
||||
tail[i] = '0' + (n / (TALER_AMOUNT_FRAC_BASE / 10));
|
||||
n = (n * 10) % (TALER_AMOUNT_FRAC_BASE);
|
||||
}
|
||||
tail[i] = '\0';
|
||||
char tail[TALER_AMOUNT_FRAC_LEN + 1];
|
||||
|
||||
amount_to_tail (&norm,
|
||||
tail);
|
||||
GNUNET_snprintf (result,
|
||||
sizeof (result),
|
||||
"%s:%llu.%s",
|
||||
|
Loading…
Reference in New Issue
Block a user