aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-17 03:11:25 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-17 03:11:25 +0100
commit4b16198b43ccb63a7efc2c170622a69759f8ed8f (patch)
treecae317c37426258766fa1817f96a465d20277d49 /src
parent097e968e1d03b0e0ae00738219a52f81b4a405b5 (diff)
moved SQL elimination
Diffstat (limited to 'src')
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c221
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c308
2 files changed, 0 insertions, 529 deletions
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 30b036c9e..52488fd2c 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -189,227 +189,6 @@ static int
postgres_create_tables (void *cls)
{
struct PostgresClosure *pc = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- /* Table with list of exchanges we are auditing */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_exchanges"
- "(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)"
- ",exchange_url VARCHAR NOT NULL"
- ")"),
- /* Table with list of signing keys of exchanges we are auditing */
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_exchange_signkeys"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",ep_start INT8 NOT NULL"
- ",ep_expire INT8 NOT NULL"
- ",ep_end INT8 NOT NULL"
- ",exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)"
- ",master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)"
- ")"),
- /* Table with all of the denomination keys that the auditor
- is aware of. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_denominations"
- "(denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)"
- ",master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",valid_from INT8 NOT NULL"
- ",expire_withdraw INT8 NOT NULL"
- ",expire_deposit INT8 NOT NULL"
- ",expire_legal INT8 NOT NULL"
- ",coin_val INT8 NOT NULL" /* value of this denom */
- ",coin_frac INT4 NOT NULL" /* fractional value of this denom */
- ",fee_withdraw_val INT8 NOT NULL"
- ",fee_withdraw_frac INT4 NOT NULL"
- ",fee_deposit_val INT8 NOT NULL"
- ",fee_deposit_frac INT4 NOT NULL"
- ",fee_refresh_val INT8 NOT NULL"
- ",fee_refresh_frac INT4 NOT NULL"
- ",fee_refund_val INT8 NOT NULL"
- ",fee_refund_frac INT4 NOT NULL"
- ")"),
- /* Table indicating up to which transactions the auditor has
- processed the exchange database. Used for SELECTing the
- statements to process. The indices below include the last
- serial ID from the respective tables that we have
- processed. Thus, we need to select those table entries that are
- strictly larger (and process in monotonically increasing
- order). */GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_progress_reserve"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",last_reserve_in_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_reserve_out_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_reserve_payback_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_reserve_close_serial_id INT8 NOT NULL DEFAULT 0"
- ")"),
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_progress_aggregation"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",last_wire_out_serial_id INT8 NOT NULL DEFAULT 0"
- ")"),
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_progress_deposit_confirmation"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",last_deposit_confirmation_serial_id INT8 NOT NULL DEFAULT 0"
- ")"),
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_progress_coin"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",last_withdraw_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_deposit_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_melt_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_refund_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_payback_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_payback_refresh_serial_id INT8 NOT NULL DEFAULT 0"
- ")"),
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS wire_auditor_account_progress"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",account_name TEXT NOT NULL"
- ",last_wire_reserve_in_serial_id INT8 NOT NULL DEFAULT 0"
- ",last_wire_wire_out_serial_id INT8 NOT NULL DEFAULT 0"
- ",wire_in_off INT8"
- ",wire_out_off INT8"
- ")"),
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS wire_auditor_progress"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",last_timestamp INT8 NOT NULL"
- ",last_reserve_close_uuid INT8 NOT NULL"
- ")"),
- /* Table with all of the customer reserves and their respective
- balances that the auditor is aware of.
- "last_reserve_out_serial_id" marks the last withdrawal from
- "reserves_out" about this reserve that the auditor is aware of,
- and "last_reserve_in_serial_id" is the last "reserve_in"
- operation about this reserve that the auditor is aware of. */GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_reserves"
- "(reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)"
- ",master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",reserve_balance_val INT8 NOT NULL"
- ",reserve_balance_frac INT4 NOT NULL"
- ",withdraw_fee_balance_val INT8 NOT NULL"
- ",withdraw_fee_balance_frac INT4 NOT NULL"
- ",expiration_date INT8 NOT NULL"
- ",auditor_reserves_rowid BIGSERIAL UNIQUE"
- ",origin_account TEXT"
- ")"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX auditor_reserves_by_reserve_pub "
- "ON auditor_reserves(reserve_pub)"),
- /* Table with the sum of the balances of all customer reserves
- (by exchange's master public key) */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_reserve_balance"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",reserve_balance_val INT8 NOT NULL"
- ",reserve_balance_frac INT4 NOT NULL"
- ",withdraw_fee_balance_val INT8 NOT NULL"
- ",withdraw_fee_balance_frac INT4 NOT NULL"
- ")"),
- /* Table with the sum of the balances of all wire fees
- (by exchange's master public key) */
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_wire_fee_balance"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",wire_fee_balance_val INT8 NOT NULL"
- ",wire_fee_balance_frac INT4 NOT NULL"
- ")"),
- /* Table with all of the outstanding denomination coins that the
- exchange is aware of and what the respective balances are
- (outstanding as well as issued overall which implies the
- maximum value at risk). We also count the number of coins
- issued (withdraw, refresh-reveal) and the number of coins seen
- at the exchange (refresh-commit, deposit), not just the amounts. */GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_denomination_pending"
- "(denom_pub_hash BYTEA PRIMARY KEY"
- " REFERENCES auditor_denominations (denom_pub_hash) ON DELETE CASCADE"
- ",denom_balance_val INT8 NOT NULL"
- ",denom_balance_frac INT4 NOT NULL"
- ",denom_loss_val INT8 NOT NULL"
- ",denom_loss_frac INT4 NOT NULL"
- ",num_issued INT8 NOT NULL"
- ",denom_risk_val INT8 NOT NULL"
- ",denom_risk_frac INT4 NOT NULL"
- ",payback_loss_val INT8 NOT NULL"
- ",payback_loss_frac INT4 NOT NULL"
- ")"),
- /* Table with the sum of the outstanding coins from
- "auditor_denomination_pending" (denom_pubs must belong to the
- respective's exchange's master public key); it represents the
- auditor_balance_summary of the exchange at this point (modulo
- unexpected historic_loss-style events where denomination keys are
- compromised) */GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_balance_summary"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",denom_balance_val INT8 NOT NULL"
- ",denom_balance_frac INT4 NOT NULL"
- ",deposit_fee_balance_val INT8 NOT NULL"
- ",deposit_fee_balance_frac INT4 NOT NULL"
- ",melt_fee_balance_val INT8 NOT NULL"
- ",melt_fee_balance_frac INT4 NOT NULL"
- ",refund_fee_balance_val INT8 NOT NULL"
- ",refund_fee_balance_frac INT4 NOT NULL"
- ",risk_val INT8 NOT NULL"
- ",risk_frac INT4 NOT NULL"
- ",loss_val INT8 NOT NULL"
- ",loss_frac INT4 NOT NULL"
- ")"),
- /* Table with historic profits; basically, when a denom_pub has
- expired and everything associated with it is garbage collected,
- the final profits end up in here; note that the "denom_pub" here
- is not a foreign key, we just keep it as a reference point.
- "revenue_balance" is the sum of all of the profits we made on the
- coin except for withdraw fees (which are in
- historic_reserve_revenue); the deposit, melt and refund fees are given
- individually; the delta to the revenue_balance is from coins that
- were withdrawn but never deposited prior to expiration. */GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_historic_denomination_revenue"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)"
- ",revenue_timestamp INT8 NOT NULL"
- ",revenue_balance_val INT8 NOT NULL"
- ",revenue_balance_frac INT4 NOT NULL"
- ",loss_balance_val INT8 NOT NULL"
- ",loss_balance_frac INT4 NOT NULL"
- ")"),
- /* Table with historic profits from reserves; we eventually
- GC "auditor_historic_reserve_revenue", and then store the totals
- in here (by time intervals). */
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_historic_reserve_summary"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",start_date INT8 NOT NULL"
- ",end_date INT8 NOT NULL"
- ",reserve_profits_val INT8 NOT NULL"
- ",reserve_profits_frac INT4 NOT NULL"
- ")"),
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX auditor_historic_reserve_summary_by_master_pub_start_date "
- "ON auditor_historic_reserve_summary(master_pub,start_date)"),
-
- /* Table with deposit confirmation sent to us by merchants;
- we must check that the exchange reported these properly. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS deposit_confirmations "
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",serial_id BIGSERIAL UNIQUE"
- ",h_contract_terms BYTEA CHECK (LENGTH(h_contract_terms)=64)"
- ",h_wire BYTEA CHECK (LENGTH(h_wire)=64)"
- ",timestamp INT8 NOT NULL"
- ",refund_deadline INT8 NOT NULL"
- ",amount_without_fee_val INT8 NOT NULL"
- ",amount_without_fee_frac INT4 NOT NULL"
- ",coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)"
- ",merchant_pub BYTEA CHECK (LENGTH(merchant_pub)=32)"
- ",exchange_sig BYTEA CHECK (LENGTH(exchange_sig)=64)"
- ",exchange_pub BYTEA CHECK (LENGTH(exchange_pub)=32)"
- ",master_sig BYTEA CHECK (LENGTH(master_sig)=64)"
- ",PRIMARY KEY (h_contract_terms, h_wire, coin_pub, "
- " merchant_pub, exchange_sig, exchange_pub, master_sig)"
- ")"),
- /* Table with the sum of the ledger, auditor_historic_revenue and
- the auditor_reserve_balance. This is the
- final amount that the exchange should have in its bank account
- right now. */
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS auditor_predicted_result"
- "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
- ",balance_val INT8 NOT NULL"
- ",balance_frac INT4 NOT NULL"
- ")"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
struct GNUNET_PQ_Context *conn;
conn = GNUNET_PQ_connect (pc->connection_cfg_str,
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index e144342f4..afdebf927 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -197,314 +197,6 @@ static int
postgres_create_tables (void *cls)
{
struct PostgresClosure *pc = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- /* Denomination table for holding the publicly available information of
- denominations keys. The denominations are to be referred to using
- foreign keys. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS denominations"
- "(denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)"
- ",denom_pub BYTEA NOT NULL"
- ",master_pub BYTEA NOT NULL CHECK (LENGTH(master_pub)=32)"
- ",master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)"
- ",valid_from INT8 NOT NULL"
- ",expire_withdraw INT8 NOT NULL"
- ",expire_deposit INT8 NOT NULL"
- ",expire_legal INT8 NOT NULL"
- ",coin_val INT8 NOT NULL" /* value of this denom */
- ",coin_frac INT4 NOT NULL" /* fractional value of this denom */
- ",fee_withdraw_val INT8 NOT NULL"
- ",fee_withdraw_frac INT4 NOT NULL"
- ",fee_deposit_val INT8 NOT NULL"
- ",fee_deposit_frac INT4 NOT NULL"
- ",fee_refresh_val INT8 NOT NULL"
- ",fee_refresh_frac INT4 NOT NULL"
- ",fee_refund_val INT8 NOT NULL"
- ",fee_refund_frac INT4 NOT NULL"
- ")"),
- /* index for gc_denominations */
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX denominations_expire_legal_index ON "
- "denominations (expire_legal);"),
-
- /* denomination_revocations table is for remembering which denomination keys have been revoked */
- GNUNET_PQ_make_execute (
- "CREATE TABLE IF NOT EXISTS denomination_revocations"
- "(denom_revocations_serial_id BIGSERIAL UNIQUE"
- ",denom_pub_hash BYTEA PRIMARY KEY REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE"
- ",master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)"
- ");"),
- /* reserves table is for summarization of a reserve. It is updated when new
- funds are added and existing funds are withdrawn. The 'expiration_date'
- can be used to eventually get rid of reserves that have not been used
- for a very long time (either by refunding the owner or by greedily
- grabbing the money, depending on the Exchange's terms of service) */GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS reserves"
- "(reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)"
- ",account_details TEXT NOT NULL "
- ",current_balance_val INT8 NOT NULL"
- ",current_balance_frac INT4 NOT NULL"
- ",expiration_date INT8 NOT NULL"
- ",gc_date INT8 NOT NULL"
- ");"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_reserve_pub_index ON "
- "reserves (reserve_pub);"),
- /* index for get_expired_reserves */
- GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_expiration_index"
- " ON reserves (expiration_date,current_balance_val,current_balance_frac);"),
- /* index for reserve GC operations */
- GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_gc_index"
- " ON reserves (gc_date);"),
- /* reserves_in table collects the transactions which transfer funds
- into the reserve. The rows of this table correspond to each
- incoming transaction. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS reserves_in"
- "(reserve_in_serial_id BIGSERIAL UNIQUE"
- ",reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
- ",wire_reference INT8 NOT NULL"
- ",credit_val INT8 NOT NULL"
- ",credit_frac INT4 NOT NULL"
- ",sender_account_details TEXT NOT NULL"
- ",exchange_account_section TEXT NOT NULL"
- ",execution_date INT8 NOT NULL"
- ",PRIMARY KEY (reserve_pub, wire_reference)"
- ");"),
- /* Create indices on reserves_in */
- GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_in_execution_index"
- " ON reserves_in (exchange_account_section,execution_date);"),
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX reserves_in_exchange_account_serial"
- " ON reserves_in (exchange_account_section,reserve_in_serial_id DESC);"),
-
- /* This table contains the data for wire transfers the exchange has
- executed to close a reserve. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS reserves_close "
- "(close_uuid BIGSERIAL PRIMARY KEY"
- ",reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
- ",execution_date INT8 NOT NULL"
- ",wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32)"
- ",receiver_account TEXT NOT NULL"
- ",amount_val INT8 NOT NULL"
- ",amount_frac INT4 NOT NULL"
- ",closing_fee_val INT8 NOT NULL"
- ",closing_fee_frac INT4 NOT NULL"
- ");"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_close_by_reserve "
- "ON reserves_close(reserve_pub)"),
- /* Table with the withdraw operations that have been performed on a reserve.
- The 'h_blind_ev' is the hash of the blinded coin. It serves as a primary
- key, as (broken) clients that use a non-random coin and blinding factor
- should fail to even withdraw, as otherwise the coins will fail to deposit
- (as they really must be unique). */GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS reserves_out"
- "(reserve_out_serial_id BIGSERIAL UNIQUE"
- ",h_blind_ev BYTEA PRIMARY KEY CHECK (LENGTH(h_blind_ev)=64)"
- ",denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash)" /* do NOT CASCADE on DELETE, we may keep the denomination key alive! */
- ",denom_sig BYTEA NOT NULL"
- ",reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
- ",reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)"
- ",execution_date INT8 NOT NULL"
- ",amount_with_fee_val INT8 NOT NULL"
- ",amount_with_fee_frac INT4 NOT NULL"
- ");"),
- /* Index blindcoins(reserve_pub) for get_reserves_out statement */
- GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_out_reserve_pub_index ON"
- " reserves_out (reserve_pub)"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_out_execution_date ON "
- "reserves_out (execution_date)"),
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX reserves_out_for_get_withdraw_info ON "
- "reserves_out (denom_pub_hash,h_blind_ev)"),
- /* Table with coins that have been (partially) spent, used to track
- coin information only once. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS known_coins "
- "(coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32)"
- ",denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE"
- ",denom_sig BYTEA NOT NULL"
- ");"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX known_coins_by_denomination ON "
- "known_coins (denom_pub_hash)"),
-
- /* Table with the commitments made when melting a coin. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS refresh_commitments "
- "(melt_serial_id BIGSERIAL UNIQUE"
- ",rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)"
- ",old_coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
- ",old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)"
- ",amount_with_fee_val INT8 NOT NULL"
- ",amount_with_fee_frac INT4 NOT NULL"
- ",noreveal_index INT4 NOT NULL"
- ");"),
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX refresh_commitments_old_coin_pub_index ON "
- "refresh_commitments (old_coin_pub);"),
-
- /* Table with the revelations about the new coins that are to be created
- during a melting session. Includes the session, the cut-and-choose
- index and the index of the new coin, and the envelope of the new
- coin to be signed, as well as the encrypted information about the
- private key and the blinding factor for the coin (for verification
- in case this newcoin_index is chosen to be revealed) */GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS refresh_revealed_coins "
- "(rc BYTEA NOT NULL REFERENCES refresh_commitments (rc) ON DELETE CASCADE"
- ",newcoin_index INT4 NOT NULL"
- ",link_sig BYTEA NOT NULL CHECK(LENGTH(link_sig)=64)"
- ",denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE"
- ",coin_ev BYTEA UNIQUE NOT NULL"
- ",h_coin_ev BYTEA NOT NULL CHECK(LENGTH(h_coin_ev)=64)"
- ",ev_sig BYTEA NOT NULL"
- ",PRIMARY KEY (rc, newcoin_index)"
- ",UNIQUE (h_coin_ev)"
- ");"),
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX refresh_revealed_coins_coin_pub_index ON "
- "refresh_revealed_coins (denom_pub_hash);"),
-
- /* Table with the transfer keys of a refresh operation; includes
- the rc for which this is the link information, the
- transfer public key (for gamma) and the revealed transfer private
- keys (array of TALER_CNC_KAPPA - 1 entries, with gamma being skipped) */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS refresh_transfer_keys "
- "(rc BYTEA NOT NULL PRIMARY KEY REFERENCES refresh_commitments (rc) ON DELETE CASCADE"
- ",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)"
- ",transfer_privs BYTEA NOT NULL"
- ");"),
- /* for "get_link" (not sure if this helps, as there should be very few
- transfer_pubs per rc, but at least in theory this helps the ORDER BY
- clause. */
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX refresh_transfer_keys_coin_tpub ON "
- "refresh_transfer_keys (rc,transfer_pub);"),
-
-
- /* This table contains the wire transfers the exchange is supposed to
- execute to transmit funds to the merchants (and manage refunds). */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS deposits "
- "(deposit_serial_id BIGSERIAL PRIMARY KEY"
- ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
- ",amount_with_fee_val INT8 NOT NULL"
- ",amount_with_fee_frac INT4 NOT NULL"
- ",timestamp INT8 NOT NULL"
- ",refund_deadline INT8 NOT NULL"
- ",wire_deadline INT8 NOT NULL"
- ",merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)"
- ",h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)"
- ",h_wire BYTEA NOT NULL CHECK (LENGTH(h_wire)=64)"
- ",coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)"
- ",wire TEXT NOT NULL"
- ",tiny BOOLEAN NOT NULL DEFAULT FALSE"
- ",done BOOLEAN NOT NULL DEFAULT FALSE"
- ",UNIQUE (coin_pub, merchant_pub, h_contract_terms)"
- ");"),
- /* Index for get_deposit_for_wtid and get_deposit_statement */
- GNUNET_PQ_make_try_execute (
- "CREATE INDEX deposits_coin_pub_merchant_contract_index "
- "ON deposits(coin_pub, merchant_pub, h_contract_terms)"),
- /* Index for deposits_get_ready */
- GNUNET_PQ_make_try_execute ("CREATE INDEX deposits_get_ready_index "
- "ON deposits(tiny,done,wire_deadline,refund_deadline)"),
- /* Index for deposits_iterate_matching */
- GNUNET_PQ_make_try_execute ("CREATE INDEX deposits_iterate_matching "
- "ON deposits(merchant_pub,h_wire,done,wire_deadline)"),
-
- /* Table with information about coins that have been refunded. (Technically
- one of the deposit operations that a coin was involved with is refunded.)*/
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS refunds "
- "(refund_serial_id BIGSERIAL UNIQUE"
- ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
- ",merchant_pub BYTEA NOT NULL CHECK(LENGTH(merchant_pub)=32)"
- ",merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)"
- ",h_contract_terms BYTEA NOT NULL CHECK(LENGTH(h_contract_terms)=64)"
- ",rtransaction_id INT8 NOT NULL"
- ",amount_with_fee_val INT8 NOT NULL"
- ",amount_with_fee_frac INT4 NOT NULL"
- ",PRIMARY KEY (coin_pub, merchant_pub, h_contract_terms, rtransaction_id)" /* this combo must be unique, and we usually select by coin_pub */
- ");"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX refunds_coin_pub_index "
- "ON refunds(coin_pub)"),
- /* This table contains the data for
- wire transfers the exchange has executed. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS wire_out "
- "(wireout_uuid BIGSERIAL PRIMARY KEY"
- ",execution_date INT8 NOT NULL"
- ",wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)="
- TALER_BANK_TRANSFER_IDENTIFIER_LEN_STR ")"
- ",wire_target TEXT NOT NULL"
- ",exchange_account_section TEXT NOT NULL"
- ",amount_val INT8 NOT NULL"
- ",amount_frac INT4 NOT NULL"
- ");"),
- /* Table for the tracking API, mapping from wire transfer identifiers
- to transactions and back */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS aggregation_tracking "
- "(aggregation_serial_id BIGSERIAL UNIQUE"
- ",deposit_serial_id INT8 PRIMARY KEY REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE"
- ",wtid_raw BYTEA CONSTRAINT wire_out_ref REFERENCES wire_out(wtid_raw) ON DELETE CASCADE DEFERRABLE"
- ");"),
- /* Index for lookup_transactions statement on wtid */
- GNUNET_PQ_make_try_execute ("CREATE INDEX aggregation_tracking_wtid_index "
- "ON aggregation_tracking(wtid_raw)"),
- /* Table for the wire fees. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS wire_fee "
- "(wire_method VARCHAR NOT NULL"
- ",start_date INT8 NOT NULL"
- ",end_date INT8 NOT NULL"
- ",wire_fee_val INT8 NOT NULL"
- ",wire_fee_frac INT4 NOT NULL"
- ",closing_fee_val INT8 NOT NULL"
- ",closing_fee_frac INT4 NOT NULL"
- ",master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)"
- ",PRIMARY KEY (wire_method, start_date)" /* this combo must be unique */
- ");"),
- /* Index for gc_wire_fee */
- GNUNET_PQ_make_try_execute ("CREATE INDEX wire_fee_gc_index "
- "ON wire_fee(end_date);"),
- /* Table for /payback information */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS payback "
- "(payback_uuid BIGSERIAL UNIQUE"
- ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub)" /* do NOT CASCADE on delete, we may keep the coin alive! */
- ",coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)"
- ",coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)"
- ",amount_val INT8 NOT NULL"
- ",amount_frac INT4 NOT NULL"
- ",timestamp INT8 NOT NULL"
- ",h_blind_ev BYTEA NOT NULL REFERENCES reserves_out (h_blind_ev) ON DELETE CASCADE"
- ");"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX payback_by_coin_index "
- "ON payback(coin_pub);"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX payback_by_h_blind_ev "
- "ON payback(h_blind_ev);"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX payback_for_by_reserve "
- "ON payback(coin_pub,h_blind_ev);"),
-
- /* Table for /payback-refresh information */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS payback_refresh "
- "(payback_refresh_uuid BIGSERIAL UNIQUE"
- ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub)" /* do NOT CASCADE on delete, we may keep the coin alive! */
- ",coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)"
- ",coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)"
- ",amount_val INT8 NOT NULL"
- ",amount_frac INT4 NOT NULL"
- ",timestamp INT8 NOT NULL"
- ",h_blind_ev BYTEA NOT NULL REFERENCES refresh_revealed_coins (h_coin_ev) ON DELETE CASCADE"
- ");"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX payback_refresh_by_coin_index "
- "ON payback_refresh(coin_pub);"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX payback_refresh_by_h_blind_ev "
- "ON payback_refresh(h_blind_ev);"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX payback_refresh_for_by_reserve "
- "ON payback_refresh(coin_pub,h_blind_ev);"),
-
- /* This table contains the pre-commit data for
- wire transfers the exchange is about to execute. */
- GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS prewire "
- "(prewire_uuid BIGSERIAL PRIMARY KEY"
- ",type TEXT NOT NULL"
- ",finished BOOLEAN NOT NULL DEFAULT false"
- ",buf BYTEA NOT NULL"
- ");"),
-
- /* Index for wire_prepare_data_get and gc_prewire statement */
- GNUNET_PQ_make_try_execute ("CREATE INDEX prepare_iteration_index "
- "ON prewire(finished);"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
struct GNUNET_PQ_Context *conn;
conn = GNUNET_PQ_connect (pc->connection_cfg_str,