include new payback-refresh possibilities in coin history generation

This commit is contained in:
Christian Grothoff 2019-07-22 13:28:48 +02:00
parent c0c80d4a67
commit a83aa1f70e
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 166 additions and 23 deletions

View File

@ -168,8 +168,8 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
// FIXME: maybe move to another module, i.e. exchangedb??? // FIXME: maybe move to another module, i.e. exchangedb???
int int
TEH_DB_calculate_transaction_list_totals (struct TALER_EXCHANGEDB_TransactionList *tl, TEH_DB_calculate_transaction_list_totals (struct TALER_EXCHANGEDB_TransactionList *tl,
const struct TALER_Amount *off, const struct TALER_Amount *off,
struct TALER_Amount *ret) struct TALER_Amount *ret)
{ {
struct TALER_Amount spent = *off; struct TALER_Amount spent = *off;
struct TALER_Amount refunded; struct TALER_Amount refunded;
@ -222,6 +222,17 @@ TEH_DB_calculate_transaction_list_totals (struct TALER_EXCHANGEDB_TransactionLis
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
break; break;
case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
/* refunded += pos->value */
if (GNUNET_OK !=
TALER_amount_add (&refunded,
&refunded,
&pos->details.old_coin_payback->value))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
break;
case TALER_EXCHANGEDB_TT_PAYBACK: case TALER_EXCHANGEDB_TT_PAYBACK:
/* spent += pos->value */ /* spent += pos->value */
if (GNUNET_OK != if (GNUNET_OK !=
@ -233,6 +244,17 @@ TEH_DB_calculate_transaction_list_totals (struct TALER_EXCHANGEDB_TransactionLis
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
break; break;
case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
/* spent += pos->value */
if (GNUNET_OK !=
TALER_amount_add (&spent,
&spent,
&pos->details.payback_refresh->value))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
break;
} }
} }
/* spent = spent - refunded */ /* spent = spent - refunded */

View File

@ -285,26 +285,6 @@ payback_transaction (void *cls,
} }
return qs; return qs;
} }
/* increment reserve balance */
qs = TEH_plugin->increment_reserve_balance (TEH_plugin->cls,
session,
&pc->reserve_pub,
pc->coin,
pc->coin_sig,
pc->coin_bks,
&pc->amount,
&pc->h_blind,
pc->now);
if (0 > qs)
{
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
TALER_LOG_WARNING ("Failed to store /payback information in database\n");
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection,
TALER_EC_PAYBACK_DB_PUT_FAILED);
}
return qs;
}
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
} }

View File

@ -236,9 +236,15 @@ refund_transaction (void *cls,
} }
} }
break; break;
case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
/* Paybacks cannot be refunded, ignore here */
break;
case TALER_EXCHANGEDB_TT_PAYBACK: case TALER_EXCHANGEDB_TT_PAYBACK:
/* Paybacks cannot be refunded, ignore here */ /* Paybacks cannot be refunded, ignore here */
break; break;
case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
/* Paybacks cannot be refunded, ignore here */
break;
} }
} }
/* handle if deposit was NOT found */ /* handle if deposit was NOT found */

View File

@ -632,6 +632,50 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
} }
} }
break; break;
case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
{
struct TALER_EXCHANGEDB_PaybackRefresh *pr = pos->details.old_coin_payback;
struct TALER_PaybackRefreshConfirmationPS pc;
struct TALER_ExchangePublicKeyP epub;
struct TALER_ExchangeSignatureP esig;
pc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH);
pc.purpose.size = htonl (sizeof (pc));
pc.timestamp = GNUNET_TIME_absolute_hton (pr->timestamp);
TALER_amount_hton (&pc.payback_amount,
&pr->value);
pc.coin_pub = pr->coin.coin_pub;
pc.old_coin_pub = pr->old_coin_pub;
if (GNUNET_OK !=
TEH_KS_sign (&pc.purpose,
&epub,
&esig))
{
GNUNET_break (0);
json_decref (history);
return NULL;
}
/* NOTE: we could also provide coin_pub's coin_sig, denomination key hash and
the denomination key's RSA signature over coin_pub, but as the
wallet should really already have this information (and cannot
check or do anything with it anyway if it doesn't), it seems
strictly unnecessary. */
if (0 !=
json_array_append_new (history,
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
"type", "OLD-COIN-PAYBACK",
"amount", TALER_JSON_from_amount (&pr->value),
"exchange_sig", GNUNET_JSON_from_data_auto (&esig),
"exchange_pub", GNUNET_JSON_from_data_auto (&epub),
"coin_pub", GNUNET_JSON_from_data_auto (&pr->coin.coin_pub),
"timestamp", GNUNET_JSON_from_time_abs (pr->timestamp))))
{
GNUNET_break (0);
json_decref (history);
return NULL;
}
break;
}
case TALER_EXCHANGEDB_TT_PAYBACK: case TALER_EXCHANGEDB_TT_PAYBACK:
{ {
const struct TALER_EXCHANGEDB_Payback *payback = pos->details.payback; const struct TALER_EXCHANGEDB_Payback *payback = pos->details.payback;
@ -671,6 +715,50 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
} }
} }
break; break;
case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
{
struct TALER_EXCHANGEDB_PaybackRefresh *pr = pos->details.payback_refresh;
struct TALER_PaybackRefreshConfirmationPS pc;
struct TALER_ExchangePublicKeyP epub;
struct TALER_ExchangeSignatureP esig;
pc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH);
pc.purpose.size = htonl (sizeof (pc));
pc.timestamp = GNUNET_TIME_absolute_hton (pr->timestamp);
TALER_amount_hton (&pc.payback_amount,
&pr->value);
pc.coin_pub = pr->coin.coin_pub;
pc.old_coin_pub = pr->old_coin_pub;
if (GNUNET_OK !=
TEH_KS_sign (&pc.purpose,
&epub,
&esig))
{
GNUNET_break (0);
json_decref (history);
return NULL;
}
/* NOTE: we could also provide coin_pub's coin_sig, denomination key
hash and the denomination key's RSA signature over coin_pub, but as
the wallet should really already have this information (and cannot
check or do anything with it anyway if it doesn't), it seems
strictly unnecessary. */
if (0 !=
json_array_append_new (history,
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
"type", "PAYBACK-REFRESH",
"amount", TALER_JSON_from_amount (&pr->value),
"exchange_sig", GNUNET_JSON_from_data_auto (&esig),
"exchange_pub", GNUNET_JSON_from_data_auto (&epub),
"old_coin_pub", GNUNET_JSON_from_data_auto (&pr->old_coin_pub),
"timestamp", GNUNET_JSON_from_time_abs (pr->timestamp))))
{
GNUNET_break (0);
json_decref (history);
return NULL;
}
break;
}
default: default:
GNUNET_assert (0); GNUNET_assert (0);
} }

View File

@ -100,6 +100,8 @@ common_free_coin_transaction_list (void *cls,
GNUNET_free (list->details.melt); GNUNET_free (list->details.melt);
break; break;
case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK: case TALER_EXCHANGEDB_TT_OLD_COIN_PAYBACK:
if (NULL != list->details.payback_refresh->coin.denom_sig.rsa_signature)
GNUNET_CRYPTO_rsa_signature_free (list->details.payback_refresh->coin.denom_sig.rsa_signature);
GNUNET_free (list->details.old_coin_payback); GNUNET_free (list->details.old_coin_payback);
break; break;
case TALER_EXCHANGEDB_TT_REFUND: case TALER_EXCHANGEDB_TT_REFUND:
@ -113,6 +115,8 @@ common_free_coin_transaction_list (void *cls,
GNUNET_free (list->details.payback); GNUNET_free (list->details.payback);
break; break;
case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH: case TALER_EXCHANGEDB_TT_PAYBACK_REFRESH:
if (NULL != list->details.payback_refresh->coin.denom_sig.rsa_signature)
GNUNET_CRYPTO_rsa_signature_free (list->details.payback_refresh->coin.denom_sig.rsa_signature);
GNUNET_free (list->details.payback_refresh); GNUNET_free (list->details.payback_refresh);
break; break;
} }

View File

@ -129,6 +129,11 @@
*/ */
#define TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED 1040 #define TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED 1040
/**
* Signature where the Exchange confirms a payback-refresh operation.
*/
#define TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH 1041
/**********************/ /**********************/
/* Auditor signatures */ /* Auditor signatures */
@ -1229,7 +1234,7 @@ struct TALER_PaybackRequestPS
/** /**
* Response by which the exchange affirms that it will * Response by which the exchange affirms that it will
* refund a coin as part of the emergency /payback * refund a coin as part of the emergency /payback
* protocol. The refund will go back to the bank * protocol. The payback will go back to the bank
* account that created the reserve. * account that created the reserve.
*/ */
struct TALER_PaybackConfirmationPS struct TALER_PaybackConfirmationPS
@ -1265,6 +1270,44 @@ struct TALER_PaybackConfirmationPS
}; };
/**
* Response by which the exchange affirms that it will refund a refreshed coin
* as part of the emergency /payback protocol. The payback will go back to the
* old coin's balance.
*/
struct TALER_PaybackRefreshConfirmationPS
{
/**
* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK_REFRESH
*/
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
/**
* When did the exchange receive the payback request?
* Indirectly determines when the wire transfer is (likely)
* to happen.
*/
struct GNUNET_TIME_AbsoluteNBO timestamp;
/**
* How much of the coin's value will the exchange transfer?
* (Needed in case the coin was partially spent.)
*/
struct TALER_AmountNBO payback_amount;
/**
* Public key of the refreshed coin.
*/
struct TALER_CoinSpendPublicKeyP coin_pub;
/**
* Public key of the old coin that will receive the payback.
*/
struct TALER_CoinSpendPublicKeyP old_coin_pub;
};
/** /**
* Response by which the exchange affirms that it has * Response by which the exchange affirms that it has
* closed a reserve and send back the funds. * closed a reserve and send back the funds.