taler-rust

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

taler-api-0001.sql (2399B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2024-2025 Taler Systems SA
      4 --
      5 -- TALER is free software; you can redistribute it and/or modify it under the
      6 -- terms of the GNU General Public License as published by the Free Software
      7 -- Foundation; either version 3, or (at your option) any later version.
      8 --
      9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11 -- A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 --
     13 -- You should have received a copy of the GNU General Public License along with
     14 -- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 
     16 SELECT _v.register_patch('taler-api-0001', NULL, NULL);
     17 
     18 CREATE SCHEMA taler_api;
     19 SET search_path TO taler_api;
     20 
     21 CREATE TYPE taler_amount AS (val INT8, frac INT4);
     22 COMMENT ON TYPE taler_amount IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
     23 
     24 CREATE TYPE incoming_type AS ENUM
     25   ('reserve' ,'kyc', 'wad');
     26 COMMENT ON TYPE incoming_type IS 'Types of incoming talerable transactions';
     27 CREATE TABLE tx_in (
     28   tx_in_id INT8 PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
     29   amount taler_amount NOT NULL,
     30   subject TEXT NOT NULL,
     31   debit_payto TEXT NOT NULL,
     32   type incoming_type NOT NULL,
     33   metadata BYTEA NOT NULL,
     34   origin_exchange_url TEXT,
     35   created_at INT8 NOT NULL,
     36   CONSTRAINT polymorphism CHECK(
     37     CASE type
     38       WHEN 'wad' THEN LENGTH(metadata)=24 AND origin_exchange_url IS NOT NULL
     39       ELSE LENGTH(metadata)=32 AND origin_exchange_url IS NULL
     40     END
     41   )
     42 );
     43 CREATE UNIQUE INDEX tx_in_unique_reserve_pub ON tx_in (metadata) WHERE type = 'reserve';
     44 COMMENT ON TABLE tx_in IS 'Incoming transactions';
     45 
     46 CREATE TYPE transfer_status AS ENUM (
     47    'pending'
     48   ,'transient_failure'
     49   ,'permanent_failure'
     50   ,'success'
     51 );
     52 COMMENT ON TYPE transfer_status IS 'Status of a Wire Gateway transfer';
     53 
     54 CREATE TABLE transfer (
     55   transfer_id INT8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
     56   request_uid BYTEA UNIQUE NOT NULL CHECK (LENGTH(request_uid)=64),
     57   amount taler_amount NOT NULL,
     58   subject TEXT NOT NULL,
     59   credit_payto TEXT NOT NULL,
     60   wtid BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid)=32),
     61   exchange_base_url TEXT NOT NULL,
     62   status transfer_status NOT NULL,
     63   status_msg TEXT,
     64   created_at INT8 NOT NULL
     65 );
     66 COMMENT ON TABLE transfer IS 'Wire Gateway transfers';