summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_pay.c3
-rw-r--r--src/backend/taler-merchant-httpd_track-deposit.c3
-rw-r--r--src/backend/taler-merchant-httpd_track-transaction.c5
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c18
-rw-r--r--src/backenddb/test_merchantdb.c220
-rw-r--r--src/include/taler_merchantdb_plugin.h4
6 files changed, 221 insertions, 32 deletions
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c
index f32d3dbb..a46f3223 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -323,6 +323,7 @@ abort_deposit (struct PayContext *pc)
* @param http_status HTTP response code, #MHD_HTTP_OK
* (200) for successful deposit; 0 if the exchange's reply is bogus (fails
* to follow the protocol)
+ * @param sign_key which key did the exchange use to sign the @a proof
* @param proof the received JSON reply,
* should be kept as proof (and, in case of errors, be forwarded to
* the customer)
@@ -330,6 +331,7 @@ abort_deposit (struct PayContext *pc)
static void
deposit_cb (void *cls,
unsigned int http_status,
+ const struct TALER_ExchangePublicKeyP *sign_key,
const json_t *proof)
{
struct DepositConfirmation *dc = cls;
@@ -379,6 +381,7 @@ deposit_cb (void *cls,
&dc->coin_pub,
&dc->amount_with_fee,
&dc->deposit_fee,
+ sign_key,
proof))
{
GNUNET_break (0);
diff --git a/src/backend/taler-merchant-httpd_track-deposit.c b/src/backend/taler-merchant-httpd_track-deposit.c
index c1d9b352..71bc18c5 100644
--- a/src/backend/taler-merchant-httpd_track-deposit.c
+++ b/src/backend/taler-merchant-httpd_track-deposit.c
@@ -234,6 +234,7 @@ check_deposit (void *cls,
*
* @param cls closure
* @param http_status HTTP status code we got, 0 on exchange protocol violation
+ * @param exchange_pub public key of the exchange used to sign @a json
* @param json original json reply (may include signatures, those have then been
* validated already)
* @param wtid extracted wire transfer identifier, or NULL if the exchange could
@@ -246,6 +247,7 @@ check_deposit (void *cls,
static void
wire_deposit_cb (void *cls,
unsigned int http_status,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
const json_t *json,
const struct GNUNET_HashCode *h_wire,
const struct TALER_Amount *total_amount,
@@ -272,6 +274,7 @@ wire_deposit_cb (void *cls,
db->store_transfer_to_proof (db->cls,
rctx->uri,
&rctx->wtid,
+ exchange_pub,
json))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c
index bfae1af9..548476a3 100644
--- a/src/backend/taler-merchant-httpd_track-transaction.c
+++ b/src/backend/taler-merchant-httpd_track-transaction.c
@@ -297,6 +297,7 @@ trace_coins (struct TrackTransactionContext *tctx);
*
* @param cls closure
* @param http_status HTTP status code we got, 0 on exchange protocol violation
+ * @param exchange_pub public key of the exchange used for signing
* @param json original json reply (may include signatures, those have then been
* validated already)
* @param wtid extracted wire transfer identifier, or NULL if the exchange could
@@ -309,6 +310,7 @@ trace_coins (struct TrackTransactionContext *tctx);
static void
wire_deposits_cb (void *cls,
unsigned int http_status,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
const json_t *json,
const struct GNUNET_HashCode *h_wire,
const struct TALER_Amount *total_amount,
@@ -334,6 +336,7 @@ wire_deposits_cb (void *cls,
db->store_transfer_to_proof (db->cls,
tctx->exchange_uri,
&tctx->current_wtid,
+ exchange_pub,
json))
{
/* Not good, but not fatal either, log error and continue */
@@ -378,6 +381,7 @@ wire_deposits_cb (void *cls,
*
* @param cls closure with a `struct TrackCoinContext`
* @param http_status HTTP status code we got, 0 on exchange protocol violation
+ * @param exchange_pub public key of the exchange used for signing @a json
* @param json original json reply (may include signatures, those have then been
* validated already)
* @param wtid wire transfer identifier used by the exchange, NULL if exchange did not
@@ -388,6 +392,7 @@ wire_deposits_cb (void *cls,
static void
wtid_cb (void *cls,
unsigned int http_status,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
const json_t *json,
const struct TALER_WireTransferIdentifierRawP *wtid,
struct GNUNET_TIME_Absolute execution_time,
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 052851ab..836be57c 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -175,6 +175,7 @@ postgres_initialize (void *cls)
",deposit_fee_val INT8 NOT NULL"
",deposit_fee_frac INT4 NOT NULL"
",deposit_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") NOT NULL"
+ ",signkey_pub BYTEA NOT NULL CHECK (LENGTH(signkey_pub)=32)"
",exchange_proof BYTEA NOT NULL"
",PRIMARY KEY (transaction_id, coin_pub)"
");");
@@ -182,6 +183,7 @@ postgres_initialize (void *cls)
"CREATE TABLE IF NOT EXISTS merchant_proofs ("
" exchange_uri VARCHAR NOT NULL"
",wtid BYTEA CHECK (LENGTH(wtid)=32)"
+ ",signkey_pub BYTEA NOT NULL CHECK (LENGTH(signkey_pub)=32)"
",proof BYTEA NOT NULL"
",PRIMARY KEY (wtid, exchange_uri)"
");");
@@ -229,9 +231,10 @@ postgres_initialize (void *cls)
",deposit_fee_val"
",deposit_fee_frac"
",deposit_fee_curr"
+ ",signkey_pub"
",exchange_proof) VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9)",
- 9);
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
+ 10);
PG_PREPARE (pg,
"insert_transfer",
"INSERT INTO merchant_transfers"
@@ -245,9 +248,10 @@ postgres_initialize (void *cls)
"INSERT INTO merchant_proofs"
"(exchange_uri"
",wtid"
+ ",signkey_pub"
",proof) VALUES "
- "($1, $2, $3)",
- 3);
+ "($1, $2, $3, $4)",
+ 4);
/* Setup prepared "SELECT" statements */
PG_PREPARE (pg,
@@ -382,6 +386,7 @@ postgres_store_transaction (void *cls,
* @param coin_pub public key of the coin
* @param amount_with_fee amount the exchange will deposit for this coin
* @param deposit_fee fee the exchange will charge for this coin
+ * @param signkey_pub public key used by the exchange for @a exchange_proof
* @param exchange_proof proof from exchange that coin was accepted
* @return #GNUNET_OK on success, #GNUNET_SYSERR upon error
*/
@@ -391,6 +396,7 @@ postgres_store_deposit (void *cls,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_Amount *amount_with_fee,
const struct TALER_Amount *deposit_fee,
+ const struct TALER_ExchangePublicKeyP *signkey_pub,
const json_t *exchange_proof)
{
struct PostgresClosure *pg = cls;
@@ -402,6 +408,7 @@ postgres_store_deposit (void *cls,
GNUNET_PQ_query_param_auto_from_type (coin_pub),
TALER_PQ_query_param_amount (amount_with_fee),
TALER_PQ_query_param_amount (deposit_fee),
+ GNUNET_PQ_query_param_auto_from_type (signkey_pub),
TALER_PQ_query_param_json (exchange_proof),
GNUNET_PQ_query_param_end
};
@@ -474,6 +481,7 @@ postgres_store_coin_to_transfer (void *cls,
* @param cls closure
* @param exchange_uri URI of the exchange
* @param wtid identifier of the wire transfer
+ * @param signkey_pub public key used by the exchange for @a exchange_proof
* @param exchange_proof proof from exchange about what the deposit was for
* @return #GNUNET_OK on success, #GNUNET_SYSERR upon error
*/
@@ -481,6 +489,7 @@ static int
postgres_store_transfer_to_proof (void *cls,
const char *exchange_uri,
const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_ExchangePublicKeyP *signkey_pub,
const json_t *exchange_proof)
{
struct PostgresClosure *pg = cls;
@@ -490,6 +499,7 @@ postgres_store_transfer_to_proof (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (exchange_uri),
GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_auto_from_type (signkey_pub),
TALER_PQ_query_param_json (exchange_proof),
GNUNET_PQ_query_param_end
};
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 2d0ca0ca..e5b78617 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -36,9 +36,122 @@
#define CURRENCY "EUR"
+#define EXCHANGE_URI "http://localhost:8888/"
+
static int result;
+
static struct TALER_MERCHANTDB_Plugin *plugin;
+static struct GNUNET_HashCode h_contract;
+
+static struct GNUNET_HashCode h_wire;
+
+static uint64_t transaction_id;
+
+static struct GNUNET_TIME_Absolute timestamp;
+
+static struct GNUNET_TIME_Absolute refund;
+
+static struct TALER_Amount amount_with_fee;
+
+static struct TALER_Amount deposit_fee;
+
+static struct TALER_CoinSpendPublicKeyP coin_pub;
+
+static struct TALER_ExchangePublicKeyP signkey_pub;
+
+static struct TALER_WireTransferIdentifierRawP wtid;
+
+static json_t *deposit_proof = NULL;
+
+static json_t *transfer_proof = NULL;
+
+
+/**
+ * Function called with information about a transaction.
+ *
+ * @param cls closure
+ * @param transaction_id of the contract
+ * @param exchange_uri URI of the exchange
+ * @param h_contract hash of the contract
+ * @param h_wire hash of our wire details
+ * @param timestamp time of the confirmation
+ * @param refund refund deadline
+ * @param total_amount total amount we receive for the contract after fees
+ */
+static void
+transaction_cb (void *cls,
+ uint64_t transaction_id,
+ const char *exchange_uri,
+ const struct GNUNET_HashCode *h_contract,
+ const struct GNUNET_HashCode *h_wire,
+ struct GNUNET_TIME_Absolute timestamp,
+ struct GNUNET_TIME_Absolute refund,
+ const struct TALER_Amount *total_amount)
+{
+}
+
+
+/**
+ * Function called with information about a coin that was deposited.
+ *
+ * @param cls closure
+ * @param transaction_id of the contract
+ * @param coin_pub public key of the coin
+ * @param amount_with_fee amount the exchange will deposit for this coin
+ * @param deposit_fee fee the exchange will charge for this coin
+ * @param exchange_proof proof from exchange that coin was accepted
+ */
+static void
+deposit_cb (void *cls,
+ uint64_t transaction_id,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *deposit_fee,
+ const json_t *exchange_proof)
+{
+}
+
+
+/**
+ * Information about the wire transfer corresponding to
+ * a deposit operation. Note that it is in theory possible
+ * that we have a @a transaction_id and @a coin_pub in the
+ * result that do not match a deposit that we know about,
+ * for example because someone else deposited funds into
+ * our account.
+ *
+ * @param cls closure
+ * @param transaction_id ID of the contract
+ * @param coin_pub public key of the coin
+ * @param wtid identifier of the wire transfer in which the exchange
+ * send us the money for the coin deposit
+ * @param exchange_proof proof from exchange about what the deposit was for
+ * NULL if we have not asked for this signature
+ */
+static void
+transfer_cb (void *cls,
+ uint64_t transaction_id,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const json_t *exchange_proof)
+{
+}
+
+
+/**
+ * Function called with information about a wire transfer identifier.
+ *
+ * @param cls closure
+ * @param proof proof from exchange about what the wire transfer was for
+ */
+static void
+proof_cb (void *cls,
+ const json_t *proof)
+{
+}
+
+
/**
* Main function that will be run by the scheduler.
*
@@ -49,14 +162,6 @@ run (void *cls)
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
/* Data for 'store_payment()' */
- struct GNUNET_HashCode h_contract;
- struct GNUNET_HashCode h_wire;
- uint64_t transaction_id;
- struct GNUNET_TIME_Absolute timestamp;
- struct GNUNET_TIME_Absolute refund;
- struct TALER_Amount amount_without_fee;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- json_t *exchange_proof = NULL;
FAILIF (NULL == (plugin = TALER_MERCHANTDB_plugin_load (cfg)));
(void) plugin->drop_tables (plugin->cls);
@@ -66,41 +171,98 @@ run (void *cls)
RND_BLK (&h_contract);
RND_BLK (&h_wire);
RND_BLK (&transaction_id);
+ RND_BLK (&signkey_pub);
+ RND_BLK (&wtid);
timestamp = GNUNET_TIME_absolute_get();
refund = GNUNET_TIME_absolute_get();
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":1.000010",
- &amount_without_fee));
+ &amount_with_fee));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &deposit_fee));
RND_BLK (&coin_pub);
- exchange_proof = json_object ();
- GNUNET_assert (0 == json_object_set (exchange_proof, "test", json_string ("backenddb test")));
-#if 0
- FAILIF (GNUNET_OK != plugin->store_payment (plugin->cls,
- &h_contract,
- &h_wire,
- transaction_id,
- timestamp,
- refund,
- &amount_without_fee,
- &coin_pub,
- exchange_proof));
- FAILIF (GNUNET_OK != plugin->check_payment (plugin->cls, transaction_id));
-#endif
+ deposit_proof = json_object ();
+ GNUNET_assert (0 ==
+ json_object_set (deposit_proof,
+ "test",
+ json_string ("backenddb test A")));
+ transfer_proof = json_object ();
+ GNUNET_assert (0 ==
+ json_object_set (transfer_proof,
+ "test",
+ json_string ("backenddb test B")));
+ FAILIF (GNUNET_OK !=
+ plugin->store_transaction (plugin->cls,
+ transaction_id,
+ EXCHANGE_URI,
+ &h_contract,
+ &h_wire,
+ timestamp,
+ refund,
+ &amount_with_fee));
+ FAILIF (GNUNET_OK !=
+ plugin->store_deposit (plugin->cls,
+ transaction_id,
+ &coin_pub,
+ &amount_with_fee,
+ &deposit_fee,
+ &signkey_pub,
+ deposit_proof));
+ FAILIF (GNUNET_OK !=
+ plugin->store_coin_to_transfer (plugin->cls,
+ transaction_id,
+ &coin_pub,
+ &wtid));
+ FAILIF (GNUNET_OK !=
+ plugin->store_transfer_to_proof (plugin->cls,
+ EXCHANGE_URI,
+ &wtid,
+ &signkey_pub,
+ transfer_proof));
+ FAILIF (GNUNET_OK !=
+ plugin->find_transaction_by_id (plugin->cls,
+ transaction_id,
+ &transaction_cb,
+ NULL));
+ FAILIF (GNUNET_OK !=
+ plugin->find_payments_by_id (plugin->cls,
+ transaction_id,
+ &deposit_cb,
+ NULL));
+ FAILIF (GNUNET_OK !=
+ plugin->find_transfers_by_id (plugin->cls,
+ transaction_id,
+ &transfer_cb,
+ NULL));
+ FAILIF (GNUNET_OK !=
+ plugin->find_deposits_by_wtid (plugin->cls,
+ &wtid,
+ &deposit_cb,
+ NULL));
+ FAILIF (GNUNET_OK !=
+ plugin->find_proof_by_wtid (plugin->cls,
+ EXCHANGE_URI,
+ &wtid,
+ &proof_cb,
+ NULL));
result = 0;
drop:
GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls));
TALER_MERCHANTDB_plugin_unload (plugin);
plugin = NULL;
- if (NULL != exchange_proof)
- json_decref(exchange_proof);
+ if (NULL != deposit_proof)
+ json_decref (deposit_proof);
+ if (NULL != transfer_proof)
+ json_decref (transfer_proof);
}
+
int
main (int argc,
char *const argv[])
{
-
const char *plugin_name;
char *config_filename;
char *testname;
@@ -115,9 +277,11 @@ main (int argc,
GNUNET_log_setup (argv[0], "WARNING", NULL);
plugin_name++;
(void) GNUNET_asprintf (&testname,
- "test-merchantdb-%s", plugin_name);
+ "test-merchantdb-%s",
+ plugin_name);
(void) GNUNET_asprintf (&config_filename,
- "%s.conf", testname);
+ "%s.conf",
+ testname);
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
GNUNET_CONFIGURATION_parse (cfg,
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index 8ce021a1..63e60e78 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -176,6 +176,7 @@ struct TALER_MERCHANTDB_Plugin
* @param coin_pub public key of the coin
* @param amount_with_fee amount the exchange will deposit for this coin
* @param deposit_fee fee the exchange will charge for this coin
+ * @param signkey_pub public key used by the exchange for @a exchange_proof
* @param exchange_proof proof from exchange that coin was accepted
* @return #GNUNET_OK on success, #GNUNET_SYSERR upon error
*/
@@ -185,6 +186,7 @@ struct TALER_MERCHANTDB_Plugin
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_Amount *amount_with_fee,
const struct TALER_Amount *deposit_fee,
+ const struct TALER_ExchangePublicKeyP *signkey_pub,
const json_t *exchange_proof);
@@ -212,6 +214,7 @@ struct TALER_MERCHANTDB_Plugin
* @param cls closure
* @param exchange_uri from which exchange did we get the @a exchange_proof
* @param wtid identifier of the wire transfer
+ * @param signkey_pub public key used by the exchange for @a exchange_proof
* @param exchange_proof proof from exchange about what the deposit was for
* @return #GNUNET_OK on success, #GNUNET_SYSERR upon error
*/
@@ -219,6 +222,7 @@ struct TALER_MERCHANTDB_Plugin
(*store_transfer_to_proof) (void *cls,
const char *exchange_uri,
const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_ExchangePublicKeyP *signkey_pub,
const json_t *exchange_proof);