-more exchange API atomization

This commit is contained in:
Christian Grothoff 2023-06-22 20:37:15 +02:00
parent 7bb9547599
commit d4a65faad4
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 45 additions and 53 deletions

View File

@ -5785,7 +5785,8 @@ struct TALER_EXCHANGE_ContractsGetHandle;
/**
* Request information about a contract from the exchange.
*
* @param exchange exchange handle
* @param ctx CURL context
* @param url exchange base URL
* @param contract_priv private key of the contract
* @param cb function to call with the exchange's result
* @param cb_cls closure for @a cb
@ -5793,7 +5794,8 @@ struct TALER_EXCHANGE_ContractsGetHandle;
*/
struct TALER_EXCHANGE_ContractsGetHandle *
TALER_EXCHANGE_contract_get (
struct TALER_EXCHANGE_Handle *exchange,
struct GNUNET_CURL_Context *ctx,
const char *url,
const struct TALER_ContractDiffiePrivateP *contract_priv,
TALER_EXCHANGE_ContractGetCallback cb,
void *cb_cls);
@ -6637,7 +6639,8 @@ typedef void
/**
* Submit a request to get the list of attestable attributes for a reserve.
*
* @param exchange the exchange handle; the exchange must be ready to operate
* @param ctx CURL context
* @param url exchange base URL
* @param reserve_pub public key of the reserve to get available attributes for
* @param cb the callback to call when a reply for this request is available
* @param cb_cls closure for the above callback
@ -6646,7 +6649,8 @@ typedef void
*/
struct TALER_EXCHANGE_ReservesGetAttestHandle *
TALER_EXCHANGE_reserves_get_attestable (
struct TALER_EXCHANGE_Handle *exchange,
struct GNUNET_CURL_Context *ctx,
const char *url,
const struct TALER_ReservePublicKeyP *reserve_pub,
TALER_EXCHANGE_ReservesGetAttestCallback cb,
void *cb_cls);

View File

