resolve #3717
This commit is contained in:
parent
33f5242ac4
commit
d080e59e27
@ -685,7 +685,9 @@ struct TALER_MINTDB_Plugin
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a incoming transaction into reserves. New reserves are
|
* Insert a incoming transaction into reserves. New reserves are
|
||||||
* also created through this function.
|
* also created through this function. Note that this API call
|
||||||
|
* starts (and stops) its own transaction scope (so the application
|
||||||
|
* must not do so).
|
||||||
*
|
*
|
||||||
* @param cls the @e cls of this struct with the plugin-specific state
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
* @param db the database connection handle
|
* @param db the database connection handle
|
||||||
|
@ -98,6 +98,9 @@ main (int argc, char *const *argv)
|
|||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Mint directory not given\n");
|
"Mint directory not given\n");
|
||||||
|
GNUNET_free_non_null (add_str);
|
||||||
|
GNUNET_free_non_null (details);
|
||||||
|
GNUNET_free_non_null (reserve_pub_str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ((NULL == reserve_pub_str) ||
|
if ((NULL == reserve_pub_str) ||
|
||||||
@ -109,6 +112,9 @@ main (int argc, char *const *argv)
|
|||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Parsing reserve key invalid\n");
|
"Parsing reserve key invalid\n");
|
||||||
|
GNUNET_free_non_null (add_str);
|
||||||
|
GNUNET_free_non_null (details);
|
||||||
|
GNUNET_free_non_null (reserve_pub_str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ( (NULL == add_str) ||
|
if ( (NULL == add_str) ||
|
||||||
@ -119,6 +125,9 @@ main (int argc, char *const *argv)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Failed to parse currency amount `%s'\n",
|
"Failed to parse currency amount `%s'\n",
|
||||||
add_str);
|
add_str);
|
||||||
|
GNUNET_free_non_null (add_str);
|
||||||
|
GNUNET_free_non_null (details);
|
||||||
|
GNUNET_free_non_null (reserve_pub_str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +135,9 @@ main (int argc, char *const *argv)
|
|||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"No wiring details given (justification required)\n");
|
"No wiring details given (justification required)\n");
|
||||||
return 1;
|
GNUNET_free_non_null (add_str);
|
||||||
|
GNUNET_free_non_null (reserve_pub_str);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg = TALER_config_load (mint_directory);
|
cfg = TALER_config_load (mint_directory);
|
||||||
@ -134,7 +145,10 @@ main (int argc, char *const *argv)
|
|||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Failed to load mint configuration\n");
|
"Failed to load mint configuration\n");
|
||||||
return 1;
|
GNUNET_free_non_null (add_str);
|
||||||
|
GNUNET_free_non_null (details);
|
||||||
|
GNUNET_free_non_null (reserve_pub_str);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
ret = 1;
|
ret = 1;
|
||||||
if (NULL ==
|
if (NULL ==
|
||||||
@ -154,24 +168,32 @@ main (int argc, char *const *argv)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
expiration = GNUNET_TIME_relative_to_absolute (RESERVE_EXPIRATION);
|
expiration = GNUNET_TIME_relative_to_absolute (RESERVE_EXPIRATION);
|
||||||
if (GNUNET_OK !=
|
ret = plugin->reserves_in_insert (plugin->cls,
|
||||||
plugin->reserves_in_insert (plugin->cls,
|
session,
|
||||||
session,
|
&reserve_pub,
|
||||||
&reserve_pub,
|
&add_value,
|
||||||
&add_value,
|
details,
|
||||||
details,
|
expiration);
|
||||||
expiration))
|
if (GNUNET_SYSERR == ret)
|
||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Failed to update reserve.\n");
|
"Failed to update reserve.\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
if (GNUNET_NO == ret)
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
"Record exists, reserve not updated.\n");
|
||||||
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
if (NULL != plugin)
|
if (NULL != plugin)
|
||||||
TALER_MINTDB_plugin_unload (plugin);
|
TALER_MINTDB_plugin_unload (plugin);
|
||||||
if (NULL != cfg)
|
if (NULL != cfg)
|
||||||
GNUNET_CONFIGURATION_destroy (cfg);
|
GNUNET_CONFIGURATION_destroy (cfg);
|
||||||
|
GNUNET_free_non_null (add_str);
|
||||||
|
GNUNET_free_non_null (details);
|
||||||
|
GNUNET_free_non_null (reserve_pub_str);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,7 +986,8 @@ postgres_reserves_update (void *cls,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a incoming transaction into reserves. New reserves are also created
|
* Insert a incoming transaction into reserves. New reserves are also created
|
||||||
* through this function.
|
* through this function. Note that this API call starts (and stops) its
|
||||||
|
* own transaction scope (so the application must not do so).
|
||||||
*
|
*
|
||||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
* @param session the database connection handle
|
* @param session the database connection handle
|
||||||
@ -1025,9 +1026,8 @@ postgres_reserves_in_insert (void *cls,
|
|||||||
&reserve);
|
&reserve);
|
||||||
if (GNUNET_SYSERR == reserve_exists)
|
if (GNUNET_SYSERR == reserve_exists)
|
||||||
{
|
{
|
||||||
postgres_rollback (cls,
|
GNUNET_break (0);
|
||||||
session);
|
goto rollback;
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
}
|
||||||
if (GNUNET_NO == reserve_exists)
|
if (GNUNET_NO == reserve_exists)
|
||||||
{
|
{
|
||||||
@ -1084,6 +1084,21 @@ postgres_reserves_in_insert (void *cls,
|
|||||||
params);
|
params);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
||||||
{
|
{
|
||||||
|
const char *efield;
|
||||||
|
|
||||||
|
efield = PQresultErrorField (result,
|
||||||
|
PG_DIAG_SQLSTATE);
|
||||||
|
if ( (PGRES_FATAL_ERROR == PQresultStatus(result)) &&
|
||||||
|
(NULL != strstr ("23505", /* unique violation */
|
||||||
|
efield)) )
|
||||||
|
{
|
||||||
|
/* This means we had the same reserve/justification/details
|
||||||
|
before */
|
||||||
|
PQclear (result);
|
||||||
|
postgres_rollback (cls,
|
||||||
|
session);
|
||||||
|
return GNUNET_NO;
|
||||||
|
}
|
||||||
QUERY_ERR (result);
|
QUERY_ERR (result);
|
||||||
goto rollback;
|
goto rollback;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user