remove currency field from databases

This commit is contained in:
Christian Grothoff 2019-08-17 21:35:21 +02:00
parent cbf6281ca2
commit 4bf425c902
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
17 changed files with 1608 additions and 2043 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,3 +5,6 @@ DB = postgres
[auditordb-postgres]
# Argument for Postgres for how to connect to the database.
CONFIG = "postgres:///talercheck"
[taler]
CURRENCY = "EUR"

View File

@ -54,7 +54,7 @@ static int result = -1;
/**
* Currency we use.
* Currency we use, must match CURRENCY in "test-auditor-db-postgres.conf".
*/
#define CURRENCY "EUR"

View File

@ -60,7 +60,7 @@ sign_account_data (void *cls,
char *json_out;
FILE *out;
int ret;
if (GNUNET_NO == ai->credit_enabled)
return;
if (NULL == ai->wire_response_filename)
@ -71,6 +71,7 @@ sign_account_data (void *cls,
global_ret = 1;
return;
}
wire = TALER_JSON_exchange_wire_signature_make (ai->payto_url,
&master_priv);
GNUNET_assert (NULL != wire);
@ -199,6 +200,9 @@ run (void *cls,
global_ret = 1;
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Signing /wire response with private key matching public key `%s'\n",
masters);
GNUNET_free (masters);
TALER_EXCHANGEDB_find_accounts (cfg,
&sign_account_data,

View File

@ -684,6 +684,9 @@ exchange_serve_process_config ()
return GNUNET_SYSERR;
}
GNUNET_free (TEH_master_public_key_str);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Launching exchange with public key `%s'...\n",
GNUNET_p2s (&TEH_master_public_key.eddsa_pub));
if ( (GNUNET_OK !=
TEH_VALIDATION_init (cfg)) ||

View File

@ -173,8 +173,9 @@ load_account (void *cls,
&TEH_master_public_key))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Invalid signature in `%s'\n",
ai->wire_response_filename);
"Invalid signature in `%s' for public key `%s'\n",
ai->wire_response_filename,
GNUNET_p2s (&TEH_master_public_key.eddsa_pub));
json_decref (wire_s);
*ret = GNUNET_SYSERR;
return;

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,8 @@ DB = postgres
#The connection string the plugin has to use for connecting to the database
CONFIG = postgres:///talercheck
[taler]
CURRENCY = EUR
[exchangedb]

View File

