depolymerizer-bitcoin-0001.sql (2461B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 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('depolymerizer-bitcoin-0001', NULL, NULL); 17 18 CREATE SCHEMA depolymerizer_bitcoin; 19 SET search_path TO depolymerizer_bitcoin; 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 debit_status AS ENUM( 25 'requested', 26 'sent' 27 ); 28 COMMENT ON TYPE debit_status IS 'Status of an outgoing transaction'; 29 30 CREATE TYPE bounce_status AS ENUM( 31 'requested', 32 'ignored', 33 'sent' 34 ); 35 COMMENT ON TYPE bounce_status IS 'Status of a bounce'; 36 37 CREATE TABLE state ( 38 name TEXT NOT NULL PRIMARY KEY, 39 value BYTEA NOT NULL 40 ); 41 COMMENT ON TABLE state IS 'Key value state'; 42 43 CREATE TABLE tx_in ( 44 id INT8 PRIMARY KEY GENERATED ALWAYS AS IDENTITY, 45 received INT8 NOT NULL, 46 amount taler_amount NOT NULL, 47 reserve_pub BYTEA NOT NULL UNIQUE CHECK (LENGTH(reserve_pub)=32), 48 debit_acc TEXT NOT NULL, 49 txid BYTEA UNIQUE CHECK (LENGTH(txid)=32) 50 ); 51 COMMENT ON TABLE state IS 'Incoming transactions'; 52 53 CREATE TABLE tx_out ( 54 id INT8 PRIMARY KEY GENERATED ALWAYS AS IDENTITY, 55 created INT8 NOT NULL, 56 amount taler_amount NOT NULL, 57 wtid BYTEA NOT NULL UNIQUE CHECK (LENGTH(wtid)=32), 58 credit_acc TEXT NOT NULL, 59 credit_name TEXT, 60 exchange_url TEXT NOT NULL, 61 request_uid BYTEA UNIQUE CHECK (LENGTH(request_uid)=64), 62 status debit_status NOT NULL, 63 txid BYTEA UNIQUE CHECK (LENGTH(txid)=32) 64 ); 65 COMMENT ON TABLE state IS 'Outgoing transactions'; 66 67 CREATE TABLE bounce ( 68 id INT8 PRIMARY KEY GENERATED ALWAYS AS IDENTITY, 69 bounced BYTEA UNIQUE NOT NULL, 70 txid BYTEA UNIQUE CHECK (LENGTH(txid)=32), 71 created INT8 NOT NULL, 72 reason TEXT, 73 status bounce_status NOT NULL 74 ); 75 COMMENT ON TABLE state IS 'Bounced incoming transactions';