aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-05-03 19:54:36 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-19 01:05:57 +0200
commitbfeb9ac5d041fe42d770b07f6adaad13ded9e9a8 (patch)
tree56a9b4281e117c05b26e464d152e99a1c5e234ec
parenteb965ac7098f33fb76da4b6576db7d44d06238f6 (diff)
downloadexchange-bfeb9ac5d041fe42d770b07f6adaad13ded9e9a8.tar.gz
exchange-bfeb9ac5d041fe42d770b07f6adaad13ded9e9a8.zip
update exchange API to return struct instead of lots of individual args for TALER_EXCHANGE_transfers_get() -- simplifies merchant later
-rw-r--r--src/include/taler_exchange_service.h72
-rw-r--r--src/lib/exchange_api_transfers_get.c164
-rw-r--r--src/testing/testing_api_cmd_transfer_get.c33
3 files changed, 140 insertions, 129 deletions
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index a57a2655a..307a76de8 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -1581,31 +1581,67 @@ struct TALER_EXCHANGE_TransfersGetHandle;
1581 1581
1582 1582
1583/** 1583/**
1584 * Information the exchange returns per wire transfer.
1585 */
1586struct TALER_EXCHANGE_TransferData
1587{
1588
1589 /**
1590 * exchange key used to sign
1591 */
1592 struct TALER_ExchangePublicKeyP exchange_pub;
1593
1594 /**
1595 * exchange signature over the transfer data
1596 */
1597 struct TALER_ExchangeSignatureP exchange_sig;
1598
1599 /**
1600 * hash of the wire transfer address the transfer went to
1601 */
1602 struct GNUNET_HashCode h_wire;
1603
1604 /**
1605 * time when the exchange claims to have performed the wire transfer
1606 */
1607 struct GNUNET_TIME_Absolute execution_time;
1608
1609 /**
1610 * amount of the wire transfer
1611 */
1612 struct TALER_Amount total_amount;
1613
1614 /**
1615 * wire fee that was charged by the exchange
1616 */
1617 struct TALER_Amount wire_fee;
1618
1619 /**
1620 * length of the @e details array
1621 */
1622 unsigned int details_length;
1623
1624 /**
1625 * array with details about the combined transactions
1626 */
1627 const struct TALER_TrackTransferDetails *details;
1628
1629};
1630
1631
1632/**
1584 * Function called with detailed wire transfer data, including all 1633 * Function called with detailed wire transfer data, including all
1585 * of the coin transactions that were combined into the wire transfer. 1634 * of the coin transactions that were combined into the wire transfer.
1586 * 1635 *
1587 * @param cls closure 1636 * @param cls closure
1588 * @param hr HTTP response data 1637 * @param hr HTTP response data
1589 * @param sign_key exchange key used to sign @a json, or NULL 1638 * @param ta transfer data, (set only if @a http_status is #MHD_HTTP_OK, otherwise NULL)
1590 * @param h_wire hash of the wire transfer address the transfer went to, or NULL on error
1591 * @param execution_time time when the exchange claims to have performed the wire transfer
1592 * @param total_amount total amount of the wire transfer, or NULL if the exchange could
1593 * not provide any @a wtid (set only if @a http_status is #MHD_HTTP_OK)
1594 * @param wire_fee wire fee that was charged by the exchange
1595 * @param details_length length of the @a details array
1596 * @param details array with details about the combined transactions
1597 */ 1639 */
1598typedef void 1640typedef void
1599(*TALER_EXCHANGE_TransfersGetCallback)( 1641(*TALER_EXCHANGE_TransfersGetCallback)(
1600 void *cls, 1642 void *cls,
1601 const struct TALER_EXCHANGE_HttpResponse *hr, 1643 const struct TALER_EXCHANGE_HttpResponse *hr,
1602 const struct TALER_ExchangePublicKeyP *sign_key, 1644 const struct TALER_EXCHANGE_TransferData *ta);
1603 const struct GNUNET_HashCode *h_wire,
1604 struct GNUNET_TIME_Absolute execution_time,
1605 const struct TALER_Amount *total_amount,
1606 const struct TALER_Amount *wire_fee,
1607 unsigned int details_length,
1608 const struct TALER_TrackTransferDetails *details);
1609 1645
1610 1646
1611/** 1647/**
@@ -1651,17 +1687,19 @@ struct TALER_EXCHANGE_DepositGetHandle;
1651 * 1687 *
1652 * @param cls closure 1688 * @param cls closure
1653 * @param hr HTTP response data 1689 * @param hr HTTP response data
1654 * @param sign_key exchange key used to sign @a json, or NULL 1690 * @param exchange_pub exchange key used to sign @a json, or NULL
1655 * @param wtid wire transfer identifier used by the exchange, NULL if exchange did not 1691 * @param wtid wire transfer identifier used by the exchange, NULL if exchange did not
1656 * yet execute the transaction 1692 * yet execute the transaction
1657 * @param execution_time actual or planned execution time for the wire transfer 1693 * @param execution_time actual or planned execution time for the wire transfer
1658 * @param coin_contribution contribution to the total amount by this coin (can be NULL) 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
1659 */ 1697 */
1660typedef void 1698typedef void
1661(*TALER_EXCHANGE_DepositGetCallback)( 1699(*TALER_EXCHANGE_DepositGetCallback)(
1662 void *cls, 1700 void *cls,
1663 const struct TALER_EXCHANGE_HttpResponse *hr, 1701 const struct TALER_EXCHANGE_HttpResponse *hr,
1664 const struct TALER_ExchangePublicKeyP *sign_key, 1702 const struct TALER_ExchangePublicKeyP *exchange_pub,
1665 const struct TALER_WireTransferIdentifierRawP *wtid, 1703 const struct TALER_WireTransferIdentifierRawP *wtid,
1666 struct GNUNET_TIME_Absolute execution_time, 1704 struct GNUNET_TIME_Absolute execution_time,
1667 const struct TALER_Amount *coin_contribution); 1705 const struct TALER_Amount *coin_contribution);
diff --git a/src/lib/exchange_api_transfers_get.c b/src/lib/exchange_api_transfers_get.c
index 552536958..dd9b64467 100644
--- a/src/lib/exchange_api_transfers_get.c
+++ b/src/lib/exchange_api_transfers_get.c
@@ -85,24 +85,18 @@ check_transfers_get_response_ok (
85 const json_t *json) 85 const json_t *json)
86{ 86{
87 json_t *details_j; 87 json_t *details_j;
88 struct GNUNET_HashCode h_wire; 88 struct TALER_EXCHANGE_TransferData td;
89 struct GNUNET_TIME_Absolute exec_time;
90 struct TALER_Amount total_amount;
91 struct TALER_Amount total_expected; 89 struct TALER_Amount total_expected;
92 struct TALER_Amount wire_fee;
93 struct TALER_MerchantPublicKeyP merchant_pub; 90 struct TALER_MerchantPublicKeyP merchant_pub;
94 unsigned int num_details;
95 struct TALER_ExchangePublicKeyP exchange_pub;
96 struct TALER_ExchangeSignatureP exchange_sig;
97 struct GNUNET_JSON_Specification spec[] = { 91 struct GNUNET_JSON_Specification spec[] = {
98 TALER_JSON_spec_amount ("total", &total_amount), 92 TALER_JSON_spec_amount ("total", &td.total_amount),
99 TALER_JSON_spec_amount ("wire_fee", &wire_fee), 93 TALER_JSON_spec_amount ("wire_fee", &td.wire_fee),
100 GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), 94 GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub),
101 GNUNET_JSON_spec_fixed_auto ("h_wire", &h_wire), 95 GNUNET_JSON_spec_fixed_auto ("h_wire", &td.h_wire),
102 GNUNET_JSON_spec_absolute_time ("execution_time", &exec_time), 96 GNUNET_JSON_spec_absolute_time ("execution_time", &td.execution_time),
103 GNUNET_JSON_spec_json ("deposits", &details_j), 97 GNUNET_JSON_spec_json ("deposits", &details_j),
104 GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig), 98 GNUNET_JSON_spec_fixed_auto ("exchange_sig", &td.exchange_sig),
105 GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), 99 GNUNET_JSON_spec_fixed_auto ("exchange_pub", &td.exchange_pub),
106 GNUNET_JSON_spec_end () 100 GNUNET_JSON_spec_end ()
107 }; 101 };
108 struct TALER_EXCHANGE_HttpResponse hr = { 102 struct TALER_EXCHANGE_HttpResponse hr = {
@@ -119,22 +113,32 @@ check_transfers_get_response_ok (
119 return GNUNET_SYSERR; 113 return GNUNET_SYSERR;
120 } 114 }
121 if (GNUNET_OK != 115 if (GNUNET_OK !=
122 TALER_amount_get_zero (total_amount.currency, 116 TALER_amount_get_zero (td.total_amount.currency,
123 &total_expected)) 117 &total_expected))
124 { 118 {
125 GNUNET_break_op (0); 119 GNUNET_break_op (0);
120 GNUNET_JSON_parse_free (spec);
126 return GNUNET_SYSERR; 121 return GNUNET_SYSERR;
127 } 122 }
128 num_details = json_array_size (details_j); 123 if (GNUNET_OK !=
124 TALER_EXCHANGE_test_signing_key (
125 TALER_EXCHANGE_get_keys (wdh->exchange),
126 &td.exchange_pub))
127 {
128 GNUNET_break_op (0);
129 GNUNET_JSON_parse_free (spec);
130 return GNUNET_SYSERR;
131 }
132 td.details_length = json_array_size (details_j);
129 { 133 {
130 struct TALER_TrackTransferDetails details[num_details];
131 unsigned int i;
132 struct GNUNET_HashContext *hash_context; 134 struct GNUNET_HashContext *hash_context;
133 struct TALER_WireDepositDetailP dd; 135 struct TALER_TrackTransferDetails *details;
134 struct TALER_WireDepositDataPS wdp;
135 136
137 details = GNUNET_new_array (td.details_length,
138 struct TALER_TrackTransferDetails);
139 td.details = details;
136 hash_context = GNUNET_CRYPTO_hash_context_start (); 140 hash_context = GNUNET_CRYPTO_hash_context_start ();
137 for (i = 0; i<num_details; i++) 141 for (unsigned int i = 0; i<td.details_length; i++)
138 { 142 {
139 struct TALER_TrackTransferDetails *detail = &details[i]; 143 struct TALER_TrackTransferDetails *detail = &details[i];
140 struct json_t *detail_j = json_array_get (details_j, i); 144 struct json_t *detail_j = json_array_get (details_j, i);
@@ -147,25 +151,11 @@ check_transfers_get_response_ok (
147 GNUNET_JSON_spec_end () 151 GNUNET_JSON_spec_end ()
148 }; 152 };
149 153
150 if (GNUNET_OK != 154 if ( (GNUNET_OK !=
151 GNUNET_JSON_parse (detail_j, 155 GNUNET_JSON_parse (detail_j,
152 spec_detail, 156 spec_detail,
153 NULL, NULL)) 157 NULL, NULL)) ||
154 { 158 (0 >
155 GNUNET_break_op (0);
156 GNUNET_CRYPTO_hash_context_abort (hash_context);
157 GNUNET_JSON_parse_free (spec);
158 return GNUNET_SYSERR;
159 }
160 /* build up big hash for signature checking later */
161 dd.h_contract_terms = detail->h_contract_terms;
162 dd.execution_time = GNUNET_TIME_absolute_hton (exec_time);
163 dd.coin_pub = detail->coin_pub;
164 TALER_amount_hton (&dd.deposit_value,
165 &detail->coin_value);
166 TALER_amount_hton (&dd.deposit_fee,
167 &detail->coin_fee);
168 if ( (0 >
169 TALER_amount_add (&total_expected, 159 TALER_amount_add (&total_expected,
170 &total_expected, 160 &total_expected,
171 &detail->coin_value)) || 161 &detail->coin_value)) ||
@@ -177,71 +167,78 @@ check_transfers_get_response_ok (
177 GNUNET_break_op (0); 167 GNUNET_break_op (0);
178 GNUNET_CRYPTO_hash_context_abort (hash_context); 168 GNUNET_CRYPTO_hash_context_abort (hash_context);
179 GNUNET_JSON_parse_free (spec); 169 GNUNET_JSON_parse_free (spec);
170 GNUNET_free (details);
180 return GNUNET_SYSERR; 171 return GNUNET_SYSERR;
181 } 172 }
182 GNUNET_CRYPTO_hash_context_read ( 173 /* build up big hash for signature checking later */
183 hash_context, 174 {
184 &dd, 175 struct TALER_WireDepositDetailP dd;
185 sizeof (struct TALER_WireDepositDetailP)); 176
177 dd.h_contract_terms = detail->h_contract_terms;
178 dd.execution_time = GNUNET_TIME_absolute_hton (td.execution_time);
179 dd.coin_pub = detail->coin_pub;
180 TALER_amount_hton (&dd.deposit_value,
181 &detail->coin_value);
182 TALER_amount_hton (&dd.deposit_fee,
183 &detail->coin_fee);
184 GNUNET_CRYPTO_hash_context_read (hash_context,
185 &dd,
186 sizeof (dd));
187 }
186 } 188 }
187 /* Check signature */ 189 /* Check signature */
188 wdp.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT);
189 wdp.purpose.size = htonl (sizeof (struct TALER_WireDepositDataPS));
190 TALER_amount_hton (&wdp.total,
191 &total_amount);
192 TALER_amount_hton (&wdp.wire_fee,
193 &wire_fee);
194 wdp.merchant_pub = merchant_pub;
195 wdp.h_wire = h_wire;
196 GNUNET_CRYPTO_hash_context_finish (hash_context,
197 &wdp.h_details);
198 if (GNUNET_OK !=
199 TALER_EXCHANGE_test_signing_key (TALER_EXCHANGE_get_keys (
200 wdh->exchange),
201 &exchange_pub))
202 { 190 {
203 GNUNET_break_op (0); 191 struct TALER_WireDepositDataPS wdp = {
204 GNUNET_JSON_parse_free (spec); 192 .purpose.purpose = htonl (
205 return GNUNET_SYSERR; 193 TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT),
206 } 194 .purpose.size = htonl (sizeof (wdp)),
207 if (GNUNET_OK != 195 .merchant_pub = merchant_pub,
208 GNUNET_CRYPTO_eddsa_verify ( 196 .h_wire = td.h_wire
209 TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT, 197 };
210 &wdp, 198
211 &exchange_sig.eddsa_signature, 199 TALER_amount_hton (&wdp.total,
212 &exchange_pub.eddsa_pub)) 200 &td.total_amount);
213 { 201 TALER_amount_hton (&wdp.wire_fee,
214 GNUNET_break_op (0); 202 &td.wire_fee);
215 GNUNET_JSON_parse_free (spec); 203 GNUNET_CRYPTO_hash_context_finish (hash_context,
216 return GNUNET_SYSERR; 204 &wdp.h_details);
205 if (GNUNET_OK !=
206 GNUNET_CRYPTO_eddsa_verify (
207 TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT,
208 &wdp,
209 &td.exchange_sig.eddsa_signature,
210 &td.exchange_pub.eddsa_pub))
211 {
212 GNUNET_break_op (0);
213 GNUNET_JSON_parse_free (spec);
214 GNUNET_free (details);
215 return GNUNET_SYSERR;
216 }
217 } 217 }
218 218
219 if (0 > 219 if (0 >
220 TALER_amount_subtract (&total_expected, 220 TALER_amount_subtract (&total_expected,
221 &total_expected, 221 &total_expected,
222 &wire_fee)) 222 &td.wire_fee))
223 { 223 {
224 GNUNET_break_op (0); 224 GNUNET_break_op (0);
225 GNUNET_JSON_parse_free (spec); 225 GNUNET_JSON_parse_free (spec);
226 GNUNET_free (details);
226 return GNUNET_SYSERR; 227 return GNUNET_SYSERR;
227 } 228 }
228 if (0 != 229 if (0 !=
229 TALER_amount_cmp (&total_expected, 230 TALER_amount_cmp (&total_expected,
230 &total_amount)) 231 &td.total_amount))
231 { 232 {
232 GNUNET_break_op (0); 233 GNUNET_break_op (0);
233 GNUNET_JSON_parse_free (spec); 234 GNUNET_JSON_parse_free (spec);
235 GNUNET_free (details);
234 return GNUNET_SYSERR; 236 return GNUNET_SYSERR;
235 } 237 }
236 wdh->cb (wdh->cb_cls, 238 wdh->cb (wdh->cb_cls,
237 &hr, 239 &hr,
238 &exchange_pub, 240 &td);
239 &h_wire, 241 GNUNET_free (details);
240 exec_time,
241 &total_amount,
242 &wire_fee,
243 num_details,
244 details);
245 } 242 }
246 GNUNET_JSON_parse_free (spec); 243 GNUNET_JSON_parse_free (spec);
247 TALER_EXCHANGE_transfers_get_cancel (wdh); 244 TALER_EXCHANGE_transfers_get_cancel (wdh);
@@ -322,12 +319,7 @@ handle_transfers_get_finished (void *cls,
322 } 319 }
323 wdh->cb (wdh->cb_cls, 320 wdh->cb (wdh->cb_cls,
324 &hr, 321 &hr,
325 NULL, 322 NULL);
326 NULL,
327 GNUNET_TIME_UNIT_ZERO_ABS,
328 NULL,
329 NULL,
330 0, NULL);
331 TALER_EXCHANGE_transfers_get_cancel (wdh); 323 TALER_EXCHANGE_transfers_get_cancel (wdh);
332} 324}
333 325
diff --git a/src/testing/testing_api_cmd_transfer_get.c b/src/testing/testing_api_cmd_transfer_get.c
index 699313e56..3ca319cb5 100644
--- a/src/testing/testing_api_cmd_transfer_get.c
+++ b/src/testing/testing_api_cmd_transfer_get.c
@@ -121,37 +121,18 @@ track_transfer_cleanup (void *cls,
121 * 121 *
122 * @param cls closure. 122 * @param cls closure.
123 * @param hr HTTP response details 123 * @param hr HTTP response details
124 * @param exchange_pub public key the exchange used for signing 124 * @param ta transfer data returned by the exchange
125 * the response.
126 * @param h_wire hash of the wire transfer address the transfer
127 * went to, or NULL on error.
128 * @param execution_time time when the exchange claims to have
129 * performed the wire transfer.
130 * @param total_amount total amount of the wire transfer, or NULL
131 * if the exchange could not provide any @a wtid (set only
132 * if @a http_status is "200 OK").
133 * @param wire_fee wire fee that was charged by the exchange.
134 * @param details_length length of the @a details array.
135 * @param details array with details about the combined
136 * transactions.
137 */ 125 */
138static void 126static void
139track_transfer_cb (void *cls, 127track_transfer_cb (void *cls,
140 const struct TALER_EXCHANGE_HttpResponse *hr, 128 const struct TALER_EXCHANGE_HttpResponse *hr,
141 const struct TALER_ExchangePublicKeyP *exchange_pub, 129 const struct TALER_EXCHANGE_TransferData *ta)
142 const struct GNUNET_HashCode *h_wire,
143 struct GNUNET_TIME_Absolute execution_time,
144 const struct TALER_Amount *total_amount,
145 const struct TALER_Amount *wire_fee,
146 unsigned int details_length,
147 const struct TALER_TrackTransferDetails *details)
148{ 130{
149 struct TrackTransferState *tts = cls; 131 struct TrackTransferState *tts = cls;
150 struct TALER_TESTING_Interpreter *is = tts->is; 132 struct TALER_TESTING_Interpreter *is = tts->is;
151 struct TALER_TESTING_Command *cmd = &is->commands[is->ip]; 133 struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
152 struct TALER_Amount expected_amount; 134 struct TALER_Amount expected_amount;
153 135
154 (void) exchange_pub;
155 tts->tth = NULL; 136 tts->tth = NULL;
156 if (tts->expected_response_code != hr->http_status) 137 if (tts->expected_response_code != hr->http_status)
157 { 138 {
@@ -193,14 +174,14 @@ track_transfer_cb (void *cls,
193 TALER_TESTING_interpreter_fail (is); 174 TALER_TESTING_interpreter_fail (is);
194 return; 175 return;
195 } 176 }
196 if (0 != TALER_amount_cmp (total_amount, 177 if (0 != TALER_amount_cmp (&ta->total_amount,
197 &expected_amount)) 178 &expected_amount))
198 { 179 {
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 180 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
200 "Total amount mismatch to command %s - " 181 "Total amount mismatch to command %s - "
201 "%s vs %s\n", 182 "%s vs %s\n",
202 cmd->label, 183 cmd->label,
203 TALER_amount_to_string (total_amount), 184 TALER_amount_to_string (&ta->total_amount),
204 TALER_amount_to_string (&expected_amount)); 185 TALER_amount_to_string (&expected_amount));
205 json_dumpf (hr->reply, 186 json_dumpf (hr->reply,
206 stderr, 187 stderr,
@@ -219,7 +200,7 @@ track_transfer_cb (void *cls,
219 return; 200 return;
220 } 201 }
221 202
222 if (0 != TALER_amount_cmp (wire_fee, 203 if (0 != TALER_amount_cmp (&ta->wire_fee,
223 &expected_amount)) 204 &expected_amount))
224 { 205 {
225 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -266,7 +247,7 @@ track_transfer_cb (void *cls,
266 TALER_JSON_merchant_wire_signature_hash (wire_details, 247 TALER_JSON_merchant_wire_signature_hash (wire_details,
267 &h_wire_details)); 248 &h_wire_details));
268 if (0 != GNUNET_memcmp (&h_wire_details, 249 if (0 != GNUNET_memcmp (&h_wire_details,
269 h_wire)) 250 &ta->h_wire))
270 { 251 {
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 252 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
272 "Wire hash missmath to command %s\n", 253 "Wire hash missmath to command %s\n",
@@ -301,7 +282,7 @@ track_transfer_cb (void *cls,
301 TALER_TESTING_interpreter_fail (is); 282 TALER_TESTING_interpreter_fail (is);
302 return; 283 return;
303 } 284 }
304 if (0 != TALER_amount_cmp (total_amount, 285 if (0 != TALER_amount_cmp (&ta->total_amount,
305 total_amount_from_reference)) 286 total_amount_from_reference))
306 { 287 {
307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 288 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,