diff options
Diffstat (limited to 'src/exchangedb/exchange_do_insert_aml_decision.sql')
-rw-r--r-- | src/exchangedb/exchange_do_insert_aml_decision.sql | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/exchangedb/exchange_do_insert_aml_decision.sql b/src/exchangedb/exchange_do_insert_aml_decision.sql index f257675a8..c8ed7e928 100644 --- a/src/exchangedb/exchange_do_insert_aml_decision.sql +++ b/src/exchangedb/exchange_do_insert_aml_decision.sql @@ -16,15 +16,14 @@ CREATE OR REPLACE FUNCTION exchange_do_insert_aml_decision( IN in_h_payto BYTEA, - IN in_new_threshold_val INT8, - IN in_new_threshold_frac INT4, + IN in_new_threshold taler_amount, IN in_new_status INT4, IN in_decision_time INT8, - IN in_justification VARCHAR, + IN in_justification TEXT, IN in_decider_pub BYTEA, IN in_decider_sig BYTEA, - IN in_notify_s VARCHAR, - IN in_kyc_requirements VARCHAR, + IN in_notify_s TEXT, + IN in_kyc_requirements TEXT, IN in_requirement_row INT8, OUT out_invalid_officer BOOLEAN, OUT out_last_date INT8) @@ -33,7 +32,7 @@ AS $$ BEGIN -- Check officer is eligible to make decisions. PERFORM - FROM exchange.aml_staff + FROM aml_staff WHERE decider_pub=in_decider_pub AND is_active AND NOT read_only; @@ -48,7 +47,7 @@ out_invalid_officer=FALSE; -- Check no more recent decision exists. SELECT decision_time INTO out_last_date - FROM exchange.aml_history + FROM aml_history WHERE h_payto=in_h_payto ORDER BY decision_time DESC; IF FOUND @@ -58,34 +57,34 @@ THEN -- Refuse to insert older decision. RETURN; END IF; - UPDATE exchange.aml_status - SET threshold_val=in_new_threshold_val - ,threshold_frac=in_new_threshold_frac + UPDATE aml_status + SET threshold=in_new_threshold ,status=in_new_status ,kyc_requirement=in_requirement_row WHERE h_payto=in_h_payto; ASSERT FOUND, 'cannot have AML decision history but no AML status'; ELSE out_last_date = 0; - INSERT INTO exchange.aml_status + INSERT INTO aml_status (h_payto - ,threshold_val - ,threshold_frac + ,threshold ,status ,kyc_requirement) VALUES (in_h_payto - ,in_new_threshold_val - ,in_new_threshold_frac + ,in_new_threshold ,in_new_status - ,in_requirement_row); + ,in_requirement_row) + ON CONFLICT (h_payto) DO + UPDATE SET + threshold=in_new_threshold + ,status=in_new_status; END IF; -INSERT INTO exchange.aml_history +INSERT INTO aml_history (h_payto - ,new_threshold_val - ,new_threshold_frac + ,new_threshold ,new_status ,decision_time ,justification @@ -95,8 +94,7 @@ INSERT INTO exchange.aml_history ,decider_sig ) VALUES (in_h_payto - ,in_new_threshold_val - ,in_new_threshold_frac + ,in_new_threshold ,in_new_status ,in_decision_time ,in_justification @@ -125,5 +123,5 @@ END IF; END $$; -COMMENT ON FUNCTION exchange_do_insert_aml_decision(BYTEA, INT8, INT4, INT4, INT8, VARCHAR, BYTEA, BYTEA, VARCHAR, VARCHAR, INT8) +COMMENT ON FUNCTION exchange_do_insert_aml_decision(BYTEA, taler_amount, INT4, INT8, TEXT, BYTEA, BYTEA, TEXT, TEXT, INT8) IS 'Checks whether the AML officer is eligible to make AML decisions and if so inserts the decision into the table'; |