diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-26 00:57:51 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-26 00:57:51 +0200 |
commit | 6ca84e4121cf4bd1b8c66d2ef4bd58eeb7003ea3 (patch) | |
tree | 413ec62a53e70f4a7ab197eb35be13091ccc1873 /src/backenddb | |
parent | ff42a36520baabd9d558ce51b2f92d54944e2d00 (diff) | |
download | merchant-6ca84e4121cf4bd1b8c66d2ef4bd58eeb7003ea3.tar.gz merchant-6ca84e4121cf4bd1b8c66d2ef4bd58eeb7003ea3.tar.bz2 merchant-6ca84e4121cf4bd1b8c66d2ef4bd58eeb7003ea3.zip |
first hack at POST /orders
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/merchant-0001.sql | 2 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 95 |
2 files changed, 49 insertions, 48 deletions
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql index a4f720ee..7c586432 100644 --- a/src/backenddb/merchant-0001.sql +++ b/src/backenddb/merchant-0001.sql @@ -188,8 +188,8 @@ CREATE TABLE IF NOT EXISTS merchant_orders ,merchant_serial BIGINT NOT NULL REFERENCES merchant_instances (merchant_serial) ON DELETE CASCADE ,order_id VARCHAR NOT NULL - ,contract_terms BYTEA NOT NULL ,pay_deadline INT8 NOT NULL + ,contract_terms BYTEA NOT NULL ,UNIQUE (merchant_serial, order_id) ); COMMENT ON TABLE merchant_orders diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 68e3f661..4ad8463c 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1114,6 +1114,43 @@ postgres_lookup_order (void *cls, } +/** + * Insert order into the DB. + * + * @param cls closure + * @param instance_id identifies the instance responsible for the order + * @param order_id alphanumeric string that uniquely identifies the proposal + * @param pay_deadline how long does the customer have to pay for the order + * @param contract_terms proposal data to store + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_insert_order (void *cls, + const char *instance_id, + const char *order_id, + struct GNUNET_TIME_Absolute pay_deadline, + const json_t *contract_terms) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_absolute_time (&pay_deadline), + TALER_PQ_query_param_json (contract_terms), + GNUNET_PQ_query_param_end + }; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "inserting order: order_id: %s, instance_id: %s.\n", + order_id, + instance_id); + check_connection (pg); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_order", + params); +} + + /* ********************* OLD API ************************** */ /** @@ -1282,43 +1319,6 @@ postgres_insert_contract_terms (void *cls, /** - * Insert order into the DB. - * - * @param cls closure - * @param order_id identificator of the proposal being stored - * @param merchant_pub merchant's public key - * @param timestamp timestamp of this proposal data - * @param contract_terms proposal data to store - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_order (void *cls, - const char *order_id, - const struct TALER_MerchantPublicKeyP *merchant_pub, - struct GNUNET_TIME_Absolute timestamp, - const json_t *contract_terms) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_absolute_time (×tamp), - TALER_PQ_query_param_json (contract_terms), - GNUNET_PQ_query_param_end - }; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "inserting order: order_id: %s, merchant_pub: %s.\n", - order_id, - TALER_B2S (merchant_pub)); - check_connection (pg); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_order", - params); -} - - -/** * Mark contract terms as paid. Needed by /history as only paid * contracts must be shown. * @@ -4193,7 +4193,17 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " WHERE merchant_id=$1)" " AND merchant_orders.order_id=$2", 2), - + GNUNET_PQ_make_prepare ("insert_order", + "INSERT INTO merchant_orders" + "(merchant_serial" + ",order_id" + ",pay_deadline" + ",contract_terms)" + " SELECT merchant_serial," + " $2, $3, $4" + " FROM merchant_instances" + " WHERE merchant_id=$1", + 4), /* OLD API: */ #if 0 GNUNET_PQ_make_prepare ("insert_deposit", @@ -4251,15 +4261,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " VALUES " "($1, $2, $3, $4, $5)", 5), - GNUNET_PQ_make_prepare ("insert_order", - "INSERT INTO merchant_orders" - "(order_id" - ",merchant_pub" - ",timestamp" - ",contract_terms)" - " VALUES " - "($1, $2, $3, $4)", - 4), GNUNET_PQ_make_prepare ("insert_session_info", "INSERT INTO merchant_session_info" "(session_id" |