summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/Makefile.am8
-rw-r--r--src/include/merchant.h204
-rw-r--r--src/include/taler_merchantdb_lib.h200
3 files changed, 207 insertions, 205 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 3db59c88..77977b5f 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -1,2 +1,8 @@
+# This Makefile.am is in the public domain
EXTRA_DIST = \
- platform.h
+ platform.h
+
+talerincludedir = $(includedir)/taler
+
+talerinclude_HEADERS = \
+ taler_merchantdb_lib.h
diff --git a/src/include/merchant.h b/src/include/merchant.h
deleted file mode 100644
index eb430360..00000000
--- a/src/include/merchant.h
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- This file is part of TALER
- (C) 2014 Christian Grothoff (and other contributing authors)
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file include/merchant.h
- * @brief Common utility functions for merchant
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
- */
-
-#ifndef MERCHANT_H
-#define MERCHANT_H
-
-#include <gnunet/gnunet_util_lib.h>
-#include <taler/taler_mint_service.h>
-#include "merchant.h"
-
-/**
- * Macro to round microseconds to seconds in GNUNET_TIME_* structs.
- */
-#define ROUND_TO_SECS(name,us_field) name.us_field -= name.us_field % (1000 * 1000)
-
-/**
- * Shorthand for exit jumps.
- */
-#define EXITIF(cond) \
- do { \
- if (cond) { GNUNET_break (0); goto EXITIF_exit; } \
- } while (0)
-
-/**
- * Outcome of a /deposit request for a coin. Typically forming an array enclosed
- * into the unique PayContext
- */
-struct MERCHANT_DepositConfirmation
-{
- /**
- * Reference to the per-deposit-handler Context. Needed by the
- * cleanup function to get it freed
- */
- struct DepositCallbackContext *dcc;
-
- /**
- * True if this coin's outcome has been read from
- * its cb
- */
- unsigned int ackd;
-
- /**
- * The mint's response to this /deposit
- */
- unsigned int exit_status;
-
- /**
- * The mint's response body (JSON). Mainly useful in case
- * some callback needs to send back to the to the wallet the
- * outcome of an erroneous coin
- */
- json_t *proof;
-
-};
-
-
-/**
- * Mint
- */
-struct MERCHANT_Mint
-{
- /**
- * Hostname
- */
- char *hostname;
-
- /**
- * Flag which indicates whether some HTTP transfer between
- * this merchant and the mint is still ongoing
- */
- int pending;
-
- /**
- * A connection to this mint
- */
- struct TALER_MINT_Handle *conn;
-
- /**
- * This mint's context (useful to the event loop)
- */
- struct TALER_MINT_Context *ctx;
-
-};
-
-struct MERCHANT_Auditor
-{
- /**
- * Auditor's legal name
- */
- char *name;
-
-};
-
-/**
- * The contract sent by the merchant to the wallet
- */
-struct MERCHANT_Contract
-{
- /**
- * Purpose header for the signature over contract
- */
- struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
-
- /**
- * Hash of the JSON contract in UTF-8 including 0-termination,
- * using JSON_COMPACT | JSON_SORT_KEYS
- */
- struct GNUNET_HashCode h_contract;
-
-};
-
-
-
-/**
- * Parses mints from the configuration.
- *
- * @param cfg the configuration
- * @param mints the array of mints upon successful parsing. Will be NULL upon
- * error.
- * @return the number of mints in the above array; GNUNET_SYSERR upon error in
- * parsing.
- */
-int
-TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct MERCHANT_Mint **mints);
-
-/**
- * Parses auditors from the configuration.
- *
- * @param cfg the configuration
- * @param mints the array of auditors upon successful parsing. Will be NULL upon
- * error.
- * @return the number of auditors in the above array; GNUNET_SYSERR upon error in
- * parsing.
- */
-int
-TALER_MERCHANT_parse_auditors (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct MERCHANT_Auditor **auditors);
-
-GNUNET_NETWORK_STRUCT_BEGIN
-struct MERCHANT_WIREFORMAT_Sepa
-{
- /**
- * The international bank account number
- */
- char *iban;
-
- /**
- * Name of the bank account holder
- */
- char *name;
-
- /**
- *The bank identification code
- */
- char *bic;
-
- /**
- * The latest payout date when the payment corresponding to this account has
- * to take place. A value of 0 indicates a transfer as soon as possible.
- */
- struct GNUNET_TIME_AbsoluteNBO payout;
-};
-GNUNET_NETWORK_STRUCT_END
-
-/**
- * Parse the SEPA information from the configuration. If any of the required
- * fileds is missing return NULL.
- *
- * @param cfg the configuration
- * @return Sepa details as a structure; NULL upon error
- */
-struct MERCHANT_WIREFORMAT_Sepa *
-TALER_MERCHANT_parse_wireformat_sepa (const struct GNUNET_CONFIGURATION_Handle *cfg);
-
-
-/**
- * Destroy and free resouces occupied by the wireformat structure
- *
- * @param wf the wireformat structure
- */
-void
-TALER_MERCHANT_destroy_wireformat_sepa (struct MERCHANT_WIREFORMAT_Sepa *wf);
-
-#endif /* MERCHANT_H */
diff --git a/src/include/taler_merchantdb_lib.h b/src/include/taler_merchantdb_lib.h
new file mode 100644
index 00000000..f650a8aa
--- /dev/null
+++ b/src/include/taler_merchantdb_lib.h
@@ -0,0 +1,200 @@
+/*
+ This file is part of TALER
+ (C) 2014, 2015 Christian Grothoff (and other contributing authors)
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file include/taler_merchantdb_lib.h
+ * @brief database helper functions used by the merchant backend
+ * @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ */
+
+#ifndef MERCHANT_DB_H
+#define MERCHANT_DB_H
+
+#include <gnunet/gnunet_postgres_lib.h>
+#include <taler/taler_util.h>
+
+
+
+/* Set of values that represent a contract. To be expanded on an
+ as-needed basis */
+struct MERCHANT_contract_handle
+{
+ /* The nounce used when hashing the wire details
+ for this contract */
+ uint64_t nounce;
+
+ /* The maximum time when the merchant expects the money tranfer
+ to his bank account to happen */
+ struct GNUNET_TIME_Absolute edate;
+
+ /* The time when this contract was generated */
+ struct GNUNET_TIME_Absolute timestamp;
+
+ /* The maximum time until which the merchant could issue a
+ refund to the customer */
+ struct GNUNET_TIME_Absolute refund_deadline;
+
+ /* The identification number for this contract */
+ uint64_t contract_id;
+
+};
+
+/**
+ * Connect to postgresql database
+ *
+ * @param cfg the configuration handle
+ * @return connection to the postgresql database; NULL upon error
+ */
+PGconn *
+MERCHANT_DB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
+ * Disconnect from the database
+ *
+ * @param conn database handle to close
+ */
+void
+MERCHANT_DB_disconnect (PGconn *conn);
+
+
+/**
+ * Initialize merchant tables
+ *
+ * @param conn the connection handle to postgres db.
+ * @param tmp GNUNET_YES if the tables are to be made temporary i.e. their
+ * contents are dropped when the @a conn is closed
+ * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
+ */
+int
+MERCHANT_DB_initialize (PGconn *conn, int tmp);
+
+
+/**
+ * Inserts a contract record into the database and if successfull returns the
+ * serial number of the inserted row.
+ *
+ * @param conn the database connection
+ * @param timestamp the timestamp of this contract
+ * @param expiry the time when the contract will expire
+ * @param edate when the merchant wants to receive the wire transfer corresponding
+ * 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 amount the taler amount corresponding to the contract
+ * @param hash of the stringified JSON corresponding to this contract
+ * @param c_id contract's id
+ * @param desc descripition of the contract
+ * @param nounce a random 64-bit nounce
+ * @param product description to identify a product
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR upon error
+ */
+uint32_t
+MERCHANT_DB_contract_create (PGconn *conn,
+ const struct GNUNET_TIME_Absolute timestamp,
+ const struct GNUNET_TIME_Absolute expiry,
+ struct GNUNET_TIME_Absolute edate,
+ struct GNUNET_TIME_Absolute refund,
+ const struct TALER_Amount *amount,
+ const struct GNUNET_HashCode *h_contract,
+ uint64_t c_id,
+ const char *desc,
+ uint64_t nounce,
+ uint64_t product);
+
+
+long long
+MERCHANT_DB_get_contract_product (PGconn *conn,
+ uint64_t contract_id);
+
+
+/**
+ * Update the pending column of a deposit permission
+ *
+ * @param conn handle to DB
+ * @param transaction_id identification number of the deposit to
+ * update
+ * @param pending true if still pending, false otherwise (i.e. the
+ * mint did respond something)
+ * @return #GNUNET_OK if successful, #GNUNET_SYSERR upon errors
+ */
+uint32_t
+MERCHANT_DB_update_deposit_permission (PGconn *conn,
+ uint64_t transaction_id,
+ unsigned int pending);
+
+unsigned int
+MERCHANT_DB_checkout_create (PGconn *conn,
+ struct GNUNET_CRYPTO_rsa_PublicKey *coin_pub,
+ uint64_t transaction_id,
+ struct TALER_Amount *amount,
+ struct GNUNET_CRYPTO_rsa_Signature *coin_sig);
+
+
+long long
+MERCHANT_DB_get_checkout_product (PGconn *conn,
+ struct GNUNET_CRYPTO_rsa_PublicKey *coin_pub);
+
+/**
+ * The query gets a contract's nounce and edate used to reproduce
+ * a 'wire' JSON object. This function is also useful to check whether
+ * a claimed contract existed or not.
+ *
+ * @param conn handle to the DB
+ * @param h_contract the parameter for the row to match against
+ * @param nounce where to store the found nounce
+ * @param edate where to store the found expiration date
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR upon errors
+ */
+uint32_t
+MERCHANT_DB_get_contract_values (PGconn *conn,
+ const struct GNUNET_HashCode *h_contract,
+ uint64_t *nounce,
+ struct GNUNET_TIME_Absolute *edate);
+
+#endif /* MERCHANT_DB_H */
+
+/**
+ * Get a set of values representing a contract. This function is meant
+ * to obsolete the '_get_contract_values' version.
+ *
+ * @param h_contract the hashcode of this contract
+ * @param contract_handle where to store the results
+ * @raturn #GNUNET_OK in case of success, #GNUNET_SYSERR
+ * upon errors
+ */
+uint32_t
+MERCHANT_DB_get_contract_handle (PGconn *conn,
+ const struct GNUNET_HashCode *h_contract,
+ struct MERCHANT_contract_handle *contract_handle);
+
+/**
+ * Store a deposit permission in DB. To be mainly used if /deposit should
+ * be retried; also, the merchant can benefit from this information in case
+ * he needs to later investigate about some transaction_id.
+ * @param conn DB handle
+ * @param transaction_id identification number of this payment (which is the
+ * same id of the related contract)
+ * @param pending if true, this payment got to a persistent state
+ * @param which mint is to get this deposit permission
+ * @return #GNUNET_OK if successful, #GNUNET_SYSERR upon errors
+ */
+uint32_t
+MERCHANT_DB_store_deposit_permission (PGconn *conn,
+ const char *deposit_permission,
+ uint64_t transaction_id,
+ unsigned int pending,
+ const char *mint_url);
+/* end of merchant-db.h */