diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_track_transaction.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_track_transaction.c | 113 |
1 files changed, 63 insertions, 50 deletions
diff --git a/src/exchange/taler-exchange-httpd_track_transaction.c b/src/exchange/taler-exchange-httpd_track_transaction.c index fdda22b8d..c89192680 100644 --- a/src/exchange/taler-exchange-httpd_track_transaction.c +++ b/src/exchange/taler-exchange-httpd_track_transaction.c | |||
@@ -40,12 +40,14 @@ | |||
40 | */ | 40 | */ |
41 | static int | 41 | static int |
42 | reply_transfer_pending (struct MHD_Connection *connection, | 42 | reply_transfer_pending (struct MHD_Connection *connection, |
43 | struct GNUNET_TIME_Absolute planned_exec_time) | 43 | struct GNUNET_TIME_Absolute planned_exec_time) |
44 | { | 44 | { |
45 | return TEH_RESPONSE_reply_json_pack (connection, | 45 | return TEH_RESPONSE_reply_json_pack (connection, |
46 | MHD_HTTP_ACCEPTED, | 46 | MHD_HTTP_ACCEPTED, |
47 | "{s:o}", | 47 | "{s:o}", |
48 | "execution_time", GNUNET_JSON_from_time_abs (planned_exec_time)); | 48 | "execution_time", |
49 | GNUNET_JSON_from_time_abs ( | ||
50 | planned_exec_time)); | ||
49 | } | 51 | } |
50 | 52 | ||
51 | 53 | ||
@@ -65,12 +67,12 @@ reply_transfer_pending (struct MHD_Connection *connection, | |||
65 | */ | 67 | */ |
66 | static int | 68 | static int |
67 | reply_track_transaction (struct MHD_Connection *connection, | 69 | reply_track_transaction (struct MHD_Connection *connection, |
68 | const struct GNUNET_HashCode *h_contract_terms, | 70 | const struct GNUNET_HashCode *h_contract_terms, |
69 | const struct GNUNET_HashCode *h_wire, | 71 | const struct GNUNET_HashCode *h_wire, |
70 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 72 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
71 | const struct TALER_Amount *coin_contribution, | 73 | const struct TALER_Amount *coin_contribution, |
72 | const struct TALER_WireTransferIdentifierRawP *wtid, | 74 | const struct TALER_WireTransferIdentifierRawP *wtid, |
73 | struct GNUNET_TIME_Absolute exec_time) | 75 | struct GNUNET_TIME_Absolute exec_time) |
74 | { | 76 | { |
75 | struct TALER_ConfirmWirePS cw; | 77 | struct TALER_ConfirmWirePS cw; |
76 | struct TALER_ExchangePublicKeyP pub; | 78 | struct TALER_ExchangePublicKeyP pub; |
@@ -87,8 +89,8 @@ reply_track_transaction (struct MHD_Connection *connection, | |||
87 | coin_contribution); | 89 | coin_contribution); |
88 | if (GNUNET_OK != | 90 | if (GNUNET_OK != |
89 | TEH_KS_sign (&cw.purpose, | 91 | TEH_KS_sign (&cw.purpose, |
90 | &pub, | 92 | &pub, |
91 | &sig)) | 93 | &sig)) |
92 | { | 94 | { |
93 | return TEH_RESPONSE_reply_internal_error (connection, | 95 | return TEH_RESPONSE_reply_internal_error (connection, |
94 | TALER_EC_EXCHANGE_BAD_CONFIGURATION, | 96 | TALER_EC_EXCHANGE_BAD_CONFIGURATION, |
@@ -97,11 +99,17 @@ reply_track_transaction (struct MHD_Connection *connection, | |||
97 | return TEH_RESPONSE_reply_json_pack (connection, | 99 | return TEH_RESPONSE_reply_json_pack (connection, |
98 | MHD_HTTP_OK, | 100 | MHD_HTTP_OK, |
99 | "{s:o, s:o, s:o, s:o, s:o}", | 101 | "{s:o, s:o, s:o, s:o, s:o}", |
100 | "wtid", GNUNET_JSON_from_data_auto (wtid), | 102 | "wtid", GNUNET_JSON_from_data_auto ( |
101 | "execution_time", GNUNET_JSON_from_time_abs (exec_time), | 103 | wtid), |
102 | "coin_contribution", TALER_JSON_from_amount (coin_contribution), | 104 | "execution_time", |
103 | "exchange_sig", GNUNET_JSON_from_data_auto (&sig), | 105 | GNUNET_JSON_from_time_abs (exec_time), |
104 | "exchange_pub", GNUNET_JSON_from_data_auto (&pub)); | 106 | "coin_contribution", |
107 | TALER_JSON_from_amount ( | ||
108 | coin_contribution), | ||
109 | "exchange_sig", | ||
110 | GNUNET_JSON_from_data_auto (&sig), | ||
111 | "exchange_pub", | ||
112 | GNUNET_JSON_from_data_auto (&pub)); | ||
105 | } | 113 | } |
106 | 114 | ||
107 | 115 | ||
@@ -173,10 +181,10 @@ struct DepositWtidContext | |||
173 | */ | 181 | */ |
174 | static void | 182 | static void |
175 | handle_wtid_data (void *cls, | 183 | handle_wtid_data (void *cls, |
176 | const struct TALER_WireTransferIdentifierRawP *wtid, | 184 | const struct TALER_WireTransferIdentifierRawP *wtid, |
177 | const struct TALER_Amount *coin_contribution, | 185 | const struct TALER_Amount *coin_contribution, |
178 | const struct TALER_Amount *coin_fee, | 186 | const struct TALER_Amount *coin_fee, |
179 | struct GNUNET_TIME_Absolute execution_time) | 187 | struct GNUNET_TIME_Absolute execution_time) |
180 | { | 188 | { |
181 | struct DepositWtidContext *ctx = cls; | 189 | struct DepositWtidContext *ctx = cls; |
182 | 190 | ||
@@ -188,8 +196,8 @@ handle_wtid_data (void *cls, | |||
188 | } | 196 | } |
189 | if (GNUNET_SYSERR == | 197 | if (GNUNET_SYSERR == |
190 | TALER_amount_subtract (&ctx->coin_delta, | 198 | TALER_amount_subtract (&ctx->coin_delta, |
191 | coin_contribution, | 199 | coin_contribution, |
192 | coin_fee)) | 200 | coin_fee)) |
193 | { | 201 | { |
194 | GNUNET_break (0); | 202 | GNUNET_break (0); |
195 | ctx->pending = GNUNET_SYSERR; | 203 | ctx->pending = GNUNET_SYSERR; |
@@ -221,35 +229,35 @@ handle_wtid_data (void *cls, | |||
221 | */ | 229 | */ |
222 | static enum GNUNET_DB_QueryStatus | 230 | static enum GNUNET_DB_QueryStatus |
223 | track_transaction_transaction (void *cls, | 231 | track_transaction_transaction (void *cls, |
224 | struct MHD_Connection *connection, | 232 | struct MHD_Connection *connection, |
225 | struct TALER_EXCHANGEDB_Session *session, | 233 | struct TALER_EXCHANGEDB_Session *session, |
226 | int *mhd_ret) | 234 | int *mhd_ret) |
227 | { | 235 | { |
228 | struct DepositWtidContext *ctx = cls; | 236 | struct DepositWtidContext *ctx = cls; |
229 | enum GNUNET_DB_QueryStatus qs; | 237 | enum GNUNET_DB_QueryStatus qs; |
230 | 238 | ||
231 | qs = TEH_plugin->wire_lookup_deposit_wtid (TEH_plugin->cls, | 239 | qs = TEH_plugin->wire_lookup_deposit_wtid (TEH_plugin->cls, |
232 | session, | 240 | session, |
233 | &ctx->tps->h_contract_terms, | 241 | &ctx->tps->h_contract_terms, |
234 | &ctx->tps->h_wire, | 242 | &ctx->tps->h_wire, |
235 | &ctx->tps->coin_pub, | 243 | &ctx->tps->coin_pub, |
236 | ctx->merchant_pub, | 244 | ctx->merchant_pub, |
237 | &handle_wtid_data, | 245 | &handle_wtid_data, |
238 | ctx); | 246 | ctx); |
239 | if (0 > qs) | 247 | if (0 > qs) |
240 | { | 248 | { |
241 | if (GNUNET_DB_STATUS_HARD_ERROR == qs) | 249 | if (GNUNET_DB_STATUS_HARD_ERROR == qs) |
242 | { | 250 | { |
243 | GNUNET_break (0); | 251 | GNUNET_break (0); |
244 | *mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection, | 252 | *mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection, |
245 | TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED); | 253 | TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED); |
246 | } | 254 | } |
247 | return qs; | 255 | return qs; |
248 | } | 256 | } |
249 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) | 257 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) |
250 | { | 258 | { |
251 | *mhd_ret = TEH_RESPONSE_reply_transaction_unknown (connection, | 259 | *mhd_ret = TEH_RESPONSE_reply_transaction_unknown (connection, |
252 | TALER_EC_TRACK_TRANSACTION_NOT_FOUND); | 260 | TALER_EC_TRACK_TRANSACTION_NOT_FOUND); |
253 | return GNUNET_DB_STATUS_HARD_ERROR; | 261 | return GNUNET_DB_STATUS_HARD_ERROR; |
254 | } | 262 | } |
255 | return qs; | 263 | return qs; |
@@ -268,23 +276,28 @@ track_transaction_transaction (void *cls, | |||
268 | */ | 276 | */ |
269 | static int | 277 | static int |
270 | check_and_handle_track_transaction_request (struct MHD_Connection *connection, | 278 | check_and_handle_track_transaction_request (struct MHD_Connection *connection, |
271 | const struct TALER_DepositTrackPS *tps, | 279 | const struct |
272 | const struct TALER_MerchantPublicKeyP *merchant_pub, | 280 | TALER_DepositTrackPS *tps, |
273 | const struct TALER_MerchantSignatureP *merchant_sig) | 281 | const struct |
282 | TALER_MerchantPublicKeyP * | ||
283 | merchant_pub, | ||
284 | const struct | ||
285 | TALER_MerchantSignatureP * | ||
286 | merchant_sig) | ||
274 | { | 287 | { |
275 | struct DepositWtidContext ctx; | 288 | struct DepositWtidContext ctx; |
276 | int mhd_ret; | 289 | int mhd_ret; |
277 | 290 | ||
278 | if (GNUNET_OK != | 291 | if (GNUNET_OK != |
279 | GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_TRACK_TRANSACTION, | 292 | GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_TRACK_TRANSACTION, |
280 | &tps->purpose, | 293 | &tps->purpose, |
281 | &merchant_sig->eddsa_sig, | 294 | &merchant_sig->eddsa_sig, |
282 | &merchant_pub->eddsa_pub)) | 295 | &merchant_pub->eddsa_pub)) |
283 | { | 296 | { |
284 | GNUNET_break_op (0); | 297 | GNUNET_break_op (0); |
285 | return TEH_RESPONSE_reply_signature_invalid (connection, | 298 | return TEH_RESPONSE_reply_signature_invalid (connection, |
286 | TALER_EC_TRACK_TRANSACTION_MERCHANT_SIGNATURE_INVALID, | 299 | TALER_EC_TRACK_TRANSACTION_MERCHANT_SIGNATURE_INVALID, |
287 | "merchant_sig"); | 300 | "merchant_sig"); |
288 | } | 301 | } |
289 | ctx.pending = GNUNET_NO; | 302 | ctx.pending = GNUNET_NO; |
290 | ctx.tps = tps; | 303 | ctx.tps = tps; |
@@ -293,23 +306,23 @@ check_and_handle_track_transaction_request (struct MHD_Connection *connection, | |||
293 | if (GNUNET_OK != | 306 | if (GNUNET_OK != |
294 | TEH_DB_run_transaction (connection, | 307 | TEH_DB_run_transaction (connection, |
295 | "handle track transaction", | 308 | "handle track transaction", |
296 | &mhd_ret, | 309 | &mhd_ret, |
297 | &track_transaction_transaction, | 310 | &track_transaction_transaction, |
298 | &ctx)) | 311 | &ctx)) |
299 | return mhd_ret; | 312 | return mhd_ret; |
300 | if (GNUNET_YES == ctx.pending) | 313 | if (GNUNET_YES == ctx.pending) |
301 | return reply_transfer_pending (connection, | 314 | return reply_transfer_pending (connection, |
302 | ctx.execution_time); | 315 | ctx.execution_time); |
303 | if (GNUNET_SYSERR == ctx.pending) | 316 | if (GNUNET_SYSERR == ctx.pending) |
304 | return TEH_RESPONSE_reply_internal_db_error (connection, | 317 | return TEH_RESPONSE_reply_internal_db_error (connection, |
305 | TALER_EC_TRACK_TRANSACTION_DB_FEE_INCONSISTENT); | 318 | TALER_EC_TRACK_TRANSACTION_DB_FEE_INCONSISTENT); |
306 | return reply_track_transaction (connection, | 319 | return reply_track_transaction (connection, |
307 | &tps->h_contract_terms, | 320 | &tps->h_contract_terms, |
308 | &tps->h_wire, | 321 | &tps->h_wire, |
309 | &tps->coin_pub, | 322 | &tps->coin_pub, |
310 | &ctx.coin_delta, | 323 | &ctx.coin_delta, |
311 | &ctx.wtid, | 324 | &ctx.wtid, |
312 | ctx.execution_time); | 325 | ctx.execution_time); |
313 | } | 326 | } |
314 | 327 | ||
315 | 328 | ||