taler-rust

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

taler-api-0001.sql (3837B)


      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 TABLE tx_in (
     25   tx_in_id INT8 PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
     26   amount taler_amount NOT NULL,
     27   subject TEXT NOT NULL,
     28   debit_payto TEXT NOT NULL,
     29   created_at INT8 NOT NULL
     30 );
     31 COMMENT ON TABLE tx_in IS 'Incoming transactions';
     32 
     33 CREATE TABLE tx_out (
     34   tx_out_id INT8 PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
     35   amount taler_amount NOT NULL,
     36   subject TEXT NOT NULL,
     37   credit_payto TEXT NOT NULL,
     38   created_at INT8 NOT NULL
     39 );
     40 COMMENT ON TABLE tx_out IS 'Outgoing transactions';
     41 
     42 CREATE TYPE incoming_type AS ENUM
     43   ('reserve' ,'kyc', 'map');
     44 COMMENT ON TYPE incoming_type IS 'Types of incoming talerable transactions';
     45 
     46 CREATE TABLE taler_in (
     47   tx_in_id INT8 PRIMARY KEY REFERENCES tx_in(tx_in_id) ON DELETE CASCADE,
     48   type incoming_type NOT NULL,
     49   account_pub BYTEA NOT NULL CHECK (LENGTH(account_pub)=32),
     50   authorization_pub BYTEA CHECK (LENGTH(authorization_pub)=32),
     51   authorization_sig BYTEA CHECK (LENGTH(authorization_sig)=64)
     52 );
     53 COMMENT ON TABLE tx_in IS 'Incoming talerable transactions';
     54 
     55 CREATE UNIQUE INDEX taler_in_unique_reserve_pub ON taler_in (account_pub) WHERE type = 'reserve';
     56 
     57 CREATE TYPE transfer_status AS ENUM (
     58    'pending'
     59   ,'transient_failure'
     60   ,'permanent_failure'
     61   ,'success'
     62 );
     63 COMMENT ON TYPE transfer_status IS 'Status of a Wire Gateway transfer';
     64 
     65 CREATE TABLE transfer (
     66   transfer_id INT8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
     67   tx_out_id INT8 NOT NULL UNIQUE REFERENCES tx_out(tx_out_id) ON DELETE CASCADE,
     68   request_uid BYTEA UNIQUE NOT NULL CHECK (LENGTH(request_uid)=64),
     69   wtid BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid)=32),
     70   exchange_base_url TEXT NOT NULL,
     71   metadata TEXT,
     72   status transfer_status NOT NULL,
     73   status_msg TEXT
     74 );
     75 COMMENT ON TABLE transfer IS 'Wire Gateway transfers';
     76 
     77 CREATE TABLE bounced(
     78   tx_in_id INT8 NOT NULL UNIQUE REFERENCES tx_in(tx_in_id) ON DELETE CASCADE
     79 );
     80 COMMENT ON TABLE tx_in IS 'Bounced transaction';
     81 
     82 CREATE TABLE prepared_in (
     83   type incoming_type NOT NULL,
     84   account_pub BYTEA NOT NULL CHECK (LENGTH(account_pub)=32),
     85   authorization_pub BYTEA UNIQUE NOT NULL CHECK (LENGTH(authorization_pub)=32),
     86   authorization_sig BYTEA NOT NULL CHECK (LENGTH(authorization_sig)=64),
     87   recurrent BOOLEAN NOT NULL,
     88   registered_at INT8 NOT NULL,
     89   tx_in_id INT8 UNIQUE REFERENCES tx_in(tx_in_id) ON DELETE CASCADE
     90 );
     91 COMMENT ON TABLE prepared_in IS 'Prepared incoming transaction';
     92 CREATE UNIQUE INDEX prepared_in_unique_reserve_pub 
     93   ON prepared_in (account_pub) WHERE type = 'reserve';
     94 
     95 CREATE TABLE pending_recurrent_in(
     96   tx_in_id INT8 NOT NULL UNIQUE REFERENCES tx_in(tx_in_id) ON DELETE CASCADE,
     97   authorization_pub BYTEA NOT NULL REFERENCES prepared_in(authorization_pub)
     98 );
     99 CREATE INDEX pending_recurrent_inc_auth_pub
    100   ON pending_recurrent_in (authorization_pub);
    101 COMMENT ON TABLE pending_recurrent_in IS 'Pending recurrent incoming transaction';
    102