From afe3f70d336e151598e02ebedb6498e13122530e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 14 Feb 2023 14:26:00 +0100 Subject: begin API change to allow AML officers to trigger KYC process --- src/exchangedb/0003-aml_history.sql | 8 +++++++- src/exchangedb/exchange_do_insert_aml_decision.sql | 7 +++++-- src/exchangedb/pg_insert_aml_decision.c | 11 ++++++++++- src/exchangedb/pg_insert_aml_decision.h | 2 ++ 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/exchangedb') diff --git a/src/exchangedb/0003-aml_history.sql b/src/exchangedb/0003-aml_history.sql index 36c0b3865..b411a6fb1 100644 --- a/src/exchangedb/0003-aml_history.sql +++ b/src/exchangedb/0003-aml_history.sql @@ -32,6 +32,7 @@ BEGIN ',new_status INT4 NOT NULL DEFAULT(0)' ',decision_time INT8 NOT NULL DEFAULT(0)' ',justification VARCHAR NOT NULL' + ',kyc_requirements VARCHAR' ',decider_pub BYTEA CHECK (LENGTH(decider_pub)=32)' ',decider_sig BYTEA CHECK (LENGTH(decider_sig)=64)' ') %s ;' @@ -80,6 +81,12 @@ BEGIN ,table_name ,partition_suffix ); + PERFORM comment_partitioned_column( + 'Additional KYC requirements imposed by the AML staff member. Serialized JSON array of strings.' + ,'kyc_requirements' + ,table_name + ,partition_suffix + ); PERFORM comment_partitioned_column( 'Signature key of the staff member affirming the AML decision; of type AML_DECISION' ,'decider_sig' @@ -114,7 +121,6 @@ BEGIN ); END $$; --- FIXME: also have INSERT on AML decisions to update AML status! INSERT INTO exchange_tables (name diff --git a/src/exchangedb/exchange_do_insert_aml_decision.sql b/src/exchangedb/exchange_do_insert_aml_decision.sql index 0009ecb40..8e22c57f8 100644 --- a/src/exchangedb/exchange_do_insert_aml_decision.sql +++ b/src/exchangedb/exchange_do_insert_aml_decision.sql @@ -24,6 +24,7 @@ CREATE OR REPLACE FUNCTION exchange_do_insert_aml_decision( IN in_decider_pub BYTEA, IN in_decider_sig BYTEA, IN in_notify_s VARCHAR, + IN in_kyc_requirements VARCHAR, OUT out_invalid_officer BOOLEAN, OUT out_last_date INT8) LANGUAGE plpgsql @@ -84,6 +85,7 @@ INSERT INTO exchange.aml_history ,new_status ,decision_time ,justification + ,kyc_requirements ,decider_pub ,decider_sig ) VALUES @@ -93,6 +95,7 @@ INSERT INTO exchange.aml_history ,in_new_status ,in_decision_time ,in_justification + ,in_kyc_requirements ,in_decider_pub ,in_decider_sig); @@ -105,7 +108,7 @@ THEN ,trigger_type) VALUES (in_h_payto,1); - + EXECUTE FORMAT ( 'NOTIFY %s' ,in_notify_s); @@ -116,5 +119,5 @@ END IF; END $$; -COMMENT ON FUNCTION exchange_do_insert_aml_decision(BYTEA, INT8, INT4, INT4, INT8, VARCHAR, BYTEA, BYTEA, VARCHAR) +COMMENT ON FUNCTION exchange_do_insert_aml_decision(BYTEA, INT8, INT4, INT4, INT8, VARCHAR, BYTEA, BYTEA, VARCHAR, VARCHAR) IS 'Checks whether the AML officer is eligible to make AML decisions and if so inserts the decision into the table'; diff --git a/src/exchangedb/pg_insert_aml_decision.c b/src/exchangedb/pg_insert_aml_decision.c index 7bdd0f575..5a1b71235 100644 --- a/src/exchangedb/pg_insert_aml_decision.c +++ b/src/exchangedb/pg_insert_aml_decision.c @@ -35,6 +35,7 @@ TEH_PG_insert_aml_decision ( enum TALER_AmlDecisionState new_status, struct GNUNET_TIME_Timestamp decision_time, const char *justification, + const json_t *kyc_requirements, const struct TALER_AmlOfficerPublicKeyP *decider_pub, const struct TALER_AmlOfficerSignatureP *decider_sig, bool *invalid_officer, @@ -48,6 +49,9 @@ TEH_PG_insert_aml_decision ( .h_payto = *h_payto }; char *notify_s = GNUNET_PG_get_event_notify_channel (&rep.header); + char *kyc_s = (NULL != kyc_requirements) + ? json_dumps (kyc_requirements, JSON_COMPACT) + : NULL; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (h_payto), TALER_PQ_query_param_amount (new_threshold), @@ -57,6 +61,9 @@ TEH_PG_insert_aml_decision ( GNUNET_PQ_query_param_auto_from_type (decider_pub), GNUNET_PQ_query_param_auto_from_type (decider_sig), GNUNET_PQ_query_param_string (notify_s), + NULL != kyc_requirements + ? GNUNET_PQ_query_param_string (kyc_s) + : GNUNET_PQ_query_param_null (), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { @@ -74,11 +81,13 @@ TEH_PG_insert_aml_decision ( " out_invalid_officer" ",out_last_date" " FROM exchange_do_insert_aml_decision" - "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "do_insert_aml_decision", params, rs); GNUNET_free (notify_s); + if (NULL != kyc_s) + free (kyc_s); return qs; } diff --git a/src/exchangedb/pg_insert_aml_decision.h b/src/exchangedb/pg_insert_aml_decision.h index b539945a7..4d4ca6e54 100644 --- a/src/exchangedb/pg_insert_aml_decision.h +++ b/src/exchangedb/pg_insert_aml_decision.h @@ -36,6 +36,7 @@ * @param new_status AML decision status * @param decision_time when was the decision made * @param justification human-readable text justifying the decision + * @param kyc_requirements JSON array with KYC requirements * @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 @@ -51,6 +52,7 @@ TEH_PG_insert_aml_decision ( enum TALER_AmlDecisionState new_status, struct GNUNET_TIME_Timestamp decision_time, const char *justification, + const json_t *kyc_requirements, const struct TALER_AmlOfficerPublicKeyP *decider_pub, const struct TALER_AmlOfficerSignatureP *decider_sig, bool *invalid_officer, -- cgit v1.2.3