diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-05-08 20:58:48 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2023-05-08 20:58:48 -0600 |
commit | c3a28e71c81677a4cf387c7473acf1ac85685c75 (patch) | |
tree | 0988b104a7537fb478da2d7fa754b964a6b36331 /src/backenddb/plugin_merchantdb_postgres.c | |
parent | 1b39e3bced6f3c8d9b7ffa885179dd9877e7ed0d (diff) | |
download | merchant-c3a28e71c81677a4cf387c7473acf1ac85685c75.tar.gz merchant-c3a28e71c81677a4cf387c7473acf1ac85685c75.tar.bz2 merchant-c3a28e71c81677a4cf387c7473acf1ac85685c75.zip |
Factor out insert_instance (shit job)
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 99 |
1 files changed, 3 insertions, 96 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index a28fd716..9605c29e 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -44,6 +44,7 @@ #include "pg_lookup_reserves.h" #include "pg_lookup_instance_auth.h" #include "pg_update_transfer_status.h" +#include "pg_insert_instance.h" #include "pg_set_transfer_status_to_confirmed.h" @@ -320,70 +321,6 @@ postgres_commit (void *cls) params); } -/** - * Insert information about an instance into our database. - * - * @param cls closure - * @param merchant_pub public key of the instance - * @param merchant_priv private key of the instance - * @param is details about the instance - * @param ias authentication settings for the instance - * @return database result code - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_instance ( - void *cls, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const struct TALER_MerchantPrivateKeyP *merchant_priv, - const struct TALER_MERCHANTDB_InstanceSettings *is, - const struct TALER_MERCHANTDB_InstanceAuthSettings *ias) -{ - struct PostgresClosure *pg = cls; - uint32_t ut32 = (uint32_t) is->ut; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash), - GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt), - GNUNET_PQ_query_param_string (is->id), - GNUNET_PQ_query_param_string (is->name), - GNUNET_PQ_query_param_uint32 (&ut32), - TALER_PQ_query_param_json (is->address), - TALER_PQ_query_param_json (is->jurisdiction), - TALER_PQ_query_param_amount (&is->default_max_deposit_fee), - TALER_PQ_query_param_amount (&is->default_max_wire_fee), - GNUNET_PQ_query_param_uint32 (&is->default_wire_fee_amortization), - GNUNET_PQ_query_param_relative_time ( - &is->default_wire_transfer_delay), - GNUNET_PQ_query_param_relative_time (&is->default_pay_delay), - (NULL == is->website) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (is->website), - (NULL == is->email) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (is->email), - (NULL == is->logo) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (is->logo), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam params_priv[] = { - GNUNET_PQ_query_param_auto_from_type (merchant_priv), - GNUNET_PQ_query_param_string (is->id), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_instance", - params); - if (qs <= 0) - return qs; - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_keys", - params_priv); -} - /** * Closure for kyc_status_cb(). @@ -6994,37 +6931,6 @@ postgres_connect (void *cls) struct GNUNET_PQ_PreparedStatement ps[] = { GNUNET_PQ_make_prepare ("end_transaction", "COMMIT"), - /* for postgres_insert_instance() */ - GNUNET_PQ_make_prepare ("insert_instance", - "INSERT INTO merchant_instances" - "(merchant_pub" - ",auth_hash" - ",auth_salt" - ",merchant_id" - ",merchant_name" - ",user_type" - ",address" - ",jurisdiction" - ",default_max_deposit_fee_val" - ",default_max_deposit_fee_frac" - ",default_max_wire_fee_val" - ",default_max_wire_fee_frac" - ",default_wire_fee_amortization" - ",default_wire_transfer_delay" - ",default_pay_delay" - ",website" - ",email" - ",logo)" - "VALUES" - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)"), - /* for postgres_insert_instance() */ - GNUNET_PQ_make_prepare ("insert_keys", - "INSERT INTO merchant_keys" - "(merchant_priv" - ",merchant_serial)" - " SELECT $1, merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$2"), /* for postgres_account_kyc_set_status */ GNUNET_PQ_make_prepare ("upsert_account_kyc", "INSERT INTO merchant_kyc" @@ -9417,7 +9323,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->commit = &postgres_commit; plugin->lookup_instance_auth = &TMH_PG_lookup_instance_auth; - plugin->insert_instance = &postgres_insert_instance; + plugin->insert_instance + = &TMH_PG_insert_instance; plugin->insert_account = &TMH_PG_insert_account; plugin->update_account |