diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-04-11 16:48:30 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-04-11 16:48:30 +0200 |
commit | 7a1dcc52ca9a6d79be10076b06b9a3e6ea35d395 (patch) | |
tree | b16344053dbf177032286a5083cc938c480b8292 /src/exchangedb | |
parent | c8c100529711959a1c18a5591b450362e648a9f6 (diff) | |
download | exchange-7a1dcc52ca9a6d79be10076b06b9a3e6ea35d395.tar.xz |
-towards new GET /contracts/$C_PUB hander
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 47ac6ad25..b79c8dd89 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -3429,9 +3429,19 @@ prepare_statements (struct PostgresClosure *pg) GNUNET_PQ_make_prepare ( "select_contract", "SELECT " + " purse_pub" + ",e_contract" + ",contract_sig" + " FROM contracts" + " WHERE pub_ckey=$1;", + 1), + /* Used in #postgres_select_contract_by_purse */ + GNUNET_PQ_make_prepare ( + "select_contract_by_purse", + "SELECT " " pub_ckey" ",e_contract" - // ",econtract_sig" + ",contract_sig" " FROM contracts" " WHERE purse_pub=$1;", 1), @@ -12997,14 +13007,58 @@ postgres_insert_partner (void *cls, */ static enum GNUNET_DB_QueryStatus postgres_select_contract (void *cls, - const struct TALER_PurseContractPublicKeyP *purse_pub, - struct TALER_ContractDiffiePublicP *pub_ckey, + const struct TALER_ContractDiffiePublicP *pub_ckey, + struct TALER_PurseContractPublicKeyP *purse_pub, struct TALER_PurseContractSignatureP *econtract_sig, size_t *econtract_size, void **econtract) { struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (pub_ckey), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("purse_pub", + purse_pub), + GNUNET_PQ_result_spec_auto_from_type ("contract_sig", + econtract_sig), + GNUNET_PQ_result_spec_variable_size ("econtract", + econtract, + econtract_size), + GNUNET_PQ_result_spec_end + }; + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "select_contract", + params, + rs); + +} + +/** + * Function called to retrieve an encrypted contract. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param purse_pub key to lookup the contract by + * @param[out] pub_ckey set to the ephemeral DH used to encrypt the contract + * @param[out] econtract_sig set to the signature over the encrypted contract + * @param[out] econtract_size set to the number of bytes in @a econtract + * @param[out] econtract set to the encrypted contract on success, to be freed by the caller + * @return transaction status code + */ +static enum GNUNET_DB_QueryStatus +postgres_select_contract_by_purse (void *cls, + const struct + TALER_PurseContractPublicKeyP *purse_pub, + struct TALER_ContractDiffiePublicP *pub_ckey, + struct TALER_PurseContractSignatureP * + econtract_sig, + size_t *econtract_size, + void **econtract) +{ + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (purse_pub), GNUNET_PQ_query_param_end @@ -13019,8 +13073,9 @@ postgres_select_contract (void *cls, econtract_size), GNUNET_PQ_result_spec_end }; + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "select_contract", + "select_contract_by_purse", params, rs); @@ -13075,12 +13130,12 @@ postgres_insert_contract ( size_t econtract_size2; void *econtract2; - qs = postgres_select_contract (pg, - purse_pub, - &pub_ckey2, - &esig2, - &econtract_size2, - &econtract2); + qs = postgres_select_contract_by_purse (pg, + purse_pub, + &pub_ckey2, + &esig2, + &econtract_size2, + &econtract2); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) { GNUNET_break (0); @@ -13797,6 +13852,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &postgres_insert_contract; plugin->select_contract = &postgres_select_contract; + plugin->select_contract_by_purse + = &postgres_select_contract_by_purse; plugin->insert_purse_request = &postgres_insert_purse_request; plugin->select_purse_request |