@ -55,7 +55,7 @@ static int result;
/**
* Currency we use.
* Currency we use. Must match test-exchange-db-*.conf.
*/
#define CURRENCY "EUR"
@ -343,61 +343,6 @@ never_called_cb (void *cls,
}
/**
* Callback used to process data of a merchant under KYC monitoring.
*
* @param cls closure
* @param payto_url payto URL of this particular merchant (bank account)
* @param general_id general identificator valid at the KYC-caring institution
* @param kyc_checked status of KYC check: if GNUNET_OK, the merchant was
* checked at least once, never otherwise.
* @param merchant_serial_id serial ID identifying this merchant (bank
* account) into the database system; it helps making more efficient
* queries instead of the payto URL.
*/
static void
kcs (void *cls,
const char *payto_url,
const char *general_id,
uint8_t kyc_checked,
uint64_t merchant_serial_id)
{
struct TALER_EXCHANGEDB_Session *session = cls;
struct TALER_Amount amount;
struct TALER_Amount sum;
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (CURRENCY,
&amount));
amount.value = 30;
FAILIF
(GNUNET_OK != plugin->insert_kyc_event (NULL,
session,
merchant_serial_id,
&amount));
amount.value = 20;
amount.fraction = 70;
FAILIF
(GNUNET_OK != plugin->insert_kyc_event (NULL,
session,
merchant_serial_id,
&amount));
FAILIF
(0 >= plugin->get_kyc_events (NULL,
session,
merchant_serial_id,
&sum));
FAILIF ((50 != sum.value) || (70 != sum.fraction));
FAILIF (2 != plugin->clean_kyc_events (NULL,
session,
merchant_serial_id));
drop:
return;
}
/**
* Function called with information about a refresh order.
* Checks that the response matches what we expect to see.
@ -2225,26 +2170,6 @@ run (void *cls)
FAILIF (GNUNET_OK !=
test_wire_fees (session));
FAILIF (GNUNET_OK !=
plugin->insert_kyc_merchant (NULL,
session,
"dummy", // NULL segfaults.
"payto://mock"));
FAILIF (GNUNET_OK !=
plugin->mark_kyc_merchant (NULL,
session,
"payto://mock"));
FAILIF (GNUNET_OK !=
plugin->get_kyc_status (NULL,
session,
"payto://mock",
&kcs,
session));
FAILIF (GNUNET_OK !=
plugin->unmark_kyc_merchant (NULL,
session,
"payto://mock"));
plugin->preflight (plugin->cls,
session);

View File

@ -793,29 +793,6 @@ typedef int
int done);
/**
* Callback used to process data of a merchant under KYC monitoring.
*
* @param cls closure
* @param payto_url payto URL of this particular
* merchant (bank account)
* @param general_id general identificator valid
* at the KYC-caring institution
* @param kyc_checked status of KYC check:
* if GNUNET_OK, the merchant was checked at least once,
* never otherwise.
* @param merchant_serial_id serial ID identifying
* this merchant (bank account) into the database system;
* it helps making more efficient queries than the payto
* URL.
*/
typedef void
(*TALER_EXCHANGEDB_KycStatusCallback)(void *cls,
const char *payto_url,
const char *general_id,
uint8_t kyc_checked,
uint64_t merchant_serial_id);
/**
* Function called with details about coins that were melted,
* with the goal of auditing the refresh's execution.
@ -918,19 +895,6 @@ typedef void
const struct TALER_TransferPublicKeyP *tp);
/**
* Callback for handling a KYC timestamped event associated with
* a certain customer (= merchant).
*
* @param cls closure
* @param url "payto" URL associated with the customer
* @param timeout last time when the KYC was issued to the customer.
*/
typedef void
(*TALER_EXCHANGEDB_KycCallback)(void *cls,
const char *url,
struct GNUNET_TIME_Absolute timeout);
/**
* Function called with details about coins that were refunding,
* with the goal of auditing the refund's execution.
@ -2509,126 +2473,6 @@ struct TALER_EXCHANGEDB_Plugin
TALER_EXCHANGEDB_WireMissingCallback cb,
void *cb_cls);
/**
* Insert a merchant into the KYC monitor table, namely it
* associates a flag to the merchant that indicates whether
* a KYC check has been done or not on this merchant.
*
* @param cls closure
* @param session db session
* @param general_id identificator at the KYC-aware institution,
* can be NULL if this is in-line wiht the rules.
* @param payto_url payto:// URL indentifying the merchant
* bank account.
* @return database transaction status.
*/
enum GNUNET_DB_QueryStatus
(*insert_kyc_merchant)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
const char *general_id,
const char *payto_url);
/**
* Mark a merchant as KYC-checked.
*
* @param cls closure
* @param session db session
* @param payto_url payto:// URL indentifying the merchant
* to check. Note, different banks may have different
* policies to check their customers.
* @return database transaction status.
*/
enum GNUNET_DB_QueryStatus
(*mark_kyc_merchant)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
const char *payto_url);
/**
* Mark a merchant as NOT KYC-checked.
*
* @param cls closure
* @param session db session
* @param payto_url payto:// URL indentifying the merchant
* to unmark. Note, different banks may have different
* policies to check their customers.
* @return database transaction status.
*/
enum GNUNET_DB_QueryStatus
(*unmark_kyc_merchant)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
const char *payto_url);
/**
* Retrieve KYC-check status related to a particular merchant.
*
* @param cls closure
* @param session db session
* @param payto_url URL identifying a merchant bank account,
* whose KYC is going to be retrieved.
* @param ksc callback to process all the row's columns. As
* expectable, it will only be called _if_ a row is found.
* @param ksc_cls closure for above callback.
* @return transaction status.
*/
enum GNUNET_DB_QueryStatus
(*get_kyc_status)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
const char *payto_url,
TALER_EXCHANGEDB_KycStatusCallback ksc,
void *ksc_cls);
/**
* Record timestamp where a particular merchant performed
* a wire transfer.
*
* @param cls closure.
* @param session db session.
* @param merchant_serial_id serial id of the merchant who
* performed the wire transfer.
* @param amount amount of the wire transfer being monitored.
* @return database transaction status.
*/
enum GNUNET_DB_QueryStatus
(*insert_kyc_event)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
uint64_t merchant_serial_id,
struct TALER_Amount *amount);
/**
* Calculate sum of money flow related to a particular merchant,
* used for KYC monitoring.
*
* @param cls closure
* @param session DB session
* @param merchant_serial_id serial id identifying the merchant
* into the KYC monitoring system.
* @param amount[out] will store the amount of money received
* by this merchant.
*/
enum GNUNET_DB_QueryStatus
(*get_kyc_events)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
uint64_t merchant_serial_id,
struct TALER_Amount *amount);
/**
* Delete wire transfer records related to a particular merchant.
* This method would be called by the logic once that merchant
* gets successfully KYC checked.
*
* @param cls closure
* @param session DB session
* @param merchant_serial_id serial id of the merchant whose
* KYC records have to be deleted.
* @return DB transaction status.
*/
enum GNUNET_DB_QueryStatus
(*clean_kyc_events)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
uint64_t merchant_serial_id);
};
#endif /* _TALER_EXCHANGE_DB_H */

View File

@ -94,24 +94,28 @@ TALER_PQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x)
* Currency amount expected.
*
* @param name name of the field in the table
* @param currency expected currency for the @a amount
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount_nbo (const char *name,
struct TALER_AmountNBO *amount);
const char *currency,
struct TALER_AmountNBO *amount);
/**
* Currency amount expected.
*
* @param name name of the field in the table
* @param currency expected currency for the @a amount
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount (const char *name,
struct TALER_Amount *amount);
const char *currency,
struct TALER_Amount *amount);
/**

View File

@ -87,7 +87,8 @@ TALER_gcrypt_init (void);
*/
const char *
TALER_b2s (const void *buf,
size_t buf_size);
size_t buf_size);
/**
* Convert a fixed-sized object to a string using

View File

@ -150,7 +150,6 @@ TALER_JSON_exchange_wire_signature_make (const char *payto_url,
GNUNET_CRYPTO_eddsa_key_get_public (&master_priv->eddsa_priv,
&master_pub.eddsa_pub);
TALER_exchange_wire_signature_make (payto_url,
master_priv,
&master_sig);

View File

@ -42,19 +42,19 @@
*/
static int
qconv_amount_nbo (void *cls,
const void *data,
size_t data_len,
void *param_values[],
int param_lengths[],
int param_formats[],
unsigned int param_length,
void *scratch[],
unsigned int scratch_length)
const void *data,
size_t data_len,
void *param_values[],
int param_lengths[],
int param_formats[],
unsigned int param_length,
void *scratch[],
unsigned int scratch_length)
{
const struct TALER_AmountNBO *amount = data;
unsigned int off = 0;
GNUNET_assert (3 == param_length);
GNUNET_assert (2 == param_length);
param_values[off] = (void *) &amount->value;
param_lengths[off] = sizeof (amount->value);
param_formats[off] = 1;
@ -62,10 +62,6 @@ qconv_amount_nbo (void *cls,
param_values[off] = (void *) &amount->fraction;
param_lengths[off] = sizeof (amount->fraction);
param_formats[off] = 1;
off++;
param_values[off] = (void *) amount->currency;
param_lengths[off] = strlen (amount->currency);
param_formats[off] = 1;
return 0;
}
@ -83,7 +79,7 @@ struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_amount_nbo, NULL, x, sizeof (*x), 3 };
{ &qconv_amount_nbo, NULL, x, sizeof (*x), 2 };
return res;
}
@ -104,14 +100,14 @@ TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
*/
static int
qconv_amount (void *cls,
const void *data,
size_t data_len,
void *param_values[],
int param_lengths[],
int param_formats[],
unsigned int param_length,
void *scratch[],
unsigned int scratch_length)
const void *data,
size_t data_len,
void *param_values[],
int param_lengths[],
int param_formats[],
unsigned int param_length,
void *scratch[],
unsigned int scratch_length)
{
const struct TALER_Amount *amount_hbo = data;
struct TALER_AmountNBO *amount;
@ -119,16 +115,16 @@ qconv_amount (void *cls,
amount = GNUNET_new (struct TALER_AmountNBO);
scratch[0] = amount;
TALER_amount_hton (amount,
amount_hbo);
amount_hbo);
qconv_amount_nbo (cls,
amount,
sizeof (struct TALER_AmountNBO),
param_values,
param_lengths,
param_formats,
param_length,
&scratch[1],
scratch_length - 1);
amount,
sizeof (struct TALER_AmountNBO),
param_values,
param_lengths,
param_formats,
param_length,
&scratch[1],
scratch_length - 1);
return 1;
}
@ -146,7 +142,7 @@ struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_amount (const struct TALER_Amount *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_amount, NULL, x, sizeof (*x), 3 };
{ &qconv_amount, NULL, x, sizeof (*x), 2 };
return res;
}
@ -167,14 +163,14 @@ TALER_PQ_query_param_amount (const struct TALER_Amount *x)
*/
static int
qconv_json (void *cls,
const void *data,
size_t data_len,
void *param_values[],
int param_lengths[],
int param_formats[],
unsigned int param_length,
void *scratch[],
unsigned int scratch_length)
const void *data,
size_t data_len,
void *param_values[],
int param_lengths[],
int param_formats[],
unsigned int param_length,
void *scratch[],
unsigned int scratch_length)
{
const json_t *json = data;
char *str;

View File

@ -40,15 +40,14 @@
*/
static int
extract_amount_nbo_helper (PGresult *result,
int row,
const char *val_name,
const char *frac_name,
const char *curr_name,
struct TALER_AmountNBO *r_amount_nbo)
int row,
const char *currency,
const char *val_name,
const char *frac_name,
struct TALER_AmountNBO *r_amount_nbo)
{
int val_num;
int frac_num;
int curr_num;
int len;
/* These checks are simply to check that clients obey by our naming
@ -59,9 +58,6 @@ extract_amount_nbo_helper (PGresult *result,
GNUNET_assert (NULL !=
strstr (frac_name,
"_frac"));
GNUNET_assert (NULL !=
strstr (curr_name,
"_curr"));
/* Set return value to invalid in case we don't finish */
memset (r_amount_nbo,
0,
@ -70,27 +66,18 @@ extract_amount_nbo_helper (PGresult *result,
val_name);
frac_num = PQfnumber (result,
frac_name);
curr_num = PQfnumber (result,
curr_name);
if (val_num < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field `%s' does not exist in result\n",
val_name);
"Field `%s' does not exist in result\n",
val_name);
return GNUNET_SYSERR;
}
if (frac_num < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field `%s' does not exist in result\n",
frac_name);
return GNUNET_SYSERR;
}
if (curr_num < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field `%s' does not exist in result\n",
curr_name);
"Field `%s' does not exist in result\n",
frac_name);
return GNUNET_SYSERR;
}
if ( (PQgetisnull (result,
@ -98,10 +85,7 @@ extract_amount_nbo_helper (PGresult *result,
val_num)) ||
(PQgetisnull (result,
row,
frac_num)) ||
(PQgetisnull (result,
row,
curr_num)) )
frac_num)) )
{
GNUNET_break (0);
return GNUNET_NO;
@ -115,13 +99,9 @@ extract_amount_nbo_helper (PGresult *result,
row,
frac_num);
len = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
PQgetlength (result,
row,
curr_num));
strlen (currency));
memcpy (r_amount_nbo->currency,
PQgetvalue (result,
row,
curr_num),
currency,
len);
return GNUNET_OK;
}
@ -130,7 +110,7 @@ extract_amount_nbo_helper (PGresult *result,
/**
* Extract data from a Postgres database @a result at row @a row.
*
* @param cls closure
* @param cls closure, a `const char *` giving the currency
* @param result where to extract data from
* @param row row to extract data from
* @param fname name (or prefix) of the fields to extract from
@ -143,35 +123,31 @@ extract_amount_nbo_helper (PGresult *result,
*/
static int
extract_amount_nbo (void *cls,
PGresult *result,
int row,
const char *fname,
size_t *dst_size,
void *dst)
PGresult *result,
int row,
const char *fname,
size_t *dst_size,
void *dst)
{
const char *currency = cls;
char *val_name;
char *frac_name;
char *curr_name;
int ret;
GNUNET_asprintf (&val_name,
"%s_val",
fname);
"%s_val",
fname);
GNUNET_asprintf (&frac_name,
"%s_frac",
fname);
GNUNET_asprintf (&curr_name,
"%s_curr",
fname);
"%s_frac",
fname);
ret = extract_amount_nbo_helper (result,
row,
val_name,
frac_name,
curr_name,
dst);
row,
currency,
val_name,
frac_name,
dst);
GNUNET_free (val_name);
GNUNET_free (frac_name);
GNUNET_free (curr_name);
return ret;
}
@ -185,12 +161,17 @@ extract_amount_nbo (void *cls,
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount_nbo (const char *name,
struct TALER_AmountNBO *amount)
const char *currency,
struct TALER_AmountNBO *amount)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_amount_nbo, NULL, NULL,
(void *) amount, sizeof (*amount),
name, NULL };
struct GNUNET_PQ_ResultSpec res = {
.conv = &extract_amount_nbo,
.cls = (void *) currency,
.dst = (void *) amount,
.dst_size = sizeof (*amount),
.fname = name
};
return res;
}
@ -198,7 +179,7 @@ TALER_PQ_result_spec_amount_nbo (const char *name,
/**
* Extract data from a Postgres database @a result at row @a row.
*
* @param cls closure
* @param cls closure, a `const char *` giving the currency
* @param result where to extract data from
* @param row row to extract data from
* @param fname name (or prefix) of the fields to extract from
@ -211,39 +192,35 @@ TALER_PQ_result_spec_amount_nbo (const char *name,
*/
static int
extract_amount (void *cls,
PGresult *result,
int row,
const char *fname,
size_t *dst_size,
void *dst)
PGresult *result,
int row,
const char *fname,
size_t *dst_size,
void *dst)
{
const char *currency = cls;
struct TALER_Amount *r_amount = dst;
char *val_name;
char *frac_name;
char *curr_name;
struct TALER_AmountNBO amount_nbo;
int ret;
GNUNET_asprintf (&val_name,
"%s_val",
fname);
"%s_val",
fname);
GNUNET_asprintf (&frac_name,
"%s_frac",
fname);
GNUNET_asprintf (&curr_name,
"%s_curr",
fname);
"%s_frac",
fname);
ret = extract_amount_nbo_helper (result,
row,
val_name,
frac_name,
curr_name,
&amount_nbo);
row,
currency,
val_name,
frac_name,
&amount_nbo);
TALER_amount_ntoh (r_amount,
&amount_nbo);
GNUNET_free (val_name);
GNUNET_free (frac_name);
GNUNET_free (curr_name);
return ret;
}
@ -252,17 +229,23 @@ extract_amount (void *cls,
* Currency amount expected.
*
* @param name name of the field in the table
* @param currency the currency the amount is in
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount (const char *name,
struct TALER_Amount *amount)
const char *currency,
struct TALER_Amount *amount)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_amount, NULL, NULL,
(void *) amount, sizeof (*amount),
name, NULL };
struct GNUNET_PQ_ResultSpec res = {
.conv = &extract_amount,
.cls = (void *) currency,
.dst = (void *) amount,
.dst_size = sizeof (*amount),
.fname = name
};
return res;
}
@ -283,11 +266,11 @@ TALER_PQ_result_spec_amount (const char *name,
*/
static int
extract_json (void *cls,
PGresult *result,
int row,
const char *fname,
size_t *dst_size,
void *dst)
PGresult *result,
int row,
const char *fname,
size_t *dst_size,
void *dst)
{
json_t **j_dst = dst;
const char *res;
@ -296,33 +279,33 @@ extract_json (void *cls,
size_t slen;
fnum = PQfnumber (result,
fname);
fname);
if (fnum < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field `%s' does not exist in result\n",
fname);
"Field `%s' does not exist in result\n",
fname);
return GNUNET_SYSERR;
}
if (PQgetisnull (result,
row,
fnum))
row,
fnum))
return GNUNET_NO;
slen = PQgetlength (result,
row,
fnum);
row,
fnum);
res = (const char *) PQgetvalue (result,
row,
fnum);
row,
fnum);
*j_dst = json_loadb (res,
slen,
JSON_REJECT_DUPLICATES,
&json_error);
slen,
JSON_REJECT_DUPLICATES,
&json_error);
if (NULL == *j_dst)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to parse JSON result for field `%s': %s (%s)\n",
fname,
"Failed to parse JSON result for field `%s': %s (%s)\n",
fname,
json_error.text,
json_error.source);
return GNUNET_SYSERR;
@ -340,7 +323,7 @@ extract_json (void *cls,
*/
static void
clean_json (void *cls,
void *rd)
void *rd)
{
json_t **dst = rd;
@ -363,15 +346,17 @@ struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_json (const char *name,
json_t **jp)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_json, &clean_json, NULL,
(void *) jp, 0,
name, NULL };
struct GNUNET_PQ_ResultSpec res = {
.conv = &extract_json,
.cleaner = &clean_json,
.dst = (void *) jp,
.fname = name
};
return res;
}
/**
* Extract data from a Postgres database @a result at row @a row.
*
@ -399,7 +384,7 @@ extract_round_time (void *cls,
int fnum;
fnum = PQfnumber (result,
fname);
fname);
if (fnum < 0)
{
GNUNET_break (0);
@ -443,10 +428,13 @@ struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_absolute_time (const char *name,
struct GNUNET_TIME_Absolute *at)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_round_time, NULL, NULL,
(void *) at, sizeof (struct GNUNET_TIME_Absolute),
name, NULL };
struct GNUNET_PQ_ResultSpec res = {
.conv = &extract_round_time,
.dst = (void *) at,
.dst_size = sizeof (struct GNUNET_TIME_Absolute),
.fname = name
};
return res;
}
@ -478,15 +466,15 @@ extract_round_time_nbo (void *cls,
int fnum;
fnum = PQfnumber (result,
fname);
fname);
if (fnum < 0)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
if (PQgetisnull (result,
row,
fnum))
row,
fnum))
{
GNUNET_break (0);
return GNUNET_SYSERR;
@ -522,10 +510,13 @@ struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_absolute_time_nbo (const char *name,
struct GNUNET_TIME_AbsoluteNBO *at)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_round_time_nbo, NULL, NULL,
(void *) at, sizeof (struct GNUNET_TIME_AbsoluteNBO),
name, NULL };
struct GNUNET_PQ_ResultSpec res = {
.conv = &extract_round_time_nbo,
.dst = (void *) at,
.dst_size = sizeof (struct GNUNET_TIME_AbsoluteNBO),
.fname = name
};
return res;
}

View File

@ -50,23 +50,18 @@ postgres_prepare (PGconn *db_conn)
"INSERT INTO test_pq ("
" hamount_val"
",hamount_frac"
",hamount_curr"
",namount_val"
",namount_frac"
",namount_curr"
",json"
") VALUES "
"($1, $2, $3, $4, $5, $6,"
"$7);",
7, NULL);
"($1, $2, $3, $4, $5);",
5, NULL);
PREPARE ("test_select",
"SELECT"
" hamount_val"
",hamount_frac"
",hamount_curr"
",namount_val"
",namount_frac"
",namount_curr"
",json"
" FROM test_pq;",
0, NULL);
@ -113,8 +108,8 @@ run_queries (PGconn *conn)
};
result = GNUNET_PQ_exec_prepared (conn,
"test_insert",
params_insert);
"test_insert",
params_insert);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -131,10 +126,10 @@ run_queries (PGconn *conn)
};
result = GNUNET_PQ_exec_prepared (conn,
"test_select",
params_select);
"test_select",
params_select);
if (1 !=
PQntuples (result))
PQntuples (result))
{
GNUNET_break (0);
PQclear (result);
@ -144,8 +139,8 @@ run_queries (PGconn *conn)
{
struct GNUNET_PQ_ResultSpec results_select[] = {
TALER_PQ_result_spec_amount ("hamount", &hamount2),
TALER_PQ_result_spec_amount_nbo ("namount", &namount2),
TALER_PQ_result_spec_amount ("hamount", "EUR", &hamount2),
TALER_PQ_result_spec_amount_nbo ("namount", "EUR", &namount2),
TALER_PQ_result_spec_json ("json", &json2),
GNUNET_PQ_result_spec_end
};
@ -163,8 +158,9 @@ run_queries (PGconn *conn)
&namount2);
GNUNET_break (0 ==
TALER_amount_cmp (&hamount,
&hamount2));
GNUNET_break (42 == json_integer_value (json_object_get (json2, "foo")));
&hamount2));
GNUNET_break (42 ==
json_integer_value (json_object_get (json2, "foo")));
GNUNET_PQ_cleanup_result (results_select);
PQclear (result);
}
@ -185,8 +181,8 @@ main(int argc,
int ret;
GNUNET_log_setup ("test-pq",
"WARNING",
NULL);
"WARNING",
NULL);
conn = PQconnectdb ("postgres:///talercheck");
if (CONNECTION_OK != PQstatus (conn))
{
@ -202,17 +198,15 @@ main(int argc,
"CREATE TEMPORARY TABLE IF NOT EXISTS test_pq ("
" hamount_val INT8 NOT NULL"
",hamount_frac INT4 NOT NULL"
",hamount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",namount_val INT8 NOT NULL"
",namount_frac INT4 NOT NULL"
",namount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",json VARCHAR NOT NULL"
")");
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
fprintf (stderr,
"Failed to create table: %s\n",
PQerrorMessage (conn));
"Failed to create table: %s\n",
PQerrorMessage (conn));
PQclear (result);
PQfinish (conn);
return 1;
@ -227,12 +221,12 @@ main(int argc,
}
ret = run_queries (conn);
result = PQexec (conn,
"DROP TABLE test_pq");
"DROP TABLE test_pq");
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
fprintf (stderr,
"Failed to create table: %s\n",
PQerrorMessage (conn));
"Failed to create table: %s\n",
PQerrorMessage (conn));
PQclear (result);
PQfinish (conn);
return 1;

View File

@ -39,7 +39,7 @@
*/
const char *
TALER_b2s (const void *buf,
size_t buf_size)
size_t buf_size)
{
static char ret[9];
struct GNUNET_HashCode hc;
@ -49,7 +49,7 @@ TALER_b2s (const void *buf,
buf_size,
&hc);
tmp = GNUNET_STRINGS_data_to_string_alloc (&hc,
sizeof (hc));
sizeof (hc));
memcpy (ret,
tmp,
8);