diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-09-30 09:00:21 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-09-30 09:00:21 +0200 |
commit | ae89e08fd7d59cd81c69221c723c64c05dfacf3f (patch) | |
tree | 8fbe1d2dbf94a9e5c0f19a62be1d57418e4ac902 /src/backend-lib/taler-merchant-httpd_contract.c | |
parent | d28fc4e6fc458573e3dc58f3f68b694337bc2384 (diff) | |
download | merchant-ae89e08fd7d59cd81c69221c723c64c05dfacf3f.tar.gz merchant-ae89e08fd7d59cd81c69221c723c64c05dfacf3f.tar.bz2 merchant-ae89e08fd7d59cd81c69221c723c64c05dfacf3f.zip |
adding error code for primary key violation
Diffstat (limited to 'src/backend-lib/taler-merchant-httpd_contract.c')
-rw-r--r-- | src/backend-lib/taler-merchant-httpd_contract.c | 73 |
1 files changed, 19 insertions, 54 deletions
diff --git a/src/backend-lib/taler-merchant-httpd_contract.c b/src/backend-lib/taler-merchant-httpd_contract.c index 1f9d095a..5a937e66 100644 --- a/src/backend-lib/taler-merchant-httpd_contract.c +++ b/src/backend-lib/taler-merchant-httpd_contract.c @@ -24,31 +24,6 @@ } while (0) /** -* Generate the hash containing the information (= a nounce + merchant's IBAN) to -* redeem money from mint in a subsequent /deposit operation -* @param nounce the nounce -* @param wire the merchant's wire details -* @return the hash to be included in the contract's blob -* -*/ - -static struct GNUNET_HashCode -hash_wireformat (uint64_t nounce, const struct MERCHANT_WIREFORMAT_Sepa *wire) -{ - struct GNUNET_HashContext *hc; - struct GNUNET_HashCode hash; - - hc = GNUNET_CRYPTO_hash_context_start (); - GNUNET_CRYPTO_hash_context_read (hc, wire->iban, strlen (wire->iban)); - GNUNET_CRYPTO_hash_context_read (hc, wire->name, strlen (wire->name)); - GNUNET_CRYPTO_hash_context_read (hc, wire->bic, strlen (wire->bic)); - nounce = GNUNET_htonll (nounce); - GNUNET_CRYPTO_hash_context_read (hc, &nounce, sizeof (nounce)); - GNUNET_CRYPTO_hash_context_finish (hc, &hash); - return hash; -} - -/** * Take the global wire details and return a JSON containing them, * compliantly with the Taler's API. * @param wire the merchant's wire details @@ -99,22 +74,24 @@ MERCHANT_get_wire_json (const struct MERCHANT_WIREFORMAT_Sepa *wire, * to this deal (this value is also a field inside the 'wire' JSON format) * @param refund deadline until which the merchant can return the paid amount * @param nounce the nounce used to hash the wire details -* @param contract_str where to store -* @return pointer to the (stringified) contract; NULL upon errors +* @param a will be pointed to the (allocated) stringified 0-terminated contract +* @return GNUNET_OK on success, GNUNET_NO if attempting to double insert the +* same contract, GNUNET_SYSERR in case of other (mostly DB related) errors. */ /** * TODO: inspect reference counting and, accordingly, free those json_t*(s) * still allocated */ -char * -MERCHANT_handle_contract (const json_t *j_contract, +uint32_t +MERCHANT_handle_contract (json_t *j_contract, PGconn *db_conn, struct Contract *contract, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Absolute expiry, struct GNUNET_TIME_Absolute edate, struct GNUNET_TIME_Absolute refund, + char **a, uint64_t nounce) { json_t *j_amount; @@ -135,39 +112,27 @@ MERCHANT_handle_contract (const json_t *j_contract, &j_product_id)) { printf ("no unpacking\n"); - return NULL; + return GNUNET_SYSERR; } - /* DB will store the amount -- WARNING: this call produces a - 'protocol violation' in json.c */ - - #if 0 - char *str = json_dumps (j_amount, JSON_INDENT(2) | JSON_PRESERVE_ORDER); - printf ("extracted amount : %s\n", str); - #endif - - TALER_json_to_amount (j_amount, &amount); contract_str = json_dumps (j_contract, JSON_COMPACT | JSON_PRESERVE_ORDER); + *a = contract_str; GNUNET_CRYPTO_hash (contract_str, strlen (contract_str) + 1, &contract->h_contract_details); contract->purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT); contract->purpose.size = htonl (sizeof (struct Contract)); // DB mgmt - if (GNUNET_SYSERR == MERCHANT_DB_contract_create (db_conn, - timestamp, - expiry, - edate, - refund, - &amount, - &contract->h_contract_details, - (uint64_t) j_trans_id, // safe? - contract_str, - nounce, - (uint64_t) j_product_id)) - return NULL; - return contract_str; + return MERCHANT_DB_contract_create (db_conn, + timestamp, + expiry, + edate, + refund, + &amount, + &contract->h_contract_details, + (uint64_t) j_trans_id, // safe? + contract_str, + nounce, + (uint64_t) j_product_id); } - - |