implement postgres_get_denomination_info (#3808)
This commit is contained in:
parent
548e19e9fd
commit
3724e3d166
@ -667,14 +667,9 @@ struct TALER_MINTDB_Plugin
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a denomination key.
|
* Insert information about a denomination key and in particular
|
||||||
*
|
* the properties (value, fees, expiration times) the coins signed
|
||||||
* FIXME: Note that the main mint currently does NOT use this API at
|
* with this key have.
|
||||||
* all. Furthermore, the function to retrieve denomination keys
|
|
||||||
* from the DB is still missing. The main mint should check if its
|
|
||||||
* denomination keys are in the DB, and if not, insert them (when it
|
|
||||||
* loads them). The auditor will (presumably) need the denomination
|
|
||||||
* key information to audit the DB. (#3808).
|
|
||||||
*
|
*
|
||||||
* @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 sesssion connection to use
|
* @param sesssion connection to use
|
||||||
@ -683,10 +678,26 @@ struct TALER_MINTDB_Plugin
|
|||||||
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
|
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
(*insert_denomination) (void *cls,
|
(*insert_denomination_info) (void *cls,
|
||||||
struct TALER_MINTDB_Session *session,
|
struct TALER_MINTDB_Session *session,
|
||||||
const struct TALER_DenominationPublicKey *denom_pub,
|
const struct TALER_DenominationPublicKey *denom_pub,
|
||||||
const struct TALER_DenominationKeyValidityPS *issue);
|
const struct TALER_DenominationKeyValidityPS *issue);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch information about a denomination key.
|
||||||
|
*
|
||||||
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
|
* @param sesssion connection to use
|
||||||
|
* @param denom_pub the public key used for signing coins of this denomination
|
||||||
|
* @param[out] issue set to issue information with value, fees and other info about the coin
|
||||||
|
* @return #GNUNET_OK on success; #GNUNET_NO if no record was found, #GNUNET_SYSERR on failure
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
(*get_denomination_info) (void *cls,
|
||||||
|
struct TALER_MINTDB_Session *session,
|
||||||
|
const struct TALER_DenominationPublicKey *denom_pub,
|
||||||
|
struct TALER_DenominationKeyValidityPS *issue);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -438,8 +438,8 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
PQclear (result); result = NULL; \
|
PQclear (result); result = NULL; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
/* Used in #postgres_insert_denomination() */
|
/* Used in #postgres_insert_denomination_info() */
|
||||||
PREPARE ("insert_denomination",
|
PREPARE ("denomination_insert",
|
||||||
"INSERT INTO denominations "
|
"INSERT INTO denominations "
|
||||||
"(pub"
|
"(pub"
|
||||||
",master_pub"
|
",master_pub"
|
||||||
@ -465,7 +465,29 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
" $11, $12, $13, $14, $15, $16, $17, $18, $19);",
|
" $11, $12, $13, $14, $15, $16, $17, $18, $19);",
|
||||||
19, NULL);
|
19, NULL);
|
||||||
|
|
||||||
/* FIXME: #3808: need a 'select_denominations' for auditor */
|
/* Used in #postgres_get_denomination_info() */
|
||||||
|
PREPARE ("denomination_get",
|
||||||
|
"SELECT FROM denominations"
|
||||||
|
" master_pub"
|
||||||
|
",master_sig"
|
||||||
|
",valid_from"
|
||||||
|
",expire_withdraw"
|
||||||
|
",expire_spend"
|
||||||
|
",expire_legal"
|
||||||
|
",coin_val" /* value of this denom */
|
||||||
|
",coin_frac" /* fractional value of this denom */
|
||||||
|
",coin_curr" /* assuming same currency for fees */
|
||||||
|
",fee_withdraw_val"
|
||||||
|
",fee_withdraw_frac"
|
||||||
|
",fee_withdraw_curr" /* must match coin_curr */
|
||||||
|
",fee_deposit_val"
|
||||||
|
",fee_deposit_frac"
|
||||||
|
",fee_deposit_curr" /* must match coin_curr */
|
||||||
|
",fee_refresh_val"
|
||||||
|
",fee_refresh_frac"
|
||||||
|
",fee_refresh_curr" /* must match coin_curr */
|
||||||
|
" WHERE pub=$1;",
|
||||||
|
1, NULL);
|
||||||
|
|
||||||
/* Used in #postgres_reserve_get() */
|
/* Used in #postgres_reserve_get() */
|
||||||
PREPARE ("reserve_get",
|
PREPARE ("reserve_get",
|
||||||
@ -1027,10 +1049,10 @@ postgres_commit (void *cls,
|
|||||||
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
|
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
postgres_insert_denomination (void *cls,
|
postgres_insert_denomination_info (void *cls,
|
||||||
struct TALER_MINTDB_Session *session,
|
struct TALER_MINTDB_Session *session,
|
||||||
const struct TALER_DenominationPublicKey *denom_pub,
|
const struct TALER_DenominationPublicKey *denom_pub,
|
||||||
const struct TALER_DenominationKeyValidityPS *issue)
|
const struct TALER_DenominationKeyValidityPS *issue)
|
||||||
{
|
{
|
||||||
PGresult *result;
|
PGresult *result;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1061,7 +1083,7 @@ postgres_insert_denomination (void *cls,
|
|||||||
&issue->fee_refresh));
|
&issue->fee_refresh));
|
||||||
|
|
||||||
result = TALER_PQ_exec_prepared (session->conn,
|
result = TALER_PQ_exec_prepared (session->conn,
|
||||||
"insert_denomination",
|
"denomination_insert",
|
||||||
params);
|
params);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus (result))
|
if (PGRES_COMMAND_OK != PQresultStatus (result))
|
||||||
{
|
{
|
||||||
@ -1077,6 +1099,86 @@ postgres_insert_denomination (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch information about a denomination key.
|
||||||
|
*
|
||||||
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
|
* @param sesssion connection to use
|
||||||
|
* @param denom_pub the public key used for signing coins of this denomination
|
||||||
|
* @param[out] issue set to issue information with value, fees and other info about the coin
|
||||||
|
* @return #GNUNET_OK on success; #GNUNET_NO if no record was found, #GNUNET_SYSERR on failure
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
postgres_get_denomination_info (void *cls,
|
||||||
|
struct TALER_MINTDB_Session *session,
|
||||||
|
const struct TALER_DenominationPublicKey *denom_pub,
|
||||||
|
struct TALER_DenominationKeyValidityPS *issue)
|
||||||
|
{
|
||||||
|
PGresult *result;
|
||||||
|
struct TALER_PQ_QueryParam params[] = {
|
||||||
|
TALER_PQ_query_param_rsa_public_key (denom_pub->rsa_public_key),
|
||||||
|
TALER_PQ_query_param_end
|
||||||
|
};
|
||||||
|
|
||||||
|
result = TALER_PQ_exec_prepared (session->conn,
|
||||||
|
"reserve_get",
|
||||||
|
params);
|
||||||
|
if (PGRES_TUPLES_OK != PQresultStatus (result))
|
||||||
|
{
|
||||||
|
QUERY_ERR (result);
|
||||||
|
PQclear (result);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
|
if (0 == PQntuples (result))
|
||||||
|
{
|
||||||
|
PQclear (result);
|
||||||
|
return GNUNET_NO;
|
||||||
|
}
|
||||||
|
if (1 != PQntuples (result))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
PQclear (result);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
struct TALER_PQ_ResultSpec rs[] = {
|
||||||
|
TALER_PQ_result_spec_auto_from_type ("master_pub",
|
||||||
|
&issue->master),
|
||||||
|
TALER_PQ_result_spec_auto_from_type ("master_sig",
|
||||||
|
&issue->signature),
|
||||||
|
TALER_PQ_result_spec_auto_from_type ("valid_from",
|
||||||
|
&issue->start.abs_value_us__),
|
||||||
|
TALER_PQ_result_spec_auto_from_type ("expire_withdraw",
|
||||||
|
&issue->expire_withdraw.abs_value_us__),
|
||||||
|
TALER_PQ_result_spec_auto_from_type ("expire_spend",
|
||||||
|
&issue->expire_spend.abs_value_us__),
|
||||||
|
TALER_PQ_result_spec_auto_from_type ("expire_legal",
|
||||||
|
&issue->expire_legal.abs_value_us__),
|
||||||
|
TALER_PQ_result_spec_amount_nbo ("coin",
|
||||||
|
&issue->value),
|
||||||
|
TALER_PQ_result_spec_amount_nbo ("fee_withdraw",
|
||||||
|
&issue->fee_withdraw),
|
||||||
|
TALER_PQ_result_spec_amount_nbo ("fee_deposit",
|
||||||
|
&issue->fee_deposit),
|
||||||
|
TALER_PQ_result_spec_amount_nbo ("fee_refresh",
|
||||||
|
&issue->fee_refresh),
|
||||||
|
TALER_PQ_result_spec_end
|
||||||
|
};
|
||||||
|
|
||||||
|
EXITIF (GNUNET_OK !=
|
||||||
|
TALER_PQ_extract_result (result,
|
||||||
|
rs,
|
||||||
|
0));
|
||||||
|
}
|
||||||
|
PQclear (result);
|
||||||
|
return GNUNET_OK;
|
||||||
|
|
||||||
|
EXITIF_exit:
|
||||||
|
PQclear (result);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the summary of a reserve.
|
* Get the summary of a reserve.
|
||||||
*
|
*
|
||||||
@ -1097,11 +1199,6 @@ postgres_reserve_get (void *cls,
|
|||||||
TALER_PQ_query_param_auto_from_type(&reserve->pub),
|
TALER_PQ_query_param_auto_from_type(&reserve->pub),
|
||||||
TALER_PQ_query_param_end
|
TALER_PQ_query_param_end
|
||||||
};
|
};
|
||||||
struct TALER_PQ_ResultSpec rs[] = {
|
|
||||||
TALER_PQ_result_spec_amount("current_balance", &reserve->balance),
|
|
||||||
TALER_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry),
|
|
||||||
TALER_PQ_result_spec_end
|
|
||||||
};
|
|
||||||
|
|
||||||
result = TALER_PQ_exec_prepared (session->conn,
|
result = TALER_PQ_exec_prepared (session->conn,
|
||||||
"reserve_get",
|
"reserve_get",
|
||||||
@ -1117,10 +1214,18 @@ postgres_reserve_get (void *cls,
|
|||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
EXITIF (GNUNET_OK !=
|
{
|
||||||
TALER_PQ_extract_result (result,
|
struct TALER_PQ_ResultSpec rs[] = {
|
||||||
rs,
|
TALER_PQ_result_spec_amount("current_balance", &reserve->balance),
|
||||||
0));
|
TALER_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry),
|
||||||
|
TALER_PQ_result_spec_end
|
||||||
|
};
|
||||||
|
|
||||||
|
EXITIF (GNUNET_OK !=
|
||||||
|
TALER_PQ_extract_result (result,
|
||||||
|
rs,
|
||||||
|
0));
|
||||||
|
}
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
|
|
||||||
@ -3047,7 +3152,8 @@ libtaler_plugin_mintdb_postgres_init (void *cls)
|
|||||||
plugin->start = &postgres_start;
|
plugin->start = &postgres_start;
|
||||||
plugin->commit = &postgres_commit;
|
plugin->commit = &postgres_commit;
|
||||||
plugin->rollback = &postgres_rollback;
|
plugin->rollback = &postgres_rollback;
|
||||||
plugin->insert_denomination = &postgres_insert_denomination;
|
plugin->insert_denomination_info = &postgres_insert_denomination_info;
|
||||||
|
plugin->get_denomination_info = &postgres_get_denomination_info;
|
||||||
plugin->reserve_get = &postgres_reserve_get;
|
plugin->reserve_get = &postgres_reserve_get;
|
||||||
plugin->reserves_in_insert = &postgres_reserves_in_insert;
|
plugin->reserves_in_insert = &postgres_reserves_in_insert;
|
||||||
plugin->get_withdraw_info = &postgres_get_withdraw_info;
|
plugin->get_withdraw_info = &postgres_get_withdraw_info;
|
||||||
|
Loading…
Reference in New Issue
Block a user