summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-02 14:24:45 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-02 14:29:44 +0200
commitcb55c1a3af9f56a6da38e5589e72df0b70d355b1 (patch)
tree5f9a3af7d9073249f77ce56c690844a6cb27c3e7 /src/exchangedb
parent7a20062bafed42f937c5388aed09042aad7014c0 (diff)
downloadexchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.tar.gz
exchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.tar.bz2
exchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.zip
Changing configuration structure to enable multiple accounts.
This change enables using multiple wire plugins at the same time. Also, we now distinguish between the wire plugin (i.e. EBICS or taler_bank) and the wire method (i.e. SEPA or x-taler-bank) that the wire plugin is implementing. The "taler-bank" wire method was renamed from "test" to "x-taler-bank". This also changes the format of the /wire response of the exchange, as we now need to return multiple accounts. Note that wire fees are specified per wire method, not per wire account. taler-exchange-keyup now automatically signs all of the /wire responses in the location specified by the configuration. Account identification in wire plugins was changed to use payto://-URLs instead of method-specific JSON fields. Signing and validation of /wire responses was moved from each wire plugin to a generic validation method in libtalerutil (crypto) or libtalerjson (for JSON-formatted inputs). Convenience methods were added to generate JSON for wire accounts (salting, signing). Various section and option names were adjusted to streamline the configuration and make it more consistent overall. Documentation was updated as well.
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/Makefile.am12
-rw-r--r--src/exchangedb/exchangedb-postgres.conf2
-rw-r--r--src/exchangedb/exchangedb_accounts.c141
-rw-r--r--src/exchangedb/perf_taler_exchangedb.c2
-rw-r--r--src/exchangedb/perf_taler_exchangedb_init.c22
-rw-r--r--src/exchangedb/perf_taler_exchangedb_interpreter.c14
-rw-r--r--src/exchangedb/plugin_exchangedb_common.c8
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c89
-rw-r--r--src/exchangedb/test-exchange-db-postgres.conf2
-rw-r--r--src/exchangedb/test_exchangedb.c98
10 files changed, 268 insertions, 122 deletions
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index 66299d78..03322f8c 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -42,6 +42,7 @@ lib_LTLIBRARIES = \
libtalerexchangedb.la
libtalerexchangedb_la_SOURCES = \
+ exchangedb_accounts.c \
exchangedb_auditorkeys.c \
exchangedb_denomkeys.c \
exchangedb_fees.c \
@@ -111,7 +112,8 @@ test_exchangedb_postgres_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_srcdir)/src/util/libtalerutil.la \
$(top_srcdir)/src/pq/libtalerpq.la \
- -lgnunetutil -ljansson
+ -ljansson \
+ -lgnunetutil
test_perf_taler_exchangedb_SOURCES = \
test_perf_taler_exchangedb.c \
@@ -121,8 +123,8 @@ test_perf_taler_exchangedb_LDADD = \
libtalerexchangedb.la \
$(top_srcdir)/src/util/libtalerutil.la \
$(top_srcdir)/src/pq/libtalerpq.la \
- -ljansson \
- -lgnunetutil
+ -lgnunetutil \
+ -ljansson
perf_exchangedb_SOURCES = \
perf_taler_exchangedb.c \
@@ -132,8 +134,8 @@ perf_exchangedb_LDADD = \
libtalerexchangedb.la \
$(top_srcdir)/src/util/libtalerutil.la \
$(top_srcdir)/src/pq/libtalerpq.la \
- -ljansson \
- -lgnunetutil
+ -lgnunetutil \
+ -ljansson
EXTRA_test_exchangedb_postgres_DEPENDENCIES = \
diff --git a/src/exchangedb/exchangedb-postgres.conf b/src/exchangedb/exchangedb-postgres.conf
index 3de7474f..5ebd656c 100644
--- a/src/exchangedb/exchangedb-postgres.conf
+++ b/src/exchangedb/exchangedb-postgres.conf
@@ -1,2 +1,2 @@
[exchangedb-postgres]
-DB_CONN_STR = "postgres:///taler"
+CONFIG = "postgres:///taler"
diff --git a/src/exchangedb/exchangedb_accounts.c b/src/exchangedb/exchangedb_accounts.c
new file mode 100644
index 00000000..275e9267
--- /dev/null
+++ b/src/exchangedb/exchangedb_accounts.c
@@ -0,0 +1,141 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2018 Taler Systems SA
+
+ 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, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/exchangedb_accounts.c
+ * @brief Logic to parse account information from the configuration
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_exchangedb_lib.h"
+
+
+/**
+ * Closure of #check_for_account.
+ */
+struct FindAccountContext
+{
+ /**
+ * Configuration we are usign.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Callback to invoke.
+ */
+ TALER_EXCHANGEDB_AccountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+};
+
+
+/**
+ * Check if @a section begins with "exchange-wire-", and if
+ * so if the "ENABLE" option is set to "YES". If both are
+ * true, call the callback from the context with the
+ * rest of the section name.
+ *
+ * @param cls our `struct FindEnabledWireContext`
+ * @param section name of a section in the configuration
+ */
+static void
+check_for_account (void *cls,
+ const char *section)
+{
+ struct FindAccountContext *ctx = cls;
+ char *plugin_name;
+ char *payto_url;
+ char *wire_response_filename;
+ struct TALER_EXCHANGEDB_AccountInfo ai;
+
+ if (0 != strncasecmp (section,
+ "account-",
+ strlen ("account-")))
+ return;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ctx->cfg,
+ section,
+ "URL",
+ &payto_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ section,
+ "URL");
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ctx->cfg,
+ section,
+ "PLUGIN",
+ &plugin_name))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ section,
+ "PLUGIN");
+ GNUNET_free (payto_url);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (ctx->cfg,
+ section,
+ "WIRE_RESPONSE",
+ &wire_response_filename))
+ wire_response_filename = NULL;
+ ai.section_name = section;
+ ai.plugin_name = plugin_name;
+ ai.payto_url = payto_url;
+ ai.wire_response_filename = wire_response_filename;
+ ai.debit_enabled = (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (ctx->cfg,
+ section,
+ "ENABLE_DEBIT"));
+ ai.credit_enabled = (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (ctx->cfg,
+ section,
+ "ENABLE_CREDIT"));
+ ctx->cb (ctx->cb_cls,
+ &ai);
+ GNUNET_free (payto_url);
+ GNUNET_free (plugin_name);
+ GNUNET_free_non_null (wire_response_filename);
+}
+
+
+/**
+ * Parse the configuration to find account information.
+ *
+ * @param cfg configuration to use
+ * @param cb callback to invoke
+ * @param cb_cls closure for @a cb
+ */
+void
+TALER_EXCHANGEDB_find_accounts (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ TALER_EXCHANGEDB_AccountCallback cb,
+ void *cb_cls)
+{
+ struct FindAccountContext ctx;
+
+ ctx.cfg = cfg;
+ ctx.cb = cb;
+ ctx.cb_cls = cb_cls;
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &check_for_account,
+ &ctx);
+}
+
+/* end of exchangedb_accounts.c */
diff --git a/src/exchangedb/perf_taler_exchangedb.c b/src/exchangedb/perf_taler_exchangedb.c
index e2591c88..5cde719c 100644
--- a/src/exchangedb/perf_taler_exchangedb.c
+++ b/src/exchangedb/perf_taler_exchangedb.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016 Inria and GNUnet e.V.
+ Copyright (C) 2014-2018 Taler Systems SA
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
diff --git a/src/exchangedb/perf_taler_exchangedb_init.c b/src/exchangedb/perf_taler_exchangedb_init.c
index 4efec391..789aaea0 100644
--- a/src/exchangedb/perf_taler_exchangedb_init.c
+++ b/src/exchangedb/perf_taler_exchangedb_init.c
@@ -204,6 +204,7 @@ PERF_TALER_EXCHANGEDB_reserve_free (struct PERF_TALER_EXCHANGEDB_Reserve *reserv
/**
* Generate a dummy deposit for testing purposes
+ *
* @param dki the denomination key used to sign the key
*/
struct TALER_EXCHANGEDB_Deposit *
@@ -214,19 +215,12 @@ PERF_TALER_EXCHANGEDB_deposit_init (const struct PERF_TALER_EXCHANGEDB_Coin *coi
struct TALER_MerchantPublicKeyP merchant_pub;
struct GNUNET_HashCode h_contract_terms;
struct GNUNET_HashCode h_wire;
- const char wire[] = "{"
- "\"type\":\"SEPA\","
- "\"IBAN\":\"DE67830654080004822650\","
- "\"NAME\":\"GNUNET E.\","
- "\"BIC\":\"GENODEF1SRL\""
- "}";
struct GNUNET_TIME_Absolute timestamp;
struct GNUNET_TIME_Absolute refund_deadline;
struct TALER_Amount amount_with_fee;
struct TALER_Amount deposit_fee;
- GNUNET_assert (NULL !=
- (deposit = GNUNET_malloc (sizeof (struct TALER_EXCHANGEDB_Deposit) + sizeof (wire))));
+ deposit = GNUNET_new (struct TALER_EXCHANGEDB_Deposit);
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
&h_contract_terms);
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -253,9 +247,8 @@ PERF_TALER_EXCHANGEDB_deposit_init (const struct PERF_TALER_EXCHANGEDB_Coin *coi
eddsa_prv = GNUNET_CRYPTO_eddsa_key_create ();
GNUNET_assert(NULL != eddsa_prv);
- GNUNET_CRYPTO_eddsa_key_get_public (
- eddsa_prv,
- &merchant_pub.eddsa_pub);
+ GNUNET_CRYPTO_eddsa_key_get_public (eddsa_prv,
+ &merchant_pub.eddsa_pub);
GNUNET_free (eddsa_prv);
}
timestamp = GNUNET_TIME_absolute_get ();
@@ -280,7 +273,10 @@ PERF_TALER_EXCHANGEDB_deposit_init (const struct PERF_TALER_EXCHANGEDB_Coin *coi
deposit->csig = csig;
deposit->h_contract_terms = h_contract_terms;
deposit->h_wire = h_wire;
- deposit->receiver_wire_account = json_loads (wire, 0, NULL);
+ deposit->receiver_wire_account
+ = json_pack ("{s:s, s:s}",
+ "url", "payto://sepa/DE67830654080004822650",
+ "salt", "this-is-a-salt-value");
deposit->timestamp = timestamp;
deposit->refund_deadline = refund_deadline;
deposit->amount_with_fee = amount_with_fee;
@@ -301,7 +297,7 @@ PERF_TALER_EXCHANGEDB_deposit_copy (const struct TALER_EXCHANGEDB_Deposit *depos
copy = GNUNET_new (struct TALER_EXCHANGEDB_Deposit);
*copy = *deposit;
- json_incref (copy->receiver_wire_account);
+ copy->receiver_wire_account = json_incref (deposit->receiver_wire_account);
copy->coin.denom_pub.rsa_public_key =
GNUNET_CRYPTO_rsa_public_key_dup (deposit->coin.denom_pub.rsa_public_key);
copy->coin.denom_sig.rsa_signature =
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c
index 8a81befd..43891e55 100644
--- a/src/exchangedb/perf_taler_exchangedb_interpreter.c
+++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c
@@ -1243,19 +1243,18 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
unsigned int reserve_index;
int ret;
struct PERF_TALER_EXCHANGEDB_Reserve *reserve;
- json_t *sndr;
+ char *sndr;
uint32_t uid;
struct GNUNET_TIME_Absolute now;
reserve_index = state->cmd[state->i].details.insert_reserve.index_reserve;
reserve = state->cmd[reserve_index].exposed.data.reserve;
- sndr = json_pack ("{s:i}",
- "account",
- (int) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT32_MAX));
+ GNUNET_asprintf (&sndr,
+ "payto://x-taler-test/localhost:8080/%u",
+ (unsigned int) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT32_MAX));
uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT32_MAX);
- GNUNET_assert (NULL != sndr);
now = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&now);
ret = state->plugin->reserves_in_insert (state->plugin->cls,
@@ -1264,10 +1263,11 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
&reserve->reserve.balance,
now,
sndr,
+ "account-1",
&uid,
sizeof (uid));
GNUNET_assert (GNUNET_SYSERR != ret);
- json_decref (sndr);
+ GNUNET_free (sndr);
}
break;
diff --git a/src/exchangedb/plugin_exchangedb_common.c b/src/exchangedb/plugin_exchangedb_common.c
index e4b83249..8344974b 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -42,8 +42,7 @@ common_free_reserve_history (void *cls,
{
case TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE:
bt = rh->details.bank;
- if (NULL != bt->sender_account_details)
- json_decref (bt->sender_account_details);
+ GNUNET_free_non_null (bt->sender_account_details);
GNUNET_free_non_null (bt->wire_reference);
GNUNET_free (bt);
break;
@@ -61,8 +60,7 @@ common_free_reserve_history (void *cls,
break;
case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
closing = rh->details.closing;
- if (NULL != closing->receiver_account_details)
- json_decref (closing->receiver_account_details);
+ GNUNET_free_non_null (closing->receiver_account_details);
GNUNET_free (closing);
break;
}
@@ -92,7 +90,7 @@ common_free_coin_transaction_list (void *cls,
switch (list->type)
{
case TALER_EXCHANGEDB_TT_DEPOSIT:
- json_decref (list->details.deposit->receiver_wire_account);
+ GNUNET_free_non_null (list->details.deposit->receiver_wire_account);
if (NULL != list->details.deposit->coin.denom_pub.rsa_public_key)
GNUNET_CRYPTO_rsa_public_key_free (list->details.deposit->coin.denom_pub.rsa_public_key);
if (NULL != list->details.deposit->coin.denom_sig.rsa_signature)
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 6c633055..140bceb2 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -127,6 +127,7 @@ postgres_drop_tables (void *cls)
PGconn *conn;
int ret;
+ /* FIXME: use GNUNET_PQ_connect_with_cfg instead? */
conn = GNUNET_PQ_connect (pc->connection_cfg_str);
if (NULL == conn)
return GNUNET_SYSERR;
@@ -218,12 +219,13 @@ postgres_create_tables (void *cls)
",credit_frac INT4 NOT NULL"
",credit_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",sender_account_details TEXT NOT NULL"
+ ",exchange_account_section TEXT NOT NULL"
",execution_date INT8 NOT NULL"
",PRIMARY KEY (reserve_pub, wire_reference)"
");"),
/* Create indices on reserves_in */
GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_in_execution_index"
- " ON reserves_in (execution_date);"),
+ " ON reserves_in (exchange_account_section,execution_date);"),
/* This table contains the data for wire transfers the exchange has
executed to close a reserve. */
GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS reserves_close "
@@ -433,6 +435,7 @@ postgres_create_tables (void *cls)
PGconn *conn;
int ret;
+ /* FIXME: use GNUNET_PQ_connect_with_cfg instead? */
conn = GNUNET_PQ_connect (pc->connection_cfg_str);
if (NULL == conn)
return GNUNET_SYSERR;
@@ -585,21 +588,23 @@ postgres_prepare (PGconn *db_conn)
",credit_val"
",credit_frac"
",credit_curr"
+ ",exchange_account_section"
",sender_account_details"
",execution_date"
") VALUES "
- "($1, $2, $3, $4, $5, $6, $7) "
+ "($1, $2, $3, $4, $5, $6, $7, $8) "
"ON CONFLICT DO NOTHING;",
- 7),
+ 8),
/* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
transactions for reserves with serial id '\geq' the given parameter */
GNUNET_PQ_make_prepare ("reserves_in_get_latest_wire_reference",
"SELECT"
" wire_reference"
" FROM reserves_in"
+ " WHERE exchange_account_section=$1"
" ORDER BY reserve_in_serial_id DESC"
" LIMIT 1;",
- 0),
+ 1),
/* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
transactions for reserves with serial id '\geq' the given parameter */
GNUNET_PQ_make_prepare ("audit_reserves_in_get_transactions_incr",
@@ -1509,6 +1514,7 @@ postgres_get_session (void *cls)
return session;
}
}
+ /* FIXME: use GNUNET_PQ_connect_with_cfg instead? */
db_conn = GNUNET_PQ_connect (pc->connection_cfg_str);
if (NULL == db_conn)
return NULL;
@@ -1836,7 +1842,9 @@ reserves_update (void *cls,
* @param reserve_pub public key of the reserve
* @param balance the amount that has to be added to the reserve
* @param execution_time when was the amount added
- * @param sender_account_details account information for the sender
+ * @param sender_account_details account information for the sender (payto://-URL)
+ * @param exchange_account_section name of the section in the configuration for the exchange's
+ * account into which the deposit was made
* @param wire_reference unique reference identifying the wire transfer (binary blob)
* @param wire_reference_size number of bytes in @a wire_reference
* @return transaction status code
@@ -1847,7 +1855,8 @@ postgres_reserves_in_insert (void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance,
struct GNUNET_TIME_Absolute execution_time,
- const json_t *sender_account_details,
+ const char *sender_account_details,
+ const char *exchange_account_section,
const void *wire_reference,
size_t wire_reference_size)
{
@@ -1900,7 +1909,7 @@ postgres_reserves_in_insert (void *cls,
as a foreign key. */
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- TALER_PQ_query_param_json (sender_account_details),
+ GNUNET_PQ_query_param_string (sender_account_details),
TALER_PQ_query_param_amount (balance),
TALER_PQ_query_param_absolute_time (&expiry),
GNUNET_PQ_query_param_end
@@ -1929,7 +1938,8 @@ postgres_reserves_in_insert (void *cls,
GNUNET_PQ_query_param_fixed_size (wire_reference,
wire_reference_size),
TALER_PQ_query_param_amount (balance),
- TALER_PQ_query_param_json (sender_account_details),
+ GNUNET_PQ_query_param_string (exchange_account_section),
+ GNUNET_PQ_query_param_string (sender_account_details),
TALER_PQ_query_param_absolute_time (&execution_time),
GNUNET_PQ_query_param_end
};
@@ -1976,6 +1986,8 @@ postgres_reserves_in_insert (void *cls,
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param session the database session handle
+ * @param exchange_account_name name of the section in the exchange's configuration
+ * for the account that we are tracking here
* @param[out] wire_reference set to unique reference identifying the wire transfer (binary blob)
* @param[out] wire_reference_size set to number of bytes in @a wire_reference
* @return transaction status code
@@ -1983,10 +1995,12 @@ postgres_reserves_in_insert (void *cls,
static enum GNUNET_DB_QueryStatus
postgres_get_latest_reserve_in_reference (void *cls,
struct TALER_EXCHANGEDB_Session *session,
+ const char *exchange_account_name,
void **wire_reference,
size_t *wire_reference_size)
{
struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (exchange_account_name),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -2222,8 +2236,8 @@ add_bank_to_exchange (void *cls,
&bt->amount),
TALER_PQ_result_spec_absolute_time ("execution_date",
&bt->execution_date),
- TALER_PQ_result_spec_json ("sender_account_details",
- &bt->sender_account_details),
+ GNUNET_PQ_result_spec_string ("sender_account_details",
+ &bt->sender_account_details),
GNUNET_PQ_result_spec_end
};
@@ -2389,8 +2403,8 @@ add_exchange_to_bank (void *cls,
&closing->closing_fee),
TALER_PQ_result_spec_absolute_time ("execution_date",
&closing->execution_date),
- TALER_PQ_result_spec_json ("receiver_account",
- &closing->receiver_account_details),
+ GNUNET_PQ_result_spec_string ("receiver_account",
+ &closing->receiver_account_details),
GNUNET_PQ_result_spec_auto_from_type ("wtid",
&closing->wtid),
GNUNET_PQ_result_spec_end
@@ -2710,7 +2724,7 @@ postgres_get_ready_deposit (void *cls,
GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
&coin_pub),
TALER_PQ_result_spec_json ("wire",
- &wire),
+ &wire),
GNUNET_PQ_result_spec_end
};
enum GNUNET_DB_QueryStatus qs;
@@ -3811,7 +3825,7 @@ add_coin_deposit (void *cls,
GNUNET_PQ_result_spec_auto_from_type ("h_wire",
&deposit->h_wire),
TALER_PQ_result_spec_json ("wire",
- &deposit->receiver_wire_account),
+ &deposit->receiver_wire_account),
GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
&deposit->csig),
GNUNET_PQ_result_spec_end
@@ -4178,8 +4192,6 @@ handle_wt_result (void *cls,
struct TALER_Amount amount_with_fee;
struct TALER_Amount deposit_fee;
json_t *wire;
- json_t *t;
- const char *wire_method;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id", &rowid),
GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", &h_contract_terms),
@@ -4202,25 +4214,11 @@ handle_wt_result (void *cls,
ctx->status = GNUNET_SYSERR;
return;
}
- t = json_object_get (wire, "type");
- if (NULL == t)
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- wire_method = json_string_value (t);
- if (NULL == wire_method)
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
ctx->cb (ctx->cb_cls,
rowid,
&merchant_pub,
- wire_method,
&h_wire,
+ wire,
exec_time,
&h_contract_terms,
&coin_pub,
@@ -4580,14 +4578,14 @@ reserve_expired_cb (void *cls,
for (unsigned int i=0;i<num_results;i++)
{
struct GNUNET_TIME_Absolute exp_date;
- json_t *account_details;
+ char *account_details;
struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_Amount remaining_balance;
struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_absolute_time ("expiration_date",
&exp_date),
- TALER_PQ_result_spec_json ("account_details",
- &account_details),
+ GNUNET_PQ_result_spec_string ("account_details",
+ &account_details),
GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
&reserve_pub),
TALER_PQ_result_spec_amount ("current_balance",
@@ -4674,7 +4672,7 @@ postgres_insert_reserve_closed (void *cls,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_ReservePublicKeyP *reserve_pub,
struct GNUNET_TIME_Absolute execution_date,
- const json_t *receiver_account,
+ const char *receiver_account,
const struct TALER_WireTransferIdentifierRawP *wtid,
const struct TALER_Amount *amount_with_fee,
const struct TALER_Amount *closing_fee)
@@ -4684,7 +4682,7 @@ postgres_insert_reserve_closed (void *cls,
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
TALER_PQ_query_param_absolute_time (&execution_date),
GNUNET_PQ_query_param_auto_from_type (wtid),
- TALER_PQ_query_param_json (receiver_account),
+ GNUNET_PQ_query_param_string (receiver_account),
TALER_PQ_query_param_amount (amount_with_fee),
TALER_PQ_query_param_amount (closing_fee),
GNUNET_PQ_query_param_end
@@ -4946,6 +4944,7 @@ postgres_gc (void *cls)
long_ago = GNUNET_TIME_absolute_subtract (now,
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
10));
+ /* FIXME: use GNUNET_PQ_connect_with_cfg instead? */
conn = GNUNET_PQ_connect (pc->connection_cfg_str);
if (NULL == conn)
return GNUNET_SYSERR;
@@ -5421,7 +5420,7 @@ reserves_in_serial_helper_cb (void *cls,
{
struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_Amount credit;
- json_t *sender_account_details;
+ char *sender_account_details;
struct GNUNET_TIME_Absolute execution_date;
uint64_t rowid;
void *wire_reference;
@@ -5436,8 +5435,8 @@ reserves_in_serial_helper_cb (void *cls,
&credit),
TALER_PQ_result_spec_absolute_time("execution_date",
&execution_date),
- TALER_PQ_result_spec_json ("sender_account_details",
- &sender_account_details),
+ GNUNET_PQ_result_spec_string ("sender_account_details",
+ &sender_account_details),
GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
&rowid),
GNUNET_PQ_result_spec_end
@@ -5943,7 +5942,7 @@ reserve_closed_serial_helper_cb (void *cls,
{
uint64_t rowid;
struct TALER_ReservePublicKeyP reserve_pub;
- json_t *receiver_account;
+ char *receiver_account;
struct TALER_WireTransferIdentifierRawP wtid;
struct TALER_Amount amount_with_fee;
struct TALER_Amount closing_fee;
@@ -5957,8 +5956,8 @@ reserve_closed_serial_helper_cb (void *cls,
&execution_date),
GNUNET_PQ_result_spec_auto_from_type ("wtid",
&wtid),
- TALER_PQ_result_spec_json ("receiver_account",
- &receiver_account),
+ GNUNET_PQ_result_spec_string ("receiver_account",
+ &receiver_account),
TALER_PQ_result_spec_amount ("amount",
&amount_with_fee),
TALER_PQ_result_spec_amount ("closing_fee",
@@ -6271,7 +6270,7 @@ missing_wire_cb (void *cls,
TALER_PQ_result_spec_amount ("amount_with_fee",
&amount),
TALER_PQ_result_spec_json ("wire",
- &wire),
+ &wire),
TALER_PQ_result_spec_absolute_time ("wire_deadline",
&deadline),
GNUNET_PQ_result_spec_auto_from_type ("tiny",
@@ -6380,12 +6379,12 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"exchangedb-postgres",
- "db_conn_str",
+ "CONFIG",
&pg->connection_cfg_str))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"exchangedb-postgres",
- "db_conn_str");
+ "CONFIG");
GNUNET_free (pg);
return NULL;
}
diff --git a/src/exchangedb/test-exchange-db-postgres.conf b/src/exchangedb/test-exchange-db-postgres.conf
index 926e2997..d0afc535 100644
--- a/src/exchangedb/test-exchange-db-postgres.conf
+++ b/src/exchangedb/test-exchange-db-postgres.conf
@@ -5,7 +5,7 @@ DB = postgres
[exchangedb-postgres]
#The connection string the plugin has to use for connecting to the database
-DB_CONN_STR = postgres:///talercheck
+CONFIG = postgres:///talercheck
[exchangedb]
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 36f0cce4..a112af24 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2017 GNUnet e.V.
+ Copyright (C) 2014-2018 Taler Systems SA
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
@@ -703,8 +703,8 @@ static void
cb_wt_never (void *cls,
uint64_t serial_id,
const struct TALER_MerchantPublicKeyP *merchant_pub,
- const char *wire_method,
const struct GNUNET_HashCode *h_wire,
+ const json_t *wire,
struct GNUNET_TIME_Absolute exec_time,
const struct GNUNET_HashCode *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
@@ -747,8 +747,8 @@ static void
cb_wt_check (void *cls,
uint64_t rowid,
const struct TALER_MerchantPublicKeyP *merchant_pub,
- const char *wire_method,
const struct GNUNET_HashCode *h_wire,
+ const json_t *wire,
struct GNUNET_TIME_Absolute exec_time,
const struct GNUNET_HashCode *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
@@ -759,8 +759,9 @@ cb_wt_check (void *cls,
GNUNET_assert (0 == memcmp (merchant_pub,
&merchant_pub_wt,
sizeof (struct TALER_MerchantPublicKeyP)));
- GNUNET_assert (0 == strcmp (wire_method,
- "SEPA"));
+ GNUNET_assert (0 == strcmp (json_string_value (json_object_get (wire,
+ "url")),
+ "payto://sepa/DE67830654080004822650"));
GNUNET_assert (0 == memcmp (h_wire,
&h_wire_wt,
sizeof (struct GNUNET_HashCode)));
@@ -842,8 +843,8 @@ deposit_cb (void *cls,
deposit_rowid = rowid;
if (NULL != wire)
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_hash (wire,
- &h_wire));
+ TALER_JSON_wire_signature_hash (wire,
+ &h_wire));
if ( (0 != memcmp (merchant_pub,
&deposit->merchant_pub,
sizeof (struct TALER_MerchantPublicKeyP))) ||
@@ -960,7 +961,7 @@ audit_reserve_in_cb (void *cls,
uint64_t rowid,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *credit,
- const json_t *sender_account_details,
+ const char *sender_account_details,
const void *wire_reference,
size_t wire_reference_size,
struct GNUNET_TIME_Absolute execution_date)
@@ -1156,8 +1157,6 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session)
}
-static json_t *wire_out_account;
-
static struct TALER_Amount wire_out_amount;
@@ -1204,11 +1203,11 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_Deposit *deposit)
{
auditor_row_cnt = 0;
- memset (&wire_out_wtid, 42, sizeof (wire_out_wtid));
+ memset (&wire_out_wtid,
+ 42,
+ sizeof (wire_out_wtid));
wire_out_date = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&wire_out_date);
- wire_out_account = json_loads ("{ \"account\":\"1\" }", 0, NULL);
- GNUNET_assert (NULL != wire_out_account);
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":1",
&wire_out_amount));
@@ -1262,13 +1261,25 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
/* Now let's fix the transient constraint violation by
putting in the WTID into the wire_out table */
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->store_wire_transfer_out (plugin->cls,
- session,
- wire_out_date,
- &wire_out_wtid,
- wire_out_account,
- &wire_out_amount));
+ {
+ json_t *wire_out_account;
+
+ wire_out_account = json_pack ("{s:s,s:s}",
+ "url", "payto://x-taler-bank/localhost:8080/1",
+ "salt", "this-is-my-salt");
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->store_wire_transfer_out (plugin->cls,
+ session,
+ wire_out_date,
+ &wire_out_wtid,
+ wire_out_account,
+ &wire_out_amount))
+ {
+ json_decref (wire_out_account);
+ FAILIF (1);
+ }
+ json_decref (wire_out_account);
+ }
/* And now the commit should still succeed! */
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->commit (plugin->cls,
@@ -1365,8 +1376,8 @@ wire_missing_cb (void *cls,
if (NULL != wire)
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_hash (wire,
- &h_wire));
+ TALER_JSON_wire_signature_hash (wire,
+ &h_wire));
else
memset (&h_wire,
0,
@@ -1500,16 +1511,8 @@ run (void *cls)
struct TALER_EXCHANGEDB_TransactionList *tl;
struct TALER_EXCHANGEDB_TransactionList *tlp;
json_t *wire;
- json_t *sndr;
+ const char *sndr = "payto://x-taler-bank/localhost:8080/1";
unsigned int matched;
- const char * const json_wire_str =
- "{ \"type\":\"SEPA\", \
-\"IBAN\":\"DE67830654080004822650\", \
-\"name\":\"GNUnet e.V.\", \
-\"bic\":\"GENODEF1SLR\", \
-\"wire_transfer_deadline\":\"1449930207000\", \
-\"r\":123456789, \
-\"address\": \"foobar\"}";
unsigned int cnt;
void *rr;
size_t rr_size;
@@ -1518,9 +1521,11 @@ run (void *cls)
dkp = NULL;
rh = NULL;
- wire = NULL;
session = NULL;
deposit.coin.denom_sig.rsa_signature = NULL;
+ wire = json_pack ("{s:s, s:s}",
+ "url", "payto://sepa/DE67830654080004822650",
+ "salt", "this-is-a-salt-value");
ZR_BLK (&cbc);
ZR_BLK (&cbc2);
if (NULL ==
@@ -1576,11 +1581,10 @@ run (void *cls)
&amount_with_fee));
result = 4;
- sndr = json_loads ("{ \"account\":\"1\" }", 0, NULL);
- GNUNET_assert (NULL != sndr);
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_latest_reserve_in_reference (plugin->cls,
session,
+ "account-1",
&rr,
&rr_size));
now = GNUNET_TIME_absolute_get ();
@@ -1592,11 +1596,13 @@ run (void *cls)
&value,
now,
sndr,
+ "account-1",
"TEST",
4));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls,
session,
+ "account-1",
&rr,
&rr_size));
FAILIF (4 != rr_size);
@@ -1617,23 +1623,25 @@ run (void *cls)
&value,
now,
sndr,
+ "account-1",
"TEST2",
5));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls,
session,
+ "account-1",
&rr,
&rr_size));
GNUNET_free (rr);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls,
session,
+ "account-1",
&rr,
&rr_size));
FAILIF (5 != rr_size);
FAILIF (0 != memcmp ("TEST2", rr, 5));
GNUNET_free (rr);
- json_decref (sndr);
FAILIF (GNUNET_OK !=
check_reserve (session,
&reserve_pub,
@@ -1731,7 +1739,6 @@ run (void *cls)
TALER_amount_add (&amount_with_fee,
&value,
&value));
- sndr = json_loads ("{ \"account\":\"1\" }", 0, NULL);
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":0.000010",
&fee_closing));
@@ -1753,7 +1760,6 @@ run (void *cls)
0,
value.currency));
- json_decref (sndr);
result = 7;
qs = plugin->get_reserve_history (plugin->cls,
session,
@@ -1840,17 +1846,18 @@ run (void *cls)
FAILIF (3 != auditor_row_cnt);
/* Tests for deposits */
- memset (&deposit, 0, sizeof (deposit));
+ memset (&deposit,
+ 0,
+ sizeof (deposit));
RND_BLK (&deposit.coin.coin_pub);
deposit.coin.denom_pub = dkp->pub;
deposit.coin.denom_sig = cbc.sig;
RND_BLK (&deposit.csig);
RND_BLK (&deposit.merchant_pub);
RND_BLK (&deposit.h_contract_terms);
- wire = json_loads (json_wire_str, 0, NULL);
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_hash (wire,
- &deposit.h_wire));
+ TALER_JSON_wire_signature_hash (wire,
+ &deposit.h_wire));
deposit.receiver_wire_account = wire;
deposit.amount_with_fee = value;
deposit.deposit_fee = fee_deposit;
@@ -1897,7 +1904,8 @@ run (void *cls)
session,
&deposit.h_wire,
&deposit.merchant_pub,
- &deposit_cb, &deposit,
+ &deposit_cb,
+ &deposit,
2));
sleep (2); /* giv deposit time to be ready */
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
@@ -2179,8 +2187,9 @@ run (void *cls)
result = 0;
drop:
- if (NULL != wire)
- json_decref (wire);
+ if (0 != result)
+ plugin->rollback (plugin->cls,
+ session);
if (NULL != rh)
plugin->free_reserve_history (plugin->cls,
rh);
@@ -2196,6 +2205,7 @@ run (void *cls)
if (NULL != cbc2.sig.rsa_signature)
GNUNET_CRYPTO_rsa_signature_free (cbc2.sig.rsa_signature);
dkp = NULL;
+ json_decref (wire);
TALER_EXCHANGEDB_plugin_unload (plugin);
plugin = NULL;
}