summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-08-16 14:36:23 +0200
committerChristian Grothoff <christian@grothoff.org>2022-08-16 14:36:23 +0200
commit68d2df88f2ec0b70c3778f7f77eeb6173bd8c08b (patch)
treeba7b155be05788a698fef6685b4fffcf9c10075a /src
parent94fa05ec2a96ca7bdc47f3dc77aa727ae81f9a44 (diff)
downloadexchange-68d2df88f2ec0b70c3778f7f77eeb6173bd8c08b.tar.gz
exchange-68d2df88f2ec0b70c3778f7f77eeb6173bd8c08b.tar.bz2
exchange-68d2df88f2ec0b70c3778f7f77eeb6173bd8c08b.zip
allow merge into non-existent reserve if KYC is disabled
Diffstat (limited to 'src')
-rw-r--r--src/exchange/Makefile.am1
-rw-r--r--src/exchange/taler-exchange-httpd.c9
-rw-r--r--src/exchange/taler-exchange-httpd_purses_merge.c11
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c10
-rw-r--r--src/exchangedb/procedures.sql29
-rw-r--r--src/include/taler_exchangedb_plugin.h1
-rw-r--r--src/templating/templating_api.c4
7 files changed, 30 insertions, 35 deletions
diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am
index 881a3f361..4d7d6d948 100644
--- a/src/exchange/Makefile.am
+++ b/src/exchange/Makefile.am
@@ -177,6 +177,7 @@ taler_exchange_httpd_LDADD = \
$(top_builddir)/src/mhd/libtalermhd.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/exchangedb/libtalerexchangedb.la \
+ $(top_builddir)/src/templating/libtalertemplating.la \
$(top_builddir)/src/kyclogic/libtalerkyclogic.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/extensions/libtalerextensions.la \
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index e7d070435..c91dbfbb4 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -28,6 +28,7 @@
#include <sys/resource.h>
#include <limits.h>
#include "taler_kyclogic_lib.h"
+#include "taler_templating_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_auditors.h"
#include "taler-exchange-httpd_batch-deposit.h"
@@ -2125,6 +2126,7 @@ do_shutdown (void *cls)
GNUNET_CURL_gnunet_rc_destroy (exchange_curl_rc);
exchange_curl_rc = NULL;
}
+ TALER_TEMPLATING_done ();
}
@@ -2162,6 +2164,13 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
+ if (GNUNET_OK !=
+ TALER_TEMPLATING_init ("exchange"))
+ {
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (GNUNET_SYSERR ==
TEH_plugin->preflight (TEH_plugin->cls))
{
diff --git a/src/exchange/taler-exchange-httpd_purses_merge.c b/src/exchange/taler-exchange-httpd_purses_merge.c
index 8751e3f15..9ce3033d5 100644
--- a/src/exchange/taler-exchange-httpd_purses_merge.c
+++ b/src/exchange/taler-exchange-httpd_purses_merge.c
@@ -275,7 +275,6 @@ merge_transaction (void *cls,
bool in_conflict = true;
bool no_balance = true;
bool no_partner = true;
- bool no_reserve = true;
const char *required;
required = TALER_KYCLOGIC_kyc_test_required (
@@ -305,7 +304,6 @@ merge_transaction (void *cls,
&pcc->reserve_pub,
&no_partner,
&no_balance,
- &no_reserve,
&in_conflict);
if (qs < 0)
{
@@ -329,15 +327,6 @@ merge_transaction (void *cls,
pcc->provider_url);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if (no_reserve)
- {
- *mhd_ret =
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
- NULL);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
if (no_balance)
{
*mhd_ret =
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 39c1be4bf..e593b0df9 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -4450,10 +4450,9 @@ prepare_statements (struct PostgresClosure *pg)
"SELECT"
" out_no_partner AS no_partner"
",out_no_balance AS no_balance"
- ",out_no_reserve AS no_reserve"
",out_conflict AS conflict"
" FROM exchange_do_purse_merge"
- " ($1, $2, $3, $4, $5, $6, $7);",
+ " ($1, $2, $3, $4, $5, $6, $7, $8);",
7),
/* Used in #postgres_do_reserve_purse() */
GNUNET_PQ_make_prepare (
@@ -16007,7 +16006,6 @@ postgres_get_purse_deposit (
* @param reserve_pub public key of the reserve to credit
* @param[out] no_partner set to true if @a partner_url is unknown
* @param[out] no_balance set to true if the @a purse_pub is not paid up yet
- * @param[out] no_reserve set to true if the @a reserve_pub is not known
* @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
* @return transaction status code
*/
@@ -16022,11 +16020,12 @@ postgres_do_purse_merge (
const struct TALER_ReservePublicKeyP *reserve_pub,
bool *no_partner,
bool *no_balance,
- bool *no_reserve,
bool *in_conflict)
{
struct PostgresClosure *pg = cls;
struct TALER_PaytoHashP h_payto;
+ struct GNUNET_TIME_Timestamp expiration
+ = GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_YEARS); /* FIXME: make this configurable? */
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub),
GNUNET_PQ_query_param_auto_from_type (merge_sig),
@@ -16037,6 +16036,7 @@ postgres_do_purse_merge (
: GNUNET_PQ_query_param_string (partner_url),
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
GNUNET_PQ_query_param_auto_from_type (&h_payto),
+ GNUNET_PQ_query_param_timestamp (&expiration),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -16044,8 +16044,6 @@ postgres_do_purse_merge (
no_partner),
GNUNET_PQ_result_spec_bool ("no_balance",
no_balance),
- GNUNET_PQ_result_spec_bool ("no_reserve",
- no_reserve),
GNUNET_PQ_result_spec_bool ("conflict",
in_conflict),
GNUNET_PQ_result_spec_end
diff --git a/src/exchangedb/procedures.sql b/src/exchangedb/procedures.sql
index 28a074b45..0c21ae41f 100644
--- a/src/exchangedb/procedures.sql
+++ b/src/exchangedb/procedures.sql
@@ -1606,9 +1606,9 @@ CREATE OR REPLACE FUNCTION exchange_do_purse_merge(
IN in_partner_url VARCHAR,
IN in_reserve_pub BYTEA,
IN in_wallet_h_payto BYTEA,
+ IN in_expiration_date INT8,
OUT out_no_partner BOOLEAN,
OUT out_no_balance BOOLEAN,
- OUT out_no_reserve BOOLEAN,
OUT out_conflict BOOLEAN)
LANGUAGE plpgsql
AS $$
@@ -1642,7 +1642,6 @@ ELSE
THEN
out_no_partner=TRUE;
out_conflict=FALSE;
- out_no_reserve=FALSE;
RETURN;
END IF;
END IF;
@@ -1670,7 +1669,6 @@ IF NOT FOUND
THEN
out_no_balance=TRUE;
out_conflict=FALSE;
- out_no_reserve=FALSE;
RETURN;
END IF;
out_no_balance=FALSE;
@@ -1703,29 +1701,30 @@ THEN
THEN
-- Purse was merged, but to some other reserve. Not allowed.
out_conflict=TRUE;
- out_no_reserve=FALSE;
RETURN;
END IF;
-- "success"
out_conflict=FALSE;
- out_no_reserve=FALSE;
RETURN;
END IF;
out_conflict=FALSE;
ASSERT NOT my_finished, 'internal invariant failed';
-PERFORM
- FROM exchange.reserves
- WHERE reserve_pub=in_reserve_pub;
-IF NOT FOUND
-THEN
- out_no_reserve=TRUE;
- RETURN;
-END IF;
-out_no_reserve=FALSE;
+-- Initialize reserve, if not yet exists.
+INSERT INTO reserves
+ (reserve_pub
+ ,expiration_date
+ ,gc_date)
+ VALUES
+ (in_reserve_pub
+ ,in_expiration_date
+ ,in_expiration_date)
+ ON CONFLICT DO NOTHING;
+
+
-- Store account merge signature.
@@ -1785,7 +1784,7 @@ RETURN;
END $$;
-COMMENT ON FUNCTION exchange_do_purse_merge(BYTEA, BYTEA, INT8, BYTEA, VARCHAR, BYTEA, BYTEA)
+COMMENT ON FUNCTION exchange_do_purse_merge(BYTEA, BYTEA, INT8, BYTEA, VARCHAR, BYTEA, BYTEA, INT8)
IS 'Checks that the partner exists, the purse has not been merged with a different reserve and that the purse is full. If so, persists the merge data and either merges the purse with the reserve or marks it as ready for the taler-exchange-router. Caller MUST abort the transaction on failures so as to not persist data by accident.';
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index 602448f70..ab6158a54 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -5394,7 +5394,6 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_ReservePublicKeyP *reserve_pub,
bool *no_partner,
bool *no_balance,
- bool *no_reserve,
bool *in_conflict);
diff --git a/src/templating/templating_api.c b/src/templating/templating_api.c
index 6d5c7c791..50356e45a 100644
--- a/src/templating/templating_api.c
+++ b/src/templating/templating_api.c
@@ -414,8 +414,8 @@ TALER_TEMPLATING_init (const char *subsystem)
}
GNUNET_asprintf (&dn,
"%s/%s/templates/",
- subsystem,
- path);
+ path,
+ subsystem);
GNUNET_free (path);
}
ret = GNUNET_DISK_directory_scan (dn,