summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-11-29 17:27:53 +0100
committerChristian Grothoff <christian@grothoff.org>2020-11-29 17:27:53 +0100
commit855e7829d764aa178020ce4423449dcb5a8536ce (patch)
tree633f77f2ab8b20a674b9c9579bea6946313cb4f2 /src/exchangedb
parent6b434c626f6335f8174e0164ead61b3874752c4a (diff)
downloadexchange-855e7829d764aa178020ce4423449dcb5a8536ce.tar.gz
exchange-855e7829d764aa178020ce4423449dcb5a8536ce.tar.bz2
exchange-855e7829d764aa178020ce4423449dcb5a8536ce.zip
more work on DB plugin for managemetn API
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/exchange-0002.sql4
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c161
2 files changed, 151 insertions, 14 deletions
diff --git a/src/exchangedb/exchange-0002.sql b/src/exchangedb/exchange-0002.sql
index 2162c45ef..f90097da4 100644
--- a/src/exchangedb/exchange-0002.sql
+++ b/src/exchangedb/exchange-0002.sql
@@ -98,6 +98,7 @@ CREATE TABLE IF NOT EXISTS auditor_denom_sigs
(auditor_pub BYTEA NOT NULL REFERENCES auditors (auditor_pub) ON DELETE CASCADE
,denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE
,auditor_sig BYTEA PRIMARY KEY CHECK (LENGTH(auditor_sig)=64)
+ ,PRIMARY KEY (denom_pub_hash, auditor_pub)
);
COMMENT ON TABLE auditor_denom_sigs
IS 'Table with auditor signatures on exchange denomination keys.';
@@ -107,9 +108,6 @@ COMMENT ON COLUMN auditor_denom_sigs.denom_pub_hash
IS 'Denomination the signature is for.';
COMMENT ON COLUMN auditor_denom_sigs.auditor_sig
IS 'Signature of the auditor, of purpose TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS.';
-CREATE INDEX IF NOT EXISTS auditor_denom_sigs_denom_hash_index
- ON auditor_denom_sigs
- (denom_pub_hash);
CREATE TABLE IF NOT EXISTS exchange_sign_keys
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 843d3901e..f7ddac5e1 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1412,7 +1412,6 @@ postgres_get_session (void *cls)
" FROM auditors"
" WHERE auditor_pub=$1;",
1),
-
/* Used in #postgres_lookup_wire_timestamp() */
GNUNET_PQ_make_prepare ("lookup_wire_timestamp",
"SELECT"
@@ -1459,6 +1458,63 @@ postgres_get_session (void *cls)
" ,last_change=$3"
" WHERE payto_uri=$1",
3),
+ /* used in #postgres_insert_signkey_revocation() */
+ GNUNET_PQ_make_prepare ("insert_signkey_revocation",
+ "INSERT INTO signkey_revocations "
+ "(exchange_pub"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2);",
+ 2),
+ /* used in #postgres_lookup_future_denomination_key() */
+ GNUNET_PQ_make_prepare ("lookup_future_denomination_key",
+ "SELECT"
+ " valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin_val"
+ ",coin_frac"
+ ",fee_withdraw_val"
+ ",fee_withdraw_frac"
+ ",fee_deposit_val"
+ ",fee_deposit_frac"
+ ",fee_refresh_val"
+ ",fee_refresh_frac"
+ ",fee_refund_val"
+ ",fee_refund_frac"
+ " FROM future_denominations"
+ " WHERE denom_pub_hash=$1;",
+ 1),
+ /* used in #postgres_lookup_denomination_key() */
+ GNUNET_PQ_make_prepare ("lookup_denomination_key",
+ "SELECT"
+ " valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin_val"
+ ",coin_frac"
+ ",fee_withdraw_val"
+ ",fee_withdraw_frac"
+ ",fee_deposit_val"
+ ",fee_deposit_frac"
+ ",fee_refresh_val"
+ ",fee_refresh_frac"
+ ",fee_refund_val"
+ ",fee_refund_frac"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1;",
+ 1),
+ /* used in #postgres_insert_auditor_denom_sig() */
+ GNUNET_PQ_make_prepare ("insert_auditor_denom_sig",
+ "INSERT INTO auditor_denom_sigs "
+ "(auditor_pub"
+ ",denom_pub_hash"
+ ",auditor_sig"
+ ") VALUES "
+ "($1, $2, $3);",
+ 3),
/* used in #postgres_commit */
GNUNET_PQ_make_prepare ("do_commit",
"COMMIT",
@@ -7629,8 +7685,16 @@ postgres_insert_signkey_revocation (
const struct TALER_ExchangePublicKeyP *exchange_pub,
const struct TALER_MasterSignatureP *master_sig)
{
- GNUNET_break (0); // FIXME: not implemented
- return GNUNET_DB_STATUS_HARD_ERROR;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ (void) cls;
+ return GNUNET_PQ_eval_prepared_non_select (session->conn,
+ "insert_signkey_revocation",
+ params);
}
@@ -7648,10 +7712,39 @@ postgres_lookup_future_denomination_key (
void *cls,
struct TALER_EXCHANGEDB_Session *session,
const struct GNUNET_HashCode *h_denom_pub,
- const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
+ struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
{
- GNUNET_break (0); // FIXME: not implemented
- return GNUNET_DB_STATUS_HARD_ERROR;
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_absolute_time ("valid_from",
+ &meta->start),
+ TALER_PQ_result_spec_absolute_time ("expire_withdraw",
+ &meta->expire_withdraw),
+ TALER_PQ_result_spec_absolute_time ("expire_deposit",
+ &meta->expire_deposit),
+ TALER_PQ_result_spec_absolute_time ("expire_legal",
+ &meta->expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
+ &meta->value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &meta->fee_withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &meta->fee_deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &meta->fee_refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &meta->fee_refund),
+ GNUNET_PQ_result_spec_end
+ };
+
+ return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
+ "lookup_future_denomination_key",
+ params,
+ rs);
}
@@ -7669,10 +7762,39 @@ postgres_lookup_denomination_key (
void *cls,
struct TALER_EXCHANGEDB_Session *session,
const struct GNUNET_HashCode *h_denom_pub,
- const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
+ struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
{
- GNUNET_break (0); // FIXME: not implemented
- return GNUNET_DB_STATUS_HARD_ERROR;
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_absolute_time ("valid_from",
+ &meta->start),
+ TALER_PQ_result_spec_absolute_time ("expire_withdraw",
+ &meta->expire_withdraw),
+ TALER_PQ_result_spec_absolute_time ("expire_deposit",
+ &meta->expire_deposit),
+ TALER_PQ_result_spec_absolute_time ("expire_legal",
+ &meta->expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
+ &meta->value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &meta->fee_withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &meta->fee_deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &meta->fee_refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &meta->fee_refund),
+ GNUNET_PQ_result_spec_end
+ };
+
+ return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
+ "lookup_denomination_key",
+ params,
+ rs);
}
@@ -7719,8 +7841,17 @@ postgres_insert_auditor_denom_sig (
const struct TALER_AuditorPublicKeyP *auditor_pub,
const struct TALER_AuditorSignatureP *auditor_sig)
{
- GNUNET_break (0); // FIXME: not implemented
- return GNUNET_DB_STATUS_HARD_ERROR;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_auto_from_type (auditor_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ (void) cls;
+ return GNUNET_PQ_eval_prepared_non_select (session->conn,
+ "insert_auditor_denom_sig",
+ params);
}
@@ -7926,6 +8057,14 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &postgres_insert_wire;
plugin->update_wire
= &postgres_update_wire;
+ plugin->insert_signkey_revocation
+ = &postgres_insert_signkey_revocation;
+ plugin->lookup_future_denomination_key
+ = &postgres_lookup_future_denomination_key;
+ plugin->lookup_denomination_key
+ = &postgres_lookup_denomination_key;
+ plugin->insert_auditor_denom_sig
+ = &postgres_insert_auditor_denom_sig;
return plugin;
}