@ -38,11 +38,6 @@
struct TALER_EXCHANGE_ContractsGetHandle
{
/**
* The connection to exchange this request handle will use
*/
struct TALER_EXCHANGE_Handle *exchange;
/**
* The url for this request.
*/
@ -194,7 +189,8 @@ handle_contract_get_finished (void *cls,
struct TALER_EXCHANGE_ContractsGetHandle *
TALER_EXCHANGE_contract_get (
struct TALER_EXCHANGE_Handle *exchange,
struct GNUNET_CURL_Context *ctx,
const char *url,
const struct TALER_ContractDiffiePrivateP *contract_priv,
TALER_EXCHANGE_ContractGetCallback cb,
void *cb_cls)
@ -203,14 +199,7 @@ TALER_EXCHANGE_contract_get (
CURL *eh;
char arg_str[sizeof (cgh->cpub) * 2 + 48];
if (GNUNET_YES !=
TEAH_handle_is_ready (exchange))
{
GNUNET_break (0);
return NULL;
}
cgh = GNUNET_new (struct TALER_EXCHANGE_ContractsGetHandle);
cgh->exchange = exchange;
cgh->cb = cb;
cgh->cb_cls = cb_cls;
GNUNET_CRYPTO_ecdhe_key_get_public (&contract_priv->ecdhe_priv,
@ -226,12 +215,13 @@ TALER_EXCHANGE_contract_get (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
"/contracts/%s",
"contracts/%s",
cpub_str);
}
cgh->url = TEAH_path_to_url (exchange,
arg_str);
cgh->url = TALER_url_join (url,
arg_str,
NULL);
if (NULL == cgh->url)
{
GNUNET_free (cgh);
@ -247,7 +237,7 @@ TALER_EXCHANGE_contract_get (
GNUNET_free (cgh);
return NULL;
}
cgh->job = GNUNET_CURL_job_add (TEAH_handle_to_context (exchange),
cgh->job = GNUNET_CURL_job_add (ctx,
eh,
&handle_contract_get_finished,
cgh);

View File

@ -226,7 +226,8 @@ TALER_EXCHANGE_reserves_get (
rgh->cb_cls = cb_cls;
rgh->reserve_pub = *reserve_pub;
rgh->url = TALER_url_join (url,
arg_str);
arg_str,
NULL);
if (NULL == rgh->url)
{
GNUNET_free (rgh);

View File

@ -38,11 +38,6 @@
struct TALER_EXCHANGE_ReservesGetAttestHandle
{
/**
* The connection to exchange this request handle will use
*/
struct TALER_EXCHANGE_Handle *exchange;
/**
* The url for this request.
*/
@ -211,22 +206,16 @@ handle_reserves_get_attestable_finished (void *cls,
struct TALER_EXCHANGE_ReservesGetAttestHandle *
TALER_EXCHANGE_reserves_get_attestable (
struct TALER_EXCHANGE_Handle *exchange,
struct GNUNET_CURL_Context *ctx,
const char *url,
const struct TALER_ReservePublicKeyP *reserve_pub,
TALER_EXCHANGE_ReservesGetAttestCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_ReservesGetAttestHandle *rgah;
struct GNUNET_CURL_Context *ctx;
CURL *eh;
char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
if (GNUNET_YES !=
TEAH_handle_is_ready (exchange))
{
GNUNET_break (0);
return NULL;
}
{
char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
char *end;
@ -239,16 +228,16 @@ TALER_EXCHANGE_reserves_get_attestable (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
"/reserves-attest/%s",
"reserves-attest/%s",
pub_str);
}
rgah = GNUNET_new (struct TALER_EXCHANGE_ReservesGetAttestHandle);
rgah->exchange = exchange;
rgah->cb = cb;
rgah->cb_cls = cb_cls;
rgah->reserve_pub = *reserve_pub;
rgah->url = TEAH_path_to_url (exchange,
arg_str);
rgah->url = TALER_url_join (url,
arg_str,
NULL);
if (NULL == rgah->url)
{
GNUNET_free (rgah);
@ -262,7 +251,6 @@ TALER_EXCHANGE_reserves_get_attestable (
GNUNET_free (rgah);
return NULL;
}
ctx = TEAH_handle_to_context (exchange);
rgah->job = GNUNET_CURL_job_add (ctx,
eh,
&handle_reserves_get_attestable_finished,

View File

@ -190,13 +190,16 @@ get_run (void *cls,
struct ContractGetState *ds = cls;
const struct TALER_ContractDiffiePrivateP *contract_priv;
const struct TALER_TESTING_Command *ref;
struct TALER_EXCHANGE_Handle *exchange
= TALER_TESTING_get_exchange (is);
const char *exchange_url;
(void) cmd;
if (NULL == exchange)
return;
ds->is = is;
exchange_url = TALER_TESTING_get_exchange_url (is);
if (NULL == exchange_url)
{
GNUNET_break (0);
return;
}
ref = TALER_TESTING_interpreter_lookup_command (ds->is,
ds->contract_ref);
GNUNET_assert (NULL != ref);
@ -210,7 +213,8 @@ get_run (void *cls,
}
ds->contract_priv = *contract_priv;
ds->dh = TALER_EXCHANGE_contract_get (
exchange,
TALER_TESTING_interpreter_get_context (is),
exchange_url,
contract_priv,
&get_cb,
ds);

View File

@ -125,12 +125,15 @@ get_attestable_run (void *cls,
const struct TALER_TESTING_Command *ref_reserve;
const struct TALER_ReservePrivateKeyP *reserve_priv;
const struct TALER_ReservePublicKeyP *reserve_pub;
struct TALER_EXCHANGE_Handle *exchange
= TALER_TESTING_get_exchange (is);
const char *exchange_url;
if (NULL == exchange)
return;
ss->is = is;
exchange_url = TALER_TESTING_get_exchange_url (is);
if (NULL == exchange_url)
{
GNUNET_break (0);
return;
}
ref_reserve
= TALER_TESTING_interpreter_lookup_command (is,
ss->reserve_reference);
@ -162,7 +165,9 @@ get_attestable_run (void *cls,
}
ss->reserve_pub = *reserve_pub;
}
ss->rgah = TALER_EXCHANGE_reserves_get_attestable (exchange,
ss->rgah = TALER_EXCHANGE_reserves_get_attestable (
TALER_TESTING_interpreter_get_context (is),
exchange_url,
&ss->reserve_pub,
&reserve_get_attestable_cb,
ss);