-removing legacy TALER_TALER API, replacing with modern TALER_DB calls

This commit is contained in:
Christian Grothoff 2015-01-29 20:45:45 +01:00
parent d751c9c6de
commit 7e46289428
4 changed files with 21 additions and 70 deletions

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 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 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 int
TALER_MINT_DB_prepare (PGconn *db_conn) TALER_MINT_DB_prepare (PGconn *db_conn)
{ {
@ -1263,12 +1222,12 @@ TALER_MINT_DB_get_reserve_history (PGconn *db_conn,
} }
{ {
int fnums[] = { if (GNUNET_OK !=
PQfnumber (result, "balance_value"), TALER_DB_extract_amount_nbo (result, 0,
PQfnumber (result, "balance_fraction"), "balance_value",
PQfnumber (result, "balance_currency"), "balance_fraction",
}; "balance_currency",
if (GNUNET_OK != TALER_TALER_DB_extract_amount_nbo (result, 0, fnums, &reserve->balance)) &reserve->balance))
{ {
GNUNET_break (0); GNUNET_break (0);
PQclear (result); PQclear (result);

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 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 terms of the GNU General Public License as published by the Free Software
@ -19,9 +19,8 @@
* @author Florian Dold * @author Florian Dold
* @author Christian Grothoff * @author Christian Grothoff
*/ */
#ifndef MINT_DB_H
#ifndef _NEURO_MINT_DB_H #define MINT_DB_H
#define _NEURO_MINT_DB_H
#include <libpq-fe.h> #include <libpq-fe.h>
#include <microhttpd.h> #include <microhttpd.h>
@ -101,21 +100,6 @@ TALER_db_get_transfer (PGconn *db_conn,
struct GNUNET_HashCode *shared_secret_enc); 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 // Chaos
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////

View File

@ -27,6 +27,7 @@
#include "taler_util.h" #include "taler_util.h"
#include "taler_signatures.h" #include "taler_signatures.h"
#include "mint_db.h" #include "mint_db.h"
#include "db_pq.h"
char *mintdir; char *mintdir;
@ -46,7 +47,7 @@ static PGconn *db_conn;
* *
* @return ... * @return ...
*/ */
int static int
reservemod_add (struct TALER_Amount denom) reservemod_add (struct TALER_Amount denom)
{ {
PGresult *result; PGresult *result;
@ -96,7 +97,6 @@ reservemod_add (struct TALER_Amount denom)
struct TALER_Amount old_denom; struct TALER_Amount old_denom;
struct TALER_Amount new_denom; struct TALER_Amount new_denom;
struct TALER_AmountNBO new_denom_nbo; struct TALER_AmountNBO new_denom_nbo;
int denom_indices[] = {0, 1, 2};
int param_lengths[] = {4, 4, 32}; int param_lengths[] = {4, 4, 32};
int param_formats[] = {1, 1, 1}; int param_formats[] = {1, 1, 1};
const void *param_values[] = { const void *param_values[] = {
@ -105,7 +105,12 @@ reservemod_add (struct TALER_Amount denom)
reserve_pub 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 = TALER_amount_add (old_denom, denom);
new_denom_nbo = TALER_amount_hton (new_denom); new_denom_nbo = TALER_amount_hton (new_denom);
result = PQexecParams (db_conn, result = PQexecParams (db_conn,

View File

@ -181,6 +181,9 @@ TALER_DB_extract_amount (PGresult *result,
const char *curr_name, const char *curr_name,
struct TALER_Amount *r_amount); struct TALER_Amount *r_amount);
#endif /* TALER_DB_LIB_H_ */ #endif /* TALER_DB_LIB_H_ */
/* end of include/taler_db_lib.h */ /* end of include/taler_db_lib.h */