diff options
author | Florian Dold <florian@dold.me> | 2021-07-22 15:53:37 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-07-22 15:54:48 +0200 |
commit | 2f4a05e7a2f947372f97d11ac8c08fc705c79e59 (patch) | |
tree | 44e64a33a043562f2ef0e9f413c694875c63a6fb /src/backend/taler-merchant-httpd_post-orders-ID-claim.c | |
parent | 1b0aca733237973bb69541d2b95295c759ad064e (diff) |
refactor order claiming
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-orders-ID-claim.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-claim.c | 77 |
1 files changed, 49 insertions, 28 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c index b764c7d7..1d201ce1 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c @@ -83,7 +83,46 @@ claim_order (const char *instance_id, return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + { + /* We already have claimed contract terms for this order_id */ + const char *stored_nonce; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_string ("nonce", + &stored_nonce), + GNUNET_JSON_spec_end () + }; + enum GNUNET_GenericReturnValue res; + + TMH_db->rollback (TMH_db->cls); + GNUNET_assert (NULL != *contract_terms); + + if (GNUNET_OK != + GNUNET_JSON_parse (*contract_terms, + spec, + NULL, + NULL)) + { + /* this should not be possible: contract_terms should always + have a nonce! */ + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + + if (0 != strcmp (stored_nonce, + nonce)) + { + GNUNET_JSON_parse_free (spec); + return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + } + GNUNET_JSON_parse_free (spec); + return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; + } + + GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs); + + /* Now we need to claim the order. */ + { struct GNUNET_HashCode unused; @@ -99,13 +138,13 @@ claim_order (const char *instance_id, TMH_db->rollback (TMH_db->cls); return qs; } - GNUNET_assert (NULL != contract_terms); + GNUNET_assert (NULL != *contract_terms); GNUNET_assert (0 == json_object_set_new (*contract_terms, "nonce", json_string (nonce))); - if (0 != GNUNET_memcmp (&order_ct, - claim_token)) + if (0 != GNUNET_memcmp_priv (&order_ct, + claim_token)) { TMH_db->rollback (TMH_db->cls); json_decref (*contract_terms); @@ -128,29 +167,6 @@ claim_order (const char *instance_id, return qs; return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; } - else - { - const char *stored_nonce; - - TMH_db->rollback (TMH_db->cls); - GNUNET_assert (NULL != *contract_terms); - stored_nonce - = json_string_value (json_object_get (*contract_terms, - "nonce")); - if (NULL == stored_nonce) - { - /* this should not be possible: contract_terms should always - have a nonce! */ - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - if (0 != strcmp (stored_nonce, - nonce)) - { - return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; - } - return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - } } @@ -225,13 +241,18 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler *rh, break; /* Good! return signature (below) */ } - /* create proposal signature */ + /* create contract signature */ { struct GNUNET_CRYPTO_EddsaSignature merchant_sig; struct TALER_ProposalDataPS pdps = { .purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT), .purpose.size = htonl (sizeof (pdps)) }; + /** + * Hash of the JSON contract in UTF-8 including 0-termination, + * using JSON_COMPACT | JSON_SORT_KEYS + */ + struct GNUNET_HashCode hash; if (GNUNET_OK != TALER_JSON_contract_hash (contract_terms, |