diff options
-rw-r--r-- | src/mint/mint_db.c | 55 | ||||
-rw-r--r-- | src/mint/mint_db.h | 22 | ||||
-rw-r--r-- | src/mint/taler-mint-reservemod.c | 11 | ||||
-rw-r--r-- | src/pq/db_pq.h | 3 |
4 files changed, 21 insertions, 70 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c index c4d1ff743..9a35ddbd4 100644 --- a/src/mint/mint_db.c +++ b/src/mint/mint_db.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014 Christian Grothoff (and other contributing authors) + (C) 2014, 2015 Christian Grothoff (and other contributing authors) TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -61,47 +61,6 @@ static char *TALER_MINT_db_connection_cfg_str; - - -int -TALER_TALER_DB_extract_amount_nbo (PGresult *result, - unsigned int row, - int indices[3], - struct TALER_AmountNBO *denom_nbo) -{ - if ((indices[0] < 0) || (indices[1] < 0) || (indices[2] < 0)) - return GNUNET_NO; - if (sizeof (uint32_t) != PQgetlength (result, row, indices[0])) - return GNUNET_SYSERR; - if (sizeof (uint32_t) != PQgetlength (result, row, indices[1])) - return GNUNET_SYSERR; - if (PQgetlength (result, row, indices[2]) > TALER_CURRENCY_LEN) - return GNUNET_SYSERR; - denom_nbo->value = *(uint32_t *) PQgetvalue (result, row, indices[0]); - denom_nbo->fraction = *(uint32_t *) PQgetvalue (result, row, indices[1]); - memset (denom_nbo->currency, 0, TALER_CURRENCY_LEN); - memcpy (denom_nbo->currency, PQgetvalue (result, row, indices[2]), PQgetlength (result, row, indices[2])); - return GNUNET_OK; -} - - -int -TALER_TALER_DB_extract_amount (PGresult *result, - unsigned int row, - int indices[3], - struct TALER_Amount *denom) -{ - struct TALER_AmountNBO denom_nbo; - int res; - - res = TALER_TALER_DB_extract_amount_nbo (result, row, indices, &denom_nbo); - if (GNUNET_OK != res) - return res; - *denom = TALER_amount_ntoh (denom_nbo); - return GNUNET_OK; -} - - int TALER_MINT_DB_prepare (PGconn *db_conn) { @@ -1263,12 +1222,12 @@ TALER_MINT_DB_get_reserve_history (PGconn *db_conn, } { - int fnums[] = { - PQfnumber (result, "balance_value"), - PQfnumber (result, "balance_fraction"), - PQfnumber (result, "balance_currency"), - }; - if (GNUNET_OK != TALER_TALER_DB_extract_amount_nbo (result, 0, fnums, &reserve->balance)) + if (GNUNET_OK != + TALER_DB_extract_amount_nbo (result, 0, + "balance_value", + "balance_fraction", + "balance_currency", + &reserve->balance)) { GNUNET_break (0); PQclear (result); diff --git a/src/mint/mint_db.h b/src/mint/mint_db.h index 5762656d0..0c0288ab2 100644 --- a/src/mint/mint_db.h +++ b/src/mint/mint_db.h @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014 Christian Grothoff (and other contributing authors) + (C) 2014, 2015 Christian Grothoff (and other contributing authors) TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -19,9 +19,8 @@ * @author Florian Dold * @author Christian Grothoff */ - -#ifndef _NEURO_MINT_DB_H -#define _NEURO_MINT_DB_H +#ifndef MINT_DB_H +#define MINT_DB_H #include <libpq-fe.h> #include <microhttpd.h> @@ -101,21 +100,6 @@ TALER_db_get_transfer (PGconn *db_conn, struct GNUNET_HashCode *shared_secret_enc); -int -TALER_TALER_DB_extract_amount (PGresult *result, - unsigned int row, - int indices[3], - struct TALER_Amount *denom); - -int -TALER_TALER_DB_extract_amount_nbo (PGresult *result, - unsigned int row, - int indices[3], - struct TALER_AmountNBO *denom_nbo); - - - - // Chaos //////////////////////////////////////////////////////////////// diff --git a/src/mint/taler-mint-reservemod.c b/src/mint/taler-mint-reservemod.c index f531dbf4b..3f299ca38 100644 --- a/src/mint/taler-mint-reservemod.c +++ b/src/mint/taler-mint-reservemod.c @@ -27,6 +27,7 @@ #include "taler_util.h" #include "taler_signatures.h" #include "mint_db.h" +#include "db_pq.h" char *mintdir; @@ -46,7 +47,7 @@ static PGconn *db_conn; * * @return ... */ -int +static int reservemod_add (struct TALER_Amount denom) { PGresult *result; @@ -96,7 +97,6 @@ reservemod_add (struct TALER_Amount denom) struct TALER_Amount old_denom; struct TALER_Amount new_denom; struct TALER_AmountNBO new_denom_nbo; - int denom_indices[] = {0, 1, 2}; int param_lengths[] = {4, 4, 32}; int param_formats[] = {1, 1, 1}; const void *param_values[] = { @@ -105,7 +105,12 @@ reservemod_add (struct TALER_Amount denom) reserve_pub }; - GNUNET_assert (GNUNET_OK == TALER_TALER_DB_extract_amount (result, 0, denom_indices, &old_denom)); + GNUNET_assert (GNUNET_OK == + TALER_DB_extract_amount (result, 0, + "balance_value", + "balance_fraction", + "balance_currency", + &old_denom)); new_denom = TALER_amount_add (old_denom, denom); new_denom_nbo = TALER_amount_hton (new_denom); result = PQexecParams (db_conn, diff --git a/src/pq/db_pq.h b/src/pq/db_pq.h index 6e2b2b2c0..167d31711 100644 --- a/src/pq/db_pq.h +++ b/src/pq/db_pq.h @@ -181,6 +181,9 @@ TALER_DB_extract_amount (PGresult *result, const char *curr_name, struct TALER_Amount *r_amount); + + + #endif /* TALER_DB_LIB_H_ */ /* end of include/taler_db_lib.h */ |