taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit 05872bb741059baae683557ab98d6a9d5e4515d9
parent 12bfddf05e550922e56122eb46891e6dea54eef4
Author: Antoine A <>
Date:   Mon,  6 Jan 2025 10:39:42 +0100

taler-api: better polymorphism schema

Diffstat:
Mtaler-api/tests/common/db.rs | 12+++++-------
Mtaler-api/tests/schema.sql | 75++++++++++++++++++++++++---------------------------------------------------
Mtaler-common/benches/base32.rs | 2+-
Mtaler-common/src/types/base32.rs | 2+-
4 files changed, 31 insertions(+), 60 deletions(-)

diff --git a/taler-api/tests/common/db.rs b/taler-api/tests/common/db.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2024 Taler Systems SA + Copyright (C) 2024-2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -271,9 +271,7 @@ pub async fn incoming_page( (amount).frac as amount_frac, creation_time, debit_payto, - reserve_pub, - account_pub, - wad_id, + metadata, origin_exchange_url FROM incoming_transactions WHERE ", @@ -287,14 +285,14 @@ pub async fn incoming_page( date: r.try_get_timestamp("creation_time")?, amount: r.try_get_amount("amount", currency)?, debit_account: r.try_get_payto("debit_payto")?, - reserve_pub: r.try_get_base32("reserve_pub")?, + reserve_pub: r.try_get_base32("metadata")?, }, IncomingType::kyc => IncomingBankTransaction::Kyc { row_id: r.try_get_safeu64("incoming_transaction_id")?, date: r.try_get_timestamp("creation_time")?, amount: r.try_get_amount("amount", currency)?, debit_account: r.try_get_payto("debit_payto")?, - account_pub: r.try_get_base32("account_pub")?, + account_pub: r.try_get_base32("metadata")?, }, IncomingType::wad => IncomingBankTransaction::Wad { row_id: r.try_get_safeu64("incoming_transaction_id")?, @@ -302,7 +300,7 @@ pub async fn incoming_page( amount: r.try_get_amount("amount", currency)?, debit_account: r.try_get_payto("debit_payto")?, origin_exchange_url: r.try_get_url("origin_exchange_url")?, - wad_id: r.try_get_base32("wa_id")?, + wad_id: r.try_get_base32("metadata")?, }, }) }, diff --git a/taler-api/tests/schema.sql b/taler-api/tests/schema.sql @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2024 Taler Systems SA +-- Copyright (C) 2024-2025 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 @@ -50,18 +50,17 @@ CREATE TABLE incoming_transactions ( ,debit_payto TEXT NOT NULL ,creation_time INT8 NOT NULL ,type incoming_type NOT NULL - ,reserve_pub BYTEA UNIQUE CHECK (LENGTH(reserve_pub)=32) - ,account_pub BYTEA CHECK (LENGTH(account_pub)=32) - ,wad_id BYTEA CHECK (LENGTH(wad_id)=24) + ,metadata BYTEA NOT NULL ,origin_exchange_url TEXT - ,CONSTRAINT incoming_polymorphism CHECK( + ,CONSTRAINT polymorphism CHECK( CASE type - WHEN 'reserve' THEN reserve_pub IS NOT NULL AND account_pub IS NULL AND origin_exchange_url IS NULL AND wad_id IS NULL - WHEN 'kyc' THEN reserve_pub IS NULL AND account_pub IS NOT NULL AND origin_exchange_url IS NULL AND wad_id IS NULL - WHEN 'wad' THEN reserve_pub IS NULL AND account_pub IS NULL AND origin_exchange_url IS NOT NULL AND wad_id IS NOT NULL + WHEN 'wad' THEN LENGTH(metadata)=24 AND origin_exchange_url IS NOT NULL + ELSE LENGTH(metadata)=32 AND origin_exchange_url IS NULL END - ) + ) ); + +CREATE UNIQUE INDEX incoming_transactions_unique_reserve_pub ON incoming_transactions (metadata) WHERE type = 'reserve'; CREATE FUNCTION taler_transfer( IN in_amount taler_amount, @@ -135,53 +134,27 @@ CREATE FUNCTION add_incoming( LANGUAGE plpgsql AS $$ BEGIN -- Check conflict -SELECT in_type = 'reserve'::incoming_type AND EXISTS(SELECT FROM incoming_transactions WHERE reserve_pub = in_key) +SELECT in_type = 'reserve'::incoming_type AND EXISTS(SELECT FROM incoming_transactions WHERE metadata = in_key AND type = 'reserve') INTO out_reserve_pub_reuse; IF out_reserve_pub_reuse THEN RETURN; END IF; -- Register incoming transaction -CASE in_type - WHEN 'reserve' THEN INSERT INTO incoming_transactions ( - amount, - debit_payto, - creation_time, - type, - reserve_pub, - account_pub, - wad_id, - origin_exchange_url - ) VALUES ( - in_amount, - in_debit_payto, - in_timestamp, - in_type, - in_key, - NULL, - NULL, - NULL - ) RETURNING incoming_transaction_id INTO out_tx_row_id; - WHEN 'kyc' THEN INSERT INTO incoming_transactions ( - amount, - debit_payto, - creation_time, - type, - reserve_pub, - account_pub, - wad_id, - origin_exchange_url - ) VALUES ( - in_amount, - in_debit_payto, - in_timestamp, - in_type, - NULL, - in_key, - NULL, - NULL - ) RETURNING incoming_transaction_id INTO out_tx_row_id; - ELSE RAISE EXCEPTION 'Unsupported incoming type %', in_type; -END CASE; +INSERT INTO incoming_transactions ( + amount, + debit_payto, + creation_time, + type, + metadata, + origin_exchange_url +) VALUES ( + in_amount, + in_debit_payto, + in_timestamp, + in_type, + in_key, + NULL +) RETURNING incoming_transaction_id INTO out_tx_row_id; -- Notify new incoming transaction PERFORM pg_notify('incoming_tx', out_tx_row_id || ''); END $$; diff --git a/taler-common/benches/base32.rs b/taler-common/benches/base32.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2025 Taler Systems SA + Copyright (C) 2024-2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software diff --git a/taler-common/src/types/base32.rs b/taler-common/src/types/base32.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2025 Taler Systems SA + Copyright (C) 2024-2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software