simplify DB access: do not fetch fields we do not need
This commit is contained in:
parent
575c10027b
commit
81fec09268
@ -507,44 +507,24 @@ deposit_cb (void *cls,
|
||||
*
|
||||
* @param cls a `struct AggregationUnit`
|
||||
* @param row_id identifies database entry
|
||||
* @param exchange_timestamp when did the exchange receive the deposit
|
||||
* @param wallet_timestamp when did the wallet sign the contract
|
||||
* @param merchant_pub public key of the merchant
|
||||
* @param coin_pub public key of the coin
|
||||
* @param amount_with_fee amount that was deposited including fee
|
||||
* @param deposit_fee amount the exchange gets to keep as transaction fees
|
||||
* @param h_contract_terms hash of the proposal data known to merchant and customer
|
||||
* @param wire_deadline by which the merchant advised that he would like the
|
||||
* wire transfer to be executed
|
||||
* @param wire wire details for the merchant
|
||||
* @return transaction status code
|
||||
*/
|
||||
static enum GNUNET_DB_QueryStatus
|
||||
aggregate_cb (void *cls,
|
||||
uint64_t row_id,
|
||||
struct GNUNET_TIME_Absolute exchange_timestamp,
|
||||
struct GNUNET_TIME_Absolute wallet_timestamp,
|
||||
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||
const struct TALER_Amount *amount_with_fee,
|
||||
const struct TALER_Amount *deposit_fee,
|
||||
const struct GNUNET_HashCode *h_contract_terms,
|
||||
struct GNUNET_TIME_Absolute wire_deadline,
|
||||
const json_t *wire)
|
||||
const struct GNUNET_HashCode *h_contract_terms)
|
||||
{
|
||||
struct AggregationUnit *au = cls;
|
||||
struct TALER_Amount old;
|
||||
enum GNUNET_DB_QueryStatus qs;
|
||||
|
||||
/* NOTE: potential optimization: use custom SQL API to not
|
||||
fetch these: */
|
||||
(void) wire_deadline; /* checked by SQL */
|
||||
(void) exchange_timestamp;
|
||||
(void) wallet_timestamp;
|
||||
(void) wire; /* must match */
|
||||
GNUNET_break (0 == GNUNET_memcmp (&au->merchant_pub,
|
||||
merchant_pub));
|
||||
|
||||
if (au->rows_offset >= TALER_EXCHANGEDB_MATCHING_DEPOSITS_LIMIT)
|
||||
{
|
||||
/* Bug: we asked for at most #TALER_EXCHANGEDB_MATCHING_DEPOSITS_LIMIT results! */
|
||||
|
@ -908,9 +908,6 @@ postgres_get_session (void *cls)
|
||||
",amount_with_fee_frac"
|
||||
",denom.fee_deposit_val"
|
||||
",denom.fee_deposit_frac"
|
||||
",wire_deadline"
|
||||
",exchange_timestamp"
|
||||
",wallet_timestamp"
|
||||
",h_contract_terms"
|
||||
",coin_pub"
|
||||
" FROM deposits"
|
||||
@ -2868,7 +2865,7 @@ struct MatchingDepositContext
|
||||
/**
|
||||
* Function to call for each result
|
||||
*/
|
||||
TALER_EXCHANGEDB_DepositIterator deposit_cb;
|
||||
TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb;
|
||||
|
||||
/**
|
||||
* Closure for @e deposit_cb.
|
||||
@ -2929,9 +2926,6 @@ match_deposit_cb (void *cls,
|
||||
{
|
||||
struct TALER_Amount amount_with_fee;
|
||||
struct TALER_Amount deposit_fee;
|
||||
struct GNUNET_TIME_Absolute exchange_timestamp;
|
||||
struct GNUNET_TIME_Absolute wallet_timestamp;
|
||||
struct GNUNET_TIME_Absolute wire_deadline;
|
||||
struct GNUNET_HashCode h_contract_terms;
|
||||
struct TALER_CoinSpendPublicKeyP coin_pub;
|
||||
uint64_t serial_id;
|
||||
@ -2943,12 +2937,6 @@ match_deposit_cb (void *cls,
|
||||
&amount_with_fee),
|
||||
TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
|
||||
&deposit_fee),
|
||||
TALER_PQ_result_spec_absolute_time ("wire_deadline",
|
||||
&wire_deadline),
|
||||
TALER_PQ_result_spec_absolute_time ("exchange_timestamp",
|
||||
&exchange_timestamp),
|
||||
TALER_PQ_result_spec_absolute_time ("wallet_timestamp",
|
||||
&wallet_timestamp),
|
||||
GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
|
||||
&h_contract_terms),
|
||||
GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
|
||||
@ -2967,15 +2955,10 @@ match_deposit_cb (void *cls,
|
||||
}
|
||||
qs = mdc->deposit_cb (mdc->deposit_cb_cls,
|
||||
serial_id,
|
||||
exchange_timestamp,
|
||||
wallet_timestamp,
|
||||
mdc->merchant_pub,
|
||||
&coin_pub,
|
||||
&amount_with_fee,
|
||||
&deposit_fee,
|
||||
&h_contract_terms,
|
||||
wire_deadline,
|
||||
NULL);
|
||||
&h_contract_terms);
|
||||
GNUNET_PQ_cleanup_result (rs);
|
||||
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
|
||||
break;
|
||||
@ -3003,7 +2986,7 @@ postgres_iterate_matching_deposits (
|
||||
struct TALER_EXCHANGEDB_Session *session,
|
||||
const struct GNUNET_HashCode *h_wire,
|
||||
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
||||
TALER_EXCHANGEDB_DepositIterator deposit_cb,
|
||||
TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb,
|
||||
void *deposit_cb_cls,
|
||||
uint32_t limit)
|
||||
{
|
||||
|
@ -842,7 +842,7 @@ static uint64_t deposit_rowid;
|
||||
* @param h_contract_terms hash of the proposal data known to merchant and customer
|
||||
* @param wire_deadline by which the merchant advised that he would like the
|
||||
* wire transfer to be executed
|
||||
* @param wire wire details for the merchant, NULL from iterate_matching_deposits()
|
||||
* @param wire wire details for the merchant
|
||||
* @return transaction status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT to continue to iterate
|
||||
*/
|
||||
static enum GNUNET_DB_QueryStatus
|
||||
@ -862,7 +862,6 @@ deposit_cb (void *cls,
|
||||
struct GNUNET_HashCode h_wire;
|
||||
|
||||
deposit_rowid = rowid;
|
||||
if (NULL != wire)
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
TALER_JSON_merchant_wire_signature_hash (wire,
|
||||
&h_wire));
|
||||
@ -877,9 +876,51 @@ deposit_cb (void *cls,
|
||||
(0 != memcmp (coin_pub,
|
||||
&deposit->coin.coin_pub,
|
||||
sizeof (struct TALER_CoinSpendPublicKeyP))) ||
|
||||
( (NULL != wire) &&
|
||||
(0 != GNUNET_memcmp (&h_wire,
|
||||
&deposit->h_wire)) ) )
|
||||
&deposit->h_wire)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||
}
|
||||
|
||||
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function called with details about deposits that
|
||||
* have been made. Called in the test on the
|
||||
* deposit given in @a cls.
|
||||
*
|
||||
* @param cls closure a `struct TALER_EXCHANGEDB_Deposit *`
|
||||
* @param rowid unique ID for the deposit in our DB, used for marking
|
||||
* it as 'tiny' or 'done'
|
||||
* @param coin_pub public key of the coin
|
||||
* @param amount_with_fee amount that was deposited including fee
|
||||
* @param deposit_fee amount the exchange gets to keep as transaction fees
|
||||
* @param h_contract_terms hash of the proposal data known to merchant and customer
|
||||
* @return transaction status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT to continue to iterate
|
||||
*/
|
||||
static enum GNUNET_DB_QueryStatus
|
||||
matching_deposit_cb (void *cls,
|
||||
uint64_t rowid,
|
||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||
const struct TALER_Amount *amount_with_fee,
|
||||
const struct TALER_Amount *deposit_fee,
|
||||
const struct GNUNET_HashCode *h_contract_terms)
|
||||
{
|
||||
struct TALER_EXCHANGEDB_Deposit *deposit = cls;
|
||||
|
||||
deposit_rowid = rowid;
|
||||
if ( (0 != TALER_amount_cmp (amount_with_fee,
|
||||
&deposit->amount_with_fee)) ||
|
||||
(0 != TALER_amount_cmp (deposit_fee,
|
||||
&deposit->deposit_fee)) ||
|
||||
(0 != GNUNET_memcmp (h_contract_terms,
|
||||
&deposit->h_contract_terms)) ||
|
||||
(0 != memcmp (coin_pub,
|
||||
&deposit->coin.coin_pub,
|
||||
sizeof (struct TALER_CoinSpendPublicKeyP))) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||
@ -1936,7 +1977,7 @@ run (void *cls)
|
||||
session,
|
||||
&deposit.h_wire,
|
||||
&deposit.merchant_pub,
|
||||
&deposit_cb,
|
||||
&matching_deposit_cb,
|
||||
&deposit,
|
||||
2));
|
||||
sleep (2); /* giv deposit time to be ready */
|
||||
|
@ -968,6 +968,29 @@ struct TALER_EXCHANGEDB_TransactionList
|
||||
struct TALER_EXCHANGEDB_Session;
|
||||
|
||||
|
||||
/**
|
||||
* Function called with details about deposits that have been made,
|
||||
* with the goal of executing the corresponding wire transaction.
|
||||
*
|
||||
* @param cls closure
|
||||
* @param rowid unique ID for the deposit in our DB, used for marking
|
||||
* it as 'tiny' or 'done'
|
||||
* @param coin_pub public key of the coin
|
||||
* @param amount_with_fee amount that was deposited including fee
|
||||
* @param deposit_fee amount the exchange gets to keep as transaction fees
|
||||
* @param h_contract_terms hash of the proposal data known to merchant and customer
|
||||
* @return transaction status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT to continue to iterate
|
||||
*/
|
||||
typedef enum GNUNET_DB_QueryStatus
|
||||
(*TALER_EXCHANGEDB_MatchingDepositIterator)(
|
||||
void *cls,
|
||||
uint64_t rowid,
|
||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||
const struct TALER_Amount *amount_with_fee,
|
||||
const struct TALER_Amount *deposit_fee,
|
||||
const struct GNUNET_HashCode *h_contract_terms);
|
||||
|
||||
|
||||
/**
|
||||
* Function called with details about deposits that have been made,
|
||||
* with the goal of executing the corresponding wire transaction.
|
||||
@ -985,7 +1008,7 @@ struct TALER_EXCHANGEDB_Session;
|
||||
* @param wire_deadline by which the merchant advised that he would like the
|
||||
* wire transfer to be executed
|
||||
* @param receiver_wire_account wire details for the merchant, includes
|
||||
* 'url' in payto://-format; NULL from iterate_matching_deposits()
|
||||
* 'url' in payto://-format;
|
||||
* @return transaction status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT to continue to iterate
|
||||
*/
|
||||
typedef enum GNUNET_DB_QueryStatus
|
||||
@ -2019,7 +2042,7 @@ struct TALER_EXCHANGEDB_Plugin
|
||||
struct TALER_EXCHANGEDB_Session *session,
|
||||
const struct GNUNET_HashCode *h_wire,
|
||||
const struct TALER_MerchantPublicKeyP *merchant_pub,
|
||||
TALER_EXCHANGEDB_DepositIterator deposit_cb,
|
||||
TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb,
|
||||
void *deposit_cb_cls,
|
||||
uint32_t limit);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user