aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-01-21 23:08:29 +0100
committerChristian Grothoff <christian@grothoff.org>2023-01-21 23:08:29 +0100
commitd131951fbe09b3415c9976acd11f660d51493086 (patch)
treee4c00b01e03de90f1d3f691ea248178195f1ebc2 /src/exchangedb
parent31286b66f253c62ab3c33827490b55a4cc025608 (diff)
downloadexchange-d131951fbe09b3415c9976acd11f660d51493086.tar.xz
add new endpoints to main dispatcher
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/0002-partners.sql1
-rw-r--r--src/exchangedb/pg_insert_aml_decision.c12
-rw-r--r--src/exchangedb/pg_insert_aml_decision.h9
-rw-r--r--src/exchangedb/pg_insert_aml_officer.c8
-rw-r--r--src/exchangedb/pg_insert_aml_officer.h9
-rw-r--r--src/exchangedb/pg_insert_partner.c19
6 files changed, 37 insertions, 21 deletions
diff --git a/src/exchangedb/0002-partners.sql b/src/exchangedb/0002-partners.sql
index ff57f8fc1..c80f2d745 100644
--- a/src/exchangedb/0002-partners.sql
+++ b/src/exchangedb/0002-partners.sql
@@ -25,6 +25,7 @@ CREATE TABLE partners
,wad_fee_frac INT4 NOT NULL
,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
,partner_base_url TEXT NOT NULL
+ ,PRIMARY KEY (partner_master_pub, start_date)
);
COMMENT ON TABLE partners
IS 'exchanges we do wad transfers to';
diff --git a/src/exchangedb/pg_insert_aml_decision.c b/src/exchangedb/pg_insert_aml_decision.c
index d046c87f9..421628f65 100644
--- a/src/exchangedb/pg_insert_aml_decision.c
+++ b/src/exchangedb/pg_insert_aml_decision.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022, 2023 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
@@ -32,10 +32,12 @@ TEH_PG_insert_aml_decision (
const struct TALER_PaytoHashP *h_payto,
const struct TALER_Amount *new_threshold,
enum TALER_AmlDecisionState new_status,
- struct GNUNET_TIME_Absolute decision_time,
+ struct GNUNET_TIME_Timestamp decision_time,
const char *justification,
const struct TALER_AmlOfficerPublicKeyP *decider_pub,
- const struct TALER_AmlOfficerSignatureP *decider_sig)
+ const struct TALER_AmlOfficerSignatureP *decider_sig,
+ bool *invalid_officer,
+ struct GNUNET_TIME_Timestamp *last_date)
{
struct PostgresClosure *pg = cls;
uint32_t ns = (uint32_t) new_status;
@@ -43,13 +45,15 @@ TEH_PG_insert_aml_decision (
GNUNET_PQ_query_param_auto_from_type (h_payto),
TALER_PQ_query_param_amount (new_threshold),
GNUNET_PQ_query_param_uint32 (&ns),
- GNUNET_PQ_query_param_absolute_time (&decision_time),
+ GNUNET_PQ_query_param_timestamp (&decision_time),
GNUNET_PQ_query_param_string (justification),
GNUNET_PQ_query_param_auto_from_type (decider_pub),
GNUNET_PQ_query_param_auto_from_type (decider_sig),
GNUNET_PQ_query_param_end
};
+ // FIXME: set invalid_officer
+ // FIXME: set last_date!
PREPARE (pg,
"insert_aml_decision",
"INSERT INTO aml_history "
diff --git a/src/exchangedb/pg_insert_aml_decision.h b/src/exchangedb/pg_insert_aml_decision.h
index 205c1c74b..94f648fb1 100644
--- a/src/exchangedb/pg_insert_aml_decision.h
+++ b/src/exchangedb/pg_insert_aml_decision.h
@@ -38,6 +38,9 @@
* @param justification human-readable text justifying the decision
* @param decider_pub public key of the staff member
* @param decider_sig signature of the staff member
+ * @param[out] invalid_officer set to TRUE if @a decider_pub is not allowed to make decisions right now
+ * @param[out] last_date set to the previous decision time;
+ * the INSERT is not performed if @a last_date is not before @a decision_time
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
@@ -46,10 +49,12 @@ TEH_PG_insert_aml_decision (
const struct TALER_PaytoHashP *h_payto,
const struct TALER_Amount *new_threshold,
enum TALER_AmlDecisionState new_status,
- struct GNUNET_TIME_Absolute decision_time,
+ struct GNUNET_TIME_Timestamp decision_time,
const char *justification,
const struct TALER_AmlOfficerPublicKeyP *decider_pub,
- const struct TALER_AmlOfficerSignatureP *decider_sig);
+ const struct TALER_AmlOfficerSignatureP *decider_sig,
+ bool *invalid_officer,
+ struct GNUNET_TIME_Timestamp *last_date);
#endif
diff --git a/src/exchangedb/pg_insert_aml_officer.c b/src/exchangedb/pg_insert_aml_officer.c
index fc2cadef2..33e6c86f7 100644
--- a/src/exchangedb/pg_insert_aml_officer.c
+++ b/src/exchangedb/pg_insert_aml_officer.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022, 2023 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
@@ -34,7 +34,8 @@ TEH_PG_insert_aml_officer (
const char *decider_name,
bool is_active,
bool read_only,
- struct GNUNET_TIME_Absolute last_change)
+ struct GNUNET_TIME_Timestamp last_change,
+ struct GNUNET_TIME_Timestamp *previous_change)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
@@ -43,10 +44,11 @@ TEH_PG_insert_aml_officer (
GNUNET_PQ_query_param_string (decider_name),
GNUNET_PQ_query_param_bool (is_active),
GNUNET_PQ_query_param_bool (read_only),
- GNUNET_PQ_query_param_absolute_time (&last_change),
+ GNUNET_PQ_query_param_timestamp (&last_change),
GNUNET_PQ_query_param_end
};
+ // FIXME: need to check for previous record!
PREPARE (pg,
"insert_aml_staff",
"INSERT INTO aml_staff "
diff --git a/src/exchangedb/pg_insert_aml_officer.h b/src/exchangedb/pg_insert_aml_officer.h
index be034d9ff..3c6f5d82e 100644
--- a/src/exchangedb/pg_insert_aml_officer.h
+++ b/src/exchangedb/pg_insert_aml_officer.h
@@ -27,7 +27,10 @@
/**
- * Insert AML staff record.
+ * Insert AML staff record. If the time given in
+ * @a last_change is before the previous change in the
+ * database, only @e previous_change is returned and
+ * no actual change is committed to the database.
*
* @param cls closure
* @param decider_pub public key of the staff member
@@ -36,6 +39,7 @@
* @param is_active true to enable, false to set as inactive
* @param read_only true to set read-only access
* @param last_change when was the change made effective
+ * @param[out] previous_change set to the time of the previous change
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
@@ -46,6 +50,7 @@ TEH_PG_insert_aml_officer (
const char *decider_name,
bool is_active,
bool read_only,
- struct GNUNET_TIME_Absolute last_change);
+ struct GNUNET_TIME_Timestamp last_change,
+ struct GNUNET_TIME_Timestamp *previous_change);
#endif
diff --git a/src/exchangedb/pg_insert_partner.c b/src/exchangedb/pg_insert_partner.c
index 567f37763..5abb2c910 100644
--- a/src/exchangedb/pg_insert_partner.c
+++ b/src/exchangedb/pg_insert_partner.c
@@ -28,13 +28,13 @@
enum GNUNET_DB_QueryStatus
TEH_PG_insert_partner (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- struct GNUNET_TIME_Relative wad_frequency,
- const struct TALER_Amount *wad_fee,
- const char *partner_base_url,
- const struct TALER_MasterSignatureP *master_sig)
+ const struct TALER_MasterPublicKeyP *master_pub,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ struct GNUNET_TIME_Relative wad_frequency,
+ const struct TALER_Amount *wad_fee,
+ const char *partner_base_url,
+ const struct TALER_MasterSignatureP *master_sig)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
@@ -61,10 +61,9 @@ TEH_PG_insert_partner (void *cls,
" ,master_sig"
" ,partner_base_url"
" ) VALUES "
- " ($1, $2, $3, $4, $5, $6, $7, $8);");
+ " ($1, $2, $3, $4, $5, $6, $7, $8)"
+ " ON CONFLICT DO NOTHING;");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_partner",
params);
}
-
-