aboutsummaryrefslogtreecommitdiff
path: root/src/mint/taler-mint-dbinit.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <sreeharsha@totakura.in>2015-03-05 16:05:06 +0100
committerSree Harsha Totakura <sreeharsha@totakura.in>2015-03-06 10:31:22 +0100
commit0acd5714e0ea48888e60d4caeeb37188a94e52b1 (patch)
tree9172d23b53b01ec71b1158ff79c0631d766c15b9 /src/mint/taler-mint-dbinit.c
parentb82a593dbbf5cf4332bd473e17421d230dbeeff8 (diff)
Move table creation logic to DB layer. Also support temporary schema creation for the sake of testing
Diffstat (limited to 'src/mint/taler-mint-dbinit.c')
-rw-r--r--src/mint/taler-mint-dbinit.c187
1 files changed, 1 insertions, 186 deletions
diff --git a/src/mint/taler-mint-dbinit.c b/src/mint/taler-mint-dbinit.c
index 7611802ea..c5b0ae4c3 100644
--- a/src/mint/taler-mint-dbinit.c
+++ b/src/mint/taler-mint-dbinit.c
@@ -36,192 +36,7 @@ static PGconn *db_conn;
static char *TALER_MINT_db_connection_cfg_str;
-static int
-TALER_MINT_init_withdraw_tables (PGconn *conn)
-{
- PGresult *result;
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS reserves"
- "("
- " reserve_pub BYTEA PRIMARY KEY"
- ",balance_value INT4 NOT NULL"
- ",balance_fraction INT4 NOT NULL"
- ",balance_currency VARCHAR(4) NOT NULL"
- ",status_sig BYTEA"
- ",status_sign_pub BYTEA"
- ",expiration_date INT8 NOT NULL"
- ")");
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS collectable_blindcoins"
- "("
- "blind_ev BYTEA PRIMARY KEY"
- ",blind_ev_sig BYTEA NOT NULL"
- ",denom_pub BYTEA NOT NULL"
- ",reserve_sig BYTEA NOT NULL"
- ",reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub)"
- ")");
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS known_coins "
- "("
- " coin_pub BYTEA NOT NULL PRIMARY KEY"
- ",denom_pub BYTEA NOT NULL"
- ",denom_sig BYTEA NOT NULL"
- ",expended_value INT4 NOT NULL"
- ",expended_fraction INT4 NOT NULL"
- ",expended_currency VARCHAR(4) NOT NULL"
- ",refresh_session_pub BYTEA"
- ")");
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS refresh_sessions "
- "("
- " session_pub BYTEA PRIMARY KEY CHECK (length(session_pub) = 32)"
- ",session_melt_sig BYTEA"
- ",session_commit_sig BYTEA"
- ",noreveal_index INT2 NOT NULL"
- // non-zero if all reveals were ok
- // and the new coin signatures are ready
- ",reveal_ok BOOLEAN NOT NULL DEFAULT false"
- ") ");
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS refresh_order "
- "( "
- " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub)"
- ",newcoin_index INT2 NOT NULL "
- ",denom_pub BYTEA NOT NULL "
- ",PRIMARY KEY (session_pub, newcoin_index)"
- ") ");
-
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS refresh_commit_link"
- "("
- " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub)"
- ",transfer_pub BYTEA NOT NULL"
- ",link_secret_enc BYTEA NOT NULL"
- // index of the old coin in the customer's request
- ",oldcoin_index INT2 NOT NULL"
- // index for cut and choose,
- // ranges from 0 to kappa-1
- ",cnc_index INT2 NOT NULL"
- ")");
-
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS refresh_commit_coin"
- "("
- " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) "
- ",link_vector_enc BYTEA NOT NULL"
- // index of the new coin in the customer's request
- ",newcoin_index INT2 NOT NULL"
- // index for cut and choose,
- ",cnc_index INT2 NOT NULL"
- ",coin_ev BYTEA NOT NULL"
- ")");
-
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS refresh_melt"
- "("
- " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) "
- ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) "
- ",denom_pub BYTEA NOT NULL "
- ",oldcoin_index INT2 NOT NULL"
- ")");
-
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS refresh_collectable"
- "("
- " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) "
- ",ev_sig BYTEA NOT NULL"
- ",newcoin_index INT2 NOT NULL"
- ")");
-
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- result = PQexec (conn,
- "CREATE TABLE IF NOT EXISTS deposits "
- "( "
- " coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (length(coin_pub)=32)"
- ",denom_pub BYTEA NOT NULL CHECK (length(denom_pub)=32)"
- ",transaction_id INT8 NOT NULL"
- ",amount_currency VARCHAR(4) NOT NULL"
- ",amount_value INT4 NOT NULL"
- ",amount_fraction INT4 NOT NULL"
- ",merchant_pub BYTEA NOT NULL"
- ",h_contract BYTEA NOT NULL CHECK (length(h_contract)=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"
- ")");
-
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- break_db_err (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
-
- return GNUNET_OK;
-}
/**
@@ -271,7 +86,7 @@ main (int argc, char *const *argv)
return 1;
}
- if (GNUNET_OK != TALER_MINT_init_withdraw_tables (db_conn))
+ if (GNUNET_OK != TALER_MINT_DB_create_tables (db_conn))
{
fprintf (stderr, "Failed to initialize database.\n");
return 1;