making DB scheme nice

This commit is contained in:
Christian Grothoff 2016-05-27 15:34:24 +02:00
parent 5f6f524a52
commit e68d07fc25
4 changed files with 128 additions and 187 deletions

View File

@ -448,14 +448,8 @@ deposit_cb (void *cls,
db_plugin->insert_aggregation_tracking (db_plugin->cls, db_plugin->insert_aggregation_tracking (db_plugin->cls,
au->session, au->session,
&au->wtid, &au->wtid,
merchant_pub, row_id,
&au->h_wire, au->execution_time))
h_contract,
transaction_id,
au->execution_time,
coin_pub,
amount_with_fee,
deposit_fee))
{ {
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -548,14 +542,8 @@ aggregate_cb (void *cls,
db_plugin->insert_aggregation_tracking (db_plugin->cls, db_plugin->insert_aggregation_tracking (db_plugin->cls,
au->session, au->session,
&au->wtid, &au->wtid,
merchant_pub, row_id,
&au->h_wire, au->execution_time))
h_contract,
transaction_id,
au->execution_time,
coin_pub,
amount_with_fee,
deposit_fee))
{ {
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;

View File

@ -300,9 +300,9 @@ postgres_create_tables (void *cls)
incoming transaction. */ incoming transaction. */
SQLEXEC("CREATE TABLE IF NOT EXISTS reserves_in" SQLEXEC("CREATE TABLE IF NOT EXISTS reserves_in"
"(reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE" "(reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
",balance_val INT8 NOT NULL" ",credit_val INT8 NOT NULL"
",balance_frac INT4 NOT NULL" ",credit_frac INT4 NOT NULL"
",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",credit_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",sender_account_details TEXT NOT NULL " ",sender_account_details TEXT NOT NULL "
",transfer_details TEXT NOT NULL " ",transfer_details TEXT NOT NULL "
",execution_date INT8 NOT NULL" ",execution_date INT8 NOT NULL"
@ -361,21 +361,6 @@ postgres_create_tables (void *cls)
",num_newcoins INT2 NOT NULL" ",num_newcoins INT2 NOT NULL"
",noreveal_index INT2 NOT NULL" ",noreveal_index INT2 NOT NULL"
")"); ")");
/* Table with information about coins that have been refunded. (Technically
one of the deposit operations that a coin was involved with is refunded.)*/
SQLEXEC("CREATE TABLE IF NOT EXISTS refunds "
"(coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
",merchant_pub BYTEA NOT NULL CHECK(LENGTH(merchant_pub)=32)"
",merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)"
",h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)"
",transaction_id INT8 NOT NULL"
",rtransaction_id INT8 NOT NULL"
",amount_with_fee_val INT8 NOT NULL"
",amount_with_fee_frac INT4 NOT NULL"
",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",PRIMARY KEY (coin_pub, merchant_pub, transaction_id, rtransaction_id)" /* this combo must be unique, and we usually select by coin_pub */
") ");
/* Table with information about the desired denominations to be created /* Table with information about the desired denominations to be created
during a refresh operation; contains the denomination key for each during a refresh operation; contains the denomination key for each
@ -398,6 +383,9 @@ postgres_create_tables (void *cls)
",link_secret_enc BYTEA NOT NULL CHECK(LENGTH(link_secret_enc)=64)" ",link_secret_enc BYTEA NOT NULL CHECK(LENGTH(link_secret_enc)=64)"
",cnc_index INT2 NOT NULL" ",cnc_index INT2 NOT NULL"
")"); ")");
SQLEXEC_INDEX("CREATE INDEX refresh_commit_link_session_hash_index "
"ON refresh_commit_link(session_hash,cnc_index)");
/* Table with the commitments for the new coins that are to be created /* Table with the commitments for the new coins that are to be created
during a melting session. Includes the session, the cut-and-choose during a melting session. Includes the session, the cut-and-choose
index and the index of the new coin, and the envelope of the new index and the index of the new coin, and the envelope of the new
@ -411,6 +399,10 @@ postgres_create_tables (void *cls)
",link_vector_enc BYTEA NOT NULL CHECK(LENGTH(link_vector_enc)=64)" ",link_vector_enc BYTEA NOT NULL CHECK(LENGTH(link_vector_enc)=64)"
",coin_ev BYTEA NOT NULL" ",coin_ev BYTEA NOT NULL"
")"); ")");
SQLEXEC_INDEX("CREATE INDEX refresh_commit_coin_session_hash_index "
"ON refresh_commit_coin(session_hash,cnc_index,newcoin_index)");
/* Table with the signatures over coins generated during a refresh /* Table with the signatures over coins generated during a refresh
operation. Needed to answer /refresh/link queries later. Stores operation. Needed to answer /refresh/link queries later. Stores
the coin signatures under the respective session hash and index. */ the coin signatures under the respective session hash and index. */
@ -419,10 +411,13 @@ postgres_create_tables (void *cls)
",newcoin_index INT2 NOT NULL" ",newcoin_index INT2 NOT NULL"
",ev_sig BYTEA NOT NULL" ",ev_sig BYTEA NOT NULL"
")"); ")");
SQLEXEC_INDEX("CREATE INDEX refresh_out_session_hash_index "
"ON refresh_out(session_hash,newcoin_index)");
/* This table contains the wire transfers the exchange is supposed to /* This table contains the wire transfers the exchange is supposed to
execute to transmit funds to the merchants (and manage refunds). */ execute to transmit funds to the merchants (and manage refunds). */
SQLEXEC("CREATE TABLE IF NOT EXISTS deposits " SQLEXEC("CREATE TABLE IF NOT EXISTS deposits "
"(serial_id BIGSERIAL PRIMARY KEY" "(deposit_serial_id BIGSERIAL PRIMARY KEY"
",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE" ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
",transaction_id INT8 NOT NULL" ",transaction_id INT8 NOT NULL"
",amount_with_fee_val INT8 NOT NULL" ",amount_with_fee_val INT8 NOT NULL"
@ -442,29 +437,32 @@ postgres_create_tables (void *cls)
/* Index for get_deposit statement on coin_pub, transaction_id and merchant_pub */ /* Index for get_deposit statement on coin_pub, transaction_id and merchant_pub */
SQLEXEC_INDEX("CREATE INDEX deposits_coin_pub_index " SQLEXEC_INDEX("CREATE INDEX deposits_coin_pub_index "
"ON deposits(coin_pub, transaction_id, merchant_pub)"); "ON deposits(coin_pub, transaction_id, merchant_pub)");
/* Table with information about coins that have been refunded. (Technically
one of the deposit operations that a coin was involved with is refunded.)*/
SQLEXEC("CREATE TABLE IF NOT EXISTS refunds "
"(coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
",merchant_pub BYTEA NOT NULL CHECK(LENGTH(merchant_pub)=32)"
",merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)"
",h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)"
",transaction_id INT8 NOT NULL"
",rtransaction_id INT8 NOT NULL"
",amount_with_fee_val INT8 NOT NULL"
",amount_with_fee_frac INT4 NOT NULL"
",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",PRIMARY KEY (coin_pub, merchant_pub, transaction_id, rtransaction_id)" /* this combo must be unique, and we usually select by coin_pub */
") ");
/* Table for the tracking API, mapping from wire transfer identifiers /* Table for the tracking API, mapping from wire transfer identifiers
to transactions and back */ to transactions and back */
SQLEXEC("CREATE TABLE IF NOT EXISTS aggregation_tracking " SQLEXEC("CREATE TABLE IF NOT EXISTS aggregation_tracking "
"(h_contract BYTEA CHECK (LENGTH(h_contract)=64) NOT NULL" "(deposit_serial_id INT8 NOT NULL REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE"
",h_wire BYTEA CHECK (LENGTH(h_wire)=64) NOT NULL" ",wtid_raw BYTEA NOT NULL CHECK (LENGTH(wtid_raw)=" TALER_WIRE_TRANSFER_IDENTIFIER_LEN_STR ")"
",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
",merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)"
",transaction_id INT8 NOT NULL"
",wtid_raw BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=" TALER_WIRE_TRANSFER_IDENTIFIER_LEN_STR ")"
",execution_time INT8 NOT NULL" ",execution_time INT8 NOT NULL"
",coin_amount_val INT8 NOT NULL"
",coin_amount_frac INT4 NOT NULL"
",coin_amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",coin_fee_val INT8 NOT NULL"
",coin_fee_frac INT4 NOT NULL"
",coin_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
")"); ")");
/* Index for lookup_transactions statement on wtid */ /* Index for lookup_transactions statement on wtid */
SQLEXEC_INDEX("CREATE INDEX aggregation_tracking_wtid_index " SQLEXEC_INDEX("CREATE INDEX aggregation_tracking_wtid_index "
"ON aggregation_tracking(wtid_raw)"); "ON aggregation_tracking(wtid_raw)");
/* Index for lookup_deposit_wtid statement */
SQLEXEC_INDEX("CREATE INDEX aggregation_tracking_deposit_index "
"ON aggregation_tracking(coin_pub,h_contract,h_wire,transaction_id,merchant_pub)");
/* This table contains the pre-commit data for /* This table contains the pre-commit data for
wire transfers the exchange is about to execute. */ wire transfers the exchange is about to execute. */
@ -611,9 +609,9 @@ postgres_prepare (PGconn *db_conn)
PREPARE ("reserves_in_add_transaction", PREPARE ("reserves_in_add_transaction",
"INSERT INTO reserves_in " "INSERT INTO reserves_in "
"(reserve_pub" "(reserve_pub"
",balance_val" ",credit_val"
",balance_frac" ",credit_frac"
",balance_curr" ",credit_curr"
",sender_account_details" ",sender_account_details"
",transfer_details" ",transfer_details"
",execution_date" ",execution_date"
@ -625,9 +623,9 @@ postgres_prepare (PGconn *db_conn)
for a reserve */ for a reserve */
PREPARE ("reserves_in_get_transactions", PREPARE ("reserves_in_get_transactions",
"SELECT" "SELECT"
" balance_val" " credit_val"
",balance_frac" ",credit_frac"
",balance_curr" ",credit_curr"
",execution_date" ",execution_date"
",sender_account_details" ",sender_account_details"
",transfer_details" ",transfer_details"
@ -947,7 +945,7 @@ postgres_prepare (PGconn *db_conn)
/* Used in #postgres_get_ready_deposit() */ /* Used in #postgres_get_ready_deposit() */
PREPARE ("deposits_get_ready", PREPARE ("deposits_get_ready",
"SELECT" "SELECT"
" serial_id" " deposit_serial_id"
",amount_with_fee_val" ",amount_with_fee_val"
",amount_with_fee_frac" ",amount_with_fee_frac"
",amount_with_fee_curr" ",amount_with_fee_curr"
@ -975,7 +973,7 @@ postgres_prepare (PGconn *db_conn)
/* Used in #postgres_iterate_matching_deposits() */ /* Used in #postgres_iterate_matching_deposits() */
PREPARE ("deposits_iterate_matching", PREPARE ("deposits_iterate_matching",
"SELECT" "SELECT"
" serial_id" " deposit_serial_id"
",amount_with_fee_val" ",amount_with_fee_val"
",amount_with_fee_frac" ",amount_with_fee_frac"
",amount_with_fee_curr" ",amount_with_fee_curr"
@ -1001,14 +999,14 @@ postgres_prepare (PGconn *db_conn)
PREPARE ("mark_deposit_tiny", PREPARE ("mark_deposit_tiny",
"UPDATE deposits" "UPDATE deposits"
" SET tiny=true" " SET tiny=true"
" WHERE serial_id=$1", " WHERE deposit_serial_id=$1",
1, NULL); 1, NULL);
/* Used in #postgres_mark_deposit_done() */ /* Used in #postgres_mark_deposit_done() */
PREPARE ("mark_deposit_done", PREPARE ("mark_deposit_done",
"UPDATE deposits" "UPDATE deposits"
" SET done=true" " SET done=true"
" WHERE serial_id=$1", " WHERE deposit_serial_id=$1",
1, NULL); 1, NULL);
/* Used in #postgres_test_deposit_done() */ /* Used in #postgres_test_deposit_done() */
@ -1100,61 +1098,56 @@ postgres_prepare (PGconn *db_conn)
/* Used in #postgres_lookup_wire_transfer */ /* Used in #postgres_lookup_wire_transfer */
PREPARE ("lookup_transactions", PREPARE ("lookup_transactions",
"SELECT" "SELECT"
" h_contract" " deposits.h_contract"
",h_wire" ",deposits.h_wire"
",coin_pub" ",deposits.coin_pub"
",merchant_pub" ",deposits.merchant_pub"
",transaction_id" ",deposits.transaction_id"
",execution_time" ",execution_time"
",coin_amount_val" ",deposits.amount_with_fee_val"
",coin_amount_frac" ",deposits.amount_with_fee_frac"
",coin_amount_curr" ",deposits.amount_with_fee_curr"
",coin_fee_val" ",denom.fee_deposit_val"
",coin_fee_frac" ",denom.fee_deposit_frac"
",coin_fee_curr" ",denom.fee_deposit_curr"
" FROM aggregation_tracking" " FROM aggregation_tracking"
" JOIN deposits USING (deposit_serial_id)"
" JOIN known_coins USING (coin_pub)"
" JOIN denominations denom USING (denom_pub)"
" WHERE wtid_raw=$1", " WHERE wtid_raw=$1",
1, NULL); 1, NULL);
/* Used in #postgres_wire_lookup_deposit_wtid */ /* Used in #postgres_wire_lookup_deposit_wtid */
PREPARE ("lookup_deposit_wtid", PREPARE ("lookup_deposit_wtid",
"SELECT" "SELECT"
" wtid_raw" " aggregation_tracking.wtid_raw"
",execution_time" ",aggregation_tracking.execution_time"
",coin_amount_val" ",amount_with_fee_val"
",coin_amount_frac" ",amount_with_fee_frac"
",coin_amount_curr" ",amount_with_fee_curr"
",coin_fee_val" ",denom.fee_deposit_val"
",coin_fee_frac" ",denom.fee_deposit_frac"
",coin_fee_curr" ",denom.fee_deposit_curr"
" FROM aggregation_tracking" " FROM deposits"
" WHERE" " JOIN aggregation_tracking USING (deposit_serial_id)"
" coin_pub=$1 AND" " JOIN known_coins USING (coin_pub)"
" h_contract=$2 AND" " JOIN denominations denom USING (denom_pub)"
" h_wire=$3 AND" " WHERE coin_pub=$1"
" transaction_id=$4 AND" " AND h_contract=$2"
" merchant_pub=$5", " AND h_wire=$3"
" AND transaction_id=$4"
" AND merchant_pub=$5",
5, NULL); 5, NULL);
/* Used in #postgres_insert_aggregation_tracking */ /* Used in #postgres_insert_aggregation_tracking */
PREPARE ("insert_aggregation_tracking", PREPARE ("insert_aggregation_tracking",
"INSERT INTO aggregation_tracking " "INSERT INTO aggregation_tracking "
"(h_contract" "(deposit_serial_id"
",h_wire"
",coin_pub"
",merchant_pub"
",transaction_id"
",wtid_raw" ",wtid_raw"
",execution_time" ",execution_time"
",coin_amount_val"
",coin_amount_frac"
",coin_amount_curr"
",coin_fee_val"
",coin_fee_frac"
",coin_fee_curr"
") VALUES " ") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)", "($1, $2, $3)",
13, NULL); 3, NULL);
/* Used in #postgres_wire_prepare_data_insert() to store /* Used in #postgres_wire_prepare_data_insert() to store
@ -1978,7 +1971,7 @@ postgres_get_reserve_history (void *cls,
bt = GNUNET_new (struct TALER_EXCHANGEDB_BankTransfer); bt = GNUNET_new (struct TALER_EXCHANGEDB_BankTransfer);
{ {
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount ("balance", TALER_PQ_result_spec_amount ("credit",
&bt->amount), &bt->amount),
GNUNET_PQ_result_spec_absolute_time ("execution_date", GNUNET_PQ_result_spec_absolute_time ("execution_date",
&bt->execution_date), &bt->execution_date),
@ -2180,7 +2173,7 @@ postgres_have_deposit (void *cls,
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to the database * @param session connection to the database
* @param deposit_rowid identifies the deposit row to modify * @param deposit_serial_id identifies the deposit row to modify
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/ */
static int static int
@ -2284,7 +2277,7 @@ postgres_test_deposit_done (void *cls,
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to the database * @param session connection to the database
* @param deposit_rowid identifies the deposit row to modify * @param deposit_serial_id identifies the deposit row to modify
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/ */
static int static int
@ -2368,7 +2361,7 @@ postgres_get_ready_deposit (void *cls,
uint64_t serial_id; uint64_t serial_id;
json_t *wire; json_t *wire;
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("serial_id", GNUNET_PQ_result_spec_uint64 ("deposit_serial_id",
&serial_id), &serial_id),
GNUNET_PQ_result_spec_uint64 ("transaction_id", GNUNET_PQ_result_spec_uint64 ("transaction_id",
&transaction_id), &transaction_id),
@ -2473,7 +2466,7 @@ postgres_iterate_matching_deposits (void *cls,
uint64_t serial_id; uint64_t serial_id;
int ret; int ret;
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("serial_id", GNUNET_PQ_result_spec_uint64 ("deposit_serial_id",
&serial_id), &serial_id),
GNUNET_PQ_result_spec_uint64 ("transaction_id", GNUNET_PQ_result_spec_uint64 ("transaction_id",
&transaction_id), &transaction_id),
@ -3875,8 +3868,8 @@ postgres_lookup_wire_transfer (void *cls,
struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_MerchantPublicKeyP merchant_pub;
uint64_t transaction_id; uint64_t transaction_id;
struct GNUNET_TIME_Absolute exec_time; struct GNUNET_TIME_Absolute exec_time;
struct TALER_Amount coin_amount; struct TALER_Amount amount_with_fee;
struct TALER_Amount coin_fee; struct TALER_Amount deposit_fee;
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("h_contract", &h_contract), GNUNET_PQ_result_spec_auto_from_type ("h_contract", &h_contract),
GNUNET_PQ_result_spec_auto_from_type ("h_wire", &h_wire), GNUNET_PQ_result_spec_auto_from_type ("h_wire", &h_wire),
@ -3884,8 +3877,8 @@ postgres_lookup_wire_transfer (void *cls,
GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", &merchant_pub), GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", &merchant_pub),
GNUNET_PQ_result_spec_uint64 ("transaction_id", &transaction_id), GNUNET_PQ_result_spec_uint64 ("transaction_id", &transaction_id),
GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time), GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time),
TALER_PQ_result_spec_amount ("coin_amount", &coin_amount), TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee),
TALER_PQ_result_spec_amount ("coin_fee", &coin_fee), TALER_PQ_result_spec_amount ("fee_deposit", &deposit_fee),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, i)) if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, i))
@ -3900,8 +3893,8 @@ postgres_lookup_wire_transfer (void *cls,
&h_contract, &h_contract,
transaction_id, transaction_id,
&coin_pub, &coin_pub,
&coin_amount, &amount_with_fee,
&coin_fee); &deposit_fee);
} }
PQclear (result); PQclear (result);
return GNUNET_OK; return GNUNET_OK;
@ -4000,11 +3993,11 @@ postgres_wire_lookup_deposit_wtid (void *cls,
executed */ executed */
{ {
struct GNUNET_TIME_Absolute exec_time; struct GNUNET_TIME_Absolute exec_time;
struct TALER_Amount coin_amount; struct TALER_Amount amount_with_fee;
struct TALER_Amount coin_fee; struct TALER_Amount deposit_fee;
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount ("amount_with_fee", &coin_amount), TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee),
TALER_PQ_result_spec_amount ("fee_deposit", &coin_fee), TALER_PQ_result_spec_amount ("fee_deposit", &deposit_fee),
GNUNET_PQ_result_spec_absolute_time ("wire_deadline", &exec_time), GNUNET_PQ_result_spec_absolute_time ("wire_deadline", &exec_time),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
@ -4017,8 +4010,8 @@ postgres_wire_lookup_deposit_wtid (void *cls,
} }
cb (cb_cls, cb (cb_cls,
NULL, NULL,
&coin_amount, &amount_with_fee,
&coin_fee, &deposit_fee,
exec_time); exec_time);
PQclear (result); PQclear (result);
return GNUNET_YES; return GNUNET_YES;
@ -4033,13 +4026,13 @@ postgres_wire_lookup_deposit_wtid (void *cls,
{ {
struct TALER_WireTransferIdentifierRawP wtid; struct TALER_WireTransferIdentifierRawP wtid;
struct GNUNET_TIME_Absolute exec_time; struct GNUNET_TIME_Absolute exec_time;
struct TALER_Amount coin_amount; struct TALER_Amount amount_with_fee;
struct TALER_Amount coin_fee; struct TALER_Amount deposit_fee;
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("wtid_raw", &wtid), GNUNET_PQ_result_spec_auto_from_type ("wtid_raw", &wtid),
GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time), GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time),
TALER_PQ_result_spec_amount ("coin_amount", &coin_amount), TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee),
TALER_PQ_result_spec_amount ("coin_fee", &coin_fee), TALER_PQ_result_spec_amount ("fee_deposit", &deposit_fee),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, 0)) if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, 0))
@ -4050,8 +4043,8 @@ postgres_wire_lookup_deposit_wtid (void *cls,
} }
cb (cb_cls, cb (cb_cls,
&wtid, &wtid,
&coin_amount, &amount_with_fee,
&coin_fee, &deposit_fee,
exec_time); exec_time);
} }
PQclear (result); PQclear (result);
@ -4065,38 +4058,22 @@ postgres_wire_lookup_deposit_wtid (void *cls,
* @param cls closure * @param cls closure
* @param session database connection * @param session database connection
* @param wtid the raw wire transfer identifier we used * @param wtid the raw wire transfer identifier we used
* @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls) * @param deposit_serial_id row in the deposits table for which this is aggregation data
* @param h_wire hash of wire transfer details of the merchant (should be same for all callbacks with the same @e cls) * @param execution_time when did we execute the transaction
* @param h_contract which contract was this payment about
* @param transaction_id merchant's transaction ID for the payment
* @param coin_pub which public key was this payment about
* @param coin_value amount contributed by this coin in total
* @param coin_fee deposit fee charged by exchange for this coin
* @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors * @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
*/ */
static int static int
postgres_insert_aggregation_tracking (void *cls, postgres_insert_aggregation_tracking (void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
const struct TALER_WireTransferIdentifierRawP *wtid, const struct TALER_WireTransferIdentifierRawP *wtid,
const struct TALER_MerchantPublicKeyP *merchant_pub, unsigned long long deposit_serial_id,
const struct GNUNET_HashCode *h_wire, struct GNUNET_TIME_Absolute execution_time)
const struct GNUNET_HashCode *h_contract,
uint64_t transaction_id,
struct GNUNET_TIME_Absolute execution_time,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_Amount *coin_value,
const struct TALER_Amount *coin_fee)
{ {
uint64_t rid = deposit_serial_id;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (h_contract), GNUNET_PQ_query_param_uint64 (&rid),
GNUNET_PQ_query_param_auto_from_type (h_wire),
GNUNET_PQ_query_param_auto_from_type (coin_pub),
GNUNET_PQ_query_param_auto_from_type (merchant_pub),
GNUNET_PQ_query_param_uint64 (&transaction_id),
GNUNET_PQ_query_param_auto_from_type (wtid), GNUNET_PQ_query_param_auto_from_type (wtid),
GNUNET_PQ_query_param_absolute_time (&execution_time), GNUNET_PQ_query_param_absolute_time (&execution_time),
TALER_PQ_query_param_amount (coin_value),
TALER_PQ_query_param_amount (coin_fee),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
PGresult *result; PGresult *result;

View File

@ -1376,24 +1376,18 @@ run (void *cls)
/* setup values for wire transfer aggregation data */ /* setup values for wire transfer aggregation data */
memset (&wtid, 42, sizeof (wtid)); memset (&wtid, 42, sizeof (wtid));
memset (&merchant_pub_wt, 43, sizeof (merchant_pub_wt)); merchant_pub_wt = deposit.merchant_pub;
memset (&h_wire_wt, 44, sizeof (h_wire_wt)); h_wire_wt = deposit.h_wire;
memset (&h_contract_wt, 45, sizeof (h_contract_wt)); h_contract_wt = deposit.h_contract;
coin_pub_wt = deposit.coin.coin_pub; coin_pub_wt = deposit.coin.coin_pub;
transaction_id_wt = 47; transaction_id_wt = deposit.transaction_id;
execution_time_wt = GNUNET_TIME_absolute_get (); execution_time_wt = GNUNET_TIME_absolute_get ();
memset (&merchant_pub_wt, 48, sizeof (merchant_pub_wt)); coin_value_wt = deposit.amount_with_fee;
coin_fee_wt = fee_deposit;
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY "KUDOS:1.000010", TALER_amount_subtract (&transfer_value_wt,
&coin_value_wt)); &coin_value_wt,
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY "KUDOS:0.000010",
&coin_fee_wt)); &coin_fee_wt));
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY "KUDOS:1.000000",
&transfer_value_wt));
FAILIF (GNUNET_NO != FAILIF (GNUNET_NO !=
plugin->lookup_wire_transfer (plugin->cls, plugin->lookup_wire_transfer (plugin->cls,
session, session,
@ -1407,7 +1401,7 @@ run (void *cls)
&h_wire_wt, &h_wire_wt,
&coin_pub_wt, &coin_pub_wt,
&merchant_pub_wt, &merchant_pub_wt,
transaction_id_wt, transaction_id_wt + 1 /* want UNKNOWN transaction here, hence + 1 */,
&cb_wtid_never, &cb_wtid_never,
NULL)); NULL));
/* insert WT data */ /* insert WT data */
@ -1415,14 +1409,8 @@ run (void *cls)
plugin->insert_aggregation_tracking (plugin->cls, plugin->insert_aggregation_tracking (plugin->cls,
session, session,
&wtid_wt, &wtid_wt,
&merchant_pub_wt, deposit_rowid,
&h_wire_wt, execution_time_wt));
&h_contract_wt,
transaction_id_wt,
execution_time_wt,
&coin_pub_wt,
&coin_value_wt,
&coin_fee_wt));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->lookup_wire_transfer (plugin->cls, plugin->lookup_wire_transfer (plugin->cls,
session, session,

View File

@ -1425,28 +1425,16 @@ struct TALER_EXCHANGEDB_Plugin
* @param cls closure * @param cls closure
* @param session database connection * @param session database connection
* @param wtid the raw wire transfer identifier we used * @param wtid the raw wire transfer identifier we used
* @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls) * @param deposit_serial_id row in the deposits table for which this is aggregation data
* @param h_wire hash of wire transfer details of the merchant (should be same for all callbacks with the same @e cls)
* @param h_contract which contract was this payment about
* @param transaction_id merchant's transaction ID for the payment
* @param execution_time when did we execute the transaction * @param execution_time when did we execute the transaction
* @param coin_pub which public key was this payment about
* @param coin_value amount contributed by this coin in total
* @param coin_fee deposit fee charged by exchange for this coin
* @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors * @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
*/ */
int int
(*insert_aggregation_tracking)(void *cls, (*insert_aggregation_tracking)(void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
const struct TALER_WireTransferIdentifierRawP *wtid, const struct TALER_WireTransferIdentifierRawP *wtid,
const struct TALER_MerchantPublicKeyP *merchant_pub, unsigned long long deposit_serial_id,
const struct GNUNET_HashCode *h_wire, struct GNUNET_TIME_Absolute execution_time);
const struct GNUNET_HashCode *h_contract,
uint64_t transaction_id,
struct GNUNET_TIME_Absolute execution_time,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_Amount *coin_value,
const struct TALER_Amount *coin_fee);
/** /**