merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 39e4f50b0a0d921f4910d390aaebd93c6a173867
parent 6e80a32260f1edc4c36e758749dedaf1622cae62
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Wed,  4 Nov 2015 12:04:18 +0100

adding (initial) DB mgmt for deposits

Diffstat:
Msrc/backend-lib/merchant_db.c | 33++++++++++++++++++++++++++++++++-
Msrc/backend/taler-merchant-httpd.c | 3+++
Msrc/backend/taler-merchant-httpd_pay.c | 29+++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/src/backend-lib/merchant_db.c b/src/backend-lib/merchant_db.c @@ -104,7 +104,12 @@ MERCHANT_DB_initialize (PGconn *conn, int tmp) "contract_id INT8 REFERENCES contracts(contract_id)," "amount INT4 NOT NULL," "amount_fraction INT4 NOT NULL," - "coin_sig BYTEA NOT NULL);", + "coin_sig BYTEA NOT NULL);" + "CREATE %1$s TABLE IF NOT EXISTS deposits (" + "dep_perm TEXT NOT NULL" + "transaction_id INT8 NOT NULL" + "pending INT4 NOT NULL" + "mint_url TEXT NOT NULL);", tmp_str); ret = GNUNET_POSTGRES_exec (conn, sql); (void) GNUNET_POSTGRES_exec (conn, @@ -165,6 +170,16 @@ MERCHANT_DB_initialize (PGconn *conn, int tmp) EXITIF (NULL == (res = PQprepare (conn, + "store_deposit_permission", + "INSERT INTO deposits" + "(dep_perm, transaction_id, pending, mint_url) " + "VALUES ($1, $2, $3, $4);", 4, NULL))); + EXITIF (PGRES_COMMAND_OK != (status = PQresultStatus(res))); + PQclear (res); + + + EXITIF (NULL == (res = PQprepare + (conn, "get_contract_product", "SELECT (" "product" @@ -219,6 +234,22 @@ MERCHANT_DB_initialize (PGconn *conn, int tmp) } +MERCHANT_DB_store_deposit_permission (PGconn *conn, + const char *deposit_permission, + uint64_t transaction_id, + unsigned int pending, + const char *mint_url) +{ + struct TALER_PQ_QueryParam params[] = { + TALER_PQ_query_param_fixed_size (deposit_permission, strlen (deposit_permission)), + TALER_PQ_query_param_uint64 (&transaction_id), + TALER_PQ_query_param_uint32 (&pending), + TALER_PQ_query_param_fixed_size (mint_url, strlen (mint_url)), + TALER_PQ_query_param_end + }; + +} + /** * Insert a contract record into the database and if successfull * return the serial number of the inserted row. diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -434,6 +434,9 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "merchant launched\n"); + EXITIF (GNUNET_SYSERR == (nmints = TALER_MERCHANT_parse_mints (config, diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c @@ -42,6 +42,7 @@ extern PGconn *db_conn; extern long long salt; extern unsigned int nmints; extern struct GNUNET_TIME_Relative edate_delay; +extern struct GNUNET_CRYPTO_EddsaPrivateKey privkey; /** * Fetch the deposit fee related to the given coin aggregate. @@ -133,6 +134,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, struct TALER_Amount coin_fee; struct GNUNET_TIME_Absolute edate; struct GNUNET_TIME_Absolute timestamp; + struct GNUNET_CRYPTO_EddsaPublicKey pubkey; struct TMH_PARSE_FieldSpecification spec[] = { TMH_PARSE_member_array ("coins", &coins), @@ -229,7 +231,34 @@ MH_handler_pay (struct TMH_RequestHandler *rh, if (-1 == TALER_amount_cmp (&max_fee, &acc_fee)) return MHD_HTTP_NOT_ACCEPTABLE; + + /* cutting off unneeded fields from deposit permission as + gotten from the wallet */ + if (-1 == json_object_del (root, "mint")) + return TMH_RESPONSE_reply_external_error (connection, + "malformed/non-existent 'mint' field"); + if (-1 == json_object_del (root, "coins")) + return TMH_RESPONSE_reply_external_error (connection, + "malformed/non-existent 'coins' field"); + + /* adding our public key to deposit permission */ + GNUNET_CRYPTO_eddsa_key_get_public (&privkey, &pubkey); + json_object_set_new (root, + "merchant_pub", + TALER_json_from_data (&pubkey, sizeof (pubkey))); + + json_array_foreach (coins, coins_cnt, coin_aggregate) + { + /* melt single coin with deposit permission "template" */ + if (-1 == json_object_update (root, coin_aggregate)) + return TMH_RESPONSE_reply_internal_error (connection, "deposit permission not generated"); + + /* store a stringification of it (paired with its transaction id) + into DB */ + char *deposit_permission_str = json_dumps (root, JSON_COMPACT); + } + /* 3 For each coin in DB a. Generate a deposit permission