From f1f6e504d5d4e4d586941b4e9e17c8f793450d46 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Mon, 17 Oct 2016 16:39:56 +0200 Subject: defining all but one exchangedb-for-audit functions --- src/exchangedb/plugin_exchangedb_postgres.c | 418 ++++++++++++++++++++++++++-- 1 file changed, 402 insertions(+), 16 deletions(-) (limited to 'src/exchangedb') diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 972d70808..c85a439fd 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -627,6 +627,23 @@ postgres_prepare (PGconn *db_conn) "($1, $2, $3, $4, $5, $6, $7);", 7, NULL); + + /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound + transactions for reserves with serial id '\geq' the given parameter */ + PREPARE ("audit_reserves_in_get_transactions_incr", + "SELECT" + " reserve_pub" + ",credit_val" + ",credit_frac" + ",credit_curr" + ",execution_date" + ",sender_account_details" + ",transfer_details" + " FROM reserves_in" + " WHERE reserve_in_serial_id>=$1" + " ORDER BY reserve_in_serial_id", + 1, NULL); + /* Used in #postgres_get_reserve_history() to obtain inbound transactions for a reserve */ PREPARE ("reserves_in_get_transactions", @@ -707,6 +724,23 @@ postgres_prepare (PGconn *db_conn) " WHERE reserve_pub=$1;", 1, NULL); + /* Used in #postgres_select_reserves_out_above_serial_id() */ + PREPARE ("audit_get_reserves_out_incr", + "SELECT" + " h_blind_ev" + ",denom_pub" + ",denom_sig" + ",reserve_sig" + ",reserve_pub" + ",execution_date" + ",amount_with_fee_val" + ",amount_with_fee_frac" + ",amount_with_fee_curr" + " FROM reserves_out" + " WHERE reserve_out_serial_id>=$1" + " ORDER BY reserve_out_serial_id ASC", + 1, NULL); + /* Used in #postgres_get_refresh_session() to fetch high-level information about a refresh session */ PREPARE ("get_refresh_session", @@ -727,6 +761,22 @@ postgres_prepare (PGconn *db_conn) " WHERE session_hash=$1 ", 1, NULL); + /* Used in #postgres_select_refreshs_above_serial_id() to fetch + refresh session with id '\geq' the given parameter */ + PREPARE ("audit_get_refresh_sessions_incr", + "SELECT" + " old_coin_pub" + ",old_coin_sig" + ",amount_with_fee_val" + ",amount_with_fee_frac" + ",amount_with_fee_curr" + ",num_newcoins" + ",noreveal_index" + " FROM refresh_sessions" + " WHERE melt_serial_id>=$1" + " ORDER BY melt_serial_id ASC", + 1, NULL); + /* Used in #postgres_create_refresh_session() to store high-level information about a refresh session */ PREPARE ("insert_refresh_session", @@ -802,6 +852,23 @@ postgres_prepare (PGconn *db_conn) " WHERE old_coin_pub=$1", 1, NULL); + /* Fetch refunds with rowid '\geq' the given parameter */ + PREPARE ("audit_get_refunds_incr", + "SELECT" + " merchant_pub" + ",merchant_sig" + ",h_contract" + ",transaction_id" + ",rtransaction_id" + ",coin_pub" + ",amount_with_fee_val" + ",amount_with_fee_frac" + ",amount_with_fee_curr" + " FROM refunds" + " WHERE refund_serial_id>=$1" + " ORDER BY refund_serial_id ASC", + 1, NULL); + /* Query the 'refunds' by coin public key */ PREPARE ("get_refunds_by_coin", "SELECT" @@ -823,6 +890,7 @@ postgres_prepare (PGconn *db_conn) 1, NULL); + /* Used in #postgres_insert_transfer_public_key() to store commitments */ PREPARE ("insert_transfer_public_key", @@ -921,8 +989,7 @@ postgres_prepare (PGconn *db_conn) " )", 3, NULL); - /* Fetch an existing deposit request, used to ensure idempotency - during /deposit processing. Used in #postgres_have_deposit(). */ + /* Fetch deposits with rowid '\geq' the given parameter */ PREPARE ("audit_get_deposits_incr", "SELECT" " amount_with_fee_val" @@ -937,11 +1004,12 @@ postgres_prepare (PGconn *db_conn) ",wire_deadline" ",h_contract" ",wire" + ",done" " FROM deposits" " WHERE (" " (deposit_serial_id>=$1)" " )" - " ORDER BY deposit_serial_id", + " ORDER BY deposit_serial_id ASC", 1, NULL); /* Fetch an existing deposit request. @@ -1207,6 +1275,17 @@ postgres_prepare (PGconn *db_conn) " FROM prewire" " WHERE finished=true", 0, NULL); + + /* Used in #postgres_select_prepare_above_serial_id() */ + PREPARE ("audit_get_wire_incr", + "SELECT" + ",type" + ",buf" + " FROM prewire" + " WHERE prewire_uuid>=$1" + " ORDER BY prewire_uuid ASC", + 1, NULL); + PREPARE ("gc_denominations", "DELETE" " FROM denominations" @@ -4307,20 +4386,62 @@ postgres_select_deposits_above_serial_id (void *cls, if (0 == nrows) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "audit_get_deposit_incr() returned 0 matching rows\n"); + "select_deposits_above_serial_id() returned 0 matching rows\n"); PQclear (result); return GNUNET_NO; } for (i=0;iconn, + "audit_get_refresh_sessions_incr", + params); + + if (PGRES_COMMAND_OK != + PQresultStatus (result)) + { + BREAK_DB_ERR (result); + PQclear (result); + return GNUNET_SYSERR; + } + int nrows; + int i; + + nrows = PQntuples (result); + if (0 == nrows) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "select_refreshs_above_serial_id() returned 0 matching rows\n"); + PQclear (result); + return GNUNET_NO; + } + + for (i=0;iconn, + "audit_get_refunds_incr", + params); + if (PGRES_COMMAND_OK != + PQresultStatus (result)) + { + BREAK_DB_ERR (result); + PQclear (result); + return GNUNET_SYSERR; + } + int nrows; + int i; + + nrows = PQntuples (result); + if (0 == nrows) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "select_refunds_above_serial_id() returned 0 matching rows\n"); + PQclear (result); + return GNUNET_NO; + } + for (i=0;iconn, + "audit_reserves_in_get_transactions_incr", + params); + if (PGRES_COMMAND_OK != + PQresultStatus (result)) + { + BREAK_DB_ERR (result); + PQclear (result); + return GNUNET_SYSERR; + } + int nrows; + int i; + + nrows = PQntuples (result); + if (0 == nrows) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "select_reserves_in_above_serial_id() returned 0 matching rows\n"); + PQclear (result); + return GNUNET_NO; + } + + for (i=0;iconn, + "audit_get_reserves_out_incr", + params); + if (PGRES_COMMAND_OK != + PQresultStatus (result)) + { + BREAK_DB_ERR (result); + PQclear (result); + return GNUNET_SYSERR; + } + int nrows; + int i; + + nrows = PQntuples (result); + if (0 == nrows) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "select_reserves_out_above_serial_id() returned 0 matching rows\n"); + PQclear (result); + return GNUNET_NO; + } + for (i=0;i