diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-01-21 11:24:18 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-01-21 11:24:18 +0100 |
commit | 9ccba0e77f1c388bbfb7e6bea1b650797d57d023 (patch) | |
tree | a3bbeb8340dbf9247d7244bb25ab96d2b818bb0e /src | |
parent | 8f071e2200f0421caf1969c71a16ed62b3356fb5 (diff) |
implementing insert function into aggregation table
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_mintdb_plugin.h | 16 | ||||
-rw-r--r-- | src/mint-lib/mint_api_context.c | 2 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_db.c | 16 | ||||
-rw-r--r-- | src/mintdb/plugin_mintdb_postgres.c | 43 |
4 files changed, 70 insertions, 7 deletions
diff --git a/src/include/taler_mintdb_plugin.h b/src/include/taler_mintdb_plugin.h index baf587886..2ffde2285 100644 --- a/src/include/taler_mintdb_plugin.h +++ b/src/include/taler_mintdb_plugin.h @@ -1229,6 +1229,7 @@ struct TALER_MINTDB_Plugin * into a wire transfer by the respective @a raw_wtid. * * @param cls the @e cls of this struct with the plugin-specific state + * @param session database connection * @param wtid the raw wire transfer identifier we used * @param cb function to call on each transaction found * @param cb_cls closure for @a cb @@ -1236,6 +1237,7 @@ struct TALER_MINTDB_Plugin */ int (*lookup_wire_transactions) (void *cls, + struct TALER_MINTDB_Session *session, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_MINTDB_TransactionDataCallback cb, void *cb_cls); @@ -1247,6 +1249,7 @@ struct TALER_MINTDB_Plugin * to be executed. * * @param cls closure + * @param session database connection * @param h_contract hash of the contract * @param h_wire hash of merchant wire details * @param coin_pub public key of deposited coin @@ -1258,6 +1261,7 @@ struct TALER_MINTDB_Plugin */ int (*wire_lookup_deposit_wtid)(void *cls, + struct TALER_MINTDB_Session *session, const struct GNUNET_HashCode *h_contract, const struct GNUNET_HashCode *h_wire, const struct TALER_CoinSpendPublicKeyP *coin_pub, @@ -1271,26 +1275,30 @@ struct TALER_MINTDB_Plugin * Function called to insert aggregation information into the DB. * * @param cls closure + * @param session database connection * @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 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 coin_pub which public key was this payment about - * @param deposit_value amount contributed by this coin in total - * @param deposit_fee deposit fee charged by mint for this coin + * @param coin_value amount contributed by this coin to the total + * @param transaction_value total amount of the wire transaction * @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors */ int (*insert_aggregation_tracking)(void *cls, + struct TALER_MINTDB_Session *session, const struct TALER_WireTransferIdentifierRawP *wtid, const struct TALER_MerchantPublicKeyP *merchant_pub, const struct GNUNET_HashCode *h_wire, 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 *deposit_value, - const struct TALER_Amount *deposit_fee); + const struct TALER_Amount *coin_value, + const struct TALER_Amount *transaction_value); }; diff --git a/src/mint-lib/mint_api_context.c b/src/mint-lib/mint_api_context.c index 3a86efb64..2767906b5 100644 --- a/src/mint-lib/mint_api_context.c +++ b/src/mint-lib/mint_api_context.c @@ -288,7 +288,7 @@ TALER_MINT_perform (struct TALER_MINT_Context *ctx) GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, CURLINFO_PRIVATE, - (char *) &job)); + (char **) &job)); GNUNET_assert (job->ctx == ctx); job->jcc (job->jcc_cls, cmsg->easy_handle); diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c index d31dcd2ba..cc1642202 100644 --- a/src/mint/taler-mint-httpd_db.c +++ b/src/mint/taler-mint-httpd_db.c @@ -1697,10 +1697,18 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection, { int ret; struct WtidTransactionContext ctx; + struct TALER_MINTDB_Session *session; + if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls, + TMH_test_mode))) + { + GNUNET_break (0); + return TMH_RESPONSE_reply_internal_db_error (connection); + } ctx.is_valid = GNUNET_NO; ctx.deposits = json_array (); ret = TMH_plugin->lookup_wire_transactions (TMH_plugin->cls, + session, &wtid->raw, &handle_transaction_data, &ctx); @@ -1838,7 +1846,14 @@ TMH_DB_execute_deposit_wtid (struct MHD_Connection *connection, { int ret; struct DepositWtidContext ctx; + struct TALER_MINTDB_Session *session; + if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls, + TMH_test_mode))) + { + GNUNET_break (0); + return TMH_RESPONSE_reply_internal_db_error (connection); + } ctx.connection = connection; ctx.h_contract = *h_contract; ctx.h_wire = *h_wire; @@ -1846,6 +1861,7 @@ TMH_DB_execute_deposit_wtid (struct MHD_Connection *connection, ctx.transaction_id = transaction_id; ctx.res = MHD_NO; /* this value should never be read... */ ret = TMH_plugin->wire_lookup_deposit_wtid (TMH_plugin->cls, + session, h_contract, h_wire, coin_pub, diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c index ca8edcffd..f3760216f 100644 --- a/src/mintdb/plugin_mintdb_postgres.c +++ b/src/mintdb/plugin_mintdb_postgres.c @@ -3451,6 +3451,7 @@ postgres_get_coin_transactions (void *cls, * into a wire transfer by the respective @a wtid. * * @param cls closure + * @param session database connection * @param wtid the raw wire transfer identifier we used * @param cb function to call on each transaction found * @param cb_cls closure for @a cb @@ -3458,6 +3459,7 @@ postgres_get_coin_transactions (void *cls, */ static int postgres_lookup_wire_transactions (void *cls, + struct TALER_MINTDB_Session *session, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_MINTDB_TransactionDataCallback cb, void *cb_cls) @@ -3473,6 +3475,7 @@ postgres_lookup_wire_transactions (void *cls, * to be executed. * * @param cls closure + * @param session database connection * @param h_contract hash of the contract * @param h_wire hash of merchant wire details * @param coin_pub public key of deposited coin @@ -3484,6 +3487,7 @@ postgres_lookup_wire_transactions (void *cls, */ static int postgres_wire_lookup_deposit_wtid (void *cls, + struct TALER_MINTDB_Session *session, const struct GNUNET_HashCode *h_contract, const struct GNUNET_HashCode *h_wire, const struct TALER_CoinSpendPublicKeyP *coin_pub, @@ -3501,6 +3505,7 @@ postgres_wire_lookup_deposit_wtid (void *cls, * Function called to insert aggregation information into the DB. * * @param cls closure + * @param session database connection * @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 h_wire hash of wire transfer details of the merchant (should be same for all callbacks with the same @e cls) @@ -3513,15 +3518,49 @@ postgres_wire_lookup_deposit_wtid (void *cls, */ static int postgres_insert_aggregation_tracking (void *cls, + struct TALER_MINTDB_Session *session, const struct TALER_WireTransferIdentifierRawP *wtid, const struct TALER_MerchantPublicKeyP *merchant_pub, const struct GNUNET_HashCode *h_wire, 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 *deposit_value, - const struct TALER_Amount *deposit_fee) + const struct TALER_Amount *coin_value, + const struct TALER_Amount *transaction_value) { + struct TALER_PQ_QueryParam params[] = { + TALER_PQ_query_param_auto_from_type (h_contract), + TALER_PQ_query_param_auto_from_type (h_wire), + TALER_PQ_query_param_auto_from_type (coin_pub), + TALER_PQ_query_param_auto_from_type (merchant_pub), + TALER_PQ_query_param_uint64 (&transaction_id), + TALER_PQ_query_param_auto_from_type (wtid), + TALER_PQ_query_param_absolute_time (&execution_time), + TALER_PQ_query_param_amount (coin_value), + TALER_PQ_query_param_amount (transaction_value), + TALER_PQ_query_param_end + }; + PGresult *result; + + result = TALER_PQ_exec_prepared (session->conn, + "insert_aggregation_tracking", + params); + if (PGRES_COMMAND_OK != PQresultStatus (result)) + { + BREAK_DB_ERR (result); + PQclear (result); + return GNUNET_SYSERR; + } + if (0 != strcmp ("1", PQcmdTuples (result))) + { + GNUNET_break (0); + PQclear (result); + return GNUNET_SYSERR; + } + PQclear (result); + return GNUNET_OK; + GNUNET_break (0); // not implemented return GNUNET_SYSERR; } |