diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-05-03 20:07:49 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-05-03 20:07:49 +0200 |
commit | 1ed77a9f2eb94a37b2571f5b4e9c4d2c5fa4e326 (patch) | |
tree | b75468121c759abe9f9fe76f4576854e0e36721d | |
parent | 35bfdbef190c90debedade678954cf4cfdd201fb (diff) | |
download | exchange-1ed77a9f2eb94a37b2571f5b4e9c4d2c5fa4e326.tar.gz exchange-1ed77a9f2eb94a37b2571f5b4e9c4d2c5fa4e326.zip |
modify TALER_EXCHANGE_deposits_get() API to combine returned arguments into a struct (simplifies merchant later)
-rw-r--r-- | src/include/taler_exchange_service.h | 52 | ||||
-rw-r--r-- | src/lib/exchange_api_deposits_get.c | 77 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_deposits_get.c | 21 |
3 files changed, 89 insertions, 61 deletions
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 307a76de8..320123041 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h | |||
@@ -1683,26 +1683,56 @@ struct TALER_EXCHANGE_DepositGetHandle; | |||
1683 | 1683 | ||
1684 | 1684 | ||
1685 | /** | 1685 | /** |
1686 | * Data returned for a successful GET /deposits/ request. Note that | ||
1687 | * most fields are only set if the status is #MHD_HTTP_OK. Only | ||
1688 | * the @e execution_time is available if the status is #MHD_HTTP_ACCEPTED. | ||
1689 | */ | ||
1690 | struct TALER_EXCHANGE_DepositData | ||
1691 | { | ||
1692 | |||
1693 | /** | ||
1694 | * exchange key used to sign, NULL if exchange did not | ||
1695 | * yet execute the transaction | ||
1696 | */ | ||
1697 | const struct TALER_ExchangePublicKeyP *exchange_pub; | ||
1698 | |||
1699 | /** | ||
1700 | * signature from the exchange over the deposit data, NULL if exchange did not | ||
1701 | * yet execute the transaction | ||
1702 | */ | ||
1703 | const struct TALER_ExchangeSignatureP *exchange_sig; | ||
1704 | |||
1705 | /** | ||
1706 | * wire transfer identifier used by the exchange, NULL if exchange did not | ||
1707 | * yet execute the transaction | ||
1708 | */ | ||
1709 | const struct TALER_WireTransferIdentifierRawP *wtid; | ||
1710 | |||
1711 | /** | ||
1712 | * actual or planned execution time for the wire transfer | ||
1713 | */ | ||
1714 | struct GNUNET_TIME_Absolute execution_time; | ||
1715 | |||
1716 | /** | ||
1717 | * contribution to the total amount by this coin, NULL if exchange did not | ||
1718 | * yet execute the transaction | ||
1719 | */ | ||
1720 | const struct TALER_Amount *coin_contribution; | ||
1721 | }; | ||
1722 | |||
1723 | |||
1724 | /** | ||
1686 | * Function called with detailed wire transfer data. | 1725 | * Function called with detailed wire transfer data. |
1687 | * | 1726 | * |
1688 | * @param cls closure | 1727 | * @param cls closure |
1689 | * @param hr HTTP response data | 1728 | * @param hr HTTP response data |
1690 | * @param exchange_pub exchange key used to sign @a json, or NULL | 1729 | * @param dd details about the deposit (NULL on errors) |
1691 | * @param wtid wire transfer identifier used by the exchange, NULL if exchange did not | ||
1692 | * yet execute the transaction | ||
1693 | * @param execution_time actual or planned execution time for the wire transfer | ||
1694 | * @param coin_contribution contribution to the total amount by this coin (can be NULL) | ||
1695 | * // FIXME: also return the exchange signature | ||
1696 | * // FIXME: combine all of the above (except cls,hr) into a 'struct'! => DepositData | ||
1697 | */ | 1730 | */ |
1698 | typedef void | 1731 | typedef void |
1699 | (*TALER_EXCHANGE_DepositGetCallback)( | 1732 | (*TALER_EXCHANGE_DepositGetCallback)( |
1700 | void *cls, | 1733 | void *cls, |
1701 | const struct TALER_EXCHANGE_HttpResponse *hr, | 1734 | const struct TALER_EXCHANGE_HttpResponse *hr, |
1702 | const struct TALER_ExchangePublicKeyP *exchange_pub, | 1735 | const struct TALER_EXCHANGE_DepositData *dd); |
1703 | const struct TALER_WireTransferIdentifierRawP *wtid, | ||
1704 | struct GNUNET_TIME_Absolute execution_time, | ||
1705 | const struct TALER_Amount *coin_contribution); | ||
1706 | 1736 | ||
1707 | 1737 | ||
1708 | /** | 1738 | /** |
diff --git a/src/lib/exchange_api_deposits_get.c b/src/lib/exchange_api_deposits_get.c index aecd88240..6a2ad5c3d 100644 --- a/src/lib/exchange_api_deposits_get.c +++ b/src/lib/exchange_api_deposits_get.c | |||
@@ -33,7 +33,7 @@ | |||
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | * @brief A Deposit Wtid Handle | 36 | * @brief A Deposit Get Handle |
37 | */ | 37 | */ |
38 | struct TALER_EXCHANGE_DepositGetHandle | 38 | struct TALER_EXCHANGE_DepositGetHandle |
39 | { | 39 | { |
@@ -84,31 +84,19 @@ struct TALER_EXCHANGE_DepositGetHandle | |||
84 | * | 84 | * |
85 | * @param dwh deposit wtid handle | 85 | * @param dwh deposit wtid handle |
86 | * @param json json reply with the signature | 86 | * @param json json reply with the signature |
87 | * @param[out] exchange_pub set to the exchange's public key | 87 | * @param exchange_pub the exchange's public key |
88 | * @param exchange_sig the exchange's signature | ||
88 | * @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not | 89 | * @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not |
89 | */ | 90 | */ |
90 | static int | 91 | static int |
91 | verify_deposit_wtid_signature_ok ( | 92 | verify_deposit_wtid_signature_ok ( |
92 | const struct TALER_EXCHANGE_DepositGetHandle *dwh, | 93 | const struct TALER_EXCHANGE_DepositGetHandle *dwh, |
93 | const json_t *json, | 94 | const json_t *json, |
94 | struct TALER_ExchangePublicKeyP *exchange_pub) | 95 | const struct TALER_ExchangePublicKeyP *exchange_pub, |
96 | const struct TALER_ExchangeSignatureP *exchange_sig) | ||
95 | { | 97 | { |
96 | struct TALER_ExchangeSignatureP exchange_sig; | ||
97 | const struct TALER_EXCHANGE_Keys *key_state; | 98 | const struct TALER_EXCHANGE_Keys *key_state; |
98 | struct GNUNET_JSON_Specification spec[] = { | ||
99 | GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig), | ||
100 | GNUNET_JSON_spec_fixed_auto ("exchange_pub", exchange_pub), | ||
101 | GNUNET_JSON_spec_end () | ||
102 | }; | ||
103 | 99 | ||
104 | if (GNUNET_OK != | ||
105 | GNUNET_JSON_parse (json, | ||
106 | spec, | ||
107 | NULL, NULL)) | ||
108 | { | ||
109 | GNUNET_break_op (0); | ||
110 | return GNUNET_SYSERR; | ||
111 | } | ||
112 | key_state = TALER_EXCHANGE_get_keys (dwh->exchange); | 100 | key_state = TALER_EXCHANGE_get_keys (dwh->exchange); |
113 | if (GNUNET_OK != | 101 | if (GNUNET_OK != |
114 | TALER_EXCHANGE_test_signing_key (key_state, | 102 | TALER_EXCHANGE_test_signing_key (key_state, |
@@ -120,7 +108,7 @@ verify_deposit_wtid_signature_ok ( | |||
120 | if (GNUNET_OK != | 108 | if (GNUNET_OK != |
121 | GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE, | 109 | GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE, |
122 | &dwh->depconf, | 110 | &dwh->depconf, |
123 | &exchange_sig.eddsa_signature, | 111 | &exchange_sig->eddsa_signature, |
124 | &exchange_pub->eddsa_pub)) | 112 | &exchange_pub->eddsa_pub)) |
125 | { | 113 | { |
126 | GNUNET_break_op (0); | 114 | GNUNET_break_op (0); |
@@ -144,12 +132,6 @@ handle_deposit_wtid_finished (void *cls, | |||
144 | const void *response) | 132 | const void *response) |
145 | { | 133 | { |
146 | struct TALER_EXCHANGE_DepositGetHandle *dwh = cls; | 134 | struct TALER_EXCHANGE_DepositGetHandle *dwh = cls; |
147 | const struct TALER_WireTransferIdentifierRawP *wtid = NULL; | ||
148 | struct GNUNET_TIME_Absolute execution_time = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
149 | const struct TALER_Amount *coin_contribution = NULL; | ||
150 | struct TALER_Amount coin_contribution_s; | ||
151 | struct TALER_ExchangePublicKeyP exchange_pub; | ||
152 | struct TALER_ExchangePublicKeyP *ep = NULL; | ||
153 | const json_t *j = response; | 135 | const json_t *j = response; |
154 | struct TALER_EXCHANGE_HttpResponse hr = { | 136 | struct TALER_EXCHANGE_HttpResponse hr = { |
155 | .reply = j, | 137 | .reply = j, |
@@ -164,10 +146,16 @@ handle_deposit_wtid_finished (void *cls, | |||
164 | break; | 146 | break; |
165 | case MHD_HTTP_OK: | 147 | case MHD_HTTP_OK: |
166 | { | 148 | { |
149 | struct GNUNET_TIME_Absolute execution_time; | ||
150 | struct TALER_Amount coin_contribution; | ||
151 | struct TALER_ExchangePublicKeyP exchange_pub; | ||
152 | struct TALER_ExchangeSignatureP exchange_sig; | ||
167 | struct GNUNET_JSON_Specification spec[] = { | 153 | struct GNUNET_JSON_Specification spec[] = { |
168 | GNUNET_JSON_spec_fixed_auto ("wtid", &dwh->depconf.wtid), | 154 | GNUNET_JSON_spec_fixed_auto ("wtid", &dwh->depconf.wtid), |
169 | GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time), | 155 | GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time), |
170 | TALER_JSON_spec_amount ("coin_contribution", &coin_contribution_s), | 156 | TALER_JSON_spec_amount ("coin_contribution", &coin_contribution), |
157 | GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig), | ||
158 | GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), | ||
171 | GNUNET_JSON_spec_end () | 159 | GNUNET_JSON_spec_end () |
172 | }; | 160 | }; |
173 | 161 | ||
@@ -181,15 +169,14 @@ handle_deposit_wtid_finished (void *cls, | |||
181 | hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE; | 169 | hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE; |
182 | break; | 170 | break; |
183 | } | 171 | } |
184 | wtid = &dwh->depconf.wtid; | ||
185 | dwh->depconf.execution_time = GNUNET_TIME_absolute_hton (execution_time); | 172 | dwh->depconf.execution_time = GNUNET_TIME_absolute_hton (execution_time); |
186 | TALER_amount_hton (&dwh->depconf.coin_contribution, | 173 | TALER_amount_hton (&dwh->depconf.coin_contribution, |
187 | &coin_contribution_s); | 174 | &coin_contribution); |
188 | coin_contribution = &coin_contribution_s; | ||
189 | if (GNUNET_OK != | 175 | if (GNUNET_OK != |
190 | verify_deposit_wtid_signature_ok (dwh, | 176 | verify_deposit_wtid_signature_ok (dwh, |
191 | j, | 177 | j, |
192 | &exchange_pub)) | 178 | &exchange_pub, |
179 | &exchange_sig)) | ||
193 | { | 180 | { |
194 | GNUNET_break_op (0); | 181 | GNUNET_break_op (0); |
195 | hr.http_status = 0; | 182 | hr.http_status = 0; |
@@ -197,13 +184,26 @@ handle_deposit_wtid_finished (void *cls, | |||
197 | } | 184 | } |
198 | else | 185 | else |
199 | { | 186 | { |
200 | ep = &exchange_pub; | 187 | struct TALER_EXCHANGE_DepositData dd = { |
188 | .exchange_pub = &exchange_pub, | ||
189 | .exchange_sig = &exchange_sig, | ||
190 | .wtid = &dwh->depconf.wtid, | ||
191 | .execution_time = execution_time, | ||
192 | .coin_contribution = &coin_contribution | ||
193 | }; | ||
194 | |||
195 | dwh->cb (dwh->cb_cls, | ||
196 | &hr, | ||
197 | &dd); | ||
198 | TALER_EXCHANGE_deposits_get_cancel (dwh); | ||
199 | return; | ||
201 | } | 200 | } |
202 | } | 201 | } |
203 | break; | 202 | break; |
204 | case MHD_HTTP_ACCEPTED: | 203 | case MHD_HTTP_ACCEPTED: |
205 | { | 204 | { |
206 | /* Transaction known, but not executed yet */ | 205 | /* Transaction known, but not executed yet */ |
206 | struct GNUNET_TIME_Absolute execution_time; | ||
207 | struct GNUNET_JSON_Specification spec[] = { | 207 | struct GNUNET_JSON_Specification spec[] = { |
208 | GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time), | 208 | GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time), |
209 | GNUNET_JSON_spec_end () | 209 | GNUNET_JSON_spec_end () |
@@ -219,6 +219,18 @@ handle_deposit_wtid_finished (void *cls, | |||
219 | hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE; | 219 | hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE; |
220 | break; | 220 | break; |
221 | } | 221 | } |
222 | else | ||
223 | { | ||
224 | struct TALER_EXCHANGE_DepositData dd = { | ||
225 | .execution_time = execution_time | ||
226 | }; | ||
227 | |||
228 | dwh->cb (dwh->cb_cls, | ||
229 | &hr, | ||
230 | &dd); | ||
231 | TALER_EXCHANGE_deposits_get_cancel (dwh); | ||
232 | return; | ||
233 | } | ||
222 | } | 234 | } |
223 | break; | 235 | break; |
224 | case MHD_HTTP_BAD_REQUEST: | 236 | case MHD_HTTP_BAD_REQUEST: |
@@ -259,10 +271,7 @@ handle_deposit_wtid_finished (void *cls, | |||
259 | } | 271 | } |
260 | dwh->cb (dwh->cb_cls, | 272 | dwh->cb (dwh->cb_cls, |
261 | &hr, | 273 | &hr, |
262 | ep, | 274 | NULL); |
263 | wtid, | ||
264 | execution_time, | ||
265 | coin_contribution); | ||
266 | TALER_EXCHANGE_deposits_get_cancel (dwh); | 275 | TALER_EXCHANGE_deposits_get_cancel (dwh); |
267 | } | 276 | } |
268 | 277 | ||
diff --git a/src/testing/testing_api_cmd_deposits_get.c b/src/testing/testing_api_cmd_deposits_get.c index fd02e75bb..6f0140116 100644 --- a/src/testing/testing_api_cmd_deposits_get.c +++ b/src/testing/testing_api_cmd_deposits_get.c | |||
@@ -81,29 +81,17 @@ struct TrackTransactionState | |||
81 | * | 81 | * |
82 | * @param cls closure. | 82 | * @param cls closure. |
83 | * @param hr HTTP response details | 83 | * @param hr HTTP response details |
84 | * @param exchange_pub public key of the exchange | 84 | * @param dd data about the wire transfer associated with the deposit |
85 | * @param wtid wire transfer identifier, NULL if exchange did not | ||
86 | * execute the transaction yet. | ||
87 | * @param execution_time actual or planned execution time for the | ||
88 | * wire transfer. | ||
89 | * @param coin_contribution contribution to the total amount of | ||
90 | * the deposited coin (can be NULL). | ||
91 | */ | 85 | */ |
92 | static void | 86 | static void |
93 | deposit_wtid_cb (void *cls, | 87 | deposit_wtid_cb (void *cls, |
94 | const struct TALER_EXCHANGE_HttpResponse *hr, | 88 | const struct TALER_EXCHANGE_HttpResponse *hr, |
95 | const struct TALER_ExchangePublicKeyP *exchange_pub, | 89 | const struct TALER_EXCHANGE_DepositData *dd) |
96 | const struct TALER_WireTransferIdentifierRawP *wtid, | ||
97 | struct GNUNET_TIME_Absolute execution_time, | ||
98 | const struct TALER_Amount *coin_contribution) | ||
99 | { | 90 | { |
100 | struct TrackTransactionState *tts = cls; | 91 | struct TrackTransactionState *tts = cls; |
101 | struct TALER_TESTING_Interpreter *is = tts->is; | 92 | struct TALER_TESTING_Interpreter *is = tts->is; |
102 | struct TALER_TESTING_Command *cmd = &is->commands[is->ip]; | 93 | struct TALER_TESTING_Command *cmd = &is->commands[is->ip]; |
103 | 94 | ||
104 | (void) coin_contribution; | ||
105 | (void) exchange_pub; | ||
106 | (void) execution_time; | ||
107 | tts->tth = NULL; | 95 | tts->tth = NULL; |
108 | if (tts->expected_response_code != hr->http_status) | 96 | if (tts->expected_response_code != hr->http_status) |
109 | { | 97 | { |
@@ -123,7 +111,8 @@ deposit_wtid_cb (void *cls, | |||
123 | switch (hr->http_status) | 111 | switch (hr->http_status) |
124 | { | 112 | { |
125 | case MHD_HTTP_OK: | 113 | case MHD_HTTP_OK: |
126 | tts->wtid = *wtid; | 114 | GNUNET_assert (NULL != dd->wtid); |
115 | tts->wtid = *dd->wtid; | ||
127 | if (NULL != tts->bank_transfer_reference) | 116 | if (NULL != tts->bank_transfer_reference) |
128 | { | 117 | { |
129 | const struct TALER_TESTING_Command *bank_transfer_cmd; | 118 | const struct TALER_TESTING_Command *bank_transfer_cmd; |
@@ -151,7 +140,7 @@ deposit_wtid_cb (void *cls, | |||
151 | } | 140 | } |
152 | 141 | ||
153 | /* Compare that expected and gotten subjects match. */ | 142 | /* Compare that expected and gotten subjects match. */ |
154 | if (0 != GNUNET_memcmp (wtid, | 143 | if (0 != GNUNET_memcmp (dd->wtid, |
155 | wtid_want)) | 144 | wtid_want)) |
156 | { | 145 | { |
157 | GNUNET_break (0); | 146 | GNUNET_break (0); |