-refactor DB for reserve history/status routines
This commit is contained in:
parent
eebc030f6c
commit
38876c503f
@ -1 +1 @@
|
||||
Subproject commit affa835c8ee4789134bdb5b49928dd3788d847da
|
||||
Subproject commit 9657bf77de05c0ac17ff39629306a604066b21de
|
@ -425,6 +425,62 @@ TEH_RESPONSE_compile_transaction_history (
|
||||
break;
|
||||
}
|
||||
|
||||
case TALER_EXCHANGEDB_TT_PURSE_REFUND:
|
||||
{
|
||||
const struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund =
|
||||
pos->details.purse_refund;
|
||||
struct TALER_Amount value;
|
||||
enum TALER_ErrorCode ec;
|
||||
struct TALER_ExchangePublicKeyP epub;
|
||||
struct TALER_ExchangeSignatureP esig;
|
||||
|
||||
if (0 >
|
||||
TALER_amount_subtract (&value,
|
||||
&prefund->refund_amount,
|
||||
&prefund->refund_fee))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
ec = TALER_exchange_online_purse_refund_sign (
|
||||
&TEH_keys_exchange_sign_,
|
||||
&value,
|
||||
&prefund->refund_fee,
|
||||
coin_pub,
|
||||
&prefund->purse_pub,
|
||||
&epub,
|
||||
&esig);
|
||||
if (TALER_EC_NONE != ec)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
if (0 !=
|
||||
json_array_append_new (
|
||||
history,
|
||||
GNUNET_JSON_PACK (
|
||||
GNUNET_JSON_pack_string ("type",
|
||||
"PURSE-REFUND"),
|
||||
TALER_JSON_pack_amount ("amount",
|
||||
&value),
|
||||
TALER_JSON_pack_amount ("refund_fee",
|
||||
&prefund->refund_fee),
|
||||
GNUNET_JSON_pack_data_auto ("exchange_sig",
|
||||
&esig),
|
||||
GNUNET_JSON_pack_data_auto ("exchange_pub",
|
||||
&epub),
|
||||
GNUNET_JSON_pack_data_auto ("purse_pub",
|
||||
&prefund->purse_pub))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
|
||||
{
|
||||
struct TALER_EXCHANGEDB_ReserveOpenListEntry *role
|
||||
|
@ -73,6 +73,7 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \
|
||||
pg_do_reserve_open.c pg_do_reserve_open.h \
|
||||
pg_get_coin_transactions.c pg_get_coin_transactions.h \
|
||||
pg_get_expired_reserves.c pg_get_expired_reserves.h \
|
||||
pg_get_reserve_history.c pg_get_reserve_history.h \
|
||||
pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \
|
||||
pg_insert_close_request.c pg_insert_close_request.h \
|
||||
pg_insert_records_by_table.c pg_insert_records_by_table.h \
|
||||
|
1018
src/exchangedb/pg_get_reserve_history.c
Normal file
1018
src/exchangedb/pg_get_reserve_history.c
Normal file
File diff suppressed because it is too large
Load Diff
67
src/exchangedb/pg_get_reserve_history.h
Normal file
67
src/exchangedb/pg_get_reserve_history.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
This file is part of TALER
|
||||
Copyright (C) 2022 Taler Systems SA
|
||||
|
||||
TALER is free software; you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 3, or (at your option) any later version.
|
||||
|
||||
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
/**
|
||||
* @file pg_get_reserve_history.h
|
||||
* @brief implementation of the get_reserve_history function
|
||||
* @author Christian Grothoff
|
||||
*/
|
||||
#ifndef PG_GET_RESERVE_HISTORY_H
|
||||
#define PG_GET_RESERVE_HISTORY_H
|
||||
|
||||
#include "taler_util.h"
|
||||
#include "taler_json_lib.h"
|
||||
#include "taler_exchangedb_plugin.h"
|
||||
|
||||
|
||||
/**
|
||||
* Get all of the transaction history associated with the specified
|
||||
* reserve.
|
||||
*
|
||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||
* @param reserve_pub public key of the reserve
|
||||
* @param[out] balance set to the reserve balance
|
||||
* @param[out] rhp set to known transaction history (NULL if reserve is unknown)
|
||||
* @return transaction status
|
||||
*/
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TEH_PG_get_reserve_history (void *cls,
|
||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||
struct TALER_Amount *balance,
|
||||
struct TALER_EXCHANGEDB_ReserveHistory **rhp);
|
||||
|
||||
|
||||
/**
|
||||
* Get a truncated transaction history associated with the specified
|
||||
* reserve.
|
||||
*
|
||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||
* @param reserve_pub public key of the reserve
|
||||
* @param[out] balance_in set to the total of inbound
|
||||
* transactions in the returned history
|
||||
* @param[out] balance_out set to the total of outbound
|
||||
* transactions in the returned history
|
||||
* @param[out] rhp set to known transaction history (NULL if reserve is unknown)
|
||||
* @return transaction status
|
||||
*/
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TEH_PG_get_reserve_status (void *cls,
|
||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||
struct TALER_Amount *balance_in,
|
||||
struct TALER_Amount *balance_out,
|
||||
struct TALER_EXCHANGEDB_ReserveHistory **rhp);
|
||||
|
||||
|
||||
#endif
|
@ -85,6 +85,22 @@ TEH_COMMON_free_reserve_history (
|
||||
GNUNET_free (history);
|
||||
break;
|
||||
}
|
||||
case TALER_EXCHANGEDB_RO_OPEN_REQUEST:
|
||||
{
|
||||
struct TALER_EXCHANGEDB_OpenRequest *or;
|
||||
|
||||
or = rh->details.open_request;
|
||||
GNUNET_free (or);
|
||||
break;
|
||||
}
|
||||
case TALER_EXCHANGEDB_RO_CLOSE_REQUEST:
|
||||
{
|
||||
struct TALER_EXCHANGEDB_CloseRequest *cr;
|
||||
|
||||
cr = rh->details.close_request;
|
||||
GNUNET_free (cr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
{
|
||||
struct TALER_EXCHANGEDB_ReserveHistory *next;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3834,6 +3834,51 @@ TALER_exchange_online_melt_confirmation_verify (
|
||||
const struct TALER_ExchangeSignatureP *sig);
|
||||
|
||||
|
||||
/**
|
||||
* Create exchange purse refund confirmation signature.
|
||||
*
|
||||
* @param scb function to call to create the signature
|
||||
* @param amount_without_fee refunded amount
|
||||
* @param refund_fee refund fee charged
|
||||
* @param coin_pub coin that was refunded
|
||||
* @param purse_pub public key of the expired purse
|
||||
* @param[out] pub where to write the public key
|
||||
* @param[out] sig where to write the signature
|
||||
* @return #TALER_EC_NONE on success
|
||||
*/
|
||||
enum TALER_ErrorCode
|
||||
TALER_exchange_online_purse_refund_sign (
|
||||
TALER_ExchangeSignCallback scb,
|
||||
const struct TALER_Amount *amount_without_fee,
|
||||
const struct TALER_Amount *refund_fee,
|
||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||
const struct TALER_PurseContractPublicKeyP *purse_pub,
|
||||
struct TALER_ExchangePublicKeyP *pub,
|
||||
struct TALER_ExchangeSignatureP *sig);
|
||||
|
||||
|
||||
/**
|
||||
* Verify signature of exchange affirming purse refund
|
||||
* from purse expiration.
|
||||
*
|
||||
* @param amount_without_fee refunded amount
|
||||
* @param refund_fee refund fee charged
|
||||
* @param coin_pub coin that was refunded
|
||||
* @param purse_pub public key of the expired purse
|
||||
* @param pub public key to verify signature against
|
||||
* @param sig signature to verify
|
||||
* @return #GNUNET_OK if the signature is valid
|
||||
*/
|
||||
enum GNUNET_GenericReturnValue
|
||||
TALER_exchange_online_purse_refund_verify (
|
||||
const struct TALER_Amount *amount_without_fee,
|
||||
const struct TALER_Amount *refund_fee,
|
||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||
const struct TALER_PurseContractPublicKeyP *purse_pub,
|
||||
const struct TALER_ExchangePublicKeyP *pub,
|
||||
const struct TALER_ExchangeSignatureP *sig);
|
||||
|
||||
|
||||
/**
|
||||
* Create exchange key set signature.
|
||||
*
|
||||
@ -3860,8 +3905,8 @@ TALER_exchange_online_key_set_sign (
|
||||
*
|
||||
* @param timestamp time when the key set was issued
|
||||
* @param hc hash over all the keys
|
||||
* @param pub where to write the public key
|
||||
* @param sig where to write the signature
|
||||
* @param pub public key to verify signature against
|
||||
* @param sig signature to verify
|
||||
* @return #GNUNET_OK if the signature is valid
|
||||
*/
|
||||
enum GNUNET_GenericReturnValue
|
||||
|
@ -1270,6 +1270,75 @@ struct TALER_EXCHANGEDB_HistoryRequest
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Details about a (paid for) reserve open request.
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_OpenRequest
|
||||
{
|
||||
/**
|
||||
* Public key of the reserve the open request was for.
|
||||
*/
|
||||
struct TALER_ReservePublicKeyP reserve_pub;
|
||||
|
||||
/**
|
||||
* Fee paid for the request from the reserve.
|
||||
*/
|
||||
struct TALER_Amount open_fee;
|
||||
|
||||
/**
|
||||
* When was the request made.
|
||||
*/
|
||||
struct GNUNET_TIME_Timestamp request_timestamp;
|
||||
|
||||
/**
|
||||
* How long was the reserve supposed to be open.
|
||||
*/
|
||||
struct GNUNET_TIME_Timestamp reserve_expiration;
|
||||
|
||||
/**
|
||||
* Signature by the reserve approving the open request.
|
||||
*/
|
||||
struct TALER_ReserveSignatureP reserve_sig;
|
||||
|
||||
/**
|
||||
* How many open purses should be included with the
|
||||
* open reserve?
|
||||
*/
|
||||
uint32_t purse_limit;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Details about an (explicit) reserve close request.
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_CloseRequest
|
||||
{
|
||||
/**
|
||||
* Public key of the reserve the history request was for.
|
||||
*/
|
||||
struct TALER_ReservePublicKeyP reserve_pub;
|
||||
|
||||
/**
|
||||
* When was the request made.
|
||||
*/
|
||||
struct GNUNET_TIME_Timestamp request_timestamp;
|
||||
|
||||
/**
|
||||
* Hash of the payto://-URI of the target account
|
||||
* for the closure, or all zeros for the reserve
|
||||
* origin account.
|
||||
*/
|
||||
struct TALER_PaytoHashP target_account_h_payto;
|
||||
|
||||
/**
|
||||
* Signature by the reserve approving the history request.
|
||||
*/
|
||||
struct TALER_ReserveSignatureP reserve_sig;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Types of operations on a reserve.
|
||||
*/
|
||||
@ -1306,7 +1375,17 @@ enum TALER_EXCHANGEDB_ReserveOperation
|
||||
/**
|
||||
* Event where a wallet paid for a full reserve history.
|
||||
*/
|
||||
TALER_EXCHANGEDB_RO_HISTORY_REQUEST = 5
|
||||
TALER_EXCHANGEDB_RO_HISTORY_REQUEST = 5,
|
||||
|
||||
/**
|
||||
* Event where a wallet paid to open a reserve for longer.
|
||||
*/
|
||||
TALER_EXCHANGEDB_RO_OPEN_REQUEST = 6,
|
||||
|
||||
/**
|
||||
* Event where a wallet requested a reserve to be closed.
|
||||
*/
|
||||
TALER_EXCHANGEDB_RO_CLOSE_REQUEST = 7
|
||||
};
|
||||
|
||||
|
||||
@ -1367,6 +1446,16 @@ struct TALER_EXCHANGEDB_ReserveHistory
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_HistoryRequest *history;
|
||||
|
||||
/**
|
||||
* Details about a (paid for) open reserve request.
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_OpenRequest *open_request;
|
||||
|
||||
/**
|
||||
* Details about an (explicit) reserve close request.
|
||||
*/
|
||||
struct TALER_EXCHANGEDB_CloseRequest *close_request;
|
||||
|
||||
} details;
|
||||
|
||||
};
|
||||
|
@ -1379,6 +1379,100 @@ TALER_exchange_online_purse_created_verify (
|
||||
}
|
||||
|
||||
|
||||
GNUNET_NETWORK_STRUCT_BEGIN
|
||||
|
||||
/**
|
||||
* Response by which the exchange affirms that it has
|
||||
* received funds deposited into a purse.
|
||||
*/
|
||||
struct TALER_CoinPurseRefundConfirmationPS
|
||||
{
|
||||
|
||||
/**
|
||||
* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND
|
||||
*/
|
||||
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
||||
|
||||
/**
|
||||
* Public key of the purse.
|
||||
*/
|
||||
struct TALER_PurseContractPublicKeyP purse_pub;
|
||||
|
||||
/**
|
||||
* Public key of the coin.
|
||||
*/
|
||||
struct TALER_CoinSpendPublicKeyP coin_pub;
|
||||
|
||||
/**
|
||||
* How much will be refunded to the purse.
|
||||
*/
|
||||
struct TALER_AmountNBO refunded_amount;
|
||||
|
||||
/**
|
||||
* How much was the refund fee.
|
||||
*/
|
||||
struct TALER_AmountNBO refund_fee;
|
||||
|
||||
};
|
||||
|
||||
GNUNET_NETWORK_STRUCT_END
|
||||
|
||||
|
||||
enum TALER_ErrorCode
|
||||
TALER_exchange_online_purse_refund_sign (
|
||||
TALER_ExchangeSignCallback scb,
|
||||
const struct TALER_Amount *amount_without_fee,
|
||||
const struct TALER_Amount *refund_fee,
|
||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||
const struct TALER_PurseContractPublicKeyP *purse_pub,
|
||||
struct TALER_ExchangePublicKeyP *pub,
|
||||
struct TALER_ExchangeSignatureP *sig)
|
||||
{
|
||||
struct TALER_CoinPurseRefundConfirmationPS dc = {
|
||||
.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND),
|
||||
.purpose.size = htonl (sizeof (dc)),
|
||||
.coin_pub = *coin_pub,
|
||||
.purse_pub = *purse_pub,
|
||||
};
|
||||
|
||||
TALER_amount_hton (&dc.refunded_amount,
|
||||
amount_without_fee);
|
||||
TALER_amount_hton (&dc.refund_fee,
|
||||
refund_fee);
|
||||
return scb (&dc.purpose,
|
||||
pub,
|
||||
sig);
|
||||
}
|
||||
|
||||
|
||||
enum GNUNET_GenericReturnValue
|
||||
TALER_exchange_online_purse_refund_verify (
|
||||
const struct TALER_Amount *amount_without_fee,
|
||||
const struct TALER_Amount *refund_fee,
|
||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||
const struct TALER_PurseContractPublicKeyP *purse_pub,
|
||||
const struct TALER_ExchangePublicKeyP *pub,
|
||||
const struct TALER_ExchangeSignatureP *sig)
|
||||
{
|
||||
struct TALER_CoinPurseRefundConfirmationPS dc = {
|
||||
.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND),
|
||||
.purpose.size = htonl (sizeof (dc)),
|
||||
.coin_pub = *coin_pub,
|
||||
.purse_pub = *purse_pub,
|
||||
};
|
||||
|
||||
TALER_amount_hton (&dc.refunded_amount,
|
||||
amount_without_fee);
|
||||
TALER_amount_hton (&dc.refund_fee,
|
||||
refund_fee);
|
||||
return
|
||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND,
|
||||
&dc,
|
||||
&sig->eddsa_signature,
|
||||
&pub->eddsa_pub);
|
||||
}
|
||||
|
||||
|
||||
GNUNET_NETWORK_STRUCT_BEGIN
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user