exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 81f1f4c80627eb28228be42cb051d60ce8bb9394
parent b6170cddc897c2ea6b2b4aa1278d14fe0a96520a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed,  1 Apr 2026 15:47:22 +0200

IBAN-sharing fix for KYC check on deposit, to be cherry-picked for v1.5.x

Diffstat:
Msrc/exchangedb/exchange_do_get_kyc_rules.sql | 59+++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/src/exchangedb/exchange_do_get_kyc_rules.sql b/src/exchangedb/exchange_do_get_kyc_rules.sql @@ -16,7 +16,7 @@ DROP FUNCTION IF EXISTS exchange_do_get_kyc_rules; CREATE FUNCTION exchange_do_get_kyc_rules( - IN in_h_payto BYTEA, + IN in_h_normalized_payto BYTEA, IN in_now INT8, IN in_merchant_pub BYTEA, -- possibly NULL OUT out_target_pub BYTEA, -- possibly NULL @@ -28,31 +28,51 @@ AS $$ DECLARE my_found BOOL; BEGIN + my_found = FALSE; IF in_merchant_pub IS NOT NULL THEN - PERFORM FROM reserves_in - WHERE reserve_pub=in_merchant_pub - AND wire_source_h_payto IN - (SELECT wire_target_h_payto - FROM wire_targets - WHERE h_normalized_payto = in_h_payto); - my_found = FOUND; - ELSE - my_found = FALSE; + -- We were given an in_account_pub, but it did not match the + -- target pub. + -- Try to see if the in_account_pub appears in ANY reserve_in + -- or kyc_auths_in for this account instead. + PERFORM + FROM reserves_in ri + JOIN wire_targets wt + ON (ri.wire_source_h_payto = wt.wire_target_h_payto) + WHERE ri.reserve_pub=in_merchant_pub + AND wt.h_normalized_payto=in_h_normalized_payto; + IF FOUND + THEN + -- Found match in reserves, use it! + out_reserve_pub = in_merchant_pub; + my_found = TRUE; + ELSE + -- Check KYC Auths inputs + PERFORM + FROM kycauths_in ki + JOIN wire_targets wt + ON (ki.wire_source_h_payto = wt.wire_target_h_payto) + WHERE ki.account_pub=in_merchant_pub + AND wt.h_normalized_payto=in_h_normalized_payto; + IF FOUND + THEN + out_reserve_pub = in_merchant_pub; + my_found = TRUE; + END IF; + END IF; END IF; - IF FOUND + + IF NOT my_found THEN - -- The merchant_pub used by the client matches, use that - out_reserve_pub = in_merchant_pub; - ELSE + -- Neither matches. Pick out_reserves_pub from reserves_in. -- If multiple reserves_in match, we pick the latest one SELECT reserve_pub INTO out_reserve_pub FROM reserves_in WHERE wire_source_h_payto IN - (SELECT wire_target_h_payto - FROM wire_targets - WHERE h_normalized_payto = in_h_payto) + (SELECT wire_target_h_payto + FROM wire_targets + WHERE h_normalized_payto = in_h_normalized_payto) ORDER BY execution_date DESC LIMIT 1; END IF; @@ -60,17 +80,16 @@ BEGIN SELECT target_pub INTO out_target_pub FROM kyc_targets - WHERE h_normalized_payto = in_h_payto; + WHERE h_normalized_payto = in_h_normalized_payto; SELECT jnew_rules INTO out_jnew_rules FROM legitimization_outcomes - WHERE h_payto = in_h_payto + WHERE h_payto = in_h_normalized_payto AND COALESCE(expiration_time >= $2, TRUE) AND COALESCE(is_active, TRUE) -- technically only one should ever be active, but we can be conservative ORDER BY expiration_time DESC LIMIT 1; - END $$;