diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-07-31 19:53:40 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-07-31 19:53:50 +0200 |
commit | 723a3b742e9b284400c5164d146dc953383b4384 (patch) | |
tree | eee2ae2fa70c3a68e3908d7e61cdc75d76b787bc | |
parent | 8742b8b8d6a56ad1e21caeb0ade90b1163034c21 (diff) | |
download | exchange-723a3b742e9b284400c5164d146dc953383b4384.tar.gz exchange-723a3b742e9b284400c5164d146dc953383b4384.zip |
-remove more json_pack calls
-rw-r--r-- | src/bank-lib/bank_api_admin.c | 14 | ||||
-rw-r--r-- | src/bank-lib/bank_api_transfer.c | 18 | ||||
-rw-r--r-- | src/bank-lib/fakebank.c | 110 | ||||
-rw-r--r-- | src/exchange-tools/taler-auditor-offline.c | 53 |
4 files changed, 111 insertions, 84 deletions
diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c index a0d68de2d..56828efa9 100644 --- a/src/bank-lib/bank_api_admin.c +++ b/src/bank-lib/bank_api_admin.c | |||
@@ -184,13 +184,13 @@ TALER_BANK_admin_add_incoming ( | |||
184 | json_t *admin_obj; | 184 | json_t *admin_obj; |
185 | CURL *eh; | 185 | CURL *eh; |
186 | 186 | ||
187 | admin_obj = json_pack ("{s:o, s:o, s:s}", | 187 | admin_obj = GNUNET_JSON_PACK ( |
188 | "reserve_pub", | 188 | GNUNET_JSON_pack_data_auto ("reserve_pub", |
189 | GNUNET_JSON_from_data_auto (reserve_pub), | 189 | reserve_pub), |
190 | "amount", | 190 | TALER_JSON_pack_amount ("amount", |
191 | TALER_JSON_from_amount (amount), | 191 | amount), |
192 | "debit_account", | 192 | GNUNET_JSON_pack_string ("debit_account", |
193 | debit_account); | 193 | debit_account)); |
194 | if (NULL == admin_obj) | 194 | if (NULL == admin_obj) |
195 | { | 195 | { |
196 | GNUNET_break (0); | 196 | GNUNET_break (0); |
diff --git a/src/bank-lib/bank_api_transfer.c b/src/bank-lib/bank_api_transfer.c index 3f482e8c4..da9ff4f55 100644 --- a/src/bank-lib/bank_api_transfer.c +++ b/src/bank-lib/bank_api_transfer.c | |||
@@ -319,13 +319,17 @@ TALER_BANK_transfer ( | |||
319 | GNUNET_break (0); | 319 | GNUNET_break (0); |
320 | return NULL; | 320 | return NULL; |
321 | } | 321 | } |
322 | transfer_obj = json_pack ("{s:o, s:o, s:s, s:o, s:s}", | 322 | transfer_obj = GNUNET_JSON_PACK ( |
323 | "request_uid", GNUNET_JSON_from_data_auto ( | 323 | GNUNET_JSON_pack_data_auto ("request_uid", |
324 | &wp->request_uid), | 324 | &wp->request_uid), |
325 | "amount", TALER_JSON_from_amount (&amount), | 325 | TALER_JSON_pack_amount ("amount", |
326 | "exchange_base_url", exchange_base_url, | 326 | &amount), |
327 | "wtid", GNUNET_JSON_from_data_auto (&wp->wtid), | 327 | GNUNET_JSON_pack_string ("exchange_base_url", |
328 | "credit_account", destination_account_uri); | 328 | exchange_base_url), |
329 | GNUNET_JSON_pack_data_auto ("wtid", | ||
330 | &wp->wtid), | ||
331 | GNUNET_JSON_pack_string ("credit_account", | ||
332 | destination_account_uri)); | ||
329 | if (NULL == transfer_obj) | 333 | if (NULL == transfer_obj) |
330 | { | 334 | { |
331 | GNUNET_break (0); | 335 | GNUNET_break (0); |
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index c6871938b..1fac5e1b6 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c | |||
@@ -1083,13 +1083,12 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h, | |||
1083 | json_decref (json); | 1083 | json_decref (json); |
1084 | 1084 | ||
1085 | /* Finally build response object */ | 1085 | /* Finally build response object */ |
1086 | return TALER_MHD_reply_json_pack (connection, | 1086 | return TALER_MHD_REPLY_JSON_PACK (connection, |
1087 | MHD_HTTP_OK, | 1087 | MHD_HTTP_OK, |
1088 | "{s:I, s:o}", | 1088 | GNUNET_JSON_pack_uint64 ("row_id", |
1089 | "row_id", | 1089 | row_id), |
1090 | (json_int_t) row_id, | 1090 | GNUNET_JSON_pack_time_abs ("timestamp", |
1091 | "timestamp", | 1091 | timestamp)); |
1092 | GNUNET_JSON_from_time_abs (timestamp)); | ||
1093 | } | 1092 | } |
1094 | 1093 | ||
1095 | 1094 | ||
@@ -1211,14 +1210,14 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h, | |||
1211 | json_decref (json); | 1210 | json_decref (json); |
1212 | 1211 | ||
1213 | /* Finally build response object */ | 1212 | /* Finally build response object */ |
1214 | return TALER_MHD_reply_json_pack (connection, | 1213 | return TALER_MHD_REPLY_JSON_PACK ( |
1215 | MHD_HTTP_OK, | 1214 | connection, |
1216 | "{s:I, s:o}", | 1215 | MHD_HTTP_OK, |
1217 | "row_id", | 1216 | GNUNET_JSON_pack_uint64 ("row_id", |
1218 | (json_int_t) row_id, | 1217 | row_id), |
1219 | /* dummy timestamp */ | 1218 | /* dummy timestamp */ |
1220 | "timestamp", GNUNET_JSON_from_time_abs ( | 1219 | GNUNET_JSON_pack_time_abs ("timestamp", |
1221 | GNUNET_TIME_UNIT_ZERO_ABS)); | 1220 | GNUNET_TIME_UNIT_ZERO_ABS)); |
1222 | } | 1221 | } |
1223 | 1222 | ||
1224 | 1223 | ||
@@ -1438,11 +1437,12 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, | |||
1438 | pthread_mutex_unlock (&h->big_lock)); | 1437 | pthread_mutex_unlock (&h->big_lock)); |
1439 | GNUNET_free (debit_payto); | 1438 | GNUNET_free (debit_payto); |
1440 | /* FIXME: suspend for long-polling instead */ | 1439 | /* FIXME: suspend for long-polling instead */ |
1441 | return TALER_MHD_reply_json_pack (connection, | 1440 | return TALER_MHD_REPLY_JSON_PACK ( |
1442 | MHD_HTTP_OK, | 1441 | connection, |
1443 | "{s:o}", | 1442 | MHD_HTTP_OK, |
1444 | "outgoing_transactions", | 1443 | GNUNET_JSON_pack_array_steal ( |
1445 | history); | 1444 | "outgoing_transactions", |
1445 | history)); | ||
1446 | } | 1446 | } |
1447 | if (t->debit_account != acc) | 1447 | if (t->debit_account != acc) |
1448 | { | 1448 | { |
@@ -1487,17 +1487,21 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, | |||
1487 | GNUNET_asprintf (&credit_payto, | 1487 | GNUNET_asprintf (&credit_payto, |
1488 | "payto://x-taler-bank/localhost/%s", | 1488 | "payto://x-taler-bank/localhost/%s", |
1489 | pos->credit_account->account_name); | 1489 | pos->credit_account->account_name); |
1490 | trans = json_pack ( | 1490 | trans = GNUNET_JSON_PACK ( |
1491 | "{s:I, s:o, s:o, s:s, s:s, s:s, s:o}", | 1491 | GNUNET_JSON_pack_uint64 ("row_id", |
1492 | "row_id", (json_int_t) pos->row_id, | 1492 | pos->row_id), |
1493 | "date", GNUNET_JSON_from_time_abs (pos->date), | 1493 | GNUNET_JSON_pack_time_abs ("date", |
1494 | "amount", TALER_JSON_from_amount (&pos->amount), | 1494 | pos->date), |
1495 | "credit_account", credit_payto, | 1495 | TALER_JSON_pack_amount ("amount", |
1496 | "debit_account", debit_payto, // FIXME: inefficient to return this here always! | 1496 | &pos->amount), |
1497 | "exchange_base_url", | 1497 | GNUNET_JSON_pack_string ("credit_account", |
1498 | pos->subject.debit.exchange_base_url, | 1498 | credit_payto), |
1499 | "wtid", GNUNET_JSON_from_data_auto ( | 1499 | GNUNET_JSON_pack_string ("debit_account", |
1500 | &pos->subject.debit.wtid)); | 1500 | debit_payto), // FIXME: inefficient to return this here always! |
1501 | GNUNET_JSON_pack_string ("exchange_base_url", | ||
1502 | pos->subject.debit.exchange_base_url), | ||
1503 | GNUNET_JSON_pack_data_auto ("wtid", | ||
1504 | &pos->subject.debit.wtid)); | ||
1501 | GNUNET_assert (NULL != trans); | 1505 | GNUNET_assert (NULL != trans); |
1502 | GNUNET_free (credit_payto); | 1506 | GNUNET_free (credit_payto); |
1503 | GNUNET_assert (0 == | 1507 | GNUNET_assert (0 == |
@@ -1515,11 +1519,11 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, | |||
1515 | GNUNET_assert (0 == | 1519 | GNUNET_assert (0 == |
1516 | pthread_mutex_unlock (&h->big_lock)); | 1520 | pthread_mutex_unlock (&h->big_lock)); |
1517 | GNUNET_free (debit_payto); | 1521 | GNUNET_free (debit_payto); |
1518 | return TALER_MHD_reply_json_pack (connection, | 1522 | return TALER_MHD_REPLY_JSON_PACK (connection, |
1519 | MHD_HTTP_OK, | 1523 | MHD_HTTP_OK, |
1520 | "{s:o}", | 1524 | GNUNET_JSON_pack_array_steal ( |
1521 | "outgoing_transactions", | 1525 | "outgoing_transactions", |
1522 | history); | 1526 | history)); |
1523 | } | 1527 | } |
1524 | 1528 | ||
1525 | 1529 | ||
@@ -1593,11 +1597,11 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h, | |||
1593 | pthread_mutex_unlock (&h->big_lock)); | 1597 | pthread_mutex_unlock (&h->big_lock)); |
1594 | GNUNET_free (credit_payto); | 1598 | GNUNET_free (credit_payto); |
1595 | /* FIXME: suspend for long-polling instead */ | 1599 | /* FIXME: suspend for long-polling instead */ |
1596 | return TALER_MHD_reply_json_pack (connection, | 1600 | return TALER_MHD_REPLY_JSON_PACK (connection, |
1597 | MHD_HTTP_OK, | 1601 | MHD_HTTP_OK, |
1598 | "{s:o}", | 1602 | GNUNET_JSON_pack_array_steal ( |
1599 | "incoming_transactions", | 1603 | "incoming_transactions", |
1600 | history); | 1604 | history)); |
1601 | } | 1605 | } |
1602 | if (skip) | 1606 | if (skip) |
1603 | { | 1607 | { |
@@ -1631,15 +1635,19 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h, | |||
1631 | GNUNET_asprintf (&debit_payto, | 1635 | GNUNET_asprintf (&debit_payto, |
1632 | "payto://x-taler-bank/localhost/%s", | 1636 | "payto://x-taler-bank/localhost/%s", |
1633 | pos->debit_account->account_name); | 1637 | pos->debit_account->account_name); |
1634 | trans = json_pack ( | 1638 | trans = GNUNET_JSON_PACK ( |
1635 | "{s:I, s:o, s:o, s:s, s:s, s:o}", | 1639 | GNUNET_JSON_pack_uint64 ("row_id", |
1636 | "row_id", (json_int_t) pos->row_id, | 1640 | pos->row_id), |
1637 | "date", GNUNET_JSON_from_time_abs (pos->date), | 1641 | GNUNET_JSON_pack_time_abs ("date", |
1638 | "amount", TALER_JSON_from_amount (&pos->amount), | 1642 | pos->date), |
1639 | "credit_account", credit_payto, // FIXME: inefficient to repeat this always here! | 1643 | TALER_JSON_pack_amount ("amount", |
1640 | "debit_account", debit_payto, | 1644 | &pos->amount), |
1641 | "reserve_pub", GNUNET_JSON_from_data_auto ( | 1645 | GNUNET_JSON_pack_string ("credit_account", |
1642 | &pos->subject.credit.reserve_pub)); | 1646 | credit_payto), // FIXME: inefficient to repeat this always here! |
1647 | GNUNET_JSON_pack_string ("debit_account", | ||
1648 | debit_payto), | ||
1649 | GNUNET_JSON_pack_data_auto ("reserve_pub", | ||
1650 | &pos->subject.credit.reserve_pub)); | ||
1643 | GNUNET_assert (NULL != trans); | 1651 | GNUNET_assert (NULL != trans); |
1644 | GNUNET_free (debit_payto); | 1652 | GNUNET_free (debit_payto); |
1645 | GNUNET_assert (0 == | 1653 | GNUNET_assert (0 == |
@@ -1657,11 +1665,11 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h, | |||
1657 | GNUNET_assert (0 == | 1665 | GNUNET_assert (0 == |
1658 | pthread_mutex_unlock (&h->big_lock)); | 1666 | pthread_mutex_unlock (&h->big_lock)); |
1659 | GNUNET_free (credit_payto); | 1667 | GNUNET_free (credit_payto); |
1660 | return TALER_MHD_reply_json_pack (connection, | 1668 | return TALER_MHD_REPLY_JSON_PACK (connection, |
1661 | MHD_HTTP_OK, | 1669 | MHD_HTTP_OK, |
1662 | "{s:o}", | 1670 | GNUNET_JSON_pack_array_steal ( |
1663 | "incoming_transactions", | 1671 | "incoming_transactions", |
1664 | history); | 1672 | history)); |
1665 | } | 1673 | } |
1666 | 1674 | ||
1667 | 1675 | ||
diff --git a/src/exchange-tools/taler-auditor-offline.c b/src/exchange-tools/taler-auditor-offline.c index cc7278e54..0fbd82baa 100644 --- a/src/exchange-tools/taler-auditor-offline.c +++ b/src/exchange-tools/taler-auditor-offline.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of TALER | 2 | This file is part of TALER |
3 | Copyright (C) 2020 Taler Systems SA | 3 | Copyright (C) 2020-2021 Taler Systems SA |
4 | 4 | ||
5 | TALER is free software; you can redistribute it and/or modify it under the | 5 | TALER is free software; you can redistribute it and/or modify it under the |
6 | terms of the GNU General Public License as published by the Free Software | 6 | terms of the GNU General Public License as published by the Free Software |
@@ -295,11 +295,11 @@ output_operation (const char *op_name, | |||
295 | json_t *action; | 295 | json_t *action; |
296 | 296 | ||
297 | GNUNET_assert (NULL != out); | 297 | GNUNET_assert (NULL != out); |
298 | action = json_pack ("{ s:s, s:o }", | 298 | action = GNUNET_JSON_PACK ( |
299 | "operation", | 299 | GNUNET_JSON_pack_string ("operation", |
300 | op_name, | 300 | op_name), |
301 | "arguments", | 301 | GNUNET_JSON_pack_object_steal ("arguments", |
302 | op_value); | 302 | op_value)); |
303 | GNUNET_break (0 == | 303 | GNUNET_break (0 == |
304 | json_array_append_new (out, | 304 | json_array_append_new (out, |
305 | action)); | 305 | action)); |
@@ -660,6 +660,15 @@ keys_cb ( | |||
660 | switch (hr->http_status) | 660 | switch (hr->http_status) |
661 | { | 661 | { |
662 | case MHD_HTTP_OK: | 662 | case MHD_HTTP_OK: |
663 | if (! json_is_object (hr->reply)) | ||
664 | { | ||
665 | GNUNET_break (0); | ||
666 | TALER_EXCHANGE_disconnect (exchange); | ||
667 | exchange = NULL; | ||
668 | test_shutdown (); | ||
669 | global_ret = EXIT_FAILURE; | ||
670 | return; | ||
671 | } | ||
663 | break; | 672 | break; |
664 | default: | 673 | default: |
665 | fprintf (stderr, | 674 | fprintf (stderr, |
@@ -673,11 +682,11 @@ keys_cb ( | |||
673 | global_ret = EXIT_FAILURE; | 682 | global_ret = EXIT_FAILURE; |
674 | return; | 683 | return; |
675 | } | 684 | } |
676 | in = json_pack ("{s:s,s:O}", | 685 | in = GNUNET_JSON_PACK ( |
677 | "operation", | 686 | GNUNET_JSON_pack_string ("operation", |
678 | OP_INPUT_KEYS, | 687 | OP_INPUT_KEYS), |
679 | "arguments", | 688 | GNUNET_JSON_pack_object_incref ("arguments", |
680 | hr->reply); | 689 | (json_t *) hr->reply)); |
681 | if (NULL == args[0]) | 690 | if (NULL == args[0]) |
682 | { | 691 | { |
683 | json_dumpf (in, | 692 | json_dumpf (in, |
@@ -1141,11 +1150,11 @@ sign_denomkeys (const json_t *denomkeys) | |||
1141 | &auditor_priv, | 1150 | &auditor_priv, |
1142 | &auditor_sig); | 1151 | &auditor_sig); |
1143 | output_operation (OP_SIGN_DENOMINATION, | 1152 | output_operation (OP_SIGN_DENOMINATION, |
1144 | json_pack ("{s:o, s:o}", | 1153 | GNUNET_JSON_PACK ( |
1145 | "h_denom_pub", | 1154 | GNUNET_JSON_pack_data_auto ("h_denom_pub", |
1146 | GNUNET_JSON_from_data_auto (&h_denom_pub), | 1155 | &h_denom_pub), |
1147 | "auditor_sig", | 1156 | GNUNET_JSON_pack_data_auto ("auditor_sig", |
1148 | GNUNET_JSON_from_data_auto (&auditor_sig))); | 1157 | &auditor_sig))); |
1149 | } | 1158 | } |
1150 | GNUNET_JSON_parse_free (spec); | 1159 | GNUNET_JSON_parse_free (spec); |
1151 | } | 1160 | } |
@@ -1214,7 +1223,10 @@ do_sign (char *const *args) | |||
1214 | return; | 1223 | return; |
1215 | } | 1224 | } |
1216 | if (NULL == out) | 1225 | if (NULL == out) |
1226 | { | ||
1217 | out = json_array (); | 1227 | out = json_array (); |
1228 | GNUNET_assert (NULL != out); | ||
1229 | } | ||
1218 | if (GNUNET_OK != | 1230 | if (GNUNET_OK != |
1219 | sign_denomkeys (denomkeys)) | 1231 | sign_denomkeys (denomkeys)) |
1220 | { | 1232 | { |
@@ -1247,11 +1259,14 @@ do_setup (char *const *args) | |||
1247 | if (NULL != *args) | 1259 | if (NULL != *args) |
1248 | { | 1260 | { |
1249 | if (NULL == out) | 1261 | if (NULL == out) |
1262 | { | ||
1250 | out = json_array (); | 1263 | out = json_array (); |
1264 | GNUNET_assert (NULL != out); | ||
1265 | } | ||
1251 | output_operation (OP_SETUP, | 1266 | output_operation (OP_SETUP, |
1252 | json_pack ("{s:o}", | 1267 | GNUNET_JSON_PACK ( |
1253 | "auditor_pub", | 1268 | GNUNET_JSON_pack_data_auto ("auditor_pub", |
1254 | GNUNET_JSON_from_data_auto (&auditor_pub))); | 1269 | &auditor_pub))); |
1255 | } | 1270 | } |
1256 | 1271 | ||
1257 | else | 1272 | else |