[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: worked on backend truth payment
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: worked on backend truth payment db fixes |
Date: |
Mon, 05 Oct 2020 19:06:44 +0200 |
This is an automated email from the git hooks/post-receive script.
ds-meister pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new a30f00e worked on backend truth payment db fixes
a30f00e is described below
commit a30f00e442dfc6a1a38cd2df6ee6cd60684736e2
Author: Dominik Meister <dominik.meister@hotmail.ch>
AuthorDate: Mon Oct 5 19:06:34 2020 +0200
worked on backend truth payment db fixes
---
src/backend/anastasis-httpd_policy_upload.c | 20 +-
src/backend/anastasis-httpd_truth.c | 388 +++++++++++++++++++++++++++-
src/include/anastasis_database_plugin.h | 36 ++-
src/stasis/plugin_anastasis_postgres.c | 199 +++++++-------
src/stasis/test_anastasis_db.c | 45 +++-
5 files changed, 558 insertions(+), 130 deletions(-)
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index c3e2b5e..ae7546a 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -336,11 +336,11 @@ proposal_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Payment-Identifier to be saved to db: %s\n",
TALER_B2S (&puc->payment_identifier));
- qs = db->record_payment (db->cls,
- &puc->account,
- post_counter,
- &puc->payment_identifier,
- &AH_annual_fee);
+ qs = db->record_recdoc_payment (db->cls,
+ &puc->account,
+ post_counter,
+ &puc->payment_identifier,
+ &AH_annual_fee);
if (0 >= qs)
{
GNUNET_break (0);
@@ -930,11 +930,11 @@ AH_handler_policy_post (struct MHD_Connection *connection,
/** FIXME: not really reasonable */
int post_counter = 10;
- qs = db->record_payment (db->cls,
- &accountPubP,
- post_counter,
- &puc->payment_identifier,
- &AH_annual_fee);
+ qs = db->record_recdoc_payment (db->cls,
+ &accountPubP,
+ &puc->payment_identifier,
+ post_counter,
+ &AH_annual_fee);
if (qs >= 0)
{
qs = db->increment_lifetime (db->cls,
diff --git a/src/backend/anastasis-httpd_truth.c
b/src/backend/anastasis-httpd_truth.c
index c28b744..8fdc280 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -27,6 +27,7 @@
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_rest_lib.h>
#include <anastasis_authorization_plugin.h>
+#include <taler/taler_merchant_service.h>
/**
* Authentication plugin which is used to verify code based authentication
@@ -50,14 +51,76 @@ struct AuthPlugin
struct GetContext
{
+ /**
+ * Kept in DLL for shutdown handling while suspended.
+ */
struct GetContext *next;
+ /**
+ * Kept in DLL for shutdown handling while suspended.
+ */
struct GetContext *prev;
-
+ /**
+ * Connection handle for closing or resuming
+ */
struct MHD_Connection *connection;
-
+ /**
+ * Reference to the authorization plugin which was loaded
+ */
struct ANASTASIS_AuthorizationPlugin *authorization;
-
+ /**
+ * Status of the authorization
+ */
struct ANASTASIS_AUTHORIZATION_State *as;
+ /**
+ * Public key of the challenge which is solved.
+ */
+ struct ANASTASIS_CRYPTO_TruthPublicKeyP truth_public_key;
+ /**
+ * Used while we are awaiting proposal creation.
+ */
+ struct TALER_MERCHANT_PostOrdersOperation *po;
+ /**
+ * Used while we are waiting payment.
+ */
+ struct TALER_MERCHANT_OrderMerchantGetHandle *cpo;
+ /**
+ * HTTP response code to use on resume, if non-NULL.
+ */
+ struct MHD_Response *resp;
+ /**
+ * Order under which the client promised payment, or NULL.
+ */
+ const char *order_id;
+ /**
+ * Order ID for the client that we found in our database.
+ */
+ char *existing_order_id;
+ /**
+ * Timestamp of the order in @e existing_order_id. Used to
+ * select the most recent unpaid offer.
+ */
+ struct GNUNET_TIME_Absolute existing_order_timestamp;
+ /**
+ * Payment Identifier
+ */
+ struct ANASTASIS_PaymentSecretP payment_identifier;
+ /**
+ * HTTP response code to use on resume, if resp is set.
+ */
+ unsigned int response_code;
+ /**
+ * Whether to generate a claim token.
+ */
+ bool make_claim_token;
+ /**
+ * The claim token
+ */
+ struct TALER_ClaimTokenP claim_token;
+ /**
+ * Information about the payment
+ */
+ struct ANASTASIS_DB_ChallengePayment cp;
+
};
@@ -166,6 +229,124 @@ request_done (struct TM_HandlerContext *hc)
hc->ctx = NULL;
}
+/**
+ * Transmit a payment request for @a order_id on @a connection
+ *
+ * @param connection MHD connection
+ * @param order_id our backend's order ID
+ * @return MHD repsonse to use
+ */
+static struct MHD_Response *
+make_payment_request (const char *order_id)
+{
+ struct MHD_Response *resp;
+
+ /* request payment via Taler */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Creating payment request for order `%s'\n",
+ order_id);
+ resp = MHD_create_response_from_buffer (0,
+ NULL,
+ MHD_RESPMEM_PERSISTENT);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
+ "*"));
+ {
+ char *hdr;
+
+ /* TODO: support instances? */
+ GNUNET_asprintf (&hdr,
+ "taler://pay/%s/-/-/%s",
+ AH_backend_url,
+ order_id);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ "Taler",
+ hdr));
+ GNUNET_free (hdr);
+ }
+ return resp;
+}
+
+/**
+ * Callbacks of this type are used to serve the result of submitting a
+ * /contract request to a merchant.
+ *
+ * @param cls our `struct PolicyUploadContext`
+ * @param hr HTTP response details
+ * @param order_id payment_identifier (base32 encoded) of the newly created
order
+ */
+static void
+proposal_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr,
+ const char *order_id,
+ const struct TALER_ClaimTokenP *claim_token)
+{
+ struct GetContext *gc = cls;
+ enum ANASTASIS_DB_QueryStatus qs;
+/*FIXME
+ puc->po = NULL; */
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Resuming connection with order `%s'\n",
+ order_id);
+ GNUNET_CONTAINER_DLL_remove (gc_head,
+ gc_tail,
+ gc);
+ MHD_resume_connection (gc->connection);
+ AH_trigger_daemon ();
+ if (MHD_HTTP_OK != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Backend returned status %u/%d\n",
+ hr->http_status,
+ (int) hr->ec);
+ GNUNET_break (0);
+ gc->resp = TALER_MHD_make_json_pack (
+ (NULL == hr->reply)
+ ? "{s:I, s:s, s:I, s:I}"
+ : "{s:I, s:s, s:I, s:I, s:O}",
+ "code",
+ (json_int_t) TALER_EC_SYNC_PAYMENT_CREATE_BACKEND_ERROR,
+ "hint",
+ "Failed to setup order with merchant backend",
+ "backend-ec",
+ (json_int_t) hr->ec,
+ "backend-http-status",
+ (json_int_t) hr->http_status,
+ "backend-reply",
+ hr->reply);
+ GNUNET_assert (NULL != gc->resp);
+ gc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Storing payment request for order `%s'\n",
+ order_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Payment-Identifier to be saved to db: %s\n",
+ TALER_B2S (&gc->payment_identifier));
+
+ qs = db->record_challenge_payment (db->cls,
+ &gc->truth_public_key,
+ &gc->payment_identifier,
+ &AH_annual_fee);
+ if (0 >= qs)
+ {
+ GNUNET_break (0);
+ gc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CREATE_DB_ERROR,
+ "Failed to persist payment request in
anastasis database");
+ gc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Obtained fresh order `%s'\n",
+ order_id);
+ gc->resp = make_payment_request (order_id);
+ GNUNET_assert (NULL != gc->resp);
+ gc->response_code = MHD_HTTP_PAYMENT_REQUIRED;
+}
static MHD_RESULT
return_key_share (const struct
@@ -200,6 +381,207 @@ return_key_share (const struct
return ret;
}
+/**
+ * Function called on all pending payments for the right
+ * account.
+ *
+ * @param cls closure, our `struct BackupContext`
+ * @param timestamp for how long have we been waiting
+ * @param order_id order id in the backend
+ * @param amount how much is the order for
+ */
+static void
+ongoing_payment_cb (void *cls,
+ struct GNUNET_TIME_Absolute timestamp,
+ const char *order_id,
+ const struct TALER_Amount *amount)
+{
+ struct GetContext *gc = cls;
+
+ (void) amount;
+ if (0 != TALER_amount_cmp (amount,
+ &AH_annual_fee))
+ return; /* can't re-use, fees changed */
+ if ( (NULL == gc->existing_order_id) ||
+ (gc->existing_order_timestamp.abs_value_us < timestamp.abs_value_us) )
+ {
+ GNUNET_free (gc->existing_order_id);
+ gc->existing_order_id = GNUNET_strdup (order_id);
+ gc->existing_order_timestamp = timestamp;
+ }
+}
+/**
+ * Callback to process a GET /check-payment request
+ *
+ * @param cls our `struct PolicyUploadContext`
+ * @param hr HTTP response details
+ * @param osr order status
+ */
+static void
+check_payment_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr,
+ const struct TALER_MERCHANT_OrderStatusResponse *osr)
+
+{
+ struct GetContext *gc = cls;
+
+ /* refunds are not supported, verify */
+ gc->cpo = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Payment status checked: %s\n",
+ osr->paid ? "paid" : "unpaid");
+ GNUNET_CONTAINER_DLL_remove (gc_head,
+ gc_tail,
+ gc);
+ MHD_resume_connection (gc->connection);
+ AH_trigger_daemon ();
+
+ /**
+ * FIXME: DELETE
+ GNUNET_break ( (GNUNET_NO == refunded) &&
+ (NULL == refund_amount) );
+ */if (osr->paid)
+ {
+ enum ANASTASIS_DB_QueryStatus qs;
+
+ qs = db->update_challenge_payment (db->cls,
+ &gc->truth_public_key,
+ &gc->payment_identifier); /* FIXME:
always annual ?*/
+ if (0 <= qs)
+ return; /* continue as planned */
+ GNUNET_break (0);
+ gc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CONFIRM_DB_ERROR,
+ "Failed to persist payment confirmation
in sync database");
+ gc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ return; /* continue as planned */
+ }
+ if (NULL != gc->existing_order_id)
+ {
+ /* repeat payment request */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Repeating payment request\n");
+ gc->resp = make_payment_request (gc->existing_order_id);
+ GNUNET_assert (NULL != gc->resp);
+ gc->response_code = MHD_HTTP_PAYMENT_REQUIRED;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Timeout waiting for payment\n");
+ gc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_TIMEOUT,
+ "Timeout awaiting promised payment");
+ GNUNET_assert (NULL != gc->resp);
+ gc->response_code = MHD_HTTP_REQUEST_TIMEOUT;
+}
+/**
+ * Helper function used to ask our backend to await
+ * a payment for the user's account.
+ *
+ * @param puc context to begin payment for.
+ * @param timeout when to give up trying
+ * @param order_id which order to check for the payment
+ */
+static void
+await_payment (struct GetContext *gc,
+ struct GNUNET_TIME_Relative timeout,
+ const char *order_id)
+{
+ GNUNET_CONTAINER_DLL_insert (gc_tail,
+ gc_head,
+ gc);
+ MHD_suspend_connection (gc->connection);
+ gc->order_id = order_id;
+ gc->cpo = TALER_MERCHANT_merchant_order_get (AH_ctx,
+ AH_backend_url,
+ order_id,
+ NULL /* our payments are NOT
session-bound */,
+ false,
+ timeout,
+ &check_payment_cb,
+ gc);
+ AH_trigger_curl ();
+}
+/**
+ * Helper function used to ask our backend to begin
+ * processing a payment for the user's account.
+ * May perform asynchronous operations by suspending the connection
+ * if required.
+ *
+ * @param puc context to begin payment for.
+ * @param pay_req #GNUNET_YES if payment was explicitly requested,
+ * #GNUNET_NO if payment is needed
+ * @return MHD status code
+ */
+static MHD_RESULT
+begin_payment (struct GetContext *gc,
+ int pay_req)
+{
+ json_t *order;
+ enum ANASTASIS_DB_QueryStatus qs;
+ const char *order_id;
+
+ qs = db->lookup_challenge_payment (db->cls,
+ &gc->truth_public_key,
+ &gc->cp);
+ if (qs < 0)
+ {
+ struct MHD_Response *resp;
+ MHD_RESULT ret;
+
+ resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CHECK_ORDER_DB_ERROR,
+ "Failed to check for expired payment in
anastasis database");
+ ret = MHD_queue_response (gc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ resp);
+ MHD_destroy_response (resp);
+ return ret;
+ }
+
+ if (NULL != gc->existing_order_id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Have existing order, waiting for `%s' to complete\n",
+ gc->existing_order_id);
+ await_payment (gc,
+ GNUNET_TIME_UNIT_ZERO /* no long polling */,
+ gc->existing_order_id);
+ return MHD_YES;
+ }
+
+ order_id = GNUNET_STRINGS_data_to_string_alloc (&gc->payment_identifier,
+ sizeof(
+ struct
+ ANASTASIS_PaymentSecretP));
+
+ GNUNET_CONTAINER_DLL_insert (gc_head,
+ gc_tail,
+ gc);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Suspending connection while creating order at `%s'\n",
+ AH_backend_url);
+ MHD_suspend_connection (gc->connection);
+ order = json_pack ("{s:o, s:s, s:s, s:s}",
+ "amount", TALER_JSON_from_amount (&AH_annual_fee),
+ "summary", "annual fee for anastasis service",
+ "fulfillment_url", AH_fulfillment_url,
+ "order_id", order_id);
+
+ gc->po = TALER_MERCHANT_orders_post2 (AH_ctx,
+ AH_backend_url,
+ order,
+ GNUNET_TIME_UNIT_ZERO,
+ NULL, /* no payment target */
+ 0,
+ NULL, /* no inventory products */
+ 0,
+ NULL, /* no uuids */
+ false, /* do NOT require claim token */
+ &proposal_cb,
+ gc);
+
+ AH_trigger_curl ();
+ json_decref (order);
+ return MHD_YES;
+}
/**
* @param connection the MHD connection to handle
diff --git a/src/include/anastasis_database_plugin.h
b/src/include/anastasis_database_plugin.h
index 7d00280..395903a 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -362,8 +362,8 @@ struct ANASTASIS_DatabasePlugin
* @param valid_counter[OUT] bool value to show if post_counter is > 0
* @return transaction status
*/
- enum ANASTASIS_DB_QueryStatus
- (*check_challenge_payment)(void *cls,
+ enum ANASTASIS_DB_QueryStatus
+ (*check_challenge_payment) (void *cls,
const struct
ANASTASIS_PaymentSecretP *payment_secret,
bool *paid);
@@ -403,8 +403,7 @@ struct ANASTASIS_DatabasePlugin
const struct
ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
uint32_t post_counter,
- const struct
- ANASTASIS_PaymentSecretP *payment_secret,
+ const struct ANASTASIS_PaymentSecretP
*payment_secret,
const struct TALER_Amount *amount);
/**
@@ -453,13 +452,12 @@ struct ANASTASIS_DatabasePlugin
* @param amount how much we asked for
* @return transaction status
*/
- enum ANASTASIS_DB_QueryStatus
- (*record_challenge_payment)(void *cls,
- const struct
- ANASTASIS_CRYPTO_TruthKeyP *truth_public_key,
- const struct
- ANASTASIS_PaymentSecretP *payment_secret,
- const struct TALER_Amount *amount);
+ enum ANASTASIS_DB_QueryStatus
+ (*record_challenge_payment) (void *cls,
+ const struct
+ ANASTASIS_CRYPTO_TruthPublicKeyP
*truth_public_key,
+ const struct ANASTASIS_PaymentSecretP
*payment_secret,
+ const struct TALER_Amount *amount);
/**
* Lookup for a pending payment for a certain challenge
@@ -469,8 +467,8 @@ struct ANASTASIS_DatabasePlugin
* @param cp returns a challenge payment struct
* @return transaction status
*/
- enum ANASTASIS_DB_QueryStatus
- (*lookup_challenge_payment)(void *cls,
+ enum ANASTASIS_DB_QueryStatus
+ (*lookup_challenge_payment)(void *cls,
const struct
ANASTASIS_CRYPTO_TruthPublicKeyP
*truth_public_key,
@@ -484,12 +482,12 @@ struct ANASTASIS_DatabasePlugin
* @param payment_identifier proof of payment, must be unique and match
pending payment
* @return transaction status
*/
- enum ANASTASIS_DB_QueryStatus
- (*update_challenge_payment)(void *cls,
- const struct
- ANASTASIS_CRYPTO_TruthPublicKeyP
*truth_public_key,
- const struct
- ANASTASIS_PaymentSecretP *payment_identifier);
+ enum ANASTASIS_DB_QueryStatus
+ (*update_challenge_payment)(void *cls,
+ const struct
+ ANASTASIS_CRYPTO_TruthPublicKeyP
*truth_public_key,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_identifier);
/**
* FIXME maybe implemented in the postgres_gc but want it seperate first
* Function called to remove all expired codes in the database
diff --git a/src/stasis/plugin_anastasis_postgres.c
b/src/stasis/plugin_anastasis_postgres.c
index 1ac779f..f632aaa 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -75,17 +75,13 @@ postgres_drop_tables (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_try_execute (
- "DROP TABLE IF EXISTS anastasis_truth CASCADE;"),
+ GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS anastasis_truth
CASCADE;"),
GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS anastasis_user
CASCADE;"),
- GNUNET_PQ_make_try_execute (
- "DROP TABLE IF EXISTS anastasis_recdoc_payment;"),
+ GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS
anastasis_recdoc_payment;"),
GNUNET_PQ_make_try_execute (
"DROP TABLE IF EXISTS anastasis_recoverydocument;"),
- GNUNET_PQ_make_try_execute (
- "DROP TABLE IF EXISTS anastasis_challengecode;"),
- GNUNET_PQ_make_try_execute (
- "DROP TABLE IF EXISTS anastasis_challenge_payment;"),
+ GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS
anastasis_challengecode;"),
+ GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS
anastasis_challenge_payment;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
return GNUNET_PQ_exec_statements (pg->conn,
@@ -856,11 +852,9 @@ postgres_increment_lifetime (void *cls,
static enum ANASTASIS_DB_QueryStatus
postgres_record_recdoc_payment (void *cls,
const struct
- ANASTASIS_CRYPTO_AccountPublicKeyP *
- anastasis_pub,
+ ANASTASIS_CRYPTO_AccountPublicKeyP
*anastasis_pub,
uint32_t post_counter,
- const struct
- ANASTASIS_PaymentSecretP *payment_secret,
+ const struct ANASTASIS_PaymentSecretP
*payment_secret,
const struct TALER_Amount *amount)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -997,48 +991,59 @@ postgres_record_recdoc_payment (void *cls,
static enum ANASTASIS_DB_QueryStatus
postgres_record_challenge_payment (void *cls,
const struct
- ANASTASIS_CRYPTO_TruthKeyP
*truth_public_key,
- const struct
- ANASTASIS_PaymentSecretP *payment_secret,
+ ANASTASIS_CRYPTO_TruthPublicKeyP
*truth_public_key,
+ const struct ANASTASIS_PaymentSecretP
*payment_secret,
const struct TALER_Amount *amount)
{
struct PostgresClosure *pg = cls;
enum ANASTASIS_DB_QueryStatus qs;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
check_connection (pg);
- postgres_preflight (pg);
- /*dummy funcion to check if truth is available*/
- void *truth;
- size_t truth_size;
- char *truth_mime;
- char *method;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d Truth Public key used to query db is: %s\n",
+ __FILE__,
+ __LINE__,
+ TALER_B2S (truth_public_key));
+ /*dummy funcion to check if truth is available*/
+ void *truth;
+ size_t truth_size;
+ char *truth_mime;
+ char *method;
+
+
+ {
+ // because of constraint at truth_id, first we have to verify
+ // if the challenge exists
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (truth_public_key),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_variable_size ("encrypted_truth",
+ &truth,
+ &truth_size),
+ GNUNET_PQ_result_spec_string ("truth_mime",
+ &truth_mime),
+ GNUNET_PQ_result_spec_string ("method",
+ &method),
+ GNUNET_PQ_result_spec_end
+ };
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+
"truth_select",
+ params,
+ rs);
+ if (qs != 1)
+ {
+ return qs;
+ }
+ }
+ if (GNUNET_OK != begin_transaction (pg,
+ "store_truth"))
{
- // because of constraint at truth_id, first we have to verify
- // if the challenge exists
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (truth_public_key),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_variable_size ("encrypted_truth",
- &truth,
- &truth_size),
- GNUNET_PQ_result_spec_string ("truth_mime",
- &truth_mime),
- GNUNET_PQ_result_spec_string ("method",
- &method),
- GNUNET_PQ_result_spec_end
- };
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "truth_select",
- params,
- rs);
- if (qs < 0)
- {
- return qs;
- }
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
}
struct GNUNET_PQ_QueryParam params[] = {
@@ -1061,7 +1066,7 @@ postgres_record_challenge_payment (void *cls,
GNUNET_break (0);
return ANASTASIS_DB_STATUS_NO_RESULTS;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+ break;
case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0);
return ANASTASIS_DB_STATUS_HARD_ERROR;
@@ -1069,6 +1074,14 @@ postgres_record_challenge_payment (void *cls,
GNUNET_break (0);
return ANASTASIS_DB_STATUS_HARD_ERROR;
}
+
+ qs = commit_transaction (pg);
+ if (qs < 0)
+ {
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
+ }
+
+ return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
}
/**
* Check payment identifier. Used to check if a payment identifier given by
@@ -1190,6 +1203,11 @@ postgres_store_truth (void *cls,
enum ANASTASIS_DB_QueryStatus qs;
struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get ();
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d Truth public key used to query db is: %s\n",
+ __FILE__,
+ __LINE__,
+ TALER_B2S (truth_public_key));
GNUNET_TIME_round_abs (&expiration);
expiration = GNUNET_TIME_absolute_add (expiration,
truth_expiration);
@@ -1692,34 +1710,34 @@ postgres_lookup_challenge_payment (void *cls,
pg->currency,
&amount),
GNUNET_PQ_result_spec_end
- };
+ };
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-
"challenge_pending_payment_select",
- params,
- rs);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+
"challenge_pending_payment_select",
+ params,
+ rs);
switch (qs)
{
- case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_HARD_ERROR:
return ANASTASIS_DB_STATUS_HARD_ERROR;
- case GNUNET_DB_STATUS_SOFT_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
return ANASTASIS_DB_STATUS_SOFT_ERROR;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
return ANASTASIS_DB_STATUS_NO_RESULTS;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
break;
- default:
+ default:
GNUNET_break (0);
return ANASTASIS_DB_STATUS_HARD_ERROR;
- }
+ }
- char *order_id;
- order_id = GNUNET_STRINGS_data_to_string_alloc (&payment_identifier,
- sizeof (struct
-
ANASTASIS_PaymentSecretP));
- cp->payment_identifier = order_id;
- cp->amount = &amount;
- return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+ char *order_id;
+ order_id = GNUNET_STRINGS_data_to_string_alloc (&payment_identifier,
+ sizeof (struct
+
ANASTASIS_PaymentSecretP));
+ cp->payment_identifier = order_id;
+ cp->amount = &amount;
+ return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
}
/**
@@ -1733,8 +1751,7 @@ postgres_lookup_challenge_payment (void *cls,
enum ANASTASIS_DB_QueryStatus
postgres_update_challenge_payment (void *cls,
const struct
- ANASTASIS_CRYPTO_TruthPublicKeyP *
- truth_public_key,
+ ANASTASIS_CRYPTO_TruthPublicKeyP
*truth_public_key,
const struct
ANASTASIS_PaymentSecretP
*payment_identifier)
{
@@ -1762,12 +1779,20 @@ postgres_update_challenge_payment (void *cls,
params);
if (0 >= qs)
{
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ROLLBACK %d", qs);
/* payment made before, or unknown, or error => no further action! */
rollback (pg);
return qs;
}
+ qs = commit_transaction (pg);
+ if (qs < 0)
+ {
+ return qs;
+ }
}
- return qs;
+ return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
}
/**
@@ -1943,27 +1968,25 @@ libanastasis_plugin_db_postgres_init (void *cls)
"( user_id BYTEA PRIMARY KEY
CHECK(LENGTH(user_id)=32),"
" expiration_date TIMESTAMP NOT NULL"
");"),
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS anastasis_recdoc_payment"
- "(payment_id BIGSERIAL PRIMARY KEY,"
- " user_id BYTEA NOT NULL REFERENCES anastasis_user(user_id),"
- " post_counter INT4 NOT NULL DEFAULT 0 CHECK(post_counter >= 0),"
- " amount_val INT8 NOT NULL," /* amount we were
paid */
- " amount_frac INT4 NOT NULL,"
- " payment_identifier BYTEA NOT NULL
CHECK(LENGTH(payment_identifier)=32),"
- " timestamp TIMESTAMP NOT NULL DEFAULT NOW(),"
- " paid BOOLEAN NOT NULL DEFAULT FALSE"
- ");"),
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS anastasis_challenge_payment"
- "(payment_id BIGSERIAL PRIMARY KEY,"
- " truth_public_key BYTEA NOT NULL REFERENCES
anastasis_truth(truth_public_key),"
- " amount_val INT8 NOT NULL," /* amount we were
paid */
- " amount_frac INT4 NOT NULL,"
- " payment_identifier BYTEA NOT NULL
CHECK(LENGTH(payment_identifier)=32),"
- " timestamp TIMESTAMP NOT NULL DEFAULT NOW(),"
- " paid BOOLEAN NOT NULL DEFAULT FALSE"
- ");"),
+ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS
anastasis_recdoc_payment"
+ "(payment_id BIGSERIAL PRIMARY KEY,"
+ " user_id BYTEA NOT NULL REFERENCES
anastasis_user(user_id),"
+ " post_counter INT4 NOT NULL DEFAULT 0
CHECK(post_counter >= 0),"
+ " amount_val INT8 NOT NULL," /* amount we were
paid */
+ " amount_frac INT4 NOT NULL,"
+ " payment_identifier BYTEA NOT NULL
CHECK(LENGTH(payment_identifier)=32),"
+ " timestamp TIMESTAMP NOT NULL DEFAULT NOW(),"
+ " paid BOOLEAN NOT NULL DEFAULT FALSE"
+ ");"),
+ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS
anastasis_challenge_payment"
+ "(payment_id BIGSERIAL PRIMARY KEY,"
+ " truth_public_key BYTEA NOT NULL,"
+ " amount_val INT8 NOT NULL," /* amount we were
paid */
+ " amount_frac INT4 NOT NULL,"
+ " payment_identifier BYTEA NOT NULL
CHECK(LENGTH(payment_identifier)=32),"
+ " timestamp TIMESTAMP NOT NULL DEFAULT NOW(),"
+ " paid BOOLEAN NOT NULL DEFAULT FALSE"
+ ");"),
GNUNET_PQ_make_execute (
"CREATE TABLE IF NOT EXISTS anastasis_recoverydocument"
"( user_id BYTEA NOT NULL REFERENCES anastasis_user(user_id),"
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index e52447e..4977883 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -236,6 +236,17 @@ run (void *cls)
TALER_string_to_amount ("EUR:1",
&amount));
+
+ FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->store_truth (plugin->cls,
+ &truth_public_key,
+ "key_share_data",
+ mime_type,
+ "encrypted_truth",
+ sizeof ("encrypted_truth"),
+ method,
+ rel_time));
+
FAILIF (ANASTASIS_DB_STATUS_NO_RESULTS !=
plugin->check_payment_identifier (plugin->cls,
&paymentSecretP,
@@ -255,21 +266,35 @@ run (void *cls)
&paymentSecretP,
rel_time));
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->check_payment_identifier (plugin->cls,
&paymentSecretP,
&paid,
&valid_counter));
+ FAILIF (ANASTASIS_DB_STATUS_NO_RESULTS !=
+ plugin->check_challenge_payment (plugin->cls,
+ &paymentSecretP,
+ &paid));
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->store_truth (plugin->cls,
- &truth_public_key,
- "key_share_data",
- mime_type,
- "encrypted_truth",
- sizeof ("encrypted_truth"),
- method,
- rel_time));
+ plugin->record_challenge_payment (plugin->cls,
+ &truth_public_key,
+ &paymentSecretP,
+ &amount));
+
+
+ FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->update_challenge_payment (plugin->cls,
+ &truth_public_key,
+ &paymentSecretP));
+
+
+ FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->check_challenge_payment (plugin->cls,
+ &paymentSecretP,
+ &paid));
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->store_recovery_document (plugin->cls,
@@ -343,8 +368,8 @@ run (void *cls)
result = 0;
drop:
- GNUNET_break (GNUNET_OK ==
- plugin->drop_tables (plugin->cls));
+/* GNUNET_break (GNUNET_OK ==
+ plugin->drop_tables (plugin->cls));*/
ANASTASIS_DB_plugin_unload (plugin);
plugin = NULL;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: worked on backend truth payment db fixes,
gnunet